simplify match sorter

This commit is contained in:
Mark Kaylor 2022-03-03 18:09:18 +01:00
parent e37e588887
commit c9e7e3bcb2

View File

@ -3,7 +3,6 @@ import { useIntl } from 'react-intl';
import { Helmet } from 'react-helmet';
import { useQuery } from 'react-query';
import matchSorter from 'match-sorter';
import toLower from 'lodash/toLower';
import {
AnErrorOccurred,
CheckPagePermissions,
@ -25,12 +24,6 @@ import useFetchInstalledPlugins from '../../hooks/useFetchInstalledPlugins';
import useFetchMarketplacePlugins from '../../hooks/useFetchMarketplacePlugins';
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 { formatMessage } = useIntl();
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 =
searchResults.length && searchQuery.length ? searchResults : marketplacePluginsResponse.data;