-
Notifications
You must be signed in to change notification settings - Fork 86
Studio: Add UI for when local tree for push has errors #2271
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,8 +52,11 @@ const useDynamicTreeState = ( | |
| skip: type === 'push', | ||
| } ); | ||
| const { fetchChildren } = useRemoteFileTree(); | ||
| const { fetchChildren: fetchLocalChildren, isLoading: isLoadingLocalFileTree } = | ||
| useLocalFileTree(); | ||
| const { | ||
| fetchChildren: fetchLocalChildren, | ||
| isLoading: isLoadingLocalFileTree, | ||
| error: localFileTreeError, | ||
| } = useLocalFileTree(); | ||
|
|
||
| // If the site was just created and if there is no rewind_id yet, | ||
| // then all options are pre-checked to allow only a full sync | ||
|
|
@@ -92,15 +95,11 @@ const useDynamicTreeState = ( | |
| if ( type === 'push' ) { | ||
| let isCancelled = false; | ||
| const loadLocalTree = async () => { | ||
| try { | ||
| const localTree = await fetchLocalChildren( localSiteId, 'wp-content' ); | ||
| if ( ! isCancelled ) { | ||
| setTreeState( ( treeState ) => | ||
| updateNodeById( treeState, 'wp-content', { children: localTree } ) | ||
| ); | ||
| } | ||
| } catch ( error ) { | ||
| console.error( 'Failed to load local file tree:', error ); | ||
| const localTree = await fetchLocalChildren( localSiteId, 'wp-content' ); | ||
| if ( ! isCancelled ) { | ||
| setTreeState( ( treeState ) => | ||
| updateNodeById( treeState, 'wp-content', { children: localTree } ) | ||
| ); | ||
| } | ||
| }; | ||
| void loadLocalTree(); | ||
|
|
@@ -118,13 +117,21 @@ const useDynamicTreeState = ( | |
| localSiteId, | ||
| ] ); | ||
|
|
||
| // Handle local file tree errors by clearing children to show custom error message | ||
| useEffect( () => { | ||
| if ( type === 'push' && localFileTreeError ) { | ||
| setTreeState( ( treeState ) => updateNodeById( treeState, 'wp-content', { children: [] } ) ); | ||
| } | ||
| }, [ type, localFileTreeError, setTreeState ] ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this useEffect is necessary or it could be just an if when rendering the node.children.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adjusted in #2352 |
||
|
|
||
| return { | ||
| rewindId, | ||
| fetchChildren, | ||
| fetchLocalChildren, | ||
| isLoadingRewindId, | ||
| isErrorRewindId, | ||
| isLoadingLocalFileTree, | ||
| localFileTreeError, | ||
| }; | ||
| }; | ||
|
|
||
|
|
@@ -155,8 +162,14 @@ export function SyncDialog( { | |
| formattedOverAmount, | ||
| } = useSelectedItemsPushSize( localSite.id, treeState, type ); | ||
|
|
||
| const { fetchChildren, rewindId, isLoadingRewindId, isErrorRewindId, isLoadingLocalFileTree } = | ||
| useDynamicTreeState( type, localSite.id, remoteSite.id, setTreeState ); | ||
| const { | ||
| fetchChildren, | ||
| rewindId, | ||
| isLoadingRewindId, | ||
| isErrorRewindId, | ||
| isLoadingLocalFileTree, | ||
| localFileTreeError, | ||
| } = useDynamicTreeState( type, localSite.id, remoteSite.id, setTreeState ); | ||
|
|
||
| const [ wpVersion ] = useGetWpVersion( localSite ); | ||
| const { data: wpVersions = [] } = useGetWordPressVersions( { | ||
|
|
@@ -355,6 +368,18 @@ export function SyncDialog( { | |
| } | ||
| return null; | ||
| } } | ||
| renderEmptyContent={ ( nodeId ) => { | ||
| if ( nodeId === 'wp-content' && type === 'push' && localFileTreeError ) { | ||
| return ( | ||
| <div className="text-gray-500 italic"> | ||
| { __( | ||
| 'Could not load files. Please close and reopen this dialog to try again.' | ||
| ) } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not add an explicit retry because this seems to be rather an edge case but we can add it if we consider it necessary |
||
| </div> | ||
| ); | ||
| } | ||
| return null; | ||
| } } | ||
| /> | ||
| </> | ||
| ) } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest renaming
renderEmptyContenttorenderErrorContent. Or in case we want to keep it tied to empty children, then I think we should move theEmptylogic into that function too. The conditionrenderEmptyContent && renderEmptyContent( node.id ) ?seems a bit tricky.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made adjustments in #2352 for this