bazarr/frontend/src/pages/System/Backups/table.tsx

110 lines
3.4 KiB
TypeScript
Raw Normal View History

2022-05-31 15:49:04 +00:00
import { useDeleteBackups, useRestoreBackups } from "@/apis/hooks";
import { Action, PageTable } from "@/components";
import { useModals } from "@/modules/modals";
import { useTableStyles } from "@/styles";
import { Environment } from "@/utilities";
import { faClock, faHistory, faTrash } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Anchor, Group, Text } from "@mantine/core";
2022-05-31 15:49:04 +00:00
import { FunctionComponent, useMemo } from "react";
import { Column } from "react-table";
interface Props {
backups: readonly System.Backups[];
}
const Table: FunctionComponent<Props> = ({ backups }) => {
const columns: Column<System.Backups>[] = useMemo<Column<System.Backups>[]>(
() => [
{
accessor: "type",
Cell: <FontAwesomeIcon icon={faClock}></FontAwesomeIcon>,
},
{
Header: "Name",
accessor: "filename",
2022-05-31 15:49:04 +00:00
Cell: ({ value }) => {
return (
<Anchor
href={`${Environment.baseUrl}/system/backup/download/${value}`}
>
{value}
</Anchor>
);
2022-05-31 15:49:04 +00:00
},
},
{
Header: "Size",
accessor: "size",
2022-05-31 15:49:04 +00:00
Cell: ({ value }) => {
const { classes } = useTableStyles();
return <Text className={classes.noWrap}>{value}</Text>;
},
},
{
Header: "Time",
accessor: "date",
2022-05-31 15:49:04 +00:00
Cell: ({ value }) => {
const { classes } = useTableStyles();
return <Text className={classes.noWrap}>{value}</Text>;
},
},
{
2022-05-31 15:49:04 +00:00
id: "actions",
accessor: "filename",
Cell: ({ value }) => {
const modals = useModals();
const restore = useRestoreBackups();
const remove = useDeleteBackups();
return (
2022-05-31 15:49:04 +00:00
<Group spacing="xs" noWrap>
<Action
2022-06-01 17:08:50 +00:00
label="Restore"
2022-03-27 06:42:28 +00:00
onClick={() =>
2022-05-31 15:49:04 +00:00
modals.openConfirmModal({
title: "Restore Backup",
children: (
<Text size="sm">
Are you sure you want to restore the backup ({value})?
Bazarr will automatically restart and reload the UI
during the restore process.
</Text>
),
labels: { confirm: "Restore", cancel: "Cancel" },
confirmProps: { color: "red" },
onConfirm: () => restore.mutate(value),
})
2022-03-27 06:42:28 +00:00
}
2022-05-31 15:49:04 +00:00
icon={faHistory}
></Action>
<Action
2022-06-01 17:08:50 +00:00
label="Delete"
color="red"
2022-03-27 06:42:28 +00:00
onClick={() =>
2022-05-31 15:49:04 +00:00
modals.openConfirmModal({
title: "Delete Backup",
children: (
<Text size="sm">
Are you sure you want to delete the backup ({value})?
</Text>
),
labels: { confirm: "Delete", cancel: "Cancel" },
confirmProps: { color: "red" },
onConfirm: () => remove.mutate(value),
})
2022-03-27 06:42:28 +00:00
}
2022-05-31 15:49:04 +00:00
icon={faTrash}
></Action>
</Group>
);
},
},
],
[]
);
2022-05-31 15:49:04 +00:00
return <PageTable columns={columns} data={backups}></PageTable>;
};
export default Table;