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