Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix discard draft optimistic rendering #9153

Merged
merged 5 commits into from
Dec 20, 2024

Conversation

martmull
Copy link
Contributor

Remove draft workflow version from cached workflow

@martmull martmull marked this pull request as ready for review December 19, 2024 15:51
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR implements proper cache management when deleting workflow versions by updating the Apollo cache to remove deleted versions from their parent workflow's version list.

  • Added cache cleanup in useDeleteOneWorkflowVersion.ts using apolloClient.cache.modify to filter out deleted versions
  • Added null checks for cachedWorkflowVersion and cachedWorkflow before cache modification
  • Uses apolloClient.cache.identify to correctly reference the workflow record in cache
  • Maintains data consistency by removing the version from both the direct record and its parent workflow's versions array

1 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

});
const getWorkflowFromCache = useGetRecordFromCache({
objectNameSingular: CoreObjectNameSingular.Workflow,
});

const deleteOneWorkflowVersion = async ({
workflowVersionId,
}: {
workflowVersionId: string;
}) => {
await deleteOneRecord(workflowVersionId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: deleteOneRecord could fail - wrap in try/catch to handle errors gracefully

Comment on lines +41 to +50
apolloClient.cache.modify({
id: apolloClient.cache.identify(cachedWorkflow),
fields: {
versions: () => {
return cachedWorkflow.versions.filter(
(version) => version.id !== workflowVersionId,
);
},
},
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: cache modification happens after deletion - if deletion fails, cache will be inconsistent

Copy link
Contributor

@bosiraphael bosiraphael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@martmull martmull merged commit 2437572 into main Dec 20, 2024
22 checks passed
@martmull martmull deleted the fix-discard-draft-optimistic-rendering branch December 20, 2024 10:36
mdrazak2001 pushed a commit to mdrazak2001/twenty that referenced this pull request Dec 20, 2024
Remove draft workflow version from cached workflow
samyakpiya pushed a commit to samyakpiya/twenty that referenced this pull request Dec 28, 2024
Remove draft workflow version from cached workflow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🔖 Planned
Development

Successfully merging this pull request may close these issues.

2 participants