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

View file

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

View file

@ -21,6 +21,31 @@ Feature: dc / nodes / index
Then the url should be /dc-1/nodes
Then I see 1 node models
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
Given 1 node model from yaml
---
@ -29,6 +54,8 @@ Feature: dc / nodes / index
ServiceID: ""
- Status: critical
ServiceID: web
Meta:
synthetic-node: "false"
---
When I visit the nodes page for yaml
---
@ -38,7 +65,24 @@ Feature: dc / nodes / index
Then I see 1 node models
And I see status on the nodes.0 like "passing"
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
---
dc: dc-1
@ -54,12 +98,18 @@ Feature: dc / nodes / index
Checks:
- Status: critical
Name: Warning check
Meta:
synthetic-node: "false"
- Address: 10.0.0.1
Checks:
- Status: passing
Meta:
synthetic-node: "false"
- Address: 10.0.0.3
Checks:
- Status: passing
Meta:
synthetic-node: "false"
---
When I visit the nodes page for yaml
---
@ -73,10 +123,16 @@ Feature: dc / nodes / index
---
- Node: node-01
Address: 10.0.0.0
Meta:
synthetic-node: "false"
- Node: node-02
Address: 10.0.0.1
Meta:
synthetic-node: "false"
- Node: node-03
Address: 10.0.0.2
Meta:
synthetic-node: "false"
---
When I visit the nodes page for yaml
---