2022-10-08 11:33:55 +00:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
|
|
|
|
export default class SearchProvider extends Component {
|
|
|
|
get items() {
|
|
|
|
const { items, search, searchProperties } = this.args;
|
|
|
|
|
2022-10-09 11:00:22 +00:00
|
|
|
if (search.length > 0) {
|
|
|
|
const regex = new RegExp(`${search}`, 'ig');
|
2022-10-08 11:33:55 +00:00
|
|
|
|
2022-10-09 11:00:22 +00:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return items;
|
|
|
|
}
|
2022-10-08 11:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get data() {
|
|
|
|
const { items } = this;
|
|
|
|
return {
|
|
|
|
items,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|