Files
twenty/packages/twenty-front/src/modules/action-menu/contexts/ActionMenuContextProviderWorkflowsEnabled.tsx
Raphaël Bosi ace515eea7 Fix workflow with manual triggers and no selection not appearing in the command menu (#11544)
Fix workflow with manual triggers and no selection not appearing in the
command menu

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
2025-04-14 11:03:29 +02:00

75 lines
2.6 KiB
TypeScript

import { useRunWorkflowRecordActions } from '@/action-menu/actions/record-actions/run-workflow-actions/hooks/useRunWorkflowRecordActions';
import { useRunWorkflowRecordAgnosticActions } from '@/action-menu/actions/record-agnostic-actions/run-workflow-actions/hooks/useRunWorkflowRecordAgnosticActions';
import {
ActionMenuContext,
ActionMenuContextType,
} from '@/action-menu/contexts/ActionMenuContext';
import { useRegisteredActions } from '@/action-menu/hooks/useRegisteredActions';
import { useShouldActionBeRegisteredParams } from '@/action-menu/hooks/useShouldActionBeRegisteredParams';
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
export const ActionMenuContextProviderWorkflowsEnabled = ({
objectMetadataItem,
isInRightDrawer,
displayType,
actionMenuType,
children,
}: {
objectMetadataItem: ObjectMetadataItem;
isInRightDrawer: ActionMenuContextType['isInRightDrawer'];
displayType: ActionMenuContextType['displayType'];
actionMenuType: ActionMenuContextType['actionMenuType'];
children: React.ReactNode;
}) => {
const params = useShouldActionBeRegisteredParams({
objectMetadataItem,
});
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(
params.selectedRecord?.id,
);
const shouldBeRegisteredParams = {
...params,
workflowWithCurrentVersion,
};
const actions = useRegisteredActions(shouldBeRegisteredParams);
const contextStoreTargetedRecordsRule = useRecoilComponentValueV2(
contextStoreTargetedRecordsRuleComponentState,
);
const isSingleRecordSelection =
contextStoreTargetedRecordsRule.mode === 'selection' &&
contextStoreTargetedRecordsRule.selectedRecordIds.length === 1;
const runWorkflowRecordActions = useRunWorkflowRecordActions({
objectMetadataItem,
skip: !isSingleRecordSelection,
});
const runWorkflowRecordAgnosticActions =
useRunWorkflowRecordAgnosticActions();
return (
<ActionMenuContext.Provider
value={{
isInRightDrawer,
displayType,
actionMenuType,
actions: [
...actions,
...runWorkflowRecordActions,
...runWorkflowRecordAgnosticActions,
],
}}
>
{children}
</ActionMenuContext.Provider>
);
};