-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11545 from hashicorp/f-ui/add-alloc-filters-on-table
Add Allocation Filters in Client View
- Loading branch information
Showing
13 changed files
with
628 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
ui: Add filters to the allocation list in the client and task group details pages | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
/* eslint-disable ember/no-incorrect-calls-with-inline-anonymous-functions */ | ||
import { inject as service } from '@ember/service'; | ||
import { alias, readOnly } from '@ember/object/computed'; | ||
import Controller from '@ember/controller'; | ||
import { action, computed, get } from '@ember/object'; | ||
import { scheduleOnce } from '@ember/runloop'; | ||
import intersection from 'lodash.intersection'; | ||
import Sortable from 'nomad-ui/mixins/sortable'; | ||
import Searchable from 'nomad-ui/mixins/searchable'; | ||
import WithNamespaceResetting from 'nomad-ui/mixins/with-namespace-resetting'; | ||
import { serialize, deserializedQueryParam as selection } from 'nomad-ui/utils/qp-serialize'; | ||
import classic from 'ember-classic-decorator'; | ||
|
||
@classic | ||
|
@@ -29,11 +33,19 @@ export default class TaskGroupController extends Controller.extend( | |
{ | ||
sortDescending: 'desc', | ||
}, | ||
{ | ||
qpStatus: 'status', | ||
}, | ||
{ | ||
qpClient: 'client', | ||
}, | ||
]; | ||
|
||
currentPage = 1; | ||
@readOnly('userSettings.pageSize') pageSize; | ||
|
||
qpStatus = ''; | ||
qpClient = ''; | ||
sortProperty = 'modifyIndex'; | ||
sortDescending = true; | ||
|
||
|
@@ -47,10 +59,29 @@ export default class TaskGroupController extends Controller.extend( | |
return this.get('model.allocations') || []; | ||
} | ||
|
||
@alias('allocations') listToSort; | ||
@computed('allocations.[]', 'selectionStatus', 'selectionClient') | ||
get filteredAllocations() { | ||
const { selectionStatus, selectionClient } = this; | ||
|
||
return this.allocations.filter(alloc => { | ||
if (selectionStatus.length && !selectionStatus.includes(alloc.clientStatus)) { | ||
return false; | ||
} | ||
if (selectionClient.length && !selectionClient.includes(alloc.get('node.shortId'))) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}); | ||
} | ||
|
||
@alias('filteredAllocations') listToSort; | ||
@alias('listSorted') listToSearch; | ||
@alias('listSearched') sortedAllocations; | ||
|
||
@selection('qpStatus') selectionStatus; | ||
@selection('qpClient') selectionClient; | ||
|
||
@computed('[email protected]', function() { | ||
const events = get(this, 'model.scaleState.events'); | ||
if (events) { | ||
|
@@ -83,4 +114,31 @@ export default class TaskGroupController extends Controller.extend( | |
scaleTaskGroup(count) { | ||
return this.model.scale(count); | ||
} | ||
|
||
get optionsAllocationStatus() { | ||
return [ | ||
{ key: 'pending', label: 'Pending' }, | ||
{ key: 'running', label: 'Running' }, | ||
{ key: 'complete', label: 'Complete' }, | ||
{ key: 'failed', label: 'Failed' }, | ||
{ key: 'lost', label: 'Lost' }, | ||
]; | ||
} | ||
|
||
@computed('model.allocations.[]', 'selectionClient') | ||
get optionsClients() { | ||
const clients = Array.from(new Set(this.model.allocations.mapBy('node.shortId'))).compact(); | ||
|
||
// Update query param when the list of clients changes. | ||
scheduleOnce('actions', () => { | ||
// eslint-disable-next-line ember/no-side-effects | ||
this.set('qpClient', serialize(intersection(clients, this.selectionClient))); | ||
}); | ||
|
||
return clients.sort().map(dc => ({ key: dc, label: dc })); | ||
} | ||
|
||
setFacetQueryParam(queryParam, selection) { | ||
this.set(queryParam, serialize(selection)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.