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 issues with Apollo cache in workflow module #7569

Merged
merged 4 commits into from
Oct 11, 2024

Conversation

Devessier
Copy link
Contributor

Fixes #7523

Copy link

TODOs/FIXMEs:

  • // TODO: same as in update, should we trigger DELETE ?: packages/twenty-front/src/modules/apollo/optimistic-effect/utils/triggerDeleteRecordsOptimisticEffect.ts

Generated by 🚫 dangerJS against c46f6eb

Copy link
Member

@charlesBochet charlesBochet left a comment

Choose a reason for hiding this comment

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

LGTM!

@charlesBochet charlesBochet marked this pull request as ready for review October 11, 2024 13:26
@charlesBochet charlesBochet merged commit 521dd04 into main Oct 11, 2024
13 checks passed
@charlesBochet charlesBochet deleted the fix-apollo-cache-issues-workflows branch October 11, 2024 13:26
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 pull request addresses Apollo cache synchronization issues in the workflow module, focusing on improving cache updates after mutations and enhancing UI consistency.

  • Simplified cache update logic in triggerDeleteRecordsOptimisticEffect.ts by removing unnecessary code and variables
  • Updated useActivateWorkflowVersion hook to directly modify cache, updating activated version status and archiving other active versions
  • Modified useDeactivateWorkflowVersion to use modifyRecordFromCache for direct cache updates instead of refetching data
  • Improved useWorkflowWithCurrentVersion hook to better handle current workflow version selection, addressing active version handling issues
  • Updated RecordShowPageWorkflowHeader and RecordShowPageWorkflowVersionHeader components to ensure proper cache updates after workflow operations

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

Comment on lines +29 to +35
const activateWorkflowVersion = async ({
workflowVersionId,
workflowId,
}: {
workflowVersionId: string;
workflowId: string;
}) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider adding a type definition for the function parameters

Comment on lines +59 to +71
for (const workflowVersion of allWorkflowVersions) {
apolloClient.cache.modify({
id: apolloClient.cache.identify(workflowVersion),
fields: {
status: () => {
return workflowVersion.id !== workflowVersionId &&
workflowVersion.status === 'ACTIVE'
? 'ARCHIVED'
: workflowVersion.status;
},
},
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: This loop modifies cache entries individually. Consider using a batch update if possible for better performance

Comment on lines 14 to +15
const apolloMetadataClient = useApolloMetadataClient();
const apolloClient = useApolloClient();
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider moving these client initializations outside the hook for better performance

Comment on lines 16 to 21
const [mutate] = useMutation<
ActivateWorkflowVersionMutation,
ActivateWorkflowVersionMutationVariables
>(DEACTIVATE_WORKFLOW_VERSION, {
client: apolloMetadataClient ?? ({} as ApolloClient<any>),
});
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The mutation type seems to be incorrect. It's using ActivateWorkflowVersionMutation for a deactivate operation

recordId: workflowVersionId,
objectMetadataItem: objectMetadataItemWorkflowVersion,
fieldModifiers: {
status: () => 'DEACTIVATED',
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider using an enum or constant for the status value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Apollo Cache after mutations in the workflow pages
2 participants