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 3c2be903f..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,13 +13,6 @@ export default class ScopesScopeProjectsTargetsTargetRoute extends Route { return this.store.findRecord('target', target_id, { reload: true }); } - /** - * Navigate to sessions within a target. - */ - afterModel() { - this.transitionTo('scopes.scope.projects.targets.target.sessions'); - } - /** * Renders the target-specific templates for header and navigation * page sections. 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) + ) + ); } } 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'); + } + }