Skip to content

The open alternative to Salesforce, designed for AI.

Add opportunities to search and fix a small bug (#6476)

Félix Malfaitff74623dbb46
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 3594533cc8f..0b7ce97eec9 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 && (
<StyledEmpty>No results found</StyledEmpty>
)}
{isCopilotEnabled && (
@@ -437,6 +461,29 @@ export const CommandMenu = () => {
</SelectableItem>
))}
</CommandGroup>
+ <CommandGroup heading="Opportunities">
+ {opportunities.map((opportunity) => (
+ <SelectableItem
+ itemId={opportunity.id}
+ key={opportunity.id}
+ >
+ <CommandMenuItem
+ id={opportunity.id}
+ key={opportunity.id}
+ label={opportunity.name}
+ to={`object/opportunity/${opportunity.id}`}
+ Icon={() => (
+ <Avatar
+ type="rounded"
+ avatarUrl={null}
+ placeholderColorSeed={opportunity.id}
+ placeholder={opportunity.name}
+ />
+ )}
+ />
+ </SelectableItem>
+ ))}
+ </CommandGroup>
<CommandGroup heading="Notes">
{notes.map((note) => (
<SelectableItem itemId={note.id} key={note.id}>
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 ef8ab611467..475badcda18 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;
}
}