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/menu.tsx
Views: 687
1
/*
2
Cloud file system menu.
3
*/
4
5
import { Button, Dropdown } from "antd";
6
import type { MenuProps } from "antd";
7
import { A, Icon } from "@cocalc/frontend/components";
8
import { useMemo, useState } from "react";
9
import openSupportTab from "@cocalc/frontend/support/open";
10
import { User } from "@cocalc/frontend/users";
11
12
function getItems(cloudFilesystem, show): MenuProps["items"] {
13
const help = {
14
key: "help",
15
icon: <Icon name="question-circle" />,
16
label: "Help",
17
children: [
18
{
19
key: "help-ops",
20
icon: <Icon name="question-circle" />,
21
label: "Filesystem Commands",
22
},
23
{
24
key: "documentation",
25
icon: <Icon name="question-circle" />,
26
label: (
27
<A href="https://doc.cocalc.com/compute_server.html">
28
Compute Server Documentation
29
</A>
30
),
31
},
32
{
33
key: "support",
34
icon: <Icon name="medkit" />,
35
label: "CoCalc Support",
36
},
37
{
38
key: "videos",
39
icon: <Icon name="youtube" style={{ color: "red" }} />,
40
label: (
41
<A href="https://www.youtube.com/playlist?list=PLOEk1mo1p5tJmEuAlou4JIWZFH7IVE2PZ">
42
Compute Server Videos
43
</A>
44
),
45
},
46
],
47
};
48
return [
49
{
50
danger: cloudFilesystem.mount,
51
key: "mount",
52
icon: <Icon name={cloudFilesystem.mount ? "stop" : "run"} />,
53
label: cloudFilesystem.mount ? "Disable Automount" : "Enable Automount",
54
},
55
{
56
key: "metrics",
57
icon: <Icon name={"graph"} />,
58
label: `${show.showMetrics ? "Hide" : "Show"} Metrics`,
59
},
60
{
61
type: "divider",
62
},
63
{
64
key: "edit-title-and-colors",
65
icon: <Icon name={"colors"} />,
66
label: "Title and Color",
67
},
68
{
69
key: "edit-bucket-storage-class",
70
icon: <Icon name="disk-snapshot" />,
71
label: "Bucket Storage Class",
72
},
73
// I think this leads to problems and corruption, and is also just really confusing to use.
74
// cocalc has timetravel, etc., and we should make a proper periodic backup-to-another-bucket
75
// functionality.
76
// {
77
// key: "edit-trash-config",
78
// icon: <Icon name={"trash"} />,
79
// label: cloudFilesystem.trash_days ? "Configure Trash" : "Enable Trash",
80
// },
81
{
82
key: "edit-lock",
83
icon: <Icon name={"lock"} />,
84
label: "Delete Protection",
85
},
86
{
87
type: "divider",
88
},
89
{
90
disabled: cloudFilesystem.mount,
91
key: "edit-mountpoint",
92
icon: <Icon name="folder-open" />,
93
label: "Change Mountpoint",
94
},
95
{
96
key: "edit-project",
97
disabled: cloudFilesystem.mount,
98
icon: <Icon name={"pencil"} />,
99
label: "Move to Another Project",
100
},
101
{
102
type: "divider",
103
},
104
{
105
key: "edit-mount-options",
106
icon: <Icon name={"database"} />,
107
label: "Mount and KeyDB Options",
108
},
109
{
110
disabled: cloudFilesystem.mount,
111
danger: true,
112
key: "delete",
113
icon: <Icon name="trash" />,
114
label: "Delete Filesystem",
115
},
116
{
117
type: "divider",
118
},
119
help,
120
];
121
}
122
123
export default function Menu({
124
cloudFilesystem,
125
style,
126
setError,
127
size,
128
fontSize,
129
show,
130
}: {
131
cloudFilesystem;
132
style?;
133
setError;
134
size?;
135
fontSize?;
136
show?: {
137
setShowHelp;
138
setShowMount;
139
setShowEditMountpoint;
140
setShowEditTitleAndColor;
141
setShowDelete;
142
setShowEditLock;
143
setShowEditTrashDays;
144
setShowEditBucketStorageClass;
145
setShowEditMountOptions;
146
setShowEditProject;
147
setShowMetrics;
148
showMetrics;
149
};
150
}) {
151
const [open, setOpen] = useState<boolean>(false);
152
const { items, onClick } = useMemo(() => {
153
if (!open) {
154
return { onClick: () => {}, items: [] };
155
}
156
157
return {
158
items: show != null ? getItems(cloudFilesystem, show) : [],
159
onClick: async (obj) => {
160
if (show == null) {
161
return;
162
}
163
setOpen(false);
164
let cmd = obj.key.startsWith("top-") ? obj.key.slice(4) : obj.key;
165
switch (cmd) {
166
case "mount":
167
show.setShowMount(true);
168
break;
169
case "metrics":
170
show.setShowMetrics(!show.showMetrics);
171
break;
172
case "edit-title-and-colors":
173
show.setShowEditTitleAndColor(true);
174
break;
175
case "edit-lock":
176
show.setShowEditLock(true);
177
break;
178
case "edit-mountpoint":
179
show.setShowEditMountpoint(true);
180
break;
181
case "edit-project":
182
show.setShowEditProject(true);
183
break;
184
case "edit-mount-options":
185
show.setShowEditMountOptions(true);
186
break;
187
case "edit-trash-config":
188
show.setShowEditTrashDays(true);
189
break;
190
case "edit-bucket-storage-class":
191
show.setShowEditBucketStorageClass(true);
192
break;
193
case "delete":
194
show.setShowDelete(true);
195
break;
196
case "help-ops":
197
show.setShowHelp(true);
198
break;
199
case "documentation":
200
case "videos":
201
// click opens new tab anyways
202
break;
203
case "support":
204
openSupportTab({
205
type: "question",
206
subject: `Cloud File System (Global Id: ${cloudFilesystem.id}; Project Specific Id: ${cloudFilesystem.project_specific_id})`,
207
body: `I am using a cloud file system, and have a question...`,
208
});
209
break;
210
211
default:
212
setError(`not implemented -- '${cmd}'`);
213
}
214
},
215
};
216
}, [cloudFilesystem, open]);
217
218
if (show == null) {
219
return (
220
<div>
221
Owner: <User account_id={cloudFilesystem.account_id} />
222
</div>
223
);
224
}
225
226
return (
227
<div style={style}>
228
<Dropdown
229
menu={{ items, onClick }}
230
trigger={["click"]}
231
disabled={cloudFilesystem.deleting}
232
onOpenChange={setOpen}
233
>
234
<Button type="text" size={size}>
235
<Icon
236
name="ellipsis"
237
style={{ fontSize: fontSize ?? "15pt", color: "#000" }}
238
rotate="90"
239
/>
240
</Button>
241
</Dropdown>
242
</div>
243
);
244
}
245
246