fix: 🐛 Fix tag bug from moving where workers list is loaded (#1284)
* fix: 🐛 Fix tag bug from moving where workers list is loaded * style: 💄 Remove unused import * refactor: 💡 Use new setting to turn off auto refresh for filter
This commit is contained in:
1 parent
c351452d71
commit
86ab7331af
3 files changed
+37
-22
No files matched your search
@@ -104,7 +104,7 @@
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
{{#if @model.cannotSave}}
|
||||
{{#unless @model.isNew}}
|
||||
<div class='worker-success'>
|
||||
<div>
|
||||
<Rose::Icon @name='flight-icons/svg/cpu-16' @size='medium' />
|
||||
@@ -118,10 +118,14 @@
|
||||
<p>{{t 'resources.worker.form.steps.3.registered'}}</p>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
{{/unless}}
|
||||
</div>
|
||||
|
||||
<Rose::LinkButton @route='scopes.scope.workers' @style='secondary'>
|
||||
<Rose::LinkButton
|
||||
@route='scopes.scope.workers'
|
||||
@style='secondary'
|
||||
{{on 'click' (route-action 'refresh')}}
|
||||
>
|
||||
{{t 'actions.done'}}
|
||||
</Rose::LinkButton>
|
||||
</Rose::Form>
|
||||
@@ -21,6 +21,18 @@ export default class ScopesScopeWorkersRoute extends Route {
|
||||
if (!this.session.isAuthenticated) this.router.transitionTo('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all workers.
|
||||
* @return {WorkerModel}
|
||||
*/
|
||||
model() {
|
||||
const scope = this.modelFor('scopes.scope');
|
||||
const { id: scope_id } = scope;
|
||||
if (this.can.can('list worker', scope, { collection: 'workers' })) {
|
||||
return this.store.query('worker', { scope_id });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes worker data.
|
||||
*/
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { action } from '@ember/object';
|
||||
import { resourceFilter } from 'core/decorators/resource-filter';
|
||||
import { inject as service } from '@ember/service';
|
||||
|
||||
export default class ScopesScopeWorkersIndexRoute extends Route {
|
||||
// =attributes
|
||||
@service can;
|
||||
|
||||
// This resource filter depends on the data from the list route so can't
|
||||
// live in the same model where the list is loaded as it needs to get loaded
|
||||
// first. If it's in the same file it might try to grab the model data before
|
||||
// it's loaded.
|
||||
@resourceFilter({
|
||||
allowed: (route) => {
|
||||
const configTags = route
|
||||
.modelFor('scopes.scope.workers.index')
|
||||
.modelFor('scopes.scope.workers')
|
||||
.toArray()
|
||||
.flatMap((worker) => worker.config_tags?.type)
|
||||
.filter(Boolean);
|
||||
@@ -18,30 +20,25 @@ export default class ScopesScopeWorkersIndexRoute extends Route {
|
||||
// Filter out duplicate tags
|
||||
return [...new Set(configTags)];
|
||||
},
|
||||
refreshRouteOnChange: false,
|
||||
})
|
||||
tags;
|
||||
|
||||
// =methods
|
||||
|
||||
model() {
|
||||
const scope = this.modelFor('scopes.scope');
|
||||
const { id: scope_id } = scope;
|
||||
if (this.can.can('list worker', scope, { collection: 'workers' })) {
|
||||
const workers = this.store.query('worker', { scope_id });
|
||||
const workers = this.modelFor('scopes.scope.workers');
|
||||
|
||||
if (this.tags?.length) {
|
||||
// Return workers that have config tags that have at
|
||||
// least one intersection with the filter tags
|
||||
return workers.filter(
|
||||
(worker) =>
|
||||
worker.config_tags?.type.filter(
|
||||
Set.prototype.has,
|
||||
new Set(this.tags)
|
||||
).length > 0
|
||||
);
|
||||
}
|
||||
return workers;
|
||||
if (this.tags?.length) {
|
||||
// Return workers that have config tags that have at
|
||||
// least one intersection with the filter tags
|
||||
return workers.filter(
|
||||
(worker) =>
|
||||
worker.config_tags.type.filter(Set.prototype.has, new Set(this.tags))
|
||||
.length > 0
|
||||
);
|
||||
}
|
||||
return workers;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,6 +47,7 @@ export default class ScopesScopeWorkersIndexRoute extends Route {
|
||||
@action
|
||||
clearAllFilters() {
|
||||
this.tags = [];
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,6 +58,7 @@ export default class ScopesScopeWorkersIndexRoute extends Route {
|
||||
@action
|
||||
filterBy(field, value) {
|
||||
this[field] = value;
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
setupController(controller) {
|
||||
|
||||
Reference in new issue
Block a user