Use reject-by composable helper instead of provider

This commit is contained in:
wenincode 2022-10-13 07:29:51 -06:00
parent 344ebaa962
commit 4218124b10
3 changed files with 111 additions and 160 deletions

View File

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

View File

@ -1,36 +0,0 @@
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

@ -1,121 +1,109 @@
<Route <Route @name={{routeName}} as |route|>
@name={{routeName}}
as |route|>
<DataSource @src={{ <DataSource
uri '/${partition}/${nspace}/${dc}/leader' @src={{uri
(hash '/${partition}/${nspace}/${dc}/leader'
partition=route.params.partition (hash partition=route.params.partition nspace=route.params.nspace dc=route.params.dc)
nspace=route.params.nspace }}
dc=route.params.dc as |leader|
) >
}} as |leader|>
<DataLoader <DataLoader
@src={{uri '/${partition}/${nspace}/${dc}/nodes' @src={{uri
(hash '/${partition}/${nspace}/${dc}/nodes'
partition=route.params.partition (hash partition=route.params.partition nspace=route.params.nspace dc=route.params.dc)
nspace=route.params.nspace
dc=route.params.dc
)
}} }}
as |api|> as |api|
>
<BlockSlot @name="error"> <BlockSlot @name='error'>
<AppError <AppError @error={{api.error}} @login={{route.model.app.login.open}} />
@error={{api.error}}
@login={{route.model.app.login.open}}
/>
</BlockSlot> </BlockSlot>
<BlockSlot @name="loaded"> <BlockSlot @name='loaded'>
{{#let {{#let
(hash value=(or sortBy 'Status:asc') change=(action (mut sortBy) value='target.selected'))
(hash
value=(or sortBy "Status:asc")
change=(action (mut sortBy) value="target.selected")
)
(hash (hash
status=(hash status=(hash
value=(if status (split status ',') undefined) value=(if status (split status ',') undefined)
change=(action (mut status) value="target.selectedItems") change=(action (mut status) value='target.selectedItems')
) )
searchproperty=(hash searchproperty=(hash
value=(if (not-eq searchproperty undefined) value=(if
(split searchproperty ',') (not-eq searchproperty undefined) (split searchproperty ',') this._searchProperties
this._searchProperties
) )
change=(action (mut searchproperty) value="target.selectedItems") change=(action (mut searchproperty) value='target.selectedItems')
default=this._searchProperties default=this._searchProperties
) )
) )
api.data api.data
leader.data leader.data
as |sort filters items leader|
as |sort filters items leader|}} }}
{{#let (reject-by 'Meta.synthetic-node' 'true' items) as |filtered|}}
<AppView> <AppView>
<BlockSlot @name="header"> <BlockSlot @name='header'>
<h1> <h1>
<route.Title @title="Nodes" /> <em>{{format-number items.length}} total</em> <route.Title @title='Nodes' />
<em>{{format-number items.length}} total</em>
</h1> </h1>
<label for="toolbar-toggle"></label> <label for='toolbar-toggle'></label>
</BlockSlot> </BlockSlot>
<BlockSlot @name="toolbar"> <BlockSlot @name='toolbar'>
{{#if (gt items.length 0) }} {{#if (gt filtered.length 0)}}
<Consul::Node::SearchBar <Consul::Node::SearchBar
@search={{search}} @search={{search}}
@onsearch={{action (mut search) value="target.value"}} @onsearch={{action (mut search) value='target.value'}}
@sort={{sort}} @sort={{sort}}
@filter={{filters}} @filter={{filters}}
/> />
{{/if}} {{/if}}
</BlockSlot> </BlockSlot>
<BlockSlot @name="content"> <BlockSlot @name='content'>
<Providers::RejectBy @items={{items}} @path="Meta.synthetic-node" @value="true" as |filtered|>
<DataCollection <DataCollection
@type="node" @type='node'
@sort={{sort.value}} @sort={{sort.value}}
@filters={{filters}} @filters={{filters}}
@search={{search}} @search={{search}}
@items={{filtered.data.items}} @items={{filtered}}
as |collection|> as |collection|
>
<collection.Collection> <collection.Collection>
<Consul::Node::List <Consul::Node::List @items={{collection.items}} @leader={{leader}} />
@items={{collection.items}}
@leader={{leader}}
/>
</collection.Collection> </collection.Collection>
<collection.Empty> <collection.Empty>
<EmptyState <EmptyState @login={{route.model.app.login.open}}>
@login={{route.model.app.login.open}} <BlockSlot @name='header'>
>
<BlockSlot @name="header">
<h2> <h2>
{{t 'routes.dc.nodes.index.empty.header' {{t 'routes.dc.nodes.index.empty.header' items=items.length}}
items=items.length
}}
</h2> </h2>
</BlockSlot> </BlockSlot>
<BlockSlot @name="body"> <BlockSlot @name='body'>
{{t 'routes.dc.nodes.index.empty.body' {{t
'routes.dc.nodes.index.empty.body'
items=items.length items=items.length
canUseACLs=(can 'use acls') canUseACLs=(can 'use acls')
htmlSafe=true htmlSafe=true
}} }}
</BlockSlot> </BlockSlot>
<BlockSlot @name="actions"> <BlockSlot @name='actions'>
<li class="docs-link"> <li class='docs-link'>
<a href="{{env 'CONSUL_DOCS_DEVELOPER_URL'}}/agent" rel="noopener noreferrer" target="_blank"> <a
href='{{env "CONSUL_DOCS_DEVELOPER_URL"}}/agent'
rel='noopener noreferrer'
target='_blank'
>
{{t 'routes.dc.nodes.index.empty.documentation'}} {{t 'routes.dc.nodes.index.empty.documentation'}}
</a> </a>
</li> </li>
<li class="learn-link"> <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"> <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'}} {{t 'routes.dc.nodes.index.empty.learn'}}
</a> </a>
</li> </li>
@ -123,11 +111,11 @@ as |route|>
</EmptyState> </EmptyState>
</collection.Empty> </collection.Empty>
</DataCollection> </DataCollection>
</Providers::RejectBy>
</BlockSlot> </BlockSlot>
</AppView> </AppView>
{{/let}} {{/let}}
{{/let}}
</BlockSlot> </BlockSlot>
</DataLoader> </DataLoader>
</DataSource> </DataSource>
</Route> </Route>