@ -1,37 +1,67 @@
import { useState , useEffect } from 'react' ;
import { reportInteraction } from '@grafana/runtime' ;
import { ConfirmModal , Text } from '@grafana/ui' ;
import { ConfirmModal , Space , Text } from '@grafana/ui' ;
import { FolderPicker } from '../../../core/components/Select/FolderPicker' ;
import { Trans , t } from '../../../core/internationalization' ;
export interface Props {
export interface RestoreModal Props {
isOpen : boolean ;
onConfirm : ( ) = > Promise < void > ;
onConfirm : ( restoreTarget : string ) = > Promise < void > ;
onDismiss : ( ) = > void ;
selectedDashboards : string [ ] ;
dashboardOrigin : { [ key : string ] : string } ;
isLoading : boolean ;
}
export const RestoreModal = ( { onConfirm , onDismiss , selectedDashboards , isLoading , . . . props } : Props ) = > {
export const RestoreModal = ( {
onConfirm ,
onDismiss ,
selectedDashboards ,
dashboardOrigin ,
isLoading ,
. . . props
} : RestoreModalProps ) = > {
const [ restoreTarget , setRestoreTarget ] = useState < string > ( ) ;
const numberOfDashboards = selectedDashboards . length ;
useEffect ( ( ) = > {
if ( Object . entries ( dashboardOrigin ) . length === 1 && dashboardOrigin [ selectedDashboards [ 0 ] ] !== 'general' ) {
setRestoreTarget ( dashboardOrigin [ selectedDashboards [ 0 ] ] ) ;
}
} , [ dashboardOrigin , selectedDashboards ] ) ;
const onRestore = async ( ) = > {
reportInteraction ( 'grafana_restore_confirm_clicked' , {
item_counts : {
dashboard : numberOfDashboards ,
} ,
} ) ;
await onConfirm ( ) ;
onDismiss ( ) ;
if ( restoreTarget !== undefined ) {
await onConfirm ( restoreTarget ) ;
onDismiss ( ) ;
}
} ;
return (
< ConfirmModal
body = {
< Text element = "p" >
< Trans i18nKey = "recently-deleted.restore-modal.text" count = { numberOfDashboards } >
This action will restore { { numberOfDashboards } } dashboards .
< / Trans >
< / Text >
< >
< Text element = "p" >
< Trans i18nKey = "recently-deleted.restore-modal.text" count = { numberOfDashboards } >
This action will restore { { numberOfDashboards } } dashboards .
< / Trans >
< / Text >
< Space v = { 3 } / >
< Text element = "p" >
< Trans i18nKey = "recently-deleted.restore-modal.folder-picker-text" count = { numberOfDashboards } >
Please choose a folder where your dashboards will be restored .
< / Trans >
< / Text >
< Space v = { 1 } / >
< FolderPicker onChange = { setRestoreTarget } value = { restoreTarget } / >
< / >
// TODO: replace by list of dashboards (list up to 5 dashboards) or number (from 6 dashboards)?
}
confirmText = {
@ -43,6 +73,7 @@ export const RestoreModal = ({ onConfirm, onDismiss, selectedDashboards, isLoadi
onDismiss = { onDismiss }
onConfirm = { onRestore }
title = { t ( 'recently-deleted.restore-modal.title' , 'Restore Dashboards' ) }
disabled = { restoreTarget === undefined }
{ . . . props }
/ >
) ;