From f7f26220ba66e52b8bb45ff751e835ac9ff01242 Mon Sep 17 00:00:00 2001 From: Michael Klein Date: Mon, 25 Jul 2022 18:46:47 +0200 Subject: [PATCH] ui: add peers to node search (#13875) * Make nodes searchable by peer * fix only surface peer filter on service search when feature is on --- .../app/controllers/_peered-resource.js | 16 ++++++++++++++++ .../consul-ui/app/controllers/dc/nodes/index.js | 3 +++ .../app/controllers/dc/services/index.js | 3 +++ .../consul-ui/app/search/predicates/node.js | 1 + .../consul-ui/app/templates/dc/nodes/index.hbs | 4 ++-- .../app/templates/dc/services/index.hbs | 4 ++-- ui/packages/consul-ui/vendor/consul-ui/routes.js | 2 +- 7 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 ui/packages/consul-ui/app/controllers/_peered-resource.js create mode 100644 ui/packages/consul-ui/app/controllers/dc/nodes/index.js create mode 100644 ui/packages/consul-ui/app/controllers/dc/services/index.js diff --git a/ui/packages/consul-ui/app/controllers/_peered-resource.js b/ui/packages/consul-ui/app/controllers/_peered-resource.js new file mode 100644 index 0000000000..1490727b67 --- /dev/null +++ b/ui/packages/consul-ui/app/controllers/_peered-resource.js @@ -0,0 +1,16 @@ +import Controller from '@ember/controller'; +import { inject as service } from '@ember/service'; + +export default class PeeredResourceController extends Controller { + @service abilities; + + get _searchProperties() { + const { searchProperties } = this; + + if (!this.abilities.can('use peers')) { + return searchProperties.filter(propertyName => propertyName !== 'PeerName'); + } else { + return searchProperties; + } + } +} diff --git a/ui/packages/consul-ui/app/controllers/dc/nodes/index.js b/ui/packages/consul-ui/app/controllers/dc/nodes/index.js new file mode 100644 index 0000000000..56c35902b7 --- /dev/null +++ b/ui/packages/consul-ui/app/controllers/dc/nodes/index.js @@ -0,0 +1,3 @@ +import PeeredResourceController from 'consul-ui/controllers/_peered-resource'; + +export default class DcNodesController extends PeeredResourceController {} diff --git a/ui/packages/consul-ui/app/controllers/dc/services/index.js b/ui/packages/consul-ui/app/controllers/dc/services/index.js new file mode 100644 index 0000000000..f112725630 --- /dev/null +++ b/ui/packages/consul-ui/app/controllers/dc/services/index.js @@ -0,0 +1,3 @@ +import PeeredResourceController from 'consul-ui/controllers/_peered-resource'; + +export default class DcServicesController extends PeeredResourceController {} diff --git a/ui/packages/consul-ui/app/search/predicates/node.js b/ui/packages/consul-ui/app/search/predicates/node.js index 82dd3e731b..b780a6b1e2 100644 --- a/ui/packages/consul-ui/app/search/predicates/node.js +++ b/ui/packages/consul-ui/app/search/predicates/node.js @@ -1,5 +1,6 @@ export default { Node: item => item.Node, Address: item => item.Address, + PeerName: item => item.PeerName, Meta: item => Object.entries(item.Meta || {}).reduce((prev, entry) => prev.concat(entry), []), }; diff --git a/ui/packages/consul-ui/app/templates/dc/nodes/index.hbs b/ui/packages/consul-ui/app/templates/dc/nodes/index.hbs index d5ba6306a9..4afaefd5bd 100644 --- a/ui/packages/consul-ui/app/templates/dc/nodes/index.hbs +++ b/ui/packages/consul-ui/app/templates/dc/nodes/index.hbs @@ -44,10 +44,10 @@ as |route|> searchproperty=(hash value=(if (not-eq searchproperty undefined) (split searchproperty ',') - searchProperties + this._searchProperties ) change=(action (mut searchproperty) value="target.selectedItems") - default=searchProperties + default=this._searchProperties ) ) diff --git a/ui/packages/consul-ui/app/templates/dc/services/index.hbs b/ui/packages/consul-ui/app/templates/dc/services/index.hbs index 4d6ae65816..6b8a13f6e8 100644 --- a/ui/packages/consul-ui/app/templates/dc/services/index.hbs +++ b/ui/packages/consul-ui/app/templates/dc/services/index.hbs @@ -43,10 +43,10 @@ as |route|> searchproperty=(hash value=(if (not-eq searchproperty undefined) (split searchproperty ',') - searchProperties + this._searchProperties ) change=(action (mut searchproperty) value="target.selectedItems") - default=searchProperties + default=this._searchProperties ) ) diff --git a/ui/packages/consul-ui/vendor/consul-ui/routes.js b/ui/packages/consul-ui/vendor/consul-ui/routes.js index 12552d42e8..459b13cc07 100644 --- a/ui/packages/consul-ui/vendor/consul-ui/routes.js +++ b/ui/packages/consul-ui/vendor/consul-ui/routes.js @@ -215,7 +215,7 @@ status: 'status', searchproperty: { as: 'searchproperty', - empty: [['Node', 'Address', 'Meta']], + empty: [['Node', 'Address', 'Meta', 'PeerName']], }, search: { as: 'filter',