Skip to content

Pull: Move progress functions to the existing progress custom hook - #1380

Merged
epeicher merged 6 commits into
trunkfrom
update/get-progress-hooks
May 15, 2025
Merged

Pull: Move progress functions to the existing progress custom hook#1380
epeicher merged 6 commits into
trunkfrom
update/get-progress-hooks

Conversation

@epeicher

Copy link
Copy Markdown
Contributor

Related issues

Proposed Changes

  • Move the existing getBackupProgress and getStatusWithProgress to the existing useSyncStatesProgressInfo hook, which exposes utility functions to return Progress. This seems to be a better location for those functions, more consistent with existing code.

Testing Instructions

  • Apply this changes and run npm start
  • Check the Pull process work exactly as in Production and no unexpected errors are triggered.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@epeicher
epeicher requested a review from a team May 13, 2025 17:44

@bcotrim bcotrim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Works as described
LGTM 👍

@fredrikekelund fredrikekelund left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I left a couple of comments on the code. I know a lot of that stuff was the same prior to this PR, but this seems like a good opportunity to address it.

If you're not already familiar with the ProgressBarWithAutoIncrement component, I'd also like to mention that. We use it for preview sites and it provides some nice interactivity. Granted, sync operations typically take longer, but you could give it a small increment prop to account for that.

Comment on lines +176 to +177
progress:
IMPORTING_INITIAL_VALUE + IMPORTING_TO_FINISHED_STEP * ( importState.progress / 100 ),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What do we accomplish with this calculation? IMPORTING_INITIAL_VALUE is always 80 and IMPORTING_TO_FINISHED_STEP is always 20, so it looks like we're saying 100 * (80 / 100). Why not just return importState.progress..?

@epeicher epeicher May 15, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not really, 80 + 20 * progress / 100 != progress 😛 . This tries to move from 80% to 100% progressively determined by importState.progress. I think I can add a comment there to clarify, as it can be difficult to read.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ofc, my bad 🤦‍♂️ Doesn't seem as bad now that I come back to it, though. Maybe assigning the IMPORTING_TO_FINISHED_STEP * ( importState.progress / 100 ) part to a separate variable first would be enough to make it easier to understand.

Comment on lines +152 to +153
newProgressInfo.progress =
IN_PROGRESS_INITIAL_VALUE + IN_PROGRESS_TO_DOWNLOADING_STEP * ( response.percent / 100 );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same thing here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same reasoning, I think some comments will help here, I'm adding them

Comment thread src/hooks/use-sync-states-progress-info.ts Outdated

const getBackupStatusWithProgress = useCallback(
(
hasBackupCompleted: boolean,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Couldn't we intuit this value inside getBackupStatusWithProgress by checking if response.status === 'finished'?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, I originally passed it as a parameter because it was already obtained here, but in this case, it could be better to calculate it the function and avoid the extra parameter, do you agree?

Comment thread src/hooks/use-sync-states-progress-info.ts Outdated
Comment on lines +21 to +26
export type SyncBackupResponse = {
status: 'in-progress' | 'finished' | 'failed';
download_url: string;
percent: number;
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This type is also defined in src/hooks/sync-sites/use-sync-pull.ts. Could we use a single definition, and, while we're at it, maybe convert it to a zod schema?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I meant to delete it from src/hooks/sync-sites/use-sync-pull.ts and declare it here instead to avoid a circular dependency. Alternatively, I can move it to an external types file and import it from there in both places (here and in use-sync-pull). Do you prefer one option over the other?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For reference, I've deleted the redundant definition in this commit 2241fd6

epeicher and others added 4 commits May 15, 2025 14:13
…ibility

Co-authored-by: Fredrik Rombach Ekelund <fredrik@f26d.dev>
Co-authored-by: Fredrik Rombach Ekelund <fredrik@f26d.dev>
@epeicher

Copy link
Copy Markdown
Contributor Author

I will merge this as I have addressed most of the comments. If there are any other suggestions, please let me know, and I will create a follow-up task for that

@epeicher
epeicher merged commit 9d2e9e9 into trunk May 15, 2025
@epeicher
epeicher deleted the update/get-progress-hooks branch May 15, 2025 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants