mirror of
https://github.com/strapi/strapi.git
synced 2025-09-20 05:52:08 +00:00
simplify match sorter
This commit is contained in:
parent
e37e588887
commit
c9e7e3bcb2
@ -3,7 +3,6 @@ import { useIntl } from 'react-intl';
|
|||||||
import { Helmet } from 'react-helmet';
|
import { Helmet } from 'react-helmet';
|
||||||
import { useQuery } from 'react-query';
|
import { useQuery } from 'react-query';
|
||||||
import matchSorter from 'match-sorter';
|
import matchSorter from 'match-sorter';
|
||||||
import toLower from 'lodash/toLower';
|
|
||||||
import {
|
import {
|
||||||
AnErrorOccurred,
|
AnErrorOccurred,
|
||||||
CheckPagePermissions,
|
CheckPagePermissions,
|
||||||
@ -25,12 +24,6 @@ import useFetchInstalledPlugins from '../../hooks/useFetchInstalledPlugins';
|
|||||||
import useFetchMarketplacePlugins from '../../hooks/useFetchMarketplacePlugins';
|
import useFetchMarketplacePlugins from '../../hooks/useFetchMarketplacePlugins';
|
||||||
import adminPermissions from '../../permissions';
|
import adminPermissions from '../../permissions';
|
||||||
|
|
||||||
const matchSearch = (plugins, search) => {
|
|
||||||
return matchSorter(plugins, toLower(search), {
|
|
||||||
keys: [item => toLower(item.attributes.name), item => toLower(item.attributes.description)],
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const MarketPlacePage = () => {
|
const MarketPlacePage = () => {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const { trackUsage } = useTracking();
|
const { trackUsage } = useTracking();
|
||||||
@ -111,7 +104,9 @@ const MarketPlacePage = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchResults = matchSearch(marketplacePluginsResponse.data, searchQuery);
|
const searchResults = matchSorter(marketplacePluginsResponse.data, searchQuery, {
|
||||||
|
keys: ['attributes.name', 'attributes.description'],
|
||||||
|
});
|
||||||
|
|
||||||
const displayedPlugins =
|
const displayedPlugins =
|
||||||
searchResults.length && searchQuery.length ? searchResults : marketplacePluginsResponse.data;
|
searchResults.length && searchQuery.length ? searchResults : marketplacePluginsResponse.data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user