Files
twenty/packages/twenty-front/src/modules/action-menu/contexts/ActionMenuContextProviderWorkflowsEnabled.tsx
Charles Bochet 0316c857d8 Remove unwanted workflow fetch on right drawer open (#13122)
There was a mistake in the ActionConfig load, we were trying to fetch a
workflow with the opened recordId (which is not always a workflow)
2025-07-09 13:12:46 +02:00

69 lines
2.3 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';
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 shouldBeRegisteredParams = {
...params,
};
const actions = useRegisteredActions(shouldBeRegisteredParams);
const contextStoreTargetedRecordsRule = useRecoilComponentValueV2(
contextStoreTargetedRecordsRuleComponentState,
);
const isRecordSelection =
contextStoreTargetedRecordsRule.mode === 'selection' &&
contextStoreTargetedRecordsRule.selectedRecordIds.length > 0;
const runWorkflowRecordActions = useRunWorkflowRecordActions({
objectMetadataItem,
skip: !isRecordSelection,
});
const runWorkflowRecordAgnosticActions =
useRunWorkflowRecordAgnosticActions();
return (
<ActionMenuContext.Provider
value={{
isInRightDrawer,
displayType,
actionMenuType,
actions: [
...actions,
...runWorkflowRecordActions,
...runWorkflowRecordAgnosticActions,
],
}}
>
{children}
</ActionMenuContext.Provider>
);
};