Skip to content

Commit 1da68e4

Browse files
yashwinclaude
andcommitted
A4A: Add backup-now action and route prefetching to agency backups
* Add the "Back up now" button (with useBackupState and the BackupNotices progress banner) to the agency backups list page. * Forward searchParams to BackupsBrowser so the DataView hydrates page/search state from the URL, matching dotcom. * Add a loader on the backups route to prefetch site settings and backups in parallel, removing the site → settings suspense waterfall. * Fix stale $siteId route comments to $siteSlug. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 8e6060d commit 1da68e4

2 files changed

Lines changed: 54 additions & 12 deletions

File tree

client/dashboard/agency/sites/site/backups-list-page.tsx

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ import { useDateRange } from '../../../app/hooks/use-date-range';
99
import { useLocale } from '../../../app/locale';
1010
import {
1111
agencySiteRoute,
12+
agencySiteBackupsRoute,
1213
agencySiteBackupsIndexRoute,
1314
agencySiteBackupDetailRoute,
1415
agencySiteBackupRestoreRoute,
1516
agencySiteBackupDownloadRoute,
1617
} from '../../../app/router/agency';
1718
import { PageHeader } from '../../../components/page-header';
1819
import PageLayout from '../../../components/page-layout';
20+
import { BackupNotices } from '../../../sites/backups/backup-notices';
21+
import { BackupNowButton } from '../../../sites/backups/backup-now-button';
1922
import { BackupsBrowser, useIsBackupsSmallViewport } from '../../../sites/backups/backups-browser';
23+
import { useBackupState } from '../../../sites/backups/use-backup-state';
2024
import type { ActivityLogEntry } from '@automattic/api-core';
2125

2226
export default function AgencySiteBackupsListPage() {
@@ -28,6 +32,7 @@ export default function AgencySiteBackupsListPage() {
2832
| { rewindId?: string }
2933
| undefined;
3034
const rewindId = routeParams?.rewindId;
35+
const searchParams = agencySiteBackupsRoute.useSearch();
3136

3237
const { data: site } = useSuspenseQuery( siteBySlugQuery( siteSlug ) );
3338

@@ -40,6 +45,8 @@ export default function AgencySiteBackupsListPage() {
4045
} );
4146
const { gmtOffset, timezoneString } = siteSettings;
4247

48+
const backupState = useBackupState( site.ID );
49+
4350
const { dateRange, handleDateRangeChange } = useDateRange( {
4451
timezoneString,
4552
gmtOffset,
@@ -95,15 +102,21 @@ export default function AgencySiteBackupsListPage() {
95102
const isMobileDetailsView = useIsBackupsSmallViewport() && !! rewindId;
96103

97104
const actions = (
98-
<DateRangePicker
99-
start={ dateRange.start }
100-
end={ dateRange.end }
101-
gmtOffset={ gmtOffset }
102-
timezoneString={ timezoneString }
103-
locale={ locale }
104-
defaultFallbackPreset="last-30-days"
105-
onChange={ handleDateRangeChangeWrapper }
106-
/>
105+
<>
106+
{ /* This div is required to fix a layout width issue when the DateRangePicker is placed together with the BackupNowButton. */ }
107+
<div>
108+
<DateRangePicker
109+
start={ dateRange.start }
110+
end={ dateRange.end }
111+
gmtOffset={ gmtOffset }
112+
timezoneString={ timezoneString }
113+
locale={ locale }
114+
defaultFallbackPreset="last-30-days"
115+
onChange={ handleDateRangeChangeWrapper }
116+
/>
117+
</div>
118+
<BackupNowButton site={ site } backupState={ backupState } />
119+
</>
107120
);
108121

109122
return (
@@ -118,13 +131,24 @@ export default function AgencySiteBackupsListPage() {
118131
actions={ isMobileDetailsView ? undefined : actions }
119132
/>
120133
}
134+
notices={
135+
! isMobileDetailsView && backupState.status !== 'idle' ? (
136+
<BackupNotices
137+
backupState={ backupState }
138+
site={ site }
139+
timezoneString={ timezoneString }
140+
gmtOffset={ gmtOffset }
141+
/>
142+
) : undefined
143+
}
121144
>
122145
<BackupsBrowser
123146
site={ site }
124147
rewindId={ rewindId }
125148
dateRange={ dateRange }
126149
timezoneString={ timezoneString }
127150
gmtOffset={ gmtOffset }
151+
searchParams={ searchParams }
128152
onSelectBackup={ navigateToBackup }
129153
onRequestRestore={ handleRequestRestore }
130154
onRequestDownload={ handleRequestDownload }

client/dashboard/app/router/agency.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import {
66
mcpSettingsQuery,
77
queryClient,
88
rawUserPreferencesQuery,
9+
siteBackupsQuery,
10+
siteBySlugQuery,
11+
siteSettingsQuery,
912
} from '@automattic/api-queries';
1013
import { createRoute, createLazyRoute, notFound } from '@tanstack/react-router';
1114
import { __ } from '@wordpress/i18n';
@@ -266,11 +269,26 @@ const agencySiteOverviewRoute = createRoute( {
266269
)
267270
);
268271

269-
// `/sites/$siteId/backups` – layout that hosts the backups list/detail views
270-
const agencySiteBackupsRoute = createRoute( {
272+
// `/sites/$siteSlug/backups` – layout that hosts the backups list/detail views
273+
export const agencySiteBackupsRoute = createRoute( {
271274
head: () => ( { meta: [ { title: __( 'Backups' ) } ] } ),
272275
getParentRoute: () => agencySiteRoute,
273276
path: 'backups',
277+
loader: async ( { params: { siteSlug } } ) => {
278+
const [ agencySite, site ] = await Promise.all( [
279+
queryClient.ensureQueryData( agencySiteQuery( siteSlug ) ),
280+
queryClient.ensureQueryData( siteBySlugQuery( siteSlug ) ),
281+
] );
282+
283+
if ( ! agencySite?.has_backup ) {
284+
return;
285+
}
286+
287+
await Promise.all( [
288+
queryClient.ensureQueryData( siteSettingsQuery( site.ID ) ),
289+
queryClient.ensureQueryData( siteBackupsQuery( site.ID ) ),
290+
] );
291+
},
274292
} ).lazy( () =>
275293
import( '../../agency/sites/site/backups' ).then( ( d ) =>
276294
createLazyRoute( 'agency-site-backups' )( {
@@ -290,7 +308,7 @@ export const agencySiteBackupsIndexRoute = createRoute( {
290308
)
291309
);
292310

293-
// `/sites/$siteId/backups/$rewindId` – layout hosting the detail view + restore/download flows
311+
// `/sites/$siteSlug/backups/$rewindId` – layout hosting the detail view + restore/download flows
294312
export const agencySiteBackupDetailRoute = createRoute( {
295313
head: () => ( { meta: [ { title: __( 'Backups' ) } ] } ),
296314
getParentRoute: () => agencySiteBackupsRoute,

0 commit comments

Comments
 (0)