Skip to content

Commit 187df97

Browse files
committed
Add UI for restoring backup checkpoint text
1 parent ddc4c8e commit 187df97

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

resources/scripts/components/elements/ConfirmationModal.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ import ModalContext from '@/context/ModalContext';
77
type Props = {
88
title: string;
99
buttonText: string;
10-
children: string;
1110
onConfirmed: () => void;
1211
showSpinnerOverlay?: boolean;
1312
};
1413

15-
const ConfirmationModal = ({ title, children, buttonText, onConfirmed }: Props) => {
14+
const ConfirmationModal: React.FC<Props> = ({ title, children, buttonText, onConfirmed }) => {
1615
const { dismiss } = useContext(ModalContext);
1716

1817
return (
1918
<>
2019
<h2 css={tw`text-2xl mb-6`}>{title}</h2>
21-
<p css={tw`text-sm`}>{children}</p>
20+
<div css={tw`text-neutral-300`}>
21+
{children}
22+
</div>
2223
<div css={tw`flex flex-wrap items-center justify-end mt-8`}>
2324
<Button isSecondary onClick={() => dismiss()} css={tw`w-full sm:w-auto border-transparent`}>
2425
Cancel

resources/scripts/components/server/backups/BackupContextMenu.tsx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState } from 'react';
2-
import { faCloudDownloadAlt, faEllipsisH, faLock, faTrashAlt } from '@fortawesome/free-solid-svg-icons';
2+
import { faBoxOpen, faCloudDownloadAlt, faEllipsisH, faLock, faTrashAlt } from '@fortawesome/free-solid-svg-icons';
33
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
44
import DropdownMenu, { DropdownButtonRow } from '@/components/elements/DropdownMenu';
55
import getBackupDownloadUrl from '@/api/server/backups/getBackupDownloadUrl';
@@ -13,6 +13,7 @@ import tw from 'twin.macro';
1313
import getServerBackups from '@/api/swr/getServerBackups';
1414
import { ServerBackup } from '@/api/server/types';
1515
import { ServerContext } from '@/state/server';
16+
import Input from '@/components/elements/Input';
1617

1718
interface Props {
1819
backup: ServerBackup;
@@ -23,6 +24,7 @@ export default ({ backup }: Props) => {
2324
const [ loading, setLoading ] = useState(false);
2425
const [ visible, setVisible ] = useState(false);
2526
const [ deleteVisible, setDeleteVisible ] = useState(false);
27+
const [ restoreVisible, setRestoreVisible ] = useState(false);
2628
const { clearFlashes, clearAndAddHttpError } = useFlash();
2729
const { mutate } = getServerBackups();
2830

@@ -69,6 +71,33 @@ export default ({ backup }: Props) => {
6971
checksum={backup.checksum}
7072
/>
7173
}
74+
<ConfirmationModal
75+
visible={restoreVisible}
76+
title={'Restore this backup?'}
77+
buttonText={'Restore backup'}
78+
onConfirmed={() => null}
79+
onModalDismissed={() => setRestoreVisible(false)}
80+
>
81+
<p css={tw`text-neutral-300`}>
82+
This server will be stopped in order to restore the backup. Once the backup has started you will
83+
not be able to control the server power state, access the file manager, or create additional backups
84+
until it has completed.
85+
</p>
86+
<p css={tw`text-neutral-300 mt-4`}>
87+
Are you sure you want to continue?
88+
</p>
89+
<p css={tw`mt-4 -mb-2 bg-neutral-900 p-3 rounded`}>
90+
<label htmlFor={'restore_truncate'} css={tw`text-base text-neutral-200 flex items-center cursor-pointer`}>
91+
<Input
92+
type={'checkbox'}
93+
css={tw`text-red-500! w-5! h-5! mr-2`}
94+
id={'restore_truncate'}
95+
value={'true'}
96+
/>
97+
Remove all files and folders before restoring this backup.
98+
</label>
99+
</p>
100+
</ConfirmationModal>
72101
<ConfirmationModal
73102
visible={deleteVisible}
74103
title={'Delete this backup?'}
@@ -98,6 +127,12 @@ export default ({ backup }: Props) => {
98127
<span css={tw`ml-2`}>Download</span>
99128
</DropdownButtonRow>
100129
</Can>
130+
<Can action={'backup.restore'}>
131+
<DropdownButtonRow onClick={() => setRestoreVisible(true)}>
132+
<FontAwesomeIcon fixedWidth icon={faBoxOpen} css={tw`text-xs`}/>
133+
<span css={tw`ml-2`}>Restore</span>
134+
</DropdownButtonRow>
135+
</Can>
101136
<DropdownButtonRow onClick={() => setVisible(true)}>
102137
<FontAwesomeIcon fixedWidth icon={faLock} css={tw`text-xs`}/>
103138
<span css={tw`ml-2`}>Checksum</span>

routes/api-client.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
Route::post('/', 'Servers\BackupController@store');
105105
Route::get('/{backup}', 'Servers\BackupController@view');
106106
Route::get('/{backup}/download', 'Servers\BackupController@download');
107+
Route::post('/{backup}/restore', 'Servers\BackupController@restore');
107108
Route::delete('/{backup}', 'Servers\BackupController@delete');
108109
});
109110

0 commit comments

Comments
 (0)