diff --git a/ui/packages/consul-ui/app/components/providers/search/index.hbs b/ui/packages/consul-ui/app/components/providers/search/index.hbs new file mode 100644 index 0000000000..c55695d4db --- /dev/null +++ b/ui/packages/consul-ui/app/components/providers/search/index.hbs @@ -0,0 +1 @@ +{{yield (hash data=this.data)}} \ No newline at end of file diff --git a/ui/packages/consul-ui/app/components/providers/search/index.js b/ui/packages/consul-ui/app/components/providers/search/index.js new file mode 100644 index 0000000000..af61de4fb1 --- /dev/null +++ b/ui/packages/consul-ui/app/components/providers/search/index.js @@ -0,0 +1,28 @@ +import Component from '@glimmer/component'; + +export default class SearchProvider extends Component { + get items() { + const { items, search, searchProperties } = this.args; + + const regex = new RegExp(`${search}`, 'ig'); + + return items.filter((item) => { + const matchesInSearchProperties = searchProperties.reduce((acc, searchProperty) => { + const match = item[searchProperty].match(regex); + if (match) { + return [...acc, match]; + } else { + return acc; + } + }, []); + return matchesInSearchProperties.length > 0; + }); + } + + get data() { + const { items } = this; + return { + items, + }; + } +}