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

Update SyncSitesProvider types #723

Merged
merged 7 commits into from
Dec 17, 2024

Conversation

fredrikekelund
Copy link
Contributor

Related issues

Proposed Changes

The type definitions in SyncSitesProvider and the related "sub-hooks" are unnecessarily complex. They cross-reference in ways that make them difficult to reason about.

This PR adds explicit return type definitions for useSyncPull, useSyncPush, and useSiteSyncManagement. I've also cleaned up SyncSitesContextType and excluded state and functions that weren't being used anywhere in the codebase.

Testing Instructions

Code review and smoke testing the sync flow should suffice

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@fredrikekelund fredrikekelund requested a review from a team December 6, 2024 12:39
@fredrikekelund fredrikekelund self-assigned this Dec 6, 2024
Comment on lines -191 to +188
const isPushError = pushState.isError;
const isPushing = pushState && isKeyPushing( pushState.status.key );
const isPushError = pushState && isKeyFailed( pushState.status.key );
const hasPushFinished = pushState && isKeyFinished( pushState.status.key );

Copy link
Contributor Author

@fredrikekelund fredrikekelund Dec 6, 2024

Choose a reason for hiding this comment

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

This change ensures that getPullState and getPushState can have the same return type. Previously, getPushState would add a few attributes to its return value to include these details. I don't see any good reason for treating getPullState and getPushState differently, though.

@@ -147,7 +141,7 @@ const SyncConnectedSitesSection = ( {
variant="link"
className="!ml-auto !text-a8c-gray-70 hover:!text-a8c-red-50 "
onClick={ handleDisconnectSite }
disabled={ isPulling || isPushing }
disabled={ isSiteIdPulling( selectedSite.id ) || isSiteIdPushing( selectedSite.id ) }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this should be the equivalent of the previous isPulling and isPushing definitions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I spotted a small regression with this one - the disconnect button now is disabled for all connected sites on a particular selected site. The expected behaviour is that it should be disabled only for the Disconnect button on a site that is syncing. I think this screenshot illustrates the issue:

Screenshot 2024-12-12 at 9 11 03 AM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, great catch 👍 Fixed now

@katinthehatsite
Copy link
Contributor

I looked through changes and tested the flow. It seemed to work as expected besides one small regression I noticed. However, I am not sure if the regression is related to the changes in this PR or to the differences with trunk. Perhaps we could resolve the conflicts with trunk and give it another review? 🙇

@fredrikekelund
Copy link
Contributor Author

Conflicts fixed and your comment addressed, @katinthehatsite. This should be good for a second look now

return sitePushState?.isInProgress;
} );
const isPulling = connectedSites.some( ( site ) => isSiteIdPulling( selectedSite.id, site.id ) );
const isPushing = connectedSites.some( ( site ) => isSiteIdPushing( selectedSite.id, site.id ) );
const isThisSiteSyncing = isPulling || isPushing;
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that we are using this logic in a couple of different files. I am wondering if we might want to create a hook to be able to reuse this check. This is not directly related to this PR though as this was already present before. We can create a separate issue to consider this.

Copy link
Contributor

@katinthehatsite katinthehatsite left a comment

Choose a reason for hiding this comment

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

The changes look good to me. I did not spot any other regressions after the conflicts with trunk were resolved 👍

I had a small suggestion but I do not think it is directly related to this PR.

@fredrikekelund fredrikekelund merged commit 2c27eaf into trunk Dec 17, 2024
6 checks passed
@fredrikekelund fredrikekelund deleted the f26d/update-sync-sites-context-types branch December 17, 2024 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants