Unverified Commit 189b5221 authored by Buck Doyle's avatar Buck Doyle Committed by GitHub
Browse files

UI: Change determination of exec sidebar active tasks (#7491)

This closes #7476. The decomposition of computed properties
is necessary to avoid nested aggregate dependent keys; the
previous dependent key of `taskGroup` will be inadequate
when the sidebar becomes live-updating.
Showing with 26 additions and 18 deletions
+26 -18
import Component from '@ember/component';
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
import { or } from '@ember/object/computed';
import { filterBy, mapBy, or } from '@ember/object/computed';
import generateExecUrl from 'nomad-ui/utils/generate-exec-url';
import openExecUrl from 'nomad-ui/utils/open-exec-url';
......@@ -26,25 +26,33 @@ export default Component.extend({
}
}),
tasksWithRunningStates: computed('taskGroup', function() {
const activeStateTaskNames = this.taskGroup.allocations.reduce(
(activeStateTaskNames, allocation) => {
activeStateTaskNames = activeStateTaskNames.concat(
allocation.states
.filter(
taskState =>
taskState.isActive && taskState.task.taskGroup.name === this.taskGroup.name
)
.mapBy('name')
);
allocationTaskStatesRecordArrays: mapBy('taskGroup.allocations', 'states'),
allocationTaskStates: computed('allocationTaskStatesRecordArrays.[]', function() {
const flattenRecordArrays = (accumulator, recordArray) =>
accumulator.concat(recordArray.toArray());
return this.allocationTaskStatesRecordArrays.reduce(flattenRecordArrays, []);
}),
return activeStateTaskNames;
},
[]
);
activeTaskStates: filterBy('allocationTaskStates', 'isActive'),
return this.taskGroup.tasks.filter(task => activeStateTaskNames.includes(task.name));
}),
activeTasks: mapBy('activeTaskStates', 'task'),
activeTaskGroups: mapBy('activeTasks', 'taskGroup'),
tasksWithRunningStates: computed(
'taskGroup.name',
'activeTaskStates.@each.name',
'activeTasks.@each.name',
'activeTaskGroups.@each.name',
function() {
const activeTaskStateNames = this.activeTaskStates
.filter(taskState => {
return taskState.task && taskState.task.taskGroup.name === this.taskGroup.name;
})
.mapBy('name');
return this.taskGroup.tasks.filter(task => activeTaskStateNames.includes(task.name));
}
),
clickedOpen: false,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment