CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/compute/cloud-filesystem/edit-trash-days.tsx
Views: 687
1
import { Button, InputNumber, Modal, Spin } from "antd";
2
import { useState } from "react";
3
4
import { A } from "@cocalc/frontend/components/A";
5
import ShowError from "@cocalc/frontend/components/error";
6
import { Icon } from "@cocalc/frontend/components/icon";
7
import { checkInAll } from "@cocalc/frontend/compute/check-in";
8
import { CancelText } from "@cocalc/frontend/i18n/components";
9
import type { CloudFilesystem } from "@cocalc/util/db-schema/cloud-filesystems";
10
import { editCloudFilesystem } from "./api";
11
import { editModalStyle } from "./util";
12
13
interface Props {
14
cloudFilesystem: CloudFilesystem;
15
open?: boolean;
16
setOpen;
17
refresh;
18
}
19
20
// Edit the title and color of a cloud file system
21
export default function EditTrashDays({
22
cloudFilesystem,
23
open,
24
setOpen,
25
refresh,
26
}: Props) {
27
const [changing, setChanging] = useState<boolean>(false);
28
const [error, setError] = useState<string>("");
29
const [trashDays, setTrashDays] = useState<number>(
30
cloudFilesystem.trash_days ?? 0,
31
);
32
33
const doEdit = async () => {
34
if (cloudFilesystem.trash_days == trashDays) {
35
// no op
36
setOpen(false);
37
return;
38
}
39
try {
40
setChanging(true);
41
await editCloudFilesystem({
42
id: cloudFilesystem.id,
43
trash_days: trashDays,
44
});
45
refresh();
46
setOpen(false);
47
if (cloudFilesystem.mount) {
48
// cause quicker update
49
checkInAll(cloudFilesystem.project_id);
50
}
51
} catch (err) {
52
setError(`${err}`);
53
} finally {
54
setChanging(false);
55
}
56
};
57
58
return (
59
<Modal
60
styles={{ body: editModalStyle(cloudFilesystem) }}
61
centered
62
title={
63
<>
64
<Icon name={"trash"} /> Edit Trash Configuration for "
65
{cloudFilesystem.title}"
66
</>
67
}
68
open={open}
69
onCancel={() => setOpen(false)}
70
footer={[
71
<Button key="cancel" onClick={() => setOpen(false)}>
72
<CancelText />
73
</Button>,
74
<Button
75
key="ok"
76
type="primary"
77
disabled={changing || cloudFilesystem.trash_days == trashDays}
78
onClick={doEdit}
79
>
80
Change{" "}
81
{changing ? <Spin style={{ marginLeft: "15px" }} /> : undefined}
82
</Button>,
83
]}
84
>
85
<p style={{ textAlign: "center", fontSize: "12pt" }}>
86
<b>
87
<A href="https://juicefs.com/docs/community/security/trash/">
88
JuiceFS Trash
89
</A>{" "}
90
is {cloudFilesystem.trash_days == 0 ? "disabled" : "enabled"}.
91
</b>
92
</p>
93
Optionally store deleted files in{" "}
94
<code>~/{cloudFilesystem.mountpoint}/.trash</code> for the number of days
95
shown below. Set to 0 to disable. You can change this at any time, even
96
when the file system is mounted, and it will be updated quickly.
97
<div style={{ textAlign: "center" }}>
98
<InputNumber
99
addonAfter={"days"}
100
min={0}
101
onPressEnter={doEdit}
102
style={{ width: "200px", margin: "10px 0", color: "red" }}
103
value={trashDays}
104
onChange={(d) => setTrashDays(Math.round(d ?? 0))}
105
/>
106
</div>
107
<p>
108
To quickly empty the trash type{" "}
109
<pre>sudo rm -rf ~/"{cloudFilesystem.mountpoint}"/.trash/*/*</pre> in a
110
terminal.
111
</p>
112
<ShowError error={error} setError={setError} />
113
</Modal>
114
);
115
}
116
117