Skip to content

Commit

Permalink
feat: add filter client allocations table
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaiWithJai committed Nov 20, 2021
1 parent 873b096 commit 727ca28
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
35 changes: 33 additions & 2 deletions ui/app/controllers/clients/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { task } from 'ember-concurrency';
import Sortable from 'nomad-ui/mixins/sortable';
import Searchable from 'nomad-ui/mixins/searchable';
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
import { serialize, deserializedQueryParam as selection } from 'nomad-ui/utils/qp-serialize';
import classic from 'ember-classic-decorator';

@classic
Expand All @@ -27,11 +28,15 @@ export default class ClientController extends Controller.extend(Sortable, Search
{
onlyPreemptions: 'preemptions',
},
{
qpStatus: 'status',
},
];

// Set in the route
flagAsDraining = false;

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

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

onlyPreemptions = false;

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

return allocations.filter(alloc => {
if (selectionStatus.length && !selectionStatus.includes(alloc.clientStatus)) {
return false;
}
return true;
});
}

@alias('visibleAllocations') listToSort;
@alias('listSorted') listToSearch;
@alias('listSearched') sortedAllocations;

@selection('qpStatus') selectionStatus;

eligibilityError = null;
stopDrainError = null;
drainError = null;
Expand Down Expand Up @@ -147,4 +162,20 @@ export default class ClientController extends Controller.extend(Sortable, Search
const error = messageFromAdapterError(err) || 'Could not run drain';
this.set('drainError', error);
}

get optionsAllocationStatus() {
return [
{ key: 'queued', label: 'Queued' },
{ key: 'starting', label: 'Starting' },
{ key: 'running', label: 'Running' },
{ key: 'complete', label: 'Complete' },
{ key: 'failed', label: 'Failed' },
{ key: 'lost', label: 'Lost' },
];
}

@action
setFacetQueryParam(queryParam, selection) {
this.set(queryParam, serialize(selection));
}
}
10 changes: 9 additions & 1 deletion ui/app/templates/clients/client/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,15 @@
@onChange={{action this.resetPagination}}
@placeholder="Search allocations..."
@class="is-inline pull-right"
@inputClass="is-compact" />
@inputClass="is-compact"
/>
<MultiSelectDropdown
data-test-allocation-status-facet
@label="Status"
@options={{this.optionsAllocationStatus}}
@selection={{this.selectionStatus}}
@onSelect={{action "setFacetQueryParam" "qpStatus"}}
/>
</div>
<div class="boxed-section-body is-full-bleed">
<ListPagination
Expand Down

0 comments on commit 727ca28

Please sign in to comment.