2020-04-05 02:54:59 +00:00
|
|
|
import React, { useState } from 'react';
|
2020-04-04 20:24:03 +00:00
|
|
|
import { ServerBackup } from '@/api/server/backups/getServerBackups';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
import { faArchive } from '@fortawesome/free-solid-svg-icons/faArchive';
|
|
|
|
import format from 'date-fns/format';
|
2020-04-05 02:54:59 +00:00
|
|
|
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
|
2020-04-04 20:24:03 +00:00
|
|
|
import Spinner from '@/components/elements/Spinner';
|
2020-04-05 02:54:59 +00:00
|
|
|
import Modal, { RequiredModalProps } from '@/components/elements/Modal';
|
|
|
|
import { bytesToHuman } from '@/helpers';
|
|
|
|
import Can from '@/components/elements/Can';
|
|
|
|
import useServer from '@/plugins/useServer';
|
2020-04-07 03:28:14 +00:00
|
|
|
import getBackupDownloadUrl from '@/api/server/backups/getBackupDownloadUrl';
|
|
|
|
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
|
|
|
import useFlash from '@/plugins/useFlash';
|
|
|
|
import { httpErrorToHuman } from '@/api/http';
|
2020-04-07 04:22:57 +00:00
|
|
|
import useWebsocketEvent from '@/plugins/useWebsocketEvent';
|
2020-04-07 05:25:54 +00:00
|
|
|
import { ServerContext } from '@/state/server';
|
2020-04-10 05:08:09 +00:00
|
|
|
import BackupContextMenu from '@/components/server/backups/BackupContextMenu';
|
|
|
|
import { faEllipsisH } from '@fortawesome/free-solid-svg-icons/faEllipsisH';
|
2020-04-04 20:24:03 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
backup: ServerBackup;
|
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
2020-04-07 05:25:54 +00:00
|
|
|
export default ({ backup, className }: Props) => {
|
|
|
|
const appendBackup = ServerContext.useStoreActions(actions => actions.backups.appendBackup);
|
|
|
|
|
2020-04-07 04:22:57 +00:00
|
|
|
useWebsocketEvent(`backup completed:${backup.uuid}`, data => {
|
|
|
|
try {
|
|
|
|
const parsed = JSON.parse(data);
|
2020-04-07 05:25:54 +00:00
|
|
|
appendBackup({
|
2020-04-07 04:22:57 +00:00
|
|
|
...backup,
|
|
|
|
sha256Hash: parsed.sha256_hash || '',
|
|
|
|
bytes: parsed.file_size || 0,
|
|
|
|
completedAt: new Date(),
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-04-04 20:24:03 +00:00
|
|
|
return (
|
|
|
|
<div className={`grey-row-box flex items-center ${className}`}>
|
|
|
|
<div className={'mr-4'}>
|
2020-04-05 02:54:59 +00:00
|
|
|
{backup.completedAt ?
|
|
|
|
<FontAwesomeIcon icon={faArchive} className={'text-neutral-300'}/>
|
|
|
|
:
|
|
|
|
<Spinner size={'tiny'}/>
|
|
|
|
}
|
2020-04-04 20:24:03 +00:00
|
|
|
</div>
|
|
|
|
<div className={'flex-1'}>
|
2020-04-05 02:54:59 +00:00
|
|
|
<p className={'text-sm mb-1'}>
|
|
|
|
{backup.name}
|
|
|
|
{backup.completedAt &&
|
|
|
|
<span className={'ml-3 text-neutral-300 text-xs font-thin'}>{bytesToHuman(backup.bytes)}</span>
|
|
|
|
}
|
|
|
|
</p>
|
|
|
|
<p className={'text-xs text-neutral-400 font-mono'}>
|
|
|
|
{backup.uuid}
|
|
|
|
</p>
|
2020-04-04 20:24:03 +00:00
|
|
|
</div>
|
2020-04-05 02:54:59 +00:00
|
|
|
<div className={'ml-8 text-center'}>
|
2020-04-04 20:24:03 +00:00
|
|
|
<p
|
|
|
|
title={format(backup.createdAt, 'ddd, MMMM Do, YYYY HH:mm:ss Z')}
|
|
|
|
className={'text-sm'}
|
|
|
|
>
|
|
|
|
{distanceInWordsToNow(backup.createdAt, { includeSeconds: true, addSuffix: true })}
|
|
|
|
</p>
|
|
|
|
<p className={'text-2xs text-neutral-500 uppercase mt-1'}>Created</p>
|
|
|
|
</div>
|
2020-04-05 02:54:59 +00:00
|
|
|
<Can action={'backup.download'}>
|
|
|
|
<div className={'ml-6'} style={{ marginRight: '-0.5rem' }}>
|
|
|
|
{!backup.completedAt ?
|
|
|
|
<div className={'p-2 invisible'}>
|
2020-04-10 05:08:09 +00:00
|
|
|
<FontAwesomeIcon icon={faEllipsisH}/>
|
2020-04-05 02:54:59 +00:00
|
|
|
</div>
|
|
|
|
:
|
2020-04-10 05:08:09 +00:00
|
|
|
<BackupContextMenu backup={backup}/>
|
2020-04-05 02:54:59 +00:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</Can>
|
2020-04-04 20:24:03 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|