mirror of
https://github.com/lingble/twenty.git
synced 2025-10-30 12:22:29 +00:00
add ActivateWorkflowActionEffect
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import { DeleteRecordsActionEffect } from '@/action-menu/actions/record-actions/components/DeleteRecordsActionEffect';
|
import { DeleteRecordsActionEffect } from '@/action-menu/actions/record-actions/components/DeleteRecordsActionEffect';
|
||||||
import { ExportRecordsActionEffect } from '@/action-menu/actions/record-actions/components/ExportRecordsActionEffect';
|
import { ExportRecordsActionEffect } from '@/action-menu/actions/record-actions/components/ExportRecordsActionEffect';
|
||||||
import { ManageFavoritesActionEffect } from '@/action-menu/actions/record-actions/components/ManageFavoritesActionEffect';
|
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 { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||||
import { useRightDrawer } from '@/ui/layout/right-drawer/hooks/useRightDrawer';
|
import { useRightDrawer } from '@/ui/layout/right-drawer/hooks/useRightDrawer';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
@@ -35,9 +37,25 @@ export const SingleRecordActionMenuEntriesSetter = ({
|
|||||||
[isInRightDrawer, closeRightDrawer],
|
[isInRightDrawer, closeRightDrawer],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const workflowActions = useMemo(() => {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
ActionEffect: ActivateWorkflowActionEffect,
|
||||||
|
onActionExecutedCallback: undefined,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const allActions = [
|
||||||
|
...(objectMetadataItem.nameSingular === CoreObjectNameSingular.Workflow
|
||||||
|
? workflowActions
|
||||||
|
: []),
|
||||||
|
...actions,
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{actions.map(({ ActionEffect, onActionExecutedCallback }, index) => (
|
{allActions.map(({ ActionEffect, onActionExecutedCallback }, index) => (
|
||||||
<ActionEffect
|
<ActionEffect
|
||||||
key={index}
|
key={index}
|
||||||
position={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;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user