Fix empty trigger on readonly + fix cache apollo on deactivation (#9912)

- On deactivation, we should not need to refresh so the workflow
disappear from cmd+k


https://github.com/user-attachments/assets/826fa4c6-3faa-49d1-b180-ed5d3ed187e5

- When readonly, step empty, we should not see the right drawer


https://github.com/user-attachments/assets/b557ef61-da81-446d-b160-f26c4c7a5191
This commit is contained in:
Thomas Trompette
2025-01-29 17:25:20 +01:00
committed by GitHub
parent 85ae7084ab
commit ce0a6c1b17
3 changed files with 31 additions and 8 deletions

View File

@ -1,9 +1,12 @@
import { useApolloClient, useMutation } from '@apollo/client';
import { triggerUpdateRecordOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerUpdateRecordOptimisticEffect';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { modifyRecordFromCache } from '@/object-record/cache/utils/modifyRecordFromCache';
import { DEACTIVATE_WORKFLOW_VERSION } from '@/workflow/graphql/mutations/deactivateWorkflowVersion';
import { WorkflowVersion } from '@/workflow/types/Workflow';
import { isDefined } from 'twenty-ui';
import {
DeactivateWorkflowVersionMutation,
DeactivateWorkflowVersionMutationVariables,
@ -37,6 +40,30 @@ export const useDeactivateWorkflowVersion = () => {
status: () => 'DEACTIVATED',
},
});
const cacheSnapshot = apolloClient.cache.extract();
const workflowVersion: WorkflowVersion | undefined = Object.values(
cacheSnapshot,
).find(
(item) =>
item.__typename === 'WorkflowVersion' &&
item.id === workflowVersionId,
);
if (!isDefined(workflowVersion)) {
return;
}
triggerUpdateRecordOptimisticEffect({
cache: apolloClient.cache,
objectMetadataItem: objectMetadataItemWorkflowVersion,
currentRecord: workflowVersion,
updatedRecord: {
...workflowVersion,
status: 'DEACTIVATED',
},
objectMetadataItems: [objectMetadataItemWorkflowVersion],
});
},
});
};

View File

@ -3,6 +3,7 @@ import { useRightDrawer } from '@/ui/layout/right-drawer/hooks/useRightDrawer';
import { RightDrawerHotkeyScope } from '@/ui/layout/right-drawer/types/RightDrawerHotkeyScope';
import { RightDrawerPages } from '@/ui/layout/right-drawer/types/RightDrawerPages';
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
import { EMPTY_TRIGGER_STEP_ID } from '@/workflow/workflow-diagram/constants/EmptyTriggerStepId';
import { useTriggerNodeSelection } from '@/workflow/workflow-diagram/hooks/useTriggerNodeSelection';
import { workflowSelectedNodeState } from '@/workflow/workflow-diagram/states/workflowSelectedNodeState';
import {
@ -27,7 +28,7 @@ export const WorkflowDiagramCanvasReadonlyEffect = () => {
const selectedNode = nodes[0] as WorkflowDiagramNode;
const isClosingStep = isDefined(selectedNode) === false;
if (isClosingStep) {
if (isClosingStep || selectedNode.type === EMPTY_TRIGGER_STEP_ID) {
closeRightDrawer();
closeCommandMenu();
return;
@ -37,6 +38,7 @@ export const WorkflowDiagramCanvasReadonlyEffect = () => {
setHotkeyScope(RightDrawerHotkeyScope.RightDrawer, { goto: false });
const selectedNodeData = selectedNode.data as WorkflowDiagramStepNodeData;
openRightDrawer(RightDrawerPages.WorkflowStepView, {
title: selectedNodeData.name,
Icon: getIcon(getWorkflowNodeIconKey(selectedNodeData)),

View File

@ -48,18 +48,12 @@ export const WorkflowStepDetail = ({
stepId,
workflowVersion,
});
if (!isDefined(stepDefinition)) {
if (!isDefined(stepDefinition) || !isDefined(stepDefinition.definition)) {
return null;
}
switch (stepDefinition.type) {
case 'trigger': {
if (!isDefined(stepDefinition.definition)) {
throw new Error(
'Expected the trigger to be defined at this point. Ensure the trigger has been set with a default value before trying to edit it.',
);
}
switch (stepDefinition.definition.type) {
case 'DATABASE_EVENT': {
return (