Skip to content

Commit

Permalink
feat: add taskgroup filter to alloc table
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaiWithJai committed Nov 20, 2021
1 parent 727ca28 commit 02aae77
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
34 changes: 32 additions & 2 deletions ui/app/controllers/clients/client/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/* eslint-disable ember/no-observers */
/* eslint-disable ember/no-incorrect-calls-with-inline-anonymous-functions */
import { alias } from '@ember/object/computed';
import Controller from '@ember/controller';
import { action, computed } from '@ember/object';
import { observes } from '@ember-decorators/object';
import { scheduleOnce } from '@ember/runloop';
import { task } from 'ember-concurrency';
import intersection from 'lodash.intersection';
import Sortable from 'nomad-ui/mixins/sortable';
import Searchable from 'nomad-ui/mixins/searchable';
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
Expand Down Expand Up @@ -31,12 +34,16 @@ export default class ClientController extends Controller.extend(Sortable, Search
{
qpStatus: 'status',
},
{
qpTaskGroup: 'taskGroup',
},
];

// Set in the route
flagAsDraining = false;

qpStatus = '';
qpTaskGroup = '';
currentPage = 1;
pageSize = 8;

Expand All @@ -50,15 +57,24 @@ export default class ClientController extends Controller.extend(Sortable, Search

onlyPreemptions = false;

@computed('model.allocations.[]', 'preemptions.[]', 'onlyPreemptions', 'selectionStatus')
@computed(
'model.allocations.[]',
'preemptions.[]',
'onlyPreemptions',
'selectionStatus',
'selectionTaskGroup'
)
get visibleAllocations() {
const allocations = this.onlyPreemptions ? this.preemptions : this.model.allocations;
const { selectionStatus } = this;
const { selectionStatus, selectionTaskGroup } = this;

return allocations.filter(alloc => {
if (selectionStatus.length && !selectionStatus.includes(alloc.clientStatus)) {
return false;
}
if (selectionTaskGroup.length && !selectionTaskGroup.includes(alloc.taskGroupName)) {
return false;
}
return true;
});
}
Expand All @@ -68,6 +84,7 @@ export default class ClientController extends Controller.extend(Sortable, Search
@alias('listSearched') sortedAllocations;

@selection('qpStatus') selectionStatus;
@selection('qpTaskGroup') selectionTaskGroup;

eligibilityError = null;
stopDrainError = null;
Expand Down Expand Up @@ -174,6 +191,19 @@ export default class ClientController extends Controller.extend(Sortable, Search
];
}

@computed('model.allocations.[]', 'selectionTaskGroup')
get optionsTaskGroups() {
const taskGroups = Array.from(new Set(this.model.allocations.mapBy('taskGroupName'))).compact();

// Update query param when the list of clients changes.
scheduleOnce('actions', () => {
// eslint-disable-next-line ember/no-side-effects
this.set('qpTaskGroup', serialize(intersection(taskGroups, this.selectionTaskGroup)));
});

return taskGroups.sort().map(dc => ({ key: dc, label: dc }));
}

@action
setFacetQueryParam(queryParam, selection) {
this.set(queryParam, serialize(selection));
Expand Down
7 changes: 7 additions & 0 deletions ui/app/templates/clients/client/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@
@selection={{this.selectionStatus}}
@onSelect={{action "setFacetQueryParam" "qpStatus"}}
/>
<MultiSelectDropdown
data-test-allocation-task-group-facet
@label="Task Group"
@options={{this.optionsTaskGroups}}
@selection={{this.selectionTaskGroup}}
@onSelect={{action "setFacetQueryParam" "qpTaskGroup"}}
/>
</div>
<div class="boxed-section-body is-full-bleed">
<ListPagination
Expand Down

0 comments on commit 02aae77

Please sign in to comment.