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:
@ -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],
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user