From 86ab7331af97c817061f1f9935d4fcb63d07ed70 Mon Sep 17 00:00:00 2001 From: Zhihe Li Date: Tue, 6 Sep 2022 13:45:22 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fix=20tag=20bug=20from=20?= =?UTF-8?q?moving=20where=20workers=20list=20is=20loaded=20(#1284)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- .../form/worker/create-worker-led/index.hbs | 10 +++-- ui/admin/app/routes/scopes/scope/workers.js | 12 ++++++ .../app/routes/scopes/scope/workers/index.js | 37 +++++++++---------- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/ui/admin/app/components/form/worker/create-worker-led/index.hbs b/ui/admin/app/components/form/worker/create-worker-led/index.hbs index 585cda81d..5b5eb9789 100644 --- a/ui/admin/app/components/form/worker/create-worker-led/index.hbs +++ b/ui/admin/app/components/form/worker/create-worker-led/index.hbs @@ -104,7 +104,7 @@ {{/if}} - {{#if @model.cannotSave}} + {{#unless @model.isNew}}
@@ -118,10 +118,14 @@

{{t 'resources.worker.form.steps.3.registered'}}

- {{/if}} + {{/unless}} - + {{t 'actions.done'}} diff --git a/ui/admin/app/routes/scopes/scope/workers.js b/ui/admin/app/routes/scopes/scope/workers.js index 159609af7..d47bcebdf 100644 --- a/ui/admin/app/routes/scopes/scope/workers.js +++ b/ui/admin/app/routes/scopes/scope/workers.js @@ -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. */ diff --git a/ui/admin/app/routes/scopes/scope/workers/index.js b/ui/admin/app/routes/scopes/scope/workers/index.js index 56a333f92..61b3b33e4 100644 --- a/ui/admin/app/routes/scopes/scope/workers/index.js +++ b/ui/admin/app/routes/scopes/scope/workers/index.js @@ -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) {