-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add filters to Allocations #11544
Merged
Merged
Add filters to Allocations #11544
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
dc3c0b1
feat: add status filter to allocations
ChaiWithJai 14206f4
feat: add client status filter
ChaiWithJai c351e68
feat: add taskgroup filter to alloc
ChaiWithJai c3f1439
disable eslint for indentation
ChaiWithJai d1ff1cb
fix: filter callbacks use different param
ChaiWithJai b394859
fix: add job version filter
ChaiWithJai febcd5e
chore: changelog entry
ChaiWithJai a8854bc
fix: remove eslint disable indent
ChaiWithJai 3f36393
changelog: fix entry for #11544
lgfa29 f8709ff
ui: fix file formating
lgfa29 ad80c84
ui: fix job allocation filter by status, remove version filter, and a…
lgfa29 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:feature | ||
ui: Add filters to allocations table in jobs/job/allocation view | ||
``` |
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,9 +1,13 @@ | ||
/* 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 { 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 | ||
|
@@ -25,8 +29,20 @@ export default class AllocationsController extends Controller.extend( | |
{ | ||
sortDescending: 'desc', | ||
}, | ||
{ | ||
qpStatus: 'status', | ||
}, | ||
{ | ||
qpClient: 'client', | ||
}, | ||
{ | ||
qpTaskGroup: 'taskGroup', | ||
}, | ||
]; | ||
|
||
qpStatus = ''; | ||
qpClient = ''; | ||
qpTaskGroup = ''; | ||
currentPage = 1; | ||
pageSize = 25; | ||
|
||
|
@@ -45,12 +61,74 @@ export default class AllocationsController extends Controller.extend( | |
return this.get('model.allocations') || []; | ||
} | ||
|
||
@alias('allocations') listToSort; | ||
@computed('allocations.[]', 'selectionStatus', 'selectionClient', 'selectionTaskGroup') | ||
get filteredAllocations() { | ||
const { selectionStatus, selectionClient, selectionTaskGroup } = 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; | ||
} | ||
if (selectionTaskGroup.length && !selectionTaskGroup.includes(alloc.taskGroupName)) { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
} | ||
|
||
@alias('filteredAllocations') listToSort; | ||
@alias('listSorted') listToSearch; | ||
@alias('listSearched') sortedAllocations; | ||
|
||
@selection('qpStatus') selectionStatus; | ||
@selection('qpClient') selectionClient; | ||
@selection('qpTaskGroup') selectionTaskGroup; | ||
|
||
@action | ||
gotoAllocation(allocation) { | ||
this.transitionToRoute('allocations.allocation', allocation); | ||
} | ||
|
||
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))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we probably don't want to trigger side-effects in computeds. Again this is done in other places as well but we should investigate why we feel this is necessary to do |
||
}); | ||
|
||
return clients.sort().map(c => ({ key: c, label: c })); | ||
} | ||
|
||
@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 task groups changes. | ||
scheduleOnce('actions', () => { | ||
// eslint-disable-next-line ember/no-side-effects | ||
this.set('qpTaskGroup', serialize(intersection(taskGroups, this.selectionTaskGroup))); | ||
}); | ||
|
||
return taskGroups.sort().map(tg => ({ key: tg, label: tg })); | ||
} | ||
|
||
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are repeating this multiple times in this file. I understand that this pattern is used in other places as well
controllers/clients/index.js
for example. It looks like we can create a computed-macro out of this pattern.