From 6fd3a896eaf8468b7b8017b2d0780f84339d42c1 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Thu, 4 Feb 2021 10:54:18 -0500 Subject: [PATCH 1/2] refactor: Move /target/hosts redirection into /target/index --- .../app/routes/scopes/scope/projects/targets/target.js | 8 -------- .../routes/scopes/scope/projects/targets/target/index.js | 9 +++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target.js index 29efcc413..5031c8a4a 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/target.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target.js @@ -13,14 +13,6 @@ export default class ScopesScopeProjectsTargetsTargetRoute extends Route { return this.store.findRecord('target', target_id, { reload: true }); } - /** - * Navigate to hostsets within a target. - * @param {TargetModel} model - */ - afterModel(model) { - this.transitionTo('scopes.scope.projects.targets.target.hosts', model); - } - /** * Renders the target-specific templates for header and navigation * page sections. diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target/index.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target/index.js index 2199146f8..dca9bcd77 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/target/index.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target/index.js @@ -1,4 +1,13 @@ import Route from '@ember/routing/route'; export default class ScopesScopeProjectsTargetsTargetIndexRoute extends Route { + // =methods + + /** + * Navigate to hosts within a target. + */ + afterModel() { + this.transitionTo('scopes.scope.projects.targets.target.hosts'); + } + } From adedc6e3eea8c6a6c83627edd27612564e4a2ef2 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Thu, 4 Feb 2021 12:03:57 -0500 Subject: [PATCH 2/2] refactor: Remove EmberArray use in /target/hosts to simplify --- .../scope/projects/targets/target/hosts.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js index 8b23f7025..fda131f12 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js @@ -1,6 +1,5 @@ import Route from '@ember/routing/route'; import { all } from 'rsvp'; -import { A } from '@ember/array'; export default class ScopesScopeProjectsTargetsTargetHostsRoute extends Route { // =methods @@ -11,25 +10,26 @@ export default class ScopesScopeProjectsTargetsTargetHostsRoute extends Route { */ async model() { const { host_sets } = this.modelFor('scopes.scope.projects.targets.target'); - const hostSetsPromises = await all( + // Load all host-sets + const hostSets = await all( host_sets.map(({ host_set_id }) => this.store.findRecord('host-set', host_set_id) ) ); - // Extract host ids from all host set - const hostIds = A(); - hostSetsPromises.map(({ host_ids }) => - host_ids.forEach(({ value }) => hostIds.push(value) ) - ); - - // Fetch all hosts - const hostPromises = await all( - hostIds.uniq().map((hostId) => - this.store.findRecord('host', hostId) - ) + // Extract host ids from all host sets + const hostIds = hostSets.map(({host_ids}) => + host_ids.content.map((hostId) => + hostId.value + ) ) - return all(hostPromises); + // Load unique hosts + const uniqueHostIds = new Set(hostIds.flat()); + return all( + [...uniqueHostIds].map((hostId) => + this.store.findRecord('host', hostId) + ) + ); } }