Fix search fallback action (#10256)

The command menu search bar was reset after clicking on the `Search
records` fallback action, but it shouldn't.
This PR:
- Introduces a new type of action: `Fallback` actions
- Reset the search bar only if the action key differs from
'record-search-fallback'
This commit is contained in:
Raphaël Bosi
2025-02-17 15:24:42 +01:00
committed by GitHub
parent e8a55fd4dc
commit e6a484bb58
7 changed files with 38 additions and 26 deletions

View File

@ -29,4 +29,17 @@ export const RECORD_AGNOSTIC_ACTIONS_CONFIG: Record<
useAction: useSearchRecordsRecordAgnosticAction, useAction: useSearchRecordsRecordAgnosticAction,
hotKeys: ['/'], hotKeys: ['/'],
}, },
searchRecordsFallback: {
type: ActionMenuEntryType.Fallback,
scope: ActionMenuEntryScope.Global,
key: RecordAgnosticActionsKey.SEARCH_RECORDS_FALLBACK,
label: msg`Search records`,
shortLabel: msg`Search`,
position: 1,
isPinned: false,
Icon: IconSearch,
availableOn: [ActionViewType.GLOBAL],
useAction: useSearchRecordsRecordAgnosticAction,
hotKeys: ['/'],
},
}; };

View File

@ -1,17 +1,11 @@
import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu'; import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu';
import { commandMenuSearchState } from '@/command-menu/states/commandMenuSearchState';
import { CommandMenuPages } from '@/command-menu/types/CommandMenuPages'; import { CommandMenuPages } from '@/command-menu/types/CommandMenuPages';
import { useSetRecoilState } from 'recoil';
import { IconSearch } from 'twenty-ui'; import { IconSearch } from 'twenty-ui';
export const useSearchRecordsRecordAgnosticAction = () => { export const useSearchRecordsRecordAgnosticAction = () => {
const { navigateCommandMenu } = useCommandMenu(); const { navigateCommandMenu } = useCommandMenu();
const setCommandMenuSearch = useSetRecoilState(commandMenuSearchState);
const onClick = () => { const onClick = () => {
setCommandMenuSearch('');
navigateCommandMenu({ navigateCommandMenu({
page: CommandMenuPages.SearchRecords, page: CommandMenuPages.SearchRecords,
pageTitle: 'Search', pageTitle: 'Search',

View File

@ -1,3 +1,4 @@
export enum RecordAgnosticActionsKey { export enum RecordAgnosticActionsKey {
SEARCH_RECORDS = 'search-records', SEARCH_RECORDS = 'search-records',
SEARCH_RECORDS_FALLBACK = 'search-records-fallback',
} }

View File

@ -7,6 +7,7 @@ import { IconComponent, MenuItemAccent } from 'twenty-ui';
export enum ActionMenuEntryType { export enum ActionMenuEntryType {
Standard = 'Standard', Standard = 'Standard',
WorkflowRun = 'WorkflowRun', WorkflowRun = 'WorkflowRun',
Fallback = 'Fallback',
} }
export enum ActionMenuEntryScope { export enum ActionMenuEntryScope {

View File

@ -9,6 +9,7 @@ import { ActionMenuComponentInstanceContext } from '@/action-menu/states/context
import { COMMAND_MENU_ANIMATION_VARIANTS } from '@/command-menu/constants/CommandMenuAnimationVariants'; import { COMMAND_MENU_ANIMATION_VARIANTS } from '@/command-menu/constants/CommandMenuAnimationVariants';
import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu'; import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu';
import { useCommandMenuHotKeys } from '@/command-menu/hooks/useCommandMenuHotKeys'; import { useCommandMenuHotKeys } from '@/command-menu/hooks/useCommandMenuHotKeys';
import { commandMenuSearchState } from '@/command-menu/states/commandMenuSearchState';
import { isCommandMenuOpenedState } from '@/command-menu/states/isCommandMenuOpenedState'; import { isCommandMenuOpenedState } from '@/command-menu/states/isCommandMenuOpenedState';
import { CommandMenuAnimationVariant } from '@/command-menu/types/CommandMenuAnimationVariant'; import { CommandMenuAnimationVariant } from '@/command-menu/types/CommandMenuAnimationVariant';
import { ContextStoreComponentInstanceContext } from '@/context-store/states/contexts/ContextStoreComponentInstanceContext'; import { ContextStoreComponentInstanceContext } from '@/context-store/states/contexts/ContextStoreComponentInstanceContext';
@ -21,7 +22,7 @@ import { useTheme } from '@emotion/react';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { motion } from 'framer-motion'; import { motion } from 'framer-motion';
import { useRef } from 'react'; import { useRef } from 'react';
import { useRecoilValue } from 'recoil'; import { useRecoilValue, useSetRecoilState } from 'recoil';
import { useIsMobile } from 'twenty-ui'; import { useIsMobile } from 'twenty-ui';
import { FeatureFlagKey } from '~/generated-metadata/graphql'; import { FeatureFlagKey } from '~/generated-metadata/graphql';
@ -78,6 +79,8 @@ export const CommandMenuContainer = ({
FeatureFlagKey.IsWorkflowEnabled, FeatureFlagKey.IsWorkflowEnabled,
); );
const setCommandMenuSearch = useSetRecoilState(commandMenuSearchState);
return ( return (
<RecordFiltersComponentInstanceContext.Provider <RecordFiltersComponentInstanceContext.Provider
value={{ instanceId: 'command-menu' }} value={{ instanceId: 'command-menu' }}
@ -94,10 +97,14 @@ export const CommandMenuContainer = ({
onActionExecutedCallback: ({ key }) => { onActionExecutedCallback: ({ key }) => {
if ( if (
key !== RecordAgnosticActionsKey.SEARCH_RECORDS && key !== RecordAgnosticActionsKey.SEARCH_RECORDS &&
key !== RecordAgnosticActionsKey.SEARCH_RECORDS_FALLBACK &&
key !== NoSelectionRecordActionKeys.CREATE_NEW_RECORD key !== NoSelectionRecordActionKeys.CREATE_NEW_RECORD
) { ) {
toggleCommandMenu(); toggleCommandMenu();
} }
if (key !== RecordAgnosticActionsKey.SEARCH_RECORDS_FALLBACK) {
setCommandMenuSearch('');
}
}, },
}} }}
> >

View File

@ -1,4 +1,3 @@
import { RecordAgnosticActionsKey } from '@/action-menu/actions/record-agnostic-actions/types/RecordAgnosticActionsKey';
import { actionMenuEntriesComponentSelector } from '@/action-menu/states/actionMenuEntriesComponentSelector'; import { actionMenuEntriesComponentSelector } from '@/action-menu/states/actionMenuEntriesComponentSelector';
import { import {
ActionMenuEntryScope, ActionMenuEntryScope,
@ -129,24 +128,20 @@ export const useCommandMenuCommands = () => {
hotKeys: actionMenuEntry.hotKeys, hotKeys: actionMenuEntry.hotKeys,
})); }));
const searchRecordsAction = actionMenuEntries.find( const fallbackCommands: Command[] = actionMenuEntries
(actionMenuEntry) => ?.filter(
actionMenuEntry.key === RecordAgnosticActionsKey.SEARCH_RECORDS, (actionMenuEntry) =>
); actionMenuEntry.type === ActionMenuEntryType.Fallback,
)
const fallbackCommands: Command[] = searchRecordsAction ?.map((actionMenuEntry) => ({
? [ id: actionMenuEntry.key,
{ label: i18n._(actionMenuEntry.label),
id: searchRecordsAction.key, Icon: actionMenuEntry.Icon,
label: i18n._(searchRecordsAction.label), onCommandClick: actionMenuEntry.onClick,
Icon: searchRecordsAction.Icon, type: CommandType.Fallback,
onCommandClick: searchRecordsAction.onClick, scope: CommandScope.Global,
type: CommandType.StandardAction, hotKeys: actionMenuEntry.hotKeys,
scope: CommandScope.Global, }));
hotKeys: searchRecordsAction.hotKeys,
},
]
: [];
return { return {
copilotCommands, copilotCommands,

View File

@ -4,6 +4,7 @@ export enum CommandType {
Create = 'Create', Create = 'Create',
StandardAction = 'StandardAction', StandardAction = 'StandardAction',
WorkflowRun = 'WorkflowRun', WorkflowRun = 'WorkflowRun',
Fallback = 'Fallback',
} }
export enum CommandScope { export enum CommandScope {