Return all items without search term exported

This commit is contained in:
Michael Klein 2022-10-09 13:00:22 +02:00
parent b356cffbc5
commit 0194eebd95
1 changed files with 16 additions and 12 deletions

View File

@ -4,19 +4,23 @@ export default class SearchProvider extends Component {
get items() {
const { items, search, searchProperties } = this.args;
const regex = new RegExp(`${search}`, 'ig');
if (search.length > 0) {
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;
});
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;
}
}
get data() {