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-bucket-storage-class.tsx
Views: 687
1
import { Button, Modal, Spin } from "antd";
2
import { useState } from "react";
3
4
import ShowError from "@cocalc/frontend/components/error";
5
import { Icon } from "@cocalc/frontend/components/icon";
6
import { CancelText } from "@cocalc/frontend/i18n/components";
7
import type { CloudFilesystem } from "@cocalc/util/db-schema/cloud-filesystems";
8
import { editCloudFilesystem } from "./api";
9
import { BucketStorageClass } from "./bucket";
10
11
interface Props {
12
cloudFilesystem: CloudFilesystem;
13
open?: boolean;
14
setOpen;
15
refresh;
16
}
17
18
export default function EditBucketStorageClass({
19
cloudFilesystem,
20
open,
21
setOpen,
22
refresh,
23
}: Props) {
24
const [changing, setChanging] = useState<boolean>(false);
25
const [error, setError] = useState<string>("");
26
const [configuration, setConfiguration] =
27
useState<CloudFilesystem>(cloudFilesystem);
28
29
const doEdit = async () => {
30
if (
31
cloudFilesystem.bucket_storage_class == configuration.bucket_storage_class
32
) {
33
// no op
34
setOpen(false);
35
return;
36
}
37
try {
38
setChanging(true);
39
await editCloudFilesystem({
40
id: cloudFilesystem.id,
41
bucket_storage_class: configuration.bucket_storage_class,
42
});
43
refresh();
44
setOpen(false);
45
} catch (err) {
46
setError(`${err}`);
47
} finally {
48
setChanging(false);
49
}
50
};
51
52
return (
53
<Modal
54
style={{ maxWidth: "100%" }}
55
width={750}
56
centered
57
title={
58
<>
59
<Icon name={"disk-snapshot"} /> Edit the Default Bucket Storage Class
60
for the cloud file system "{cloudFilesystem.title?.trim()}"
61
</>
62
}
63
open={open}
64
onCancel={() => setOpen(false)}
65
footer={[
66
<Button key="cancel" onClick={() => setOpen(false)}>
67
<CancelText />
68
</Button>,
69
<Button
70
key="ok"
71
type="primary"
72
disabled={
73
changing ||
74
cloudFilesystem.bucket_storage_class ==
75
configuration.bucket_storage_class
76
}
77
onClick={doEdit}
78
>
79
Change{" "}
80
{changing ? <Spin style={{ marginLeft: "15px" }} /> : undefined}
81
</Button>,
82
]}
83
>
84
<BucketStorageClass
85
configuration={configuration}
86
setConfiguration={setConfiguration}
87
/>
88
89
<ShowError error={error} setError={setError} />
90
</Modal>
91
);
92
}
93
94