Filter synthetic nodes on nodes list page

This commit is contained in:
wenincode 2022-10-12 15:11:05 -06:00
parent be1a4438a9
commit 1de0af4be1
5 changed files with 142 additions and 46 deletions

View File

@ -0,0 +1 @@
{{yield (hash data=this.data)}}

View File

@ -0,0 +1,36 @@
import Component from '@glimmer/component';
import { isArray } from '@ember/array';
import { get } from '@ember/object';
import { isEmpty, isEqual, isPresent } from '@ember/utils';
export default class RejectByProvider extends Component {
get items() {
const { items, path, value } = this.args;
if (!isArray) {
return [];
} else if (isEmpty(path)) {
return items;
}
let filterFn;
if (isPresent(value)) {
if (typeof value === 'function') {
filterFn = (item) => !value(get(item, path));
} else {
filterFn = (item) => !isEqual(get(item, path), value);
}
} else {
filterFn = (item) => !get(item, path);
}
return items.filter(filterFn);
}
get data() {
const { items } = this;
return {
items,
};
}
}

View File

@ -76,52 +76,54 @@ as |route|>
{{/if}} {{/if}}
</BlockSlot> </BlockSlot>
<BlockSlot @name="content"> <BlockSlot @name="content">
<DataCollection <Providers::RejectBy @items={{items}} @path="Meta.synthetic-node" @value="true" as |filtered|>
@type="node" <DataCollection
@sort={{sort.value}} @type="node"
@filters={{filters}} @sort={{sort.value}}
@search={{search}} @filters={{filters}}
@items={{items}} @search={{search}}
as |collection|> @items={{filtered.data.items}}
<collection.Collection> as |collection|>
<Consul::Node::List <collection.Collection>
@items={{collection.items}} <Consul::Node::List
@leader={{leader}} @items={{collection.items}}
/> @leader={{leader}}
</collection.Collection> />
<collection.Empty> </collection.Collection>
<EmptyState <collection.Empty>
@login={{route.model.app.login.open}} <EmptyState
> @login={{route.model.app.login.open}}
<BlockSlot @name="header"> >
<h2> <BlockSlot @name="header">
{{t 'routes.dc.nodes.index.empty.header' <h2>
{{t 'routes.dc.nodes.index.empty.header'
items=items.length
}}
</h2>
</BlockSlot>
<BlockSlot @name="body">
{{t 'routes.dc.nodes.index.empty.body'
items=items.length items=items.length
canUseACLs=(can 'use acls')
htmlSafe=true
}} }}
</h2> </BlockSlot>
</BlockSlot> <BlockSlot @name="actions">
<BlockSlot @name="body"> <li class="docs-link">
{{t 'routes.dc.nodes.index.empty.body' <a href="{{env 'CONSUL_DOCS_DEVELOPER_URL'}}/agent" rel="noopener noreferrer" target="_blank">
items=items.length {{t 'routes.dc.nodes.index.empty.documentation'}}
canUseACLs=(can 'use acls') </a>
htmlSafe=true </li>
}} <li class="learn-link">
</BlockSlot> <a href="{{env "CONSUL_DOCS_LEARN_URL"}}/tutorials/consul/deployment-guide?in=consul/production-deploy#configure-consul-agents" rel="noopener noreferrer" target="_blank">
<BlockSlot @name="actions"> {{t 'routes.dc.nodes.index.empty.learn'}}
<li class="docs-link"> </a>
<a href="{{env 'CONSUL_DOCS_DEVELOPER_URL'}}/agent" rel="noopener noreferrer" target="_blank"> </li>
{{t 'routes.dc.nodes.index.empty.documentation'}} </BlockSlot>
</a> </EmptyState>
</li> </collection.Empty>
<li class="learn-link"> </DataCollection>
<a href="{{env "CONSUL_DOCS_LEARN_URL"}}/tutorials/consul/deployment-guide?in=consul/production-deploy#configure-consul-agents" rel="noopener noreferrer" target="_blank"> </Providers::RejectBy>
{{t 'routes.dc.nodes.index.empty.learn'}}
</a>
</li>
</BlockSlot>
</EmptyState>
</collection.Empty>
</DataCollection>
</BlockSlot> </BlockSlot>
</AppView> </AppView>
{{/let}} {{/let}}

View File

@ -24,7 +24,8 @@
"wan":"${fake.internet.ip()}" "wan":"${fake.internet.ip()}"
}, },
"Meta": { "Meta": {
"consul-network-segment":"" "consul-network-segment":"",
"synthetic-node": "${fake.helpers.randomize(["true", "false", "false", "false"])}"
}, },
"Services":[ "Services":[
${ ${

View File

@ -21,6 +21,31 @@ Feature: dc / nodes / index
Then the url should be /dc-1/nodes Then the url should be /dc-1/nodes
Then I see 1 node models Then I see 1 node models
And I see status on the nodes.0 like "critical" And I see status on the nodes.0 like "critical"
Scenario: Viewing nodes list page should not show synthetic nodes
Given 3 node model from yaml
---
- Meta:
synthetic-node: "true"
Checks:
- Status: passing
ServiceID: ""
- Meta:
synthetic-node: "false"
Checks:
- Status: passing
ServiceID: ""
- Meta:
synthetic-node: "false"
Checks:
- Status: critical
ServiceID: ""
---
When I visit the nodes page for yaml
---
dc: dc-1
---
Then the url should be /dc-1/nodes
Then I see 2 node models
Scenario: Viewing a node with an unhealthy ServiceCheck Scenario: Viewing a node with an unhealthy ServiceCheck
Given 1 node model from yaml Given 1 node model from yaml
--- ---
@ -29,6 +54,8 @@ Feature: dc / nodes / index
ServiceID: "" ServiceID: ""
- Status: critical - Status: critical
ServiceID: web ServiceID: web
Meta:
synthetic-node: "false"
--- ---
When I visit the nodes page for yaml When I visit the nodes page for yaml
--- ---
@ -38,7 +65,24 @@ Feature: dc / nodes / index
Then I see 1 node models Then I see 1 node models
And I see status on the nodes.0 like "passing" And I see status on the nodes.0 like "passing"
Scenario: Viewing nodes in the listing Scenario: Viewing nodes in the listing
Given 3 node models Given 3 node model from yaml
---
- Meta:
synthetic-node: "false"
Checks:
- Status: passing
ServiceID: ""
- Meta:
synthetic-node: "false"
Checks:
- Status: passing
ServiceID: ""
- Meta:
synthetic-node: "false"
Checks:
- Status: critical
ServiceID: ""
---
When I visit the nodes page for yaml When I visit the nodes page for yaml
--- ---
dc: dc-1 dc: dc-1
@ -54,12 +98,18 @@ Feature: dc / nodes / index
Checks: Checks:
- Status: critical - Status: critical
Name: Warning check Name: Warning check
Meta:
synthetic-node: "false"
- Address: 10.0.0.1 - Address: 10.0.0.1
Checks: Checks:
- Status: passing - Status: passing
Meta:
synthetic-node: "false"
- Address: 10.0.0.3 - Address: 10.0.0.3
Checks: Checks:
- Status: passing - Status: passing
Meta:
synthetic-node: "false"
--- ---
When I visit the nodes page for yaml When I visit the nodes page for yaml
--- ---
@ -73,10 +123,16 @@ Feature: dc / nodes / index
--- ---
- Node: node-01 - Node: node-01
Address: 10.0.0.0 Address: 10.0.0.0
Meta:
synthetic-node: "false"
- Node: node-02 - Node: node-02
Address: 10.0.0.1 Address: 10.0.0.1
Meta:
synthetic-node: "false"
- Node: node-03 - Node: node-03
Address: 10.0.0.2 Address: 10.0.0.2
Meta:
synthetic-node: "false"
--- ---
When I visit the nodes page for yaml When I visit the nodes page for yaml
--- ---