11import { Layout as DashboardLayout } from "/src/layouts/index.js" ;
22import { HeaderedTabbedLayout } from "/src/layouts/HeaderedTabbedLayout" ;
3+ import { useState } from "react" ;
4+ import { useForm , useWatch } from "react-hook-form" ;
35import {
46 Button ,
57 Box ,
@@ -31,6 +33,7 @@ import { CippBackupScheduleDrawer } from "/src/components/CippComponents/CippBac
3133import { CippRestoreBackupDrawer } from "/src/components/CippComponents/CippRestoreBackupDrawer" ;
3234import { CippApiDialog } from "/src/components/CippComponents/CippApiDialog" ;
3335import { CippTimeAgo } from "/src/components/CippComponents/CippTimeAgo" ;
36+ import { CippFormTenantSelector } from "/src/components/CippComponents/CippFormTenantSelector" ;
3437import { useDialog } from "/src/hooks/use-dialog" ;
3538import ReactTimeAgo from "react-time-ago" ;
3639import tabOptions from "./tabOptions.json" ;
@@ -42,6 +45,8 @@ const Page = () => {
4245 const { templateId } = router . query ;
4346 const settings = useSettings ( ) ;
4447 const removeDialog = useDialog ( ) ;
48+ const tenantFilterForm = useForm ( { defaultValues : { tenantFilter : null } } ) ;
49+ const backupTenantFilter = useWatch ( { control : tenantFilterForm . control , name : "tenantFilter" } ) ;
4550 // Prioritize URL query parameter, then fall back to settings
4651 const currentTenant = router . query . tenantFilter || settings . currentTenant ;
4752
@@ -79,19 +84,28 @@ const Page = () => {
7984 return [ "Configuration" ] ;
8085 } ;
8186
82- const backupDisplayItems = filteredBackupData . map ( ( backup , index ) => ( {
87+ // Filter backup data by selected tenant if in AllTenants view
88+ const tenantFilteredBackupData =
89+ settings . currentTenant === "AllTenants" &&
90+ backupTenantFilter &&
91+ backupTenantFilter !== "AllTenants"
92+ ? filteredBackupData . filter ( ( backup ) => backup . TenantFilter === backupTenantFilter )
93+ : filteredBackupData ;
94+
95+ const backupDisplayItems = tenantFilteredBackupData . map ( ( backup , index ) => ( {
8396 id : backup . RowKey || index ,
8497 name : backup . BackupName || "Unnamed Backup" ,
8598 timestamp : backup . Timestamp ,
86- tenantSource : backup . BackupName ?. includes ( "AllTenants" )
87- ? "All Tenants"
88- : backup . BackupName ?. replace ( "CIPP Backup - " , "" ) || settings . currentTenant ,
99+ tenantSource : backup . TenantFilter || settings . currentTenant ,
89100 tags : generateBackupTags ( backup ) ,
90101 } ) ) ;
91102
92103 // Process existing backup configuration, find tenantFilter. by comparing settings.currentTenant with Tenant.value
93104 const currentConfig = Array . isArray ( existingBackupConfig . data )
94- ? existingBackupConfig . data . find ( ( tenant ) => tenant . Tenant . value === settings . currentTenant )
105+ ? existingBackupConfig . data . find (
106+ ( tenant ) =>
107+ tenant . Tenant . value === settings . currentTenant || tenant . Tenant . value === "AllTenants"
108+ )
95109 : null ;
96110 const hasExistingConfig = currentConfig && currentConfig . Parameters ?. ScheduledBackupValues ;
97111
@@ -281,13 +295,33 @@ const Page = () => {
281295
282296 < Grid size = { { md : 6 , xs : 12 } } >
283297 { /* Backup History */ }
284- < Card sx = { { height : "100%" } } >
285- < CardContent >
286- < Stack spacing = { 3 } >
287- < Typography variant = "h6" sx = { { display : "flex" , alignItems : "center" , gap : 1 } } >
288- < History color = "primary" />
289- Backup History
290- </ Typography >
298+ < Card sx = { { height : "100%" , display : "flex" , flexDirection : "column" } } >
299+ < CardContent sx = { { flex : 1 , display : "flex" , flexDirection : "column" } } >
300+ < Stack
301+ spacing = { 3 }
302+ sx = { { height : "100%" , display : "flex" , flexDirection : "column" } }
303+ >
304+ < Box
305+ sx = { { display : "flex" , justifyContent : "space-between" , alignItems : "center" } }
306+ >
307+ < Typography variant = "h6" sx = { { display : "flex" , alignItems : "center" , gap : 1 } } >
308+ < History color = "primary" />
309+ Backup History
310+ </ Typography >
311+ { settings . currentTenant === "AllTenants" && (
312+ < Box sx = { { minWidth : 250 } } >
313+ < CippFormTenantSelector
314+ formControl = { tenantFilterForm }
315+ componentType = "select"
316+ name = "tenantFilter"
317+ type = "single"
318+ required = { false }
319+ disableClearable = { false }
320+ allTenants = { true }
321+ />
322+ </ Box >
323+ ) }
324+ </ Box >
291325
292326 < Typography variant = "body2" color = "text.secondary" >
293327 { settings . currentTenant === "AllTenants"
@@ -307,7 +341,7 @@ const Page = () => {
307341 < Skeleton variant = "rectangular" width = "100%" height = { 200 } />
308342 </ Stack >
309343 ) : (
310- < Box sx = { { maxHeight : "400px " , overflowY : "auto" } } >
344+ < Box sx = { { maxHeight : "calc(100vh - 525px) " , overflowY : "auto" } } >
311345 < Stack spacing = { 2 } >
312346 { backupDisplayItems . map ( ( backup ) => (
313347 < Card key = { backup . id } variant = "outlined" >
@@ -334,6 +368,14 @@ const Page = () => {
334368 < Typography variant = "body2" color = "text.secondary" >
335369 < ReactTimeAgo date = { backup . timestamp } />
336370 </ Typography >
371+ { settings . currentTenant === "AllTenants" && (
372+ < Chip
373+ label = { `Tenant: ${ backup . tenantSource } ` }
374+ size = "small"
375+ sx = { { mt : 1 } }
376+ variant = "outlined"
377+ />
378+ ) }
337379 </ Box >
338380 < Stack direction = "row" spacing = { 1 } sx = { { flexShrink : 0 } } >
339381 < CippRestoreBackupDrawer
0 commit comments