The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix icon search menu (#4565) (#4712)
Simão Sanguinho743e203bc757
diff --git a/packages/twenty-front/src/modules/ui/input/components/IconPicker.tsx b/packages/twenty-front/src/modules/ui/input/components/IconPicker.tsxindex ebc209d6302..3b8b78748b6 100644--- a/packages/twenty-front/src/modules/ui/input/components/IconPicker.tsx+++ b/packages/twenty-front/src/modules/ui/input/components/IconPicker.tsx@@ -101,35 +101,47 @@ export const IconPicker = ({const { getIcons, getIcon } = useIcons();const icons = getIcons();const matchingSearchIconKeys = useMemo(() => {- const filteredIconKeys = icons- ? Object.keys(icons).filter((iconKey) => {- if (searchString === '') {- return true;- }-- const isMatchingSearchString = [- iconKey,- convertIconKeyToLabel(iconKey),- ].some((label) =>- label.toLowerCase().includes(searchString.toLowerCase()),- );-- return isMatchingSearchString;- })- : [];+ if (icons == null) return [];+ const scoreIconMatch = (iconKey: string, searchString: string) => {+ const iconLabel = convertIconKeyToLabel(iconKey)+ .toLowerCase()+ .replace('icon ', '')+ .replace(/\s/g, '');++ const searchLower = searchString+ .toLowerCase()+ .trimEnd()+ .replace(/\s/g, '');++ if (iconKey === searchString || iconLabel === searchString) return 100;+ if (iconKey.startsWith(searchLower) || iconLabel.startsWith(searchLower))+ return 75;+ if (iconKey.includes(searchLower) || iconLabel.includes(searchLower))+ return 50;++ return 0;+ };+ const scoredIcons = Object.keys(icons).map((iconKey) => ({+ iconKey,+ score: scoreIconMatch(iconKey, searchString),+ }));++ const filteredAndSortedIconKeys = scoredIcons+ .filter(({ score }) => score > 0)+ .sort((a, b) => b.score - a.score)+ .map(({ iconKey }) => iconKey);const isSelectedIconMatchingFilter =- selectedIconKey && filteredIconKeys.includes(selectedIconKey);-- const uniqueFilteredIconKeys = [- ...new Set(- selectedIconKey && isSelectedIconMatchingFilter- ? [selectedIconKey, ...filteredIconKeys]- : filteredIconKeys,- ),- ];-- return uniqueFilteredIconKeys.slice(0, 25);+ selectedIconKey && filteredAndSortedIconKeys.includes(selectedIconKey);++ return isSelectedIconMatchingFilter+ ? [+ selectedIconKey,+ ...filteredAndSortedIconKeys.filter(+ (iconKey) => iconKey !== selectedIconKey,+ ),+ ].slice(0, 25)+ : filteredAndSortedIconKeys.slice(0, 25);}, [icons, searchString, selectedIconKey]);const iconKeys2d = useMemo(