Refactor: Unify command menu item execution (#18908)
- Makes engineComponentKey non-nullable on CommandMenuItem. Adds two new engine component keys: TRIGGER_WORKFLOW_VERSION and FRONT_COMPONENT_RENDERER to cover the former standalone cases. - Unifies the previously separated engine, front component and workflow runners into a single `CommandRunner` component with a unified `useMountCommand` hook that handles all command types.
This commit is contained in:
-60
@@ -1,60 +0,0 @@
|
||||
import { Suspense, lazy } from 'react';
|
||||
|
||||
import { CommandMenuItemErrorBoundary } from '@/command-menu-item/display/components/CommandMenuItemErrorBoundary';
|
||||
import { useUnmountHeadlessFrontComponent } from '@/front-components/hooks/useUnmountHeadlessFrontComponent';
|
||||
import { mountedHeadlessFrontComponentMapsState } from '@/front-components/states/mountedHeadlessFrontComponentMapsState';
|
||||
import { LayoutRenderingProvider } from '@/ui/layout/contexts/LayoutRenderingContext';
|
||||
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { PageLayoutType } from '~/generated-metadata/graphql';
|
||||
|
||||
const FrontComponentRenderer = lazy(() =>
|
||||
import('@/front-components/components/FrontComponentRenderer').then(
|
||||
(module) => ({ default: module.FrontComponentRenderer }),
|
||||
),
|
||||
);
|
||||
|
||||
export const HeadlessFrontComponentMountRoot = () => {
|
||||
const mountedHeadlessFrontComponentMaps = useAtomStateValue(
|
||||
mountedHeadlessFrontComponentMapsState,
|
||||
);
|
||||
|
||||
const unmountHeadlessFrontComponent = useUnmountHeadlessFrontComponent();
|
||||
|
||||
return (
|
||||
<>
|
||||
{[...mountedHeadlessFrontComponentMaps.entries()].map(
|
||||
([frontComponentId, mountContext]) => (
|
||||
<CommandMenuItemErrorBoundary
|
||||
key={frontComponentId}
|
||||
engineCommandId={frontComponentId}
|
||||
onError={() => unmountHeadlessFrontComponent(frontComponentId)}
|
||||
>
|
||||
<Suspense fallback={null}>
|
||||
<LayoutRenderingProvider
|
||||
value={{
|
||||
targetRecordIdentifier:
|
||||
isDefined(mountContext.objectNameSingular) &&
|
||||
isDefined(mountContext.recordId)
|
||||
? {
|
||||
id: mountContext.recordId,
|
||||
targetObjectNameSingular:
|
||||
mountContext.objectNameSingular,
|
||||
}
|
||||
: undefined,
|
||||
layoutType: PageLayoutType.DASHBOARD,
|
||||
isInSidePanel: false,
|
||||
}}
|
||||
>
|
||||
<FrontComponentRenderer
|
||||
frontComponentId={frontComponentId}
|
||||
commandMenuItemId={mountContext.commandMenuItemId}
|
||||
/>
|
||||
</LayoutRenderingProvider>
|
||||
</Suspense>
|
||||
</CommandMenuItemErrorBoundary>
|
||||
),
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user