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],
});
},
});
};