From 1be711b8d749b188f8d5d93863aa0bfa479c971f Mon Sep 17 00:00:00 2001 From: bosiraphael Date: Thu, 2 Jan 2025 17:44:29 +0100 Subject: [PATCH 01/22] create command menu router --- .../command-menu/components/CommandMenu.tsx | 163 +++++++----------- .../components/CommandMenuContainer.tsx | 57 ++++-- .../components/CommandMenuPages.ts | 4 + .../components/CommandMenuRouter.tsx | 23 +++ .../components/CommandMenuShowPage.tsx | 10 ++ .../components/CommandMenuTopBar.tsx | 14 +- .../constants/CommandMenuPagesConfig.tsx | 11 ++ .../command-menu/hooks/useCommandMenu.ts | 2 + .../hooks/useCommandMenuHotKeys.ts | 15 +- .../states/commandMenuPageState.ts | 7 + .../commandMenuViewableRecordIdState.ts | 6 + .../layout/page/components/DefaultLayout.tsx | 4 +- 12 files changed, 188 insertions(+), 128 deletions(-) create mode 100644 packages/twenty-front/src/modules/command-menu/components/CommandMenuPages.ts create mode 100644 packages/twenty-front/src/modules/command-menu/components/CommandMenuRouter.tsx create mode 100644 packages/twenty-front/src/modules/command-menu/components/CommandMenuShowPage.tsx create mode 100644 packages/twenty-front/src/modules/command-menu/constants/CommandMenuPagesConfig.tsx create mode 100644 packages/twenty-front/src/modules/command-menu/states/commandMenuPageState.ts create mode 100644 packages/twenty-front/src/modules/command-menu/states/commandMenuViewableRecordIdState.ts 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 66b152f4665b..8d4ba17d467a 100644 --- a/packages/twenty-front/src/modules/command-menu/components/CommandMenu.tsx +++ b/packages/twenty-front/src/modules/command-menu/components/CommandMenu.tsx @@ -1,23 +1,19 @@ import { CommandGroup } from '@/command-menu/components/CommandGroup'; import { CommandMenuDefaultSelectionEffect } from '@/command-menu/components/CommandMenuDefaultSelectionEffect'; import { CommandMenuItem } from '@/command-menu/components/CommandMenuItem'; -import { CommandMenuTopBar } from '@/command-menu/components/CommandMenuTopBar'; import { COMMAND_MENU_SEARCH_BAR_HEIGHT } from '@/command-menu/constants/CommandMenuSearchBarHeight'; import { COMMAND_MENU_SEARCH_BAR_PADDING } from '@/command-menu/constants/CommandMenuSearchBarPadding'; import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu'; -import { useCommandMenuHotKeys } from '@/command-menu/hooks/useCommandMenuHotKeys'; import { useMatchingCommandMenuCommands } from '@/command-menu/hooks/useMatchingCommandMenuCommands'; import { commandMenuSearchState } from '@/command-menu/states/commandMenuSearchState'; import { Command } from '@/command-menu/types/Command'; import { SelectableItem } from '@/ui/layout/selectable-list/components/SelectableItem'; import { SelectableList } from '@/ui/layout/selectable-list/components/SelectableList'; import { AppHotkeyScope } from '@/ui/utilities/hotkey/types/AppHotkeyScope'; -import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside'; import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile'; import { ScrollWrapper } from '@/ui/utilities/scroll/components/ScrollWrapper'; import styled from '@emotion/styled'; -import { useRef } from 'react'; -import { useRecoilState } from 'recoil'; +import { useRecoilValue } from 'recoil'; import { isDefined } from 'twenty-ui'; const MOBILE_NAVIGATION_BAR_HEIGHT = 64; @@ -27,21 +23,6 @@ type CommandGroupConfig = { items?: Command[]; }; -const StyledCommandMenu = styled.div` - background: ${({ theme }) => theme.background.secondary}; - border-left: 1px solid ${({ theme }) => theme.border.color.medium}; - box-shadow: ${({ theme }) => theme.boxShadow.strong}; - font-family: ${({ theme }) => theme.font.family}; - height: 100%; - overflow: hidden; - padding: 0; - position: fixed; - right: 0%; - top: 0%; - width: ${() => (useIsMobile() ? '100%' : '500px')}; - z-index: 1000; -`; - const StyledList = styled.div` background: ${({ theme }) => theme.background.secondary}; overscroll-behavior: contain; @@ -75,24 +56,12 @@ const StyledEmpty = styled.div` `; export const CommandMenu = () => { - const { onItemClick, closeCommandMenu } = useCommandMenu(); - const commandMenuRef = useRef(null); + const { onItemClick } = useCommandMenu(); - const [commandMenuSearch, setCommandMenuSearch] = useRecoilState( - commandMenuSearchState, - ); + const commandMenuSearch = useRecoilValue(commandMenuSearchState); const isMobile = useIsMobile(); - useCommandMenuHotKeys(); - - useListenClickOutside({ - refs: [commandMenuRef], - callback: closeCommandMenu, - listenerId: 'COMMAND_MENU_LISTENER_ID', - hotkeyScope: AppHotkeyScope.CommandMenuOpen, - }); - const { isNoResults, isLoading, @@ -184,74 +153,66 @@ export const CommandMenu = () => { - - - - - - { - const command = selectableItems.find( - (item) => item.id === itemId, - ); - - if (isDefined(command)) { - const { - to, - onCommandClick, - shouldCloseCommandMenuOnClick, - } = command; - onItemClick({ - shouldCloseCommandMenuOnClick, - onClick: onCommandClick, - to, - }); - } - }} - > - {isNoResults && !isLoading && ( - No results found - )} - {commandGroups.map(({ heading, items }) => - items?.length ? ( - - {items.map((item) => { - return ( - - - - ); - })} - - ) : null, - )} - - - - - + + + + { + const command = selectableItems.find( + (item) => item.id === itemId, + ); + + if (isDefined(command)) { + const { to, onCommandClick, shouldCloseCommandMenuOnClick } = + command; + + onItemClick({ + shouldCloseCommandMenuOnClick, + onClick: onCommandClick, + to, + }); + } + }} + > + {isNoResults && !isLoading && ( + No results found + )} + {commandGroups.map(({ heading, items }) => + items?.length ? ( + + {items.map((item) => { + return ( + + + + ); + })} + + ) : null, + )} + + + + ); }; diff --git a/packages/twenty-front/src/modules/command-menu/components/CommandMenuContainer.tsx b/packages/twenty-front/src/modules/command-menu/components/CommandMenuContainer.tsx index fe3802cd00e4..4b07986a1ab5 100644 --- a/packages/twenty-front/src/modules/command-menu/components/CommandMenuContainer.tsx +++ b/packages/twenty-front/src/modules/command-menu/components/CommandMenuContainer.tsx @@ -3,35 +3,56 @@ import { RecordAgnosticActionsSetterEffect } from '@/action-menu/actions/record- import { ActionMenuConfirmationModals } from '@/action-menu/components/ActionMenuConfirmationModals'; import { ActionMenuContext } from '@/action-menu/contexts/ActionMenuContext'; import { ActionMenuComponentInstanceContext } from '@/action-menu/states/contexts/ActionMenuComponentInstanceContext'; -import { CommandMenu } from '@/command-menu/components/CommandMenu'; import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu'; +import { useCommandMenuHotKeys } from '@/command-menu/hooks/useCommandMenuHotKeys'; import { isCommandMenuOpenedState } from '@/command-menu/states/isCommandMenuOpenedState'; import { ContextStoreComponentInstanceContext } from '@/context-store/states/contexts/ContextStoreComponentInstanceContext'; -import { useKeyboardShortcutMenu } from '@/keyboard-shortcut-menu/hooks/useKeyboardShortcutMenu'; -import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys'; import { AppHotkeyScope } from '@/ui/utilities/hotkey/types/AppHotkeyScope'; +import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside'; import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled'; +import styled from '@emotion/styled'; +import { useRef } from 'react'; import { useRecoilValue } from 'recoil'; +import { useIsMobile } from 'twenty-ui'; import { FeatureFlagKey } from '~/generated/graphql'; -export const CommandMenuContainer = () => { - const { toggleCommandMenu } = useCommandMenu(); - const { closeKeyboardShortcutMenu } = useKeyboardShortcutMenu(); +const StyledCommandMenu = styled.div` + background: ${({ theme }) => theme.background.secondary}; + border-left: 1px solid ${({ theme }) => theme.border.color.medium}; + box-shadow: ${({ theme }) => theme.boxShadow.strong}; + font-family: ${({ theme }) => theme.font.family}; + height: 100%; + overflow: hidden; + padding: 0; + position: fixed; + right: 0%; + top: 0%; + width: ${() => (useIsMobile() ? '100%' : '500px')}; + z-index: 1000; +`; + +export const CommandMenuContainer = ({ + children, +}: { + children: React.ReactNode; +}) => { + const { toggleCommandMenu, closeCommandMenu } = useCommandMenu(); const isWorkflowEnabled = useIsFeatureEnabled( FeatureFlagKey.IsWorkflowEnabled, ); const isCommandMenuOpened = useRecoilValue(isCommandMenuOpenedState); - useScopedHotkeys( - 'ctrl+k,meta+k', - () => { - closeKeyboardShortcutMenu(); - toggleCommandMenu(); - }, - AppHotkeyScope.CommandMenu, - [toggleCommandMenu], - ); + const commandMenuRef = useRef(null); + + useCommandMenuHotKeys(); + + useListenClickOutside({ + refs: [commandMenuRef], + callback: closeCommandMenu, + listenerId: 'COMMAND_MENU_LISTENER_ID', + hotkeyScope: AppHotkeyScope.CommandMenuOpen, + }); return ( { {isWorkflowEnabled && } - {isCommandMenuOpened && } + {isCommandMenuOpened && ( + + {children} + + )} diff --git a/packages/twenty-front/src/modules/command-menu/components/CommandMenuPages.ts b/packages/twenty-front/src/modules/command-menu/components/CommandMenuPages.ts new file mode 100644 index 000000000000..e783f76dee70 --- /dev/null +++ b/packages/twenty-front/src/modules/command-menu/components/CommandMenuPages.ts @@ -0,0 +1,4 @@ +export enum CommandMenuPages { + Root = 'root', + ViewRecord = 'view-record', +} diff --git a/packages/twenty-front/src/modules/command-menu/components/CommandMenuRouter.tsx b/packages/twenty-front/src/modules/command-menu/components/CommandMenuRouter.tsx new file mode 100644 index 000000000000..9c90f6e471fc --- /dev/null +++ b/packages/twenty-front/src/modules/command-menu/components/CommandMenuRouter.tsx @@ -0,0 +1,23 @@ +import { CommandMenuContainer } from '@/command-menu/components/CommandMenuContainer'; +import { CommandMenuTopBar } from '@/command-menu/components/CommandMenuTopBar'; +import { COMMAND_MENU_PAGES_CONFIG } from '@/command-menu/constants/CommandMenuPagesConfig'; +import { commandMenuPageState } from '@/command-menu/states/commandMenuPageState'; +import { useRecoilValue } from 'recoil'; +import { isDefined } from 'twenty-ui'; + +export const CommandMenuRouter = () => { + const commandMenuPage = useRecoilValue(commandMenuPageState); + + const commandMenuPageComponent = isDefined(commandMenuPage) ? ( + COMMAND_MENU_PAGES_CONFIG.get(commandMenuPage) + ) : ( + <> + ); + + return ( + + + {commandMenuPageComponent} + + ); +}; diff --git a/packages/twenty-front/src/modules/command-menu/components/CommandMenuShowPage.tsx b/packages/twenty-front/src/modules/command-menu/components/CommandMenuShowPage.tsx new file mode 100644 index 000000000000..dfafe3c6f137 --- /dev/null +++ b/packages/twenty-front/src/modules/command-menu/components/CommandMenuShowPage.tsx @@ -0,0 +1,10 @@ +import { commandMenuViewableRecordIdState } from '@/command-menu/states/commandMenuViewableRecordIdState'; +import { useRecoilValue } from 'recoil'; + +export const CommandMenuShowPage = () => { + const commandMenuViewableRecordId = useRecoilValue( + commandMenuViewableRecordIdState, + ); + + return
{commandMenuViewableRecordId}
; +}; diff --git a/packages/twenty-front/src/modules/command-menu/components/CommandMenuTopBar.tsx b/packages/twenty-front/src/modules/command-menu/components/CommandMenuTopBar.tsx index 4bb2bc9040fe..47cd9459a8f2 100644 --- a/packages/twenty-front/src/modules/command-menu/components/CommandMenuTopBar.tsx +++ b/packages/twenty-front/src/modules/command-menu/components/CommandMenuTopBar.tsx @@ -2,9 +2,11 @@ import { CommandMenuContextRecordChip } from '@/command-menu/components/CommandM import { COMMAND_MENU_SEARCH_BAR_HEIGHT } from '@/command-menu/constants/CommandMenuSearchBarHeight'; import { COMMAND_MENU_SEARCH_BAR_PADDING } from '@/command-menu/constants/CommandMenuSearchBarPadding'; import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu'; +import { commandMenuSearchState } from '@/command-menu/states/commandMenuSearchState'; import { contextStoreCurrentObjectMetadataIdComponentState } from '@/context-store/states/contextStoreCurrentObjectMetadataIdComponentState'; import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2'; import styled from '@emotion/styled'; +import { useRecoilState } from 'recoil'; import { IconX, LightIconButton, isDefined, useIsMobile } from 'twenty-ui'; const StyledInputContainer = styled.div` @@ -50,15 +52,11 @@ const StyledCloseButtonContainer = styled.div` justify-content: center; `; -type CommandMenuTopBarProps = { - commandMenuSearch: string; - setCommandMenuSearch: (search: string) => void; -}; +export const CommandMenuTopBar = () => { + const [commandMenuSearch, setCommandMenuSearch] = useRecoilState( + commandMenuSearchState, + ); -export const CommandMenuTopBar = ({ - commandMenuSearch, - setCommandMenuSearch, -}: CommandMenuTopBarProps) => { const handleSearchChange = (event: React.ChangeEvent) => { setCommandMenuSearch(event.target.value); }; diff --git a/packages/twenty-front/src/modules/command-menu/constants/CommandMenuPagesConfig.tsx b/packages/twenty-front/src/modules/command-menu/constants/CommandMenuPagesConfig.tsx new file mode 100644 index 000000000000..81a753197b4b --- /dev/null +++ b/packages/twenty-front/src/modules/command-menu/constants/CommandMenuPagesConfig.tsx @@ -0,0 +1,11 @@ +import { CommandMenu } from '@/command-menu/components/CommandMenu'; +import { CommandMenuPages } from '@/command-menu/components/CommandMenuPages'; +import { CommandMenuShowPage } from '@/command-menu/components/CommandMenuShowPage'; + +export const COMMAND_MENU_PAGES_CONFIG = new Map< + CommandMenuPages, + React.ReactNode +>([ + [CommandMenuPages.Root, ], + [CommandMenuPages.ViewRecord, ], +]); diff --git a/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenu.ts b/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenu.ts index 3b32e5a6e1c8..9246e53203a4 100644 --- a/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenu.ts +++ b/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenu.ts @@ -10,6 +10,7 @@ import { AppHotkeyScope } from '@/ui/utilities/hotkey/types/AppHotkeyScope'; import { isDefined } from '~/utils/isDefined'; import { actionMenuEntriesComponentState } from '@/action-menu/states/actionMenuEntriesComponentState'; +import { commandMenuViewableRecordIdState } from '@/command-menu/states/commandMenuViewableRecordIdState'; import { contextStoreCurrentObjectMetadataIdComponentState } from '@/context-store/states/contextStoreCurrentObjectMetadataIdComponentState'; import { contextStoreCurrentViewIdComponentState } from '@/context-store/states/contextStoreCurrentViewIdComponentState'; import { contextStoreCurrentViewTypeComponentState } from '@/context-store/states/contextStoreCurrentViewTypeComponentState'; @@ -212,6 +213,7 @@ export const useCommandMenu = () => { ); if (isCommandMenuOpened) { + set(commandMenuViewableRecordIdState, null); setIsCommandMenuOpened(false); resetSelectedItem(); goBackToPreviousHotkeyScope(); diff --git a/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenuHotKeys.ts b/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenuHotKeys.ts index f905b29ceec6..d237a4f41f66 100644 --- a/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenuHotKeys.ts +++ b/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenuHotKeys.ts @@ -2,6 +2,7 @@ import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu'; import { commandMenuSearchState } from '@/command-menu/states/commandMenuSearchState'; import { contextStoreNumberOfSelectedRecordsComponentState } from '@/context-store/states/contextStoreNumberOfSelectedRecordsComponentState'; import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState'; +import { useKeyboardShortcutMenu } from '@/keyboard-shortcut-menu/hooks/useKeyboardShortcutMenu'; import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys'; import { AppHotkeyScope } from '@/ui/utilities/hotkey/types/AppHotkeyScope'; import { useSetRecoilComponentStateV2 } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentStateV2'; @@ -10,7 +11,7 @@ import { useRecoilValue } from 'recoil'; import { Key } from 'ts-key-enum'; export const useCommandMenuHotKeys = () => { - const { closeCommandMenu } = useCommandMenu(); + const { closeCommandMenu, toggleCommandMenu } = useCommandMenu(); const commandMenuSearch = useRecoilValue(commandMenuSearchState); @@ -24,6 +25,18 @@ export const useCommandMenuHotKeys = () => { 'command-menu', ); + const { closeKeyboardShortcutMenu } = useKeyboardShortcutMenu(); + + useScopedHotkeys( + 'ctrl+k,meta+k', + () => { + closeKeyboardShortcutMenu(); + toggleCommandMenu(); + }, + AppHotkeyScope.CommandMenu, + [toggleCommandMenu], + ); + useScopedHotkeys( [Key.Escape], () => { diff --git a/packages/twenty-front/src/modules/command-menu/states/commandMenuPageState.ts b/packages/twenty-front/src/modules/command-menu/states/commandMenuPageState.ts new file mode 100644 index 000000000000..d5a41917d217 --- /dev/null +++ b/packages/twenty-front/src/modules/command-menu/states/commandMenuPageState.ts @@ -0,0 +1,7 @@ +import { CommandMenuPages } from '@/command-menu/components/CommandMenuPages'; +import { createState } from '@ui/utilities/state/utils/createState'; + +export const commandMenuPageState = createState({ + key: 'command-menu/commandMenuPageState', + defaultValue: CommandMenuPages.Root, +}); diff --git a/packages/twenty-front/src/modules/command-menu/states/commandMenuViewableRecordIdState.ts b/packages/twenty-front/src/modules/command-menu/states/commandMenuViewableRecordIdState.ts new file mode 100644 index 000000000000..25a45175de22 --- /dev/null +++ b/packages/twenty-front/src/modules/command-menu/states/commandMenuViewableRecordIdState.ts @@ -0,0 +1,6 @@ +import { atom } from 'recoil'; + +export const commandMenuViewableRecordIdState = atom({ + key: 'command-menu/commandMenuViewableRecordIdState', + default: null, +}); diff --git a/packages/twenty-front/src/modules/ui/layout/page/components/DefaultLayout.tsx b/packages/twenty-front/src/modules/ui/layout/page/components/DefaultLayout.tsx index d39531099976..00c966ba257c 100644 --- a/packages/twenty-front/src/modules/ui/layout/page/components/DefaultLayout.tsx +++ b/packages/twenty-front/src/modules/ui/layout/page/components/DefaultLayout.tsx @@ -1,5 +1,5 @@ import { AuthModal } from '@/auth/components/AuthModal'; -import { CommandMenuContainer } from '@/command-menu/components/CommandMenuContainer'; +import { CommandMenuRouter } from '@/command-menu/components/CommandMenuRouter'; import { AppErrorBoundary } from '@/error-handler/components/AppErrorBoundary'; import { KeyboardShortcutMenu } from '@/keyboard-shortcut-menu/components/KeyboardShortcutMenu'; import { AppNavigationDrawer } from '@/navigation/components/AppNavigationDrawer'; @@ -82,7 +82,7 @@ export const DefaultLayout = () => { {!showAuthModal && ( <> - + )} From 50c000bb61a4467ed9b012a99a121e217d83a9ea Mon Sep 17 00:00:00 2001 From: bosiraphael Date: Tue, 7 Jan 2025 14:57:14 +0100 Subject: [PATCH 02/22] Add openRecordInCommandMenu to useCommandMenu --- .../command-menu/hooks/useCommandMenu.ts | 19 +++++++++++++++++-- .../commandMenuViewableRecordIdState.ts | 6 ------ 2 files changed, 17 insertions(+), 8 deletions(-) delete mode 100644 packages/twenty-front/src/modules/command-menu/states/commandMenuViewableRecordIdState.ts diff --git a/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenu.ts b/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenu.ts index 9246e53203a4..58e595a7de58 100644 --- a/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenu.ts +++ b/packages/twenty-front/src/modules/command-menu/hooks/useCommandMenu.ts @@ -10,7 +10,8 @@ import { AppHotkeyScope } from '@/ui/utilities/hotkey/types/AppHotkeyScope'; import { isDefined } from '~/utils/isDefined'; import { actionMenuEntriesComponentState } from '@/action-menu/states/actionMenuEntriesComponentState'; -import { commandMenuViewableRecordIdState } from '@/command-menu/states/commandMenuViewableRecordIdState'; +import { CommandMenuPages } from '@/command-menu/components/CommandMenuPages'; +import { commandMenuPageState } from '@/command-menu/states/commandMenuPageState'; import { contextStoreCurrentObjectMetadataIdComponentState } from '@/context-store/states/contextStoreCurrentObjectMetadataIdComponentState'; import { contextStoreCurrentViewIdComponentState } from '@/context-store/states/contextStoreCurrentViewIdComponentState'; import { contextStoreCurrentViewTypeComponentState } from '@/context-store/states/contextStoreCurrentViewTypeComponentState'; @@ -18,6 +19,7 @@ import { contextStoreFiltersComponentState } from '@/context-store/states/contex import { contextStoreNumberOfSelectedRecordsComponentState } from '@/context-store/states/contextStoreNumberOfSelectedRecordsComponentState'; import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState'; import { mainContextStoreComponentInstanceIdState } from '@/context-store/states/mainContextStoreComponentInstanceId'; +import { viewableRecordIdState } from '@/object-record/record-right-drawer/states/viewableRecordIdState'; import { isCommandMenuOpenedState } from '../states/isCommandMenuOpenedState'; export const useCommandMenu = () => { @@ -213,7 +215,8 @@ export const useCommandMenu = () => { ); if (isCommandMenuOpened) { - set(commandMenuViewableRecordIdState, null); + set(viewableRecordIdState, null); + set(commandMenuPageState, CommandMenuPages.Root); setIsCommandMenuOpened(false); resetSelectedItem(); goBackToPreviousHotkeyScope(); @@ -269,9 +272,21 @@ export const useCommandMenu = () => { [navigate, toggleCommandMenu], ); + const openRecordInCommandMenu = useRecoilCallback( + ({ set }) => { + return (recordId: string) => { + openCommandMenu(); + set(commandMenuPageState, CommandMenuPages.ViewRecord); + set(viewableRecordIdState, recordId); + }; + }, + [openCommandMenu], + ); + return { openCommandMenu, closeCommandMenu, + openRecordInCommandMenu, toggleCommandMenu, onItemClick, }; diff --git a/packages/twenty-front/src/modules/command-menu/states/commandMenuViewableRecordIdState.ts b/packages/twenty-front/src/modules/command-menu/states/commandMenuViewableRecordIdState.ts deleted file mode 100644 index 25a45175de22..000000000000 --- a/packages/twenty-front/src/modules/command-menu/states/commandMenuViewableRecordIdState.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { atom } from 'recoil'; - -export const commandMenuViewableRecordIdState = atom({ - key: 'command-menu/commandMenuViewableRecordIdState', - default: null, -}); From 30c10cdd3dd2fa5312af93a06ad1451b53eca345 Mon Sep 17 00:00:00 2001 From: bosiraphael Date: Tue, 7 Jan 2025 15:31:33 +0100 Subject: [PATCH 03/22] update feature flag --- .../src/generated-metadata/graphql.ts | 15 ++++++++++++++- packages/twenty-front/src/generated/graphql.tsx | 2 +- .../components/RecordActionMenuEntriesSetter.tsx | 6 +++--- .../action-menu/actions/utils/getActionConfig.ts | 4 ++-- .../components/RecordIndexActionMenu.tsx | 6 +++--- .../components/RecordShowActionMenu.tsx | 6 +++--- .../components/CommandMenuShowPage.tsx | 10 ---------- .../constants/CommandMenuPagesConfig.tsx | 4 ++-- .../favorites/components/PageFavoriteButton.tsx | 6 +++--- .../components/RecordIndexContainer.tsx | 6 +++--- .../components/RecordIndexPageHeader.tsx | 8 ++++---- .../PageHeaderOpenCommandMenuButton.tsx | 6 +++--- .../ui/layout/page/components/PageAddButton.tsx | 6 +++--- .../ui/layout/page/components/PageHeader.tsx | 6 +++--- .../show-page/components/ShowPageAddButton.tsx | 6 +++--- .../src/pages/object-record/RecordShowPage.tsx | 10 +++++----- .../database/typeorm-seeds/core/feature-flags.ts | 2 +- .../feature-flag/enums/feature-flag-key.enum.ts | 2 +- 18 files changed, 57 insertions(+), 54 deletions(-) delete mode 100644 packages/twenty-front/src/modules/command-menu/components/CommandMenuShowPage.tsx diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.ts index 417a5c9696d1..96d10ecb6679 100644 --- a/packages/twenty-front/src/generated-metadata/graphql.ts +++ b/packages/twenty-front/src/generated-metadata/graphql.ts @@ -199,6 +199,13 @@ export type CreateAppTokenInput = { expiresAt: Scalars['DateTime']['input']; }; +export type CreateDraftFromWorkflowVersionInput = { + /** Workflow ID */ + workflowId: Scalars['String']['input']; + /** Workflow version ID */ + workflowVersionIdToCopy: Scalars['String']['input']; +}; + export type CreateFieldInput = { defaultValue?: InputMaybe; description?: InputMaybe; @@ -387,6 +394,7 @@ export enum FeatureFlagKey { IsAggregateQueryEnabled = 'IsAggregateQueryEnabled', IsAirtableIntegrationEnabled = 'IsAirtableIntegrationEnabled', IsAnalyticsV2Enabled = 'IsAnalyticsV2Enabled', + IsCommandMenuV2Enabled = 'IsCommandMenuV2Enabled', IsCopilotEnabled = 'IsCopilotEnabled', IsCrmMigrationEnabled = 'IsCrmMigrationEnabled', IsEventObjectEnabled = 'IsEventObjectEnabled', @@ -395,7 +403,6 @@ export enum FeatureFlagKey { IsGmailSendEmailScopeEnabled = 'IsGmailSendEmailScopeEnabled', IsJsonFilterEnabled = 'IsJsonFilterEnabled', IsMicrosoftSyncEnabled = 'IsMicrosoftSyncEnabled', - IsPageHeaderV2Enabled = 'IsPageHeaderV2Enabled', IsPostgreSqlIntegrationEnabled = 'IsPostgreSQLIntegrationEnabled', IsSsoEnabled = 'IsSSOEnabled', IsStripeIntegrationEnabled = 'IsStripeIntegrationEnabled', @@ -579,6 +586,7 @@ export type Mutation = { challenge: LoginToken; checkoutSession: SessionEntity; computeStepOutputSchema: Scalars['JSON']['output']; + createDraftFromWorkflowVersion: Scalars['Boolean']['output']; createOIDCIdentityProvider: SetupSsoOutput; createOneAppToken: AppToken; createOneField: Field; @@ -685,6 +693,11 @@ export type MutationComputeStepOutputSchemaArgs = { }; +export type MutationCreateDraftFromWorkflowVersionArgs = { + input: CreateDraftFromWorkflowVersionInput; +}; + + export type MutationCreateOidcIdentityProviderArgs = { input: SetupOidcSsoInput; }; diff --git a/packages/twenty-front/src/generated/graphql.tsx b/packages/twenty-front/src/generated/graphql.tsx index 1bd6c5271464..ecc79a5e5a35 100644 --- a/packages/twenty-front/src/generated/graphql.tsx +++ b/packages/twenty-front/src/generated/graphql.tsx @@ -324,6 +324,7 @@ export enum FeatureFlagKey { IsAggregateQueryEnabled = 'IsAggregateQueryEnabled', IsAirtableIntegrationEnabled = 'IsAirtableIntegrationEnabled', IsAnalyticsV2Enabled = 'IsAnalyticsV2Enabled', + IsCommandMenuV2Enabled = 'IsCommandMenuV2Enabled', IsCopilotEnabled = 'IsCopilotEnabled', IsCrmMigrationEnabled = 'IsCrmMigrationEnabled', IsEventObjectEnabled = 'IsEventObjectEnabled', @@ -332,7 +333,6 @@ export enum FeatureFlagKey { IsGmailSendEmailScopeEnabled = 'IsGmailSendEmailScopeEnabled', IsJsonFilterEnabled = 'IsJsonFilterEnabled', IsMicrosoftSyncEnabled = 'IsMicrosoftSyncEnabled', - IsPageHeaderV2Enabled = 'IsPageHeaderV2Enabled', IsPostgreSqlIntegrationEnabled = 'IsPostgreSQLIntegrationEnabled', IsSsoEnabled = 'IsSSOEnabled', IsStripeIntegrationEnabled = 'IsStripeIntegrationEnabled', diff --git a/packages/twenty-front/src/modules/action-menu/actions/record-actions/components/RecordActionMenuEntriesSetter.tsx b/packages/twenty-front/src/modules/action-menu/actions/record-actions/components/RecordActionMenuEntriesSetter.tsx index 5ae6cf1d6bd6..15f8d08502ba 100644 --- a/packages/twenty-front/src/modules/action-menu/actions/record-actions/components/RecordActionMenuEntriesSetter.tsx +++ b/packages/twenty-front/src/modules/action-menu/actions/record-actions/components/RecordActionMenuEntriesSetter.tsx @@ -35,8 +35,8 @@ export const RecordActionMenuEntriesSetter = () => { FeatureFlagKey.IsWorkflowEnabled, ); - const isPageHeaderV2Enabled = useIsFeatureEnabled( - FeatureFlagKey.IsPageHeaderV2Enabled, + const isCommandMenuV2Enabled = useIsFeatureEnabled( + FeatureFlagKey.IsCommandMenuV2Enabled, ); if ( @@ -53,7 +53,7 @@ export const RecordActionMenuEntriesSetter = () => { const actionConfig = getActionConfig( objectMetadataItem, - isPageHeaderV2Enabled, + isCommandMenuV2Enabled, ); const actionsToRegister = isDefined(viewType) diff --git a/packages/twenty-front/src/modules/action-menu/actions/utils/getActionConfig.ts b/packages/twenty-front/src/modules/action-menu/actions/utils/getActionConfig.ts index 9d2cd4b216cf..c63566edaa6b 100644 --- a/packages/twenty-front/src/modules/action-menu/actions/utils/getActionConfig.ts +++ b/packages/twenty-front/src/modules/action-menu/actions/utils/getActionConfig.ts @@ -8,7 +8,7 @@ import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; export const getActionConfig = ( objectMetadataItem: ObjectMetadataItem, - isPageHeaderV2Enabled: boolean, + isCommandMenuV2Enabled: boolean, ) => { switch (objectMetadataItem.nameSingular) { case CoreObjectNameSingular.Workflow: @@ -18,7 +18,7 @@ export const getActionConfig = ( case CoreObjectNameSingular.WorkflowRun: return WORKFLOW_RUNS_ACTIONS_CONFIG; default: - return isPageHeaderV2Enabled + return isCommandMenuV2Enabled ? DEFAULT_ACTIONS_CONFIG_V2 : DEFAULT_ACTIONS_CONFIG_V1; } diff --git a/packages/twenty-front/src/modules/action-menu/components/RecordIndexActionMenu.tsx b/packages/twenty-front/src/modules/action-menu/components/RecordIndexActionMenu.tsx index 835322427d3b..2590dadd2465 100644 --- a/packages/twenty-front/src/modules/action-menu/components/RecordIndexActionMenu.tsx +++ b/packages/twenty-front/src/modules/action-menu/components/RecordIndexActionMenu.tsx @@ -25,8 +25,8 @@ export const RecordIndexActionMenu = ({ indexId }: { indexId: string }) => { FeatureFlagKey.IsWorkflowEnabled, ); - const isPageHeaderV2Enabled = useIsFeatureEnabled( - FeatureFlagKey.IsPageHeaderV2Enabled, + const isCommandMenuV2Enabled = useIsFeatureEnabled( + FeatureFlagKey.IsCommandMenuV2Enabled, ); const isMobile = useIsMobile(); @@ -54,7 +54,7 @@ export const RecordIndexActionMenu = ({ indexId }: { indexId: string }) => { }, }} > - {isPageHeaderV2Enabled ? ( + {isCommandMenuV2Enabled ? ( <>{!isMobile && } ) : ( diff --git a/packages/twenty-front/src/modules/action-menu/components/RecordShowActionMenu.tsx b/packages/twenty-front/src/modules/action-menu/components/RecordShowActionMenu.tsx index a1df8e65518c..3d032945b3ed 100644 --- a/packages/twenty-front/src/modules/action-menu/components/RecordShowActionMenu.tsx +++ b/packages/twenty-front/src/modules/action-menu/components/RecordShowActionMenu.tsx @@ -33,8 +33,8 @@ export const RecordShowActionMenu = ({ FeatureFlagKey.IsWorkflowEnabled, ); - const isPageHeaderV2Enabled = useIsFeatureEnabled( - FeatureFlagKey.IsPageHeaderV2Enabled, + const isCommandMenuV2Enabled = useIsFeatureEnabled( + FeatureFlagKey.IsCommandMenuV2Enabled, ); // TODO: refactor RecordShowPageBaseHeader to use the context store @@ -48,7 +48,7 @@ export const RecordShowActionMenu = ({ onActionExecutedCallback: () => {}, }} > - {isPageHeaderV2Enabled ? ( + {isCommandMenuV2Enabled ? ( ) : ( { - const commandMenuViewableRecordId = useRecoilValue( - commandMenuViewableRecordIdState, - ); - - return
{commandMenuViewableRecordId}
; -}; diff --git a/packages/twenty-front/src/modules/command-menu/constants/CommandMenuPagesConfig.tsx b/packages/twenty-front/src/modules/command-menu/constants/CommandMenuPagesConfig.tsx index 81a753197b4b..ca1a09097ddc 100644 --- a/packages/twenty-front/src/modules/command-menu/constants/CommandMenuPagesConfig.tsx +++ b/packages/twenty-front/src/modules/command-menu/constants/CommandMenuPagesConfig.tsx @@ -1,11 +1,11 @@ import { CommandMenu } from '@/command-menu/components/CommandMenu'; import { CommandMenuPages } from '@/command-menu/components/CommandMenuPages'; -import { CommandMenuShowPage } from '@/command-menu/components/CommandMenuShowPage'; +import { RightDrawerRecord } from '@/object-record/record-right-drawer/components/RightDrawerRecord'; export const COMMAND_MENU_PAGES_CONFIG = new Map< CommandMenuPages, React.ReactNode >([ [CommandMenuPages.Root, ], - [CommandMenuPages.ViewRecord, ], + [CommandMenuPages.ViewRecord, ], ]); diff --git a/packages/twenty-front/src/modules/favorites/components/PageFavoriteButton.tsx b/packages/twenty-front/src/modules/favorites/components/PageFavoriteButton.tsx index 3ab95cd67e83..100abe308da9 100644 --- a/packages/twenty-front/src/modules/favorites/components/PageFavoriteButton.tsx +++ b/packages/twenty-front/src/modules/favorites/components/PageFavoriteButton.tsx @@ -13,13 +13,13 @@ export const PageFavoriteButton = ({ }: PageFavoriteButtonProps) => { const title = isFavorite ? 'Remove from favorites' : 'Add to favorites'; - const isPageHeaderV2Enabled = useIsFeatureEnabled( - FeatureFlagKey.IsPageHeaderV2Enabled, + const isCommandMenuV2Enabled = useIsFeatureEnabled( + FeatureFlagKey.IsCommandMenuV2Enabled, ); return ( <> - {isPageHeaderV2Enabled ? ( + {isCommandMenuV2Enabled ? (