mirror of
https://github.com/twentyhq/twenty.git
synced 2024-11-22 03:17:40 +03:00
add ActivateWorkflowActionEffect
This commit is contained in:
parent
e8a2b3e42f
commit
673876da0c
@ -1,6 +1,8 @@
|
||||
import { DeleteRecordsActionEffect } from '@/action-menu/actions/record-actions/components/DeleteRecordsActionEffect';
|
||||
import { ExportRecordsActionEffect } from '@/action-menu/actions/record-actions/components/ExportRecordsActionEffect';
|
||||
import { ManageFavoritesActionEffect } from '@/action-menu/actions/record-actions/components/ManageFavoritesActionEffect';
|
||||
import { ActivateWorkflowActionEffect } from '@/action-menu/actions/record-actions/workflow-actions/components/ActivateWorkflowActionEffect';
|
||||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { useRightDrawer } from '@/ui/layout/right-drawer/hooks/useRightDrawer';
|
||||
import { useMemo } from 'react';
|
||||
@ -35,9 +37,25 @@ export const SingleRecordActionMenuEntriesSetter = ({
|
||||
[isInRightDrawer, closeRightDrawer],
|
||||
);
|
||||
|
||||
const workflowActions = useMemo(() => {
|
||||
return [
|
||||
{
|
||||
ActionEffect: ActivateWorkflowActionEffect,
|
||||
onActionExecutedCallback: undefined,
|
||||
},
|
||||
];
|
||||
}, []);
|
||||
|
||||
const allActions = [
|
||||
...(objectMetadataItem.nameSingular === CoreObjectNameSingular.Workflow
|
||||
? workflowActions
|
||||
: []),
|
||||
...actions,
|
||||
];
|
||||
|
||||
return (
|
||||
<>
|
||||
{actions.map(({ ActionEffect, onActionExecutedCallback }, index) => (
|
||||
{allActions.map(({ ActionEffect, onActionExecutedCallback }, index) => (
|
||||
<ActionEffect
|
||||
key={index}
|
||||
position={index}
|
||||
|
@ -0,0 +1,74 @@
|
||||
import { useActionMenuEntries } from '@/action-menu/hooks/useActionMenuEntries';
|
||||
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
|
||||
import { useActivateWorkflowVersion } from '@/workflow/hooks/useActivateWorkflowVersion';
|
||||
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
||||
import { useEffect } from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { IconPower, isDefined } from 'twenty-ui';
|
||||
|
||||
export const ActivateWorkflowActionEffect = ({
|
||||
position,
|
||||
objectMetadataItem,
|
||||
}: {
|
||||
position: number;
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
}) => {
|
||||
const { addActionMenuEntry, removeActionMenuEntry } = useActionMenuEntries();
|
||||
|
||||
const contextStoreTargetedRecordsRule = useRecoilComponentValueV2(
|
||||
contextStoreTargetedRecordsRuleComponentState,
|
||||
);
|
||||
|
||||
const selectedRecordId =
|
||||
contextStoreTargetedRecordsRule.mode === 'selection'
|
||||
? contextStoreTargetedRecordsRule.selectedRecordIds[0]
|
||||
: undefined;
|
||||
|
||||
const selectedRecord = useRecoilValue(
|
||||
recordStoreFamilyState(selectedRecordId ?? ''),
|
||||
);
|
||||
|
||||
const { activateWorkflowVersion } = useActivateWorkflowVersion();
|
||||
|
||||
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(
|
||||
selectedRecord?.id,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isDefined(objectMetadataItem) || objectMetadataItem.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
addActionMenuEntry({
|
||||
key: 'activate-workflow',
|
||||
label: 'Activate workflow',
|
||||
position,
|
||||
Icon: IconPower,
|
||||
onClick: () => {
|
||||
if (isDefined(workflowWithCurrentVersion)) {
|
||||
activateWorkflowVersion({
|
||||
workflowVersionId: workflowWithCurrentVersion.currentVersion.id,
|
||||
workflowId: workflowWithCurrentVersion.id,
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return () => {
|
||||
removeActionMenuEntry('activate-workflow');
|
||||
};
|
||||
}, [
|
||||
activateWorkflowVersion,
|
||||
addActionMenuEntry,
|
||||
objectMetadataItem,
|
||||
position,
|
||||
removeActionMenuEntry,
|
||||
selectedRecord,
|
||||
workflowWithCurrentVersion,
|
||||
]);
|
||||
|
||||
return null;
|
||||
};
|
Loading…
Reference in New Issue
Block a user