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-project.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 { SelectProject } from "@cocalc/frontend/projects/select-project";
8
import type { CloudFilesystem } from "@cocalc/util/db-schema/cloud-filesystems";
9
import { editCloudFilesystem } from "./api";
10
import { editModalStyle } from "./util";
11
12
interface Props {
13
cloudFilesystem: CloudFilesystem;
14
open?: boolean;
15
setOpen;
16
refresh;
17
}
18
19
// Edit the project_id of a cloud file system
20
export default function EditProjectId({
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 [project_id, setProjectId] = useState<string>(
29
cloudFilesystem.project_id,
30
);
31
32
const doEdit = async () => {
33
if (cloudFilesystem.project_id == project_id) {
34
// no op
35
setOpen(false);
36
return;
37
}
38
try {
39
setChanging(true);
40
await editCloudFilesystem({
41
id: cloudFilesystem.id,
42
project_id,
43
});
44
refresh();
45
setOpen(false);
46
} catch (err) {
47
setError(`${err}`);
48
} finally {
49
setChanging(false);
50
}
51
};
52
53
return (
54
<Modal
55
styles={{ body: editModalStyle(cloudFilesystem) }}
56
centered
57
title={
58
<>
59
<Icon name={"folder-open"} /> Move "{cloudFilesystem.title}" to
60
Another Project
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={changing || cloudFilesystem.project_id == project_id}
73
onClick={doEdit}
74
>
75
Move Filesystem{" "}
76
{changing ? <Spin style={{ marginLeft: "15px" }} /> : undefined}
77
</Button>,
78
]}
79
>
80
<p>
81
You can instantly move this cloud file system to any other project that
82
you are a collaborator on.
83
</p>
84
<SelectProject
85
at_top={[cloudFilesystem.project_id]}
86
value={project_id}
87
onChange={setProjectId}
88
/>
89
<ShowError error={error} setError={setError} />
90
</Modal>
91
);
92
}
93
94