Skip to content

Commit

Permalink
Update cache queries
Browse files Browse the repository at this point in the history
  • Loading branch information
thomtrp committed Jan 10, 2025
1 parent 7b2debf commit 4c4d996
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useApolloMetadataClient } from '@/object-metadata/hooks/useApolloMetadataClient';
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';
Expand Down Expand Up @@ -56,7 +57,16 @@ export const useActivateWorkflowVersion = () => {
item.workflowId === workflowId,
);

for (const workflowVersion of allWorkflowVersions) {
const previousActiveWorkflowVersions = allWorkflowVersions.filter(
(version) =>
version.status === 'ACTIVE' && version.id !== workflowVersionId,
);

if (!previousActiveWorkflowVersions) {
return;
}

for (const workflowVersion of previousActiveWorkflowVersions) {
apolloClient.cache.modify({
id: apolloClient.cache.identify(workflowVersion),
fields: {
Expand All @@ -68,6 +78,17 @@ export const useActivateWorkflowVersion = () => {
},
},
});

triggerUpdateRecordOptimisticEffect({
cache: apolloClient.cache,
objectMetadataItem: objectMetadataItemWorkflowVersion,
currentRecord: workflowVersion,
updatedRecord: {
...workflowVersion,
status: 'ARCHIVED',
},
objectMetadataItems: [objectMetadataItemWorkflowVersion],
});
}
},
});
Expand Down

0 comments on commit 4c4d996

Please sign in to comment.