refactor: Remove EmberArray use in /target/hosts to simplify
This commit is contained in:
1 file changed
+14
-14
@@ -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)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user