Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/components/site-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ function ButtonToRun( { running, id, name }: Pick< SiteDetails, 'running' | 'id'
function SiteItem( { site }: { site: SiteDetails } ) {
const { selectedSite, setSelectedSiteId } = useSiteDetails();
const isSelected = site === selectedSite;
const { isSiteImporting } = useImportExport();
const { isSiteImporting, isSiteExporting } = useImportExport();
const { isSiteIdPulling } = useSyncSites();
const isImporting = isSiteImporting( site.id );
const isExporting = isSiteExporting( site.id );
const isPulling = isSiteIdPulling( site.id );
const showSpinner = site.isAddingSite || isImporting || isPulling;
const showSpinner = site.isAddingSite || isImporting || isPulling || isExporting;

let tooltipText;
if ( site.isAddingSite ) {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/tests/use-import-export.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe( 'useImportExport hook', () => {
expect( result.current.exportState ).toEqual( {
[ SITE_ID ]: {
statusMessage: 'Backing up files...',
progress: 100,
progress: 95,
},
} );

Expand Down
11 changes: 10 additions & 1 deletion src/hooks/use-import-export.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface ImportExportContext {
) => Promise< void >;
clearImportState: ( siteId: string ) => void;
isSiteImporting: ( siteId: string ) => boolean;
isSiteExporting: ( siteId: string ) => boolean;
exportState: ExportProgressState;
exportFullSite: ( selectedSite: SiteDetails ) => Promise< string | undefined >;
exportDatabase: ( selectedSite: SiteDetails ) => Promise< string | undefined >;
Expand All @@ -52,6 +53,7 @@ const ImportExportContext = createContext< ImportExportContext >( {
importFile: async () => undefined,
clearImportState: () => undefined,
isSiteImporting: () => false,
isSiteExporting: () => false,
exportState: {},
exportFullSite: async () => undefined,
exportDatabase: async () => undefined,
Expand Down Expand Up @@ -301,6 +303,11 @@ export const ImportExportProvider = ( { children }: { children: React.ReactNode
[ exportState ]
);

const isSiteExporting = useCallback(
( siteId: string ) => !! exportState[ siteId ] && exportState[ siteId ].progress < 100,
[ exportState ]
);

const exportFullSite = useCallback(
async ( selectedSite: SiteDetails ): Promise< string | undefined > => {
const fileName = generateBackupFilename( selectedSite.name );
Expand Down Expand Up @@ -421,7 +428,7 @@ export const ImportExportProvider = ( { children }: { children: React.ReactNode
[ siteId ]: {
...currentProgress,
statusMessage: __( 'Backing up files...' ),
progress: Math.min( 100, 20 + entriesProgress * 80 ), // Backup creation takes progress from 20% to 100%
progress: Math.min( 95, 20 + entriesProgress * 80 ), // Backup creation takes progress from 20% to 95%

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.

It is not clear to me why is this change needed? 🤔

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 question. It's because I made the logic in isSiteExporting check that progress < 100 (identical to isSiteImporting). However, the BACKUP_CREATE_PROGRESS event handler would previously increment the progress all the way up to 100, which made the sidebar spinner disappear before the export was actually complete.

This change makes the event handler stop the progress at 95.

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.

Thanks, that makes sense.

},
} ) );
break;
Expand Down Expand Up @@ -454,6 +461,7 @@ export const ImportExportProvider = ( { children }: { children: React.ReactNode
importFile,
clearImportState,
isSiteImporting,
isSiteExporting,
exportState,
exportFullSite,
exportDatabase,
Expand All @@ -463,6 +471,7 @@ export const ImportExportProvider = ( { children }: { children: React.ReactNode
importFile,
clearImportState,
isSiteImporting,
isSiteExporting,
exportState,
exportFullSite,
exportDatabase,
Expand Down