-
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.
Adds searching and filtering for nodes on topology view (#14913)
* Adds searching and filtering for nodes on topology view * Lintfix and changelog * Acceptance tests for topology search and filter * Search terms also apply to class and dc on topo page * Initialize queryparam values so as to not break history state
- Loading branch information
1 parent
3fd800c
commit aa5b83b
Showing
7 changed files
with
233 additions
and
12 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: 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