Merge remote-tracking branch 'origin/navigate-into-a-target' into active-sessions-in-a-target

This commit is contained in:
Susmitha Girumala committed 2021-02-04 14:48:01 -05:00
commit bd1cbb8748
3 files changed
+23 -21

No files matched your search

@@ -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.
@@ -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)
)
);
}
}
@@ -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');
}
}