From ff74623dbb4641236e2f61c7b01a7564548a40e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Malfait?= Date: Wed, 31 Jul 2024 16:50:16 +0200 Subject: [PATCH] Add opportunities to search and fix a small bug (#6476) --- .../command-menu/components/CommandMenu.tsx | 51 ++++++++++++++++++- .../utils/getFirstNonEmptyLineOfRichText.ts | 2 +- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/packages/twenty-front/src/modules/command-menu/components/CommandMenu.tsx b/packages/twenty-front/src/modules/command-menu/components/CommandMenu.tsx index 3594533cc..0b7ce97ee 100644 --- a/packages/twenty-front/src/modules/command-menu/components/CommandMenu.tsx +++ b/packages/twenty-front/src/modules/command-menu/components/CommandMenu.tsx @@ -194,6 +194,17 @@ export const CommandMenu = () => { limit: 3, }); + const { records: opportunities } = useFindManyRecords({ + skip: !isCommandMenuOpened, + objectNameSingular: CoreObjectNameSingular.Opportunity, + filter: commandMenuSearch + ? { + name: { ilike: `%${commandMenuSearch}%` }, + } + : undefined, + limit: 3, + }); + const peopleCommands = useMemo( () => people.map(({ id, name: { firstName, lastName } }) => ({ @@ -214,6 +225,16 @@ export const CommandMenu = () => { [companies], ); + const opportunityCommands = useMemo( + () => + opportunities.map(({ id, name }) => ({ + id, + label: name ?? '', + to: `object/opportunity/${id}`, + })), + [opportunities], + ); + const noteCommands = useMemo( () => notes.map((note) => ({ @@ -229,9 +250,10 @@ export const CommandMenu = () => { return [ ...peopleCommands, ...companyCommands, + ...opportunityCommands, ...noteCommands, ] as Command[]; - }, [peopleCommands, companyCommands, noteCommands]); + }, [peopleCommands, companyCommands, noteCommands, opportunityCommands]); const checkInShortcuts = (cmd: Command, search: string) => { return (cmd.firstHotKey + (cmd.secondHotKey ?? '')) @@ -291,6 +313,7 @@ export const CommandMenu = () => { .concat(matchingNavigateCommand.map((cmd) => cmd.id)) .concat(people.map((person) => person.id)) .concat(companies.map((company) => company.id)) + .concat(opportunities.map((opportunity) => opportunity.id)) .concat(notes.map((note) => note.id)); return ( @@ -339,7 +362,8 @@ export const CommandMenu = () => { !matchingNavigateCommand.length && !people.length && !companies.length && - !notes.length && ( + !notes.length && + !opportunities.length && ( No results found )} {isCopilotEnabled && ( @@ -437,6 +461,29 @@ export const CommandMenu = () => { ))} + + {opportunities.map((opportunity) => ( + + ( + + )} + /> + + ))} + {notes.map((note) => ( diff --git a/packages/twenty-front/src/modules/ui/input/editor/utils/getFirstNonEmptyLineOfRichText.ts b/packages/twenty-front/src/modules/ui/input/editor/utils/getFirstNonEmptyLineOfRichText.ts index ef8ab6114..475badcda 100644 --- a/packages/twenty-front/src/modules/ui/input/editor/utils/getFirstNonEmptyLineOfRichText.ts +++ b/packages/twenty-front/src/modules/ui/input/editor/utils/getFirstNonEmptyLineOfRichText.ts @@ -12,7 +12,7 @@ export const getFirstNonEmptyLineOfRichText = ( const contentArray = node.content as Array<{ text: string }>; if (contentArray.length > 0) { for (const content of contentArray) { - if (content.text.trim() !== '') { + if (content.text?.trim() !== '') { return content.text; } }