The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Command menu search bar (#4337)
Charles Bochetb08b361dc001
diff --git a/packages/twenty-front/src/modules/command-menu/components/CommandMenu.tsx b/packages/twenty-front/src/modules/command-menu/components/CommandMenu.tsxindex 15bc43d088c..b5a9a164fdc 100644--- a/packages/twenty-front/src/modules/command-menu/components/CommandMenu.tsx+++ b/packages/twenty-front/src/modules/command-menu/components/CommandMenu.tsx@@ -1,10 +1,11 @@-import { useMemo, useRef, useState } from 'react';+import { useMemo, useRef } from 'react';import styled from '@emotion/styled';-import { useRecoilValue } from 'recoil';+import { useRecoilState, useRecoilValue } from 'recoil';import { Key } from 'ts-key-enum';import { useOpenActivityRightDrawer } from '@/activities/hooks/useOpenActivityRightDrawer';import { Activity } from '@/activities/types/Activity';+import { commandMenuSearchState } from '@/command-menu/states/commandMenuSearchState';import { Company } from '@/companies/types/Company';import { useKeyboardShortcutMenu } from '@/keyboard-shortcut-menu/hooks/useKeyboardShortcutMenu';import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';@@ -105,23 +106,24 @@ export const CommandMenu = () => {const openActivityRightDrawer = useOpenActivityRightDrawer();const isCommandMenuOpened = useRecoilValue(isCommandMenuOpenedState);- const [search, setSearch] = useState('');+ const [commandMenuSearch, setCommandMenuSearch] = useRecoilState(+ commandMenuSearchState,+ );const commandMenuCommands = useRecoilValue(commandMenuCommandsState);const { closeKeyboardShortcutMenu } = useKeyboardShortcutMenu();const handleSearchChange = (event: React.ChangeEvent<HTMLInputElement>) => {- setSearch(event.target.value);+ setCommandMenuSearch(event.target.value);};useScopedHotkeys('ctrl+k,meta+k',() => {closeKeyboardShortcutMenu();- setSearch('');toggleCommandMenu();},AppHotkeyScope.CommandMenu,- [toggleCommandMenu, setSearch],+ [toggleCommandMenu],);useScopedHotkeys(@@ -136,12 +138,12 @@ export const CommandMenu = () => {const { records: people } = useFindManyRecords<Person>({skip: !isCommandMenuOpened,objectNameSingular: CoreObjectNameSingular.Person,- filter: search+ filter: commandMenuSearch? makeOrFilterVariables([- { name: { firstName: { ilike: `%${search}%` } } },- { name: { lastName: { ilike: `%${search}%` } } },- { email: { ilike: `%${search}%` } },- { phone: { ilike: `%${search}%` } },+ { name: { firstName: { ilike: `%${commandMenuSearch}%` } } },+ { name: { lastName: { ilike: `%${commandMenuSearch}%` } } },+ { email: { ilike: `%${commandMenuSearch}%` } },+ { phone: { ilike: `%${commandMenuSearch}%` } },]): undefined,limit: 3,@@ -150,9 +152,9 @@ export const CommandMenu = () => {const { records: companies } = useFindManyRecords<Company>({skip: !isCommandMenuOpened,objectNameSingular: CoreObjectNameSingular.Company,- filter: search+ filter: commandMenuSearch? {- name: { ilike: `%${search}%` },+ name: { ilike: `%${commandMenuSearch}%` },}: undefined,limit: 3,@@ -161,10 +163,10 @@ export const CommandMenu = () => {const { records: activities } = useFindManyRecords<Activity>({skip: !isCommandMenuOpened,objectNameSingular: CoreObjectNameSingular.Activity,- filter: search+ filter: commandMenuSearch? makeOrFilterVariables([- { title: { ilike: `%${search}%` } },- { body: { ilike: `%${search}%` } },+ { title: { ilike: `%${commandMenuSearch}%` } },+ { body: { ilike: `%${commandMenuSearch}%` } },]): undefined,limit: 3,@@ -224,15 +226,17 @@ export const CommandMenu = () => {const matchingNavigateCommand = commandMenuCommands.filter((cmd) =>- (search.length > 0- ? checkInShortcuts(cmd, search) || checkInLabels(cmd, search)+ (commandMenuSearch.length > 0+ ? checkInShortcuts(cmd, commandMenuSearch) ||+ checkInLabels(cmd, commandMenuSearch): true) && cmd.type === CommandType.Navigate,);const matchingCreateCommand = commandMenuCommands.filter((cmd) =>- (search.length > 0- ? checkInShortcuts(cmd, search) || checkInLabels(cmd, search)+ (commandMenuSearch.length > 0+ ? checkInShortcuts(cmd, commandMenuSearch) ||+ checkInLabels(cmd, commandMenuSearch): true) && cmd.type === CommandType.Create,);@@ -254,7 +258,7 @@ export const CommandMenu = () => {<StyledDialog ref={commandMenuRef}><StyledInputautoFocus- value={search}+ value={commandMenuSearch}placeholder="Search"onChange={handleSearchChange}/>diff --git a/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenu.ts b/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenu.tsindex 0d806f586be..9e9944af74e 100644--- a/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenu.ts+++ b/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenu.ts@@ -2,6 +2,7 @@ import { useCallback } from 'react';import { useNavigate } from 'react-router-dom';import { useRecoilCallback, useSetRecoilState } from 'recoil';+import { commandMenuSearchState } from '@/command-menu/states/commandMenuSearchState';import { useSelectableList } from '@/ui/layout/selectable-list/hooks/useSelectableList';import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousHotkeyScope';import { AppHotkeyScope } from '@/ui/utilities/hotkey/types/AppHotkeyScope';@@ -42,17 +43,22 @@ export const useCommandMenu = () => {[goBackToPreviousHotkeyScope, resetSelectedItem, setIsCommandMenuOpened],);- const toggleCommandMenu = useRecoilCallback(({ snapshot }) => async () => {- const isCommandMenuOpened = snapshot- .getLoadable(isCommandMenuOpenedState)- .getValue();+ const toggleCommandMenu = useRecoilCallback(+ ({ snapshot, set }) =>+ async () => {+ const isCommandMenuOpened = snapshot+ .getLoadable(isCommandMenuOpenedState)+ .getValue();++ set(commandMenuSearchState, '');- if (isCommandMenuOpened) {- closeCommandMenu();- } else {- openCommandMenu();- }- });+ if (isCommandMenuOpened) {+ closeCommandMenu();+ } else {+ openCommandMenu();+ }+ },+ );const addToCommandMenu = useCallback((addCommand: Command[]) => {diff --git a/packages/twenty-front/src/modules/command-menu/states/commandMenuSearchState.ts b/packages/twenty-front/src/modules/command-menu/states/commandMenuSearchState.tsnew file mode 100644index 00000000000..b5be2a5d7ac--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu/states/commandMenuSearchState.ts@@ -0,0 +1,6 @@+import { atom } from 'recoil';++export const commandMenuSearchState = atom<string>({+ key: 'command-menu/commandMenuSearchState',+ default: '',+});diff --git a/packages/twenty-front/src/modules/object-metadata/hooks/__tests__/useMapFieldMetadataToGraphQLQuery.test.tsx b/packages/twenty-front/src/modules/object-metadata/hooks/__tests__/useMapFieldMetadataToGraphQLQuery.test.tsxindex 0425726a6e6..43a5b676a2e 100644--- a/packages/twenty-front/src/modules/object-metadata/hooks/__tests__/useMapFieldMetadataToGraphQLQuery.test.tsx+++ b/packages/twenty-front/src/modules/object-metadata/hooks/__tests__/useMapFieldMetadataToGraphQLQuery.test.tsx@@ -20,43 +20,20 @@ const getOneToManyRelation = () => {return {field: objectMetadataItem.fields.find((field) => field.name === 'company')!,res: `company- {- __typename- id+ {+ __typename+ idxLink{labelurl}-accountOwner- {- __typename- id- }linkedinLink{labelurl}-attachments- {- edges {- node {- __typename- id- }- }- }domainName-opportunities- {- edges {- node {- __typename- id- }- }- }annualRecurringRevenue{amountMicros@@ -65,39 +42,12 @@ opportunitiescreatedAtaddressupdatedAt-activityTargets- {- edges {- node {- __typename- id- }- }- }-favorites- {- edges {- node {- __typename- id- }- }- }-people- {- edges {- node {- __typename- id- }- }- }nameaccountOwnerIdemployeesididealCustomerProfile- }`,+ }`,};};@@ -133,27 +83,17 @@ const getOneToManyFromRelationField = () => {return {field,res: `opportunities- {- edges {- node {- __typename- id- personId+ {+ edges {+ node {+ __typename+ id+ personIdpointOfContactIdupdatedAt-company- {- __typename- id- }companyIdpipelineStepIdprobability-pipelineStep- {- __typename- id- }closeDateamount{@@ -162,19 +102,9 @@ closeDate}idcreatedAt-pointOfContact- {- __typename- id- }-person- {- __typename- id- }+ }}- }- }`,+ }`,};};