-
Notifications
You must be signed in to change notification settings - Fork 86
Studio: Add failed state when the preview site fails to update #977
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
b1b4dd1
cb361fc
ca3b289
6d3e5d2
69c4b08
3f8cd26
e57be3a
37ff84c
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 |
|---|---|---|
|
|
@@ -10,11 +10,13 @@ import { getIpcApi } from 'src/lib/get-ipc-api'; | |
| interface DemoSiteUpdateContextType { | ||
| updateDemoSite: ( snapshot: Snapshot, localSite: SiteDetails ) => Promise< void >; | ||
| isDemoSiteUpdating: ( atomicSiteId: number ) => boolean; | ||
| hasDemoSiteError: ( atomicSiteId: number ) => boolean; | ||
| } | ||
|
|
||
| const DemoSiteUpdateContext = createContext< DemoSiteUpdateContextType >( { | ||
| updateDemoSite: async () => undefined, | ||
| isDemoSiteUpdating: () => false, | ||
| hasDemoSiteError: () => false, | ||
| } ); | ||
|
|
||
| interface DemoSiteUpdateProviderProps { | ||
|
|
@@ -25,6 +27,7 @@ export const DemoSiteUpdateProvider: React.FC< DemoSiteUpdateProviderProps > = ( | |
| const { client } = useAuth(); | ||
| const { __ } = useI18n(); | ||
| const [ updatingSites, setUpdatingSites ] = useState< Set< number > >( new Set() ); | ||
| const [ errorSites, setErrorSites ] = useState< Set< number > >( new Set() ); | ||
| const { updateSnapshot } = useSnapshots(); | ||
|
|
||
| const updateDemoSite = useCallback( | ||
|
|
@@ -34,6 +37,14 @@ export const DemoSiteUpdateProvider: React.FC< DemoSiteUpdateProviderProps > = ( | |
| return; | ||
| } | ||
| setUpdatingSites( ( prev ) => new Set( prev ).add( snapshot.atomicSiteId ) ); | ||
| // Clear error when user retries | ||
| if ( errorSites.has( snapshot.atomicSiteId ) ) { | ||
| setErrorSites( ( prev ) => { | ||
| const next = new Set( prev ); | ||
| next.delete( snapshot.atomicSiteId ); | ||
| return next; | ||
| } ); | ||
| } | ||
|
|
||
| let archivePath = ''; | ||
| try { | ||
|
|
@@ -96,6 +107,7 @@ export const DemoSiteUpdateProvider: React.FC< DemoSiteUpdateProviderProps > = ( | |
| } ); | ||
| return response; | ||
| } catch ( error ) { | ||
| setErrorSites( ( prev ) => new Set( prev ).add( snapshot.atomicSiteId ) ); | ||
|
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 believe we only add sites to errorSites and never remove them. Is that correct?
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 think the state should be cleared by itself when the component unmounts. And the UI should be reset after 1 minute timeout: In any case, I added some clean up when we attemp another update: https://github.com/Automattic/studio/pull/977/commits/69c4b08f0e6ecfc1bd493fdf35a377d288d91d76k |
||
| getIpcApi().showErrorMessageBox( { | ||
| title: __( 'Update failed' ), | ||
| message: sprintf( | ||
|
|
@@ -116,22 +128,26 @@ export const DemoSiteUpdateProvider: React.FC< DemoSiteUpdateProviderProps > = ( | |
| } | ||
| } | ||
| }, | ||
| [ __, client, updateSnapshot ] | ||
| [ __, client, errorSites, updateSnapshot ] | ||
| ); | ||
|
|
||
| const isDemoSiteUpdating = useCallback( | ||
| ( atomicSiteId: number ) => { | ||
| return updatingSites.has( atomicSiteId ); | ||
| }, | ||
| ( atomicSiteId: number ) => updatingSites.has( atomicSiteId ), | ||
| [ updatingSites ] | ||
| ); | ||
|
|
||
| const hasDemoSiteError = useCallback( | ||
| ( atomicSiteId: number ) => errorSites.has( atomicSiteId ), | ||
| [ errorSites ] | ||
| ); | ||
|
|
||
| const contextValue = useMemo( | ||
| () => ( { | ||
| updateDemoSite, | ||
| isDemoSiteUpdating, | ||
| hasDemoSiteError, | ||
| } ), | ||
| [ updateDemoSite, isDemoSiteUpdating ] | ||
| [ updateDemoSite, isDemoSiteUpdating, hasDemoSiteError ] | ||
| ); | ||
|
|
||
| return ( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.