-
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
Adds searching and filtering for nodes on topology view #14913
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
184b928
Adds searching and filtering for nodes on topology view
philrenaud a1f347e
Lintfix and changelog
philrenaud 56bd954
Acceptance tests for topology search and filter
philrenaud 6ab4613
Search terms also apply to class and dc on topo page
philrenaud a6331cf
Initialize queryparam values so as to not break history state
philrenaud 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:improvement | ||
ui: adds searching and filtering to the topology page | ||
``` |
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,23 +1,158 @@ | ||
/* eslint-disable ember/no-incorrect-calls-with-inline-anonymous-functions */ | ||
import Controller from '@ember/controller'; | ||
import { computed, action } from '@ember/object'; | ||
import { alias } from '@ember/object/computed'; | ||
import { inject as service } from '@ember/service'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import classic from 'ember-classic-decorator'; | ||
import { reduceBytes, reduceHertz } from 'nomad-ui/utils/units'; | ||
import { | ||
serialize, | ||
deserializedQueryParam as selection, | ||
} from 'nomad-ui/utils/qp-serialize'; | ||
import { scheduleOnce } from '@ember/runloop'; | ||
import intersection from 'lodash.intersection'; | ||
import Searchable from 'nomad-ui/mixins/searchable'; | ||
|
||
const sumAggregator = (sum, value) => sum + (value || 0); | ||
const formatter = new Intl.NumberFormat(window.navigator.locale || 'en', { | ||
maximumFractionDigits: 2, | ||
}); | ||
|
||
@classic | ||
export default class TopologyControllers extends Controller { | ||
export default class TopologyControllers extends Controller.extend(Searchable) { | ||
@service userSettings; | ||
|
||
queryParams = [ | ||
{ | ||
searchTerm: 'search', | ||
}, | ||
{ | ||
qpState: 'status', | ||
}, | ||
{ | ||
qpVersion: 'version', | ||
}, | ||
{ | ||
qpClass: 'class', | ||
}, | ||
{ | ||
qpDatacenter: 'dc', | ||
}, | ||
]; | ||
|
||
@tracked searchTerm = ''; | ||
qpState = ''; | ||
qpVersion = ''; | ||
qpClass = ''; | ||
qpDatacenter = ''; | ||
|
||
setFacetQueryParam(queryParam, selection) { | ||
this.set(queryParam, serialize(selection)); | ||
} | ||
|
||
@selection('qpState') selectionState; | ||
@selection('qpClass') selectionClass; | ||
@selection('qpDatacenter') selectionDatacenter; | ||
@selection('qpVersion') selectionVersion; | ||
|
||
@computed | ||
get optionsState() { | ||
return [ | ||
{ key: 'initializing', label: 'Initializing' }, | ||
{ key: 'ready', label: 'Ready' }, | ||
{ key: 'down', label: 'Down' }, | ||
{ key: 'ineligible', label: 'Ineligible' }, | ||
{ key: 'draining', label: 'Draining' }, | ||
{ key: 'disconnected', label: 'Disconnected' }, | ||
]; | ||
} | ||
|
||
@computed('model.nodes', 'nodes.[]', 'selectionClass') | ||
get optionsClass() { | ||
const classes = Array.from(new Set(this.model.nodes.mapBy('nodeClass'))) | ||
.compact() | ||
.without(''); | ||
|
||
// Remove any invalid node classes from the query param/selection | ||
scheduleOnce('actions', () => { | ||
// eslint-disable-next-line ember/no-side-effects | ||
this.set( | ||
'qpClass', | ||
serialize(intersection(classes, this.selectionClass)) | ||
); | ||
}); | ||
|
||
return classes.sort().map((dc) => ({ key: dc, label: dc })); | ||
} | ||
|
||
@computed('model.nodes', 'nodes.[]', 'selectionDatacenter') | ||
get optionsDatacenter() { | ||
const datacenters = Array.from( | ||
new Set(this.model.nodes.mapBy('datacenter')) | ||
).compact(); | ||
|
||
// Remove any invalid datacenters from the query param/selection | ||
scheduleOnce('actions', () => { | ||
// eslint-disable-next-line ember/no-side-effects | ||
this.set( | ||
'qpDatacenter', | ||
serialize(intersection(datacenters, this.selectionDatacenter)) | ||
); | ||
}); | ||
|
||
return datacenters.sort().map((dc) => ({ key: dc, label: dc })); | ||
} | ||
|
||
@computed('model.nodes', 'nodes.[]', 'selectionVersion') | ||
get optionsVersion() { | ||
const versions = Array.from( | ||
new Set(this.model.nodes.mapBy('version')) | ||
).compact(); | ||
|
||
// Remove any invalid versions from the query param/selection | ||
scheduleOnce('actions', () => { | ||
// eslint-disable-next-line ember/no-side-effects | ||
this.set( | ||
'qpVersion', | ||
serialize(intersection(versions, this.selectionVersion)) | ||
); | ||
}); | ||
|
||
return versions.sort().map((v) => ({ key: v, label: v })); | ||
} | ||
|
||
@alias('userSettings.showTopoVizPollingNotice') showPollingNotice; | ||
|
||
@tracked filteredNodes = null; | ||
@tracked pre09Nodes = null; | ||
|
||
get filteredNodes() { | ||
const { nodes } = this.model; | ||
return nodes.filter((node) => { | ||
const { | ||
searchTerm, | ||
selectionState, | ||
selectionVersion, | ||
selectionDatacenter, | ||
selectionClass, | ||
} = this; | ||
return ( | ||
(selectionState.length ? selectionState.includes(node.status) : true) && | ||
(selectionVersion.length | ||
? selectionVersion.includes(node.version) | ||
: true) && | ||
(selectionDatacenter.length | ||
? selectionDatacenter.includes(node.datacenter) | ||
: true) && | ||
(selectionClass.length | ||
? selectionClass.includes(node.nodeClass) | ||
: true) && | ||
(node.name.includes(searchTerm) || | ||
node.datacenter.includes(searchTerm) || | ||
node.nodeClass.includes(searchTerm)) | ||
); | ||
}); | ||
} | ||
|
||
@computed('[email protected]') | ||
get datacenters() { | ||
|
@@ -156,9 +291,9 @@ export default class TopologyControllers extends Controller { | |
|
||
@action | ||
handleTopoVizDataError(errors) { | ||
const filteredNodesError = errors.findBy('type', 'filtered-nodes'); | ||
if (filteredNodesError) { | ||
this.filteredNodes = filteredNodesError.context; | ||
const pre09NodesError = errors.findBy('type', 'filtered-nodes'); | ||
if (pre09NodesError) { | ||
this.pre09Nodes = pre09NodesError.context; | ||
} | ||
} | ||
} |
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
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.
Because we want to be able to filter nodes now, I've renamed what was
filteredNodes
topre09Nodes
. This modifies the code added from #9733 but I think in a healthy way. cc @DingoEatingFuzz