From 16f94f739e995944345acf0911a0f4af429f596f Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Thu, 27 Aug 2020 09:52:44 -0400 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20cleanup=20model=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/targets/target/host-sets.js | 48 +++++++++---------- ui/core/tests/acceptance/targets-test.js | 4 ++ 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/ui/core/app/routes/scopes/scope/projects/project/targets/target/host-sets.js b/ui/core/app/routes/scopes/scope/projects/project/targets/target/host-sets.js index 0ccd3290b..34418acea 100644 --- a/ui/core/app/routes/scopes/scope/projects/project/targets/target/host-sets.js +++ b/ui/core/app/routes/scopes/scope/projects/project/targets/target/host-sets.js @@ -1,5 +1,5 @@ import Route from '@ember/routing/route'; -import { all } from 'rsvp'; +import { all, hash } from 'rsvp'; export default class ScopesScopeProjectsProjectTargetsTargetHostSetsRoute extends Route { // =methods @@ -10,34 +10,32 @@ export default class ScopesScopeProjectsProjectTargetsTargetHostSetsRoute extend * @return {Promise{[HostSetModel, HostCatalogModel]}} */ beforeModel() { - const hostSets = [], hostCatalogs = []; - const target = this.modelFor('scopes.scope.projects.project.targets.target'); - const scopeID = this.modelFor('scopes.scope.projects.project').id; - - target.host_sets.map((hostSet) => { - hostSets.push( - this.store.findRecord( - 'host-set', - hostSet.host_set_id, - { adapterOptions : { scopeID, hostCatalogID: hostSet.host_catalog_id } } - ) + const { scopeID, host_sets } = + this.modelFor('scopes.scope.projects.project.targets.target'); + const promises = host_sets + .map(({ host_set_id, host_catalog_id: hostCatalogID }) => + hash({ + // TODO: multiple host sets may belong to the same catalog, + // resulting in the catalog being loaded multiple times. + // An improvement would be to find the unique set of catalogs first. + hostCatalog: this.store.findRecord( + 'host-catalog', + hostCatalogID, + { adapterOptions: { scopeID } } + ), + hostSet: this.store.findRecord( + 'host-set', + host_set_id, + { adapterOptions: { scopeID, hostCatalogID } } + ) + }) ); - - hostCatalogs.push( - this.store.findRecord( - 'host-catalog', - hostSet.host_catalog_id, - { adapterOptions : { scopeID } } - ) - ); - }); - - return all(hostSets.concat(hostCatalogs)); + return all(promises); } /** - * Load current target and it's associated host-sets and host-catalogs - * @return {Promise{[TargetModel]}} + * Returns the previously loaded target instance. + * @return {TargetModel} */ model() { return this.modelFor('scopes.scope.projects.project.targets.target'); diff --git a/ui/core/tests/acceptance/targets-test.js b/ui/core/tests/acceptance/targets-test.js index 8ff26fa7f..01f73d443 100644 --- a/ui/core/tests/acceptance/targets-test.js +++ b/ui/core/tests/acceptance/targets-test.js @@ -58,4 +58,8 @@ module('Acceptance | targets', function (hooks) { test('saving an existing target with invalid fields displays error messages', async function (assert) { assert.expect(0); }); + + test('viewing target host sets', async function (assert) { + assert.expect(0); + }); });