mirror of https://github.com/iconify/api.git
fix: filter icon sets by category and tags in search
This commit is contained in:
parent
88387371c8
commit
71ac3ec2f1
|
|
@ -57,6 +57,23 @@ export function filterSearchPrefixes(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filter by category
|
||||||
|
const category = params.category;
|
||||||
|
if (category) {
|
||||||
|
prefixes = (prefixes || data.sortedPrefixes).filter(
|
||||||
|
(prefix) => iconSets[prefix].item.info?.category === category
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter by tag
|
||||||
|
const tag = params.tag;
|
||||||
|
if (tag) {
|
||||||
|
prefixes = (prefixes || data.sortedPrefixes).filter((prefix) => {
|
||||||
|
const tags = iconSets[prefix].item.info?.tags;
|
||||||
|
return tags && tags.indexOf(tag) !== -1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Filter by prefix
|
// Filter by prefix
|
||||||
if (params.prefixes) {
|
if (params.prefixes) {
|
||||||
prefixes = filterSearchPrefixesList(prefixes || data.sortedPrefixes, params.prefixes);
|
prefixes = filterSearchPrefixesList(prefixes || data.sortedPrefixes, params.prefixes);
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,41 @@ describe('Searching icons', () => {
|
||||||
hasMore: false,
|
hasMore: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Search with category filter
|
||||||
|
expect(
|
||||||
|
search(
|
||||||
|
{
|
||||||
|
keyword: 'cycle',
|
||||||
|
limit: 999,
|
||||||
|
category: 'General',
|
||||||
|
},
|
||||||
|
searchIndex,
|
||||||
|
iconSets
|
||||||
|
)
|
||||||
|
).toEqual({
|
||||||
|
prefixes: ['mdi-test-prefix'],
|
||||||
|
names: [
|
||||||
|
'mdi-test-prefix:cash-cycle',
|
||||||
|
'mdi-test-prefix:hand-cycle',
|
||||||
|
'mdi-test-prefix:power-cycle',
|
||||||
|
'mdi-test-prefix:bicycle',
|
||||||
|
'mdi-test-prefix:bicycle-basket',
|
||||||
|
'mdi-test-prefix:bicycle-cargo',
|
||||||
|
'mdi-test-prefix:bicycle-electric',
|
||||||
|
'mdi-test-prefix:bicycle-penny-farthing',
|
||||||
|
'mdi-test-prefix:battery-recycle',
|
||||||
|
'mdi-test-prefix:battery-recycle-outline',
|
||||||
|
'mdi-test-prefix:recycle',
|
||||||
|
'mdi-test-prefix:recycle-variant',
|
||||||
|
'mdi-test-prefix:water-recycle',
|
||||||
|
'mdi-test-prefix:unicycle',
|
||||||
|
'mdi-test-prefix:motorcycle',
|
||||||
|
'mdi-test-prefix:motorcycle-electric',
|
||||||
|
'mdi-test-prefix:motorcycle-off',
|
||||||
|
],
|
||||||
|
hasMore: false,
|
||||||
|
});
|
||||||
|
|
||||||
// Search with style and palette
|
// Search with style and palette
|
||||||
expect(
|
expect(
|
||||||
search(
|
search(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue