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-mount-options.tsx
Views: 687
1
import { Button, InputNumber, 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 { MAX_PORT, MIN_PORT } from "@cocalc/util/db-schema/cloud-filesystems";
9
import { editCloudFilesystem } from "./api";
10
import { MountAndKeyDBOptions } from "./create";
11
import { editModalStyle } from "./util";
12
13
interface Props {
14
cloudFilesystem: CloudFilesystem;
15
open?: boolean;
16
setOpen;
17
refresh;
18
}
19
20
export default function EditMountOptions({
21
cloudFilesystem,
22
open,
23
setOpen,
24
refresh,
25
}: Props) {
26
const [changing, setChanging] = useState<boolean>(false);
27
const [error, setError] = useState<string>("");
28
const [configuration, setConfiguration] = useState<{
29
keydb_options: string;
30
mount_options: string;
31
port: number | null;
32
}>({
33
keydb_options: cloudFilesystem.keydb_options ?? "",
34
mount_options: cloudFilesystem.mount_options ?? "",
35
port: cloudFilesystem.port,
36
});
37
38
const changed = !(
39
cloudFilesystem.keydb_options == configuration.keydb_options &&
40
cloudFilesystem.mount_options == configuration.mount_options &&
41
cloudFilesystem.port == configuration.port
42
);
43
44
const doEdit = async () => {
45
if (!changed) {
46
// no op
47
setOpen(false);
48
return;
49
}
50
try {
51
setChanging(true);
52
await editCloudFilesystem({
53
id: cloudFilesystem.id,
54
...configuration,
55
});
56
refresh();
57
setOpen(false);
58
} catch (err) {
59
setError(`${err}`);
60
} finally {
61
setChanging(false);
62
}
63
};
64
65
return (
66
<Modal
67
style={{ maxWidth: "100%" }}
68
styles={{ body: editModalStyle(cloudFilesystem) }}
69
width={750}
70
centered
71
title={
72
<>
73
<Icon name={"disk-snapshot"} /> Edit the Mount and KeyDB Options for
74
the cloud file system "{cloudFilesystem.title?.trim()}"
75
</>
76
}
77
open={open}
78
onCancel={() => setOpen(false)}
79
footer={[
80
<Button key="cancel" onClick={() => setOpen(false)}>
81
<CancelText />
82
</Button>,
83
<Button
84
key="ok"
85
type="primary"
86
disabled={changing || !changed}
87
onClick={doEdit}
88
>
89
Change{" "}
90
{changing ? <Spin style={{ marginLeft: "15px" }} /> : undefined}
91
</Button>,
92
]}
93
>
94
<MountAndKeyDBOptions
95
showHeader={false}
96
configuration={configuration}
97
setConfiguration={setConfiguration}
98
disabled={cloudFilesystem.mount}
99
/>
100
<h6>KeyDB Port</h6>
101
<p>
102
The KeyDB server will listen on port {configuration.port}. You can
103
change this to a different port between {MIN_PORT} and {MAX_PORT}, in
104
case it conflicts with some other software you are using.
105
</p>
106
<div style={{ textAlign: "center" }}>
107
<InputNumber
108
disabled={cloudFilesystem.mount}
109
size="large"
110
style={{ width: "200px" }}
111
min={MIN_PORT}
112
max={MAX_PORT}
113
value={configuration.port}
114
onChange={(port) => setConfiguration({ ...configuration, port })}
115
/>
116
</div>
117
118
<ShowError
119
style={{ marginTop: "15px" }}
120
error={error}
121
setError={setError}
122
/>
123
<h6>Advanced</h6>
124
<pre style={{ overflowY: "scroll", maxHeight: "100px" }}>
125
{JSON.stringify(cloudFilesystem, undefined, 2)}
126
</pre>
127
</Modal>
128
);
129
}
130
131