From aebb988dafd2bd0bc5c576a2fc39b3244d6a4510 Mon Sep 17 00:00:00 2001 From: Michael Klein Date: Sat, 8 Oct 2022 13:33:55 +0200 Subject: [PATCH] Create search-provider --- .../app/components/providers/search/index.hbs | 1 + .../app/components/providers/search/index.js | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 ui/packages/consul-ui/app/components/providers/search/index.hbs create mode 100644 ui/packages/consul-ui/app/components/providers/search/index.js 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, + }; + } +}