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/course/configuration/datastore-config.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
// This configures the datastore configuration for student and the shared project.
7
// basically: if it is "true", the datastore config of the teacher project is looked up when the project starts
8
// and used to configure it in read-only mode. In the future, a natural extension is to explicitly list the datastores
9
// that should be inherited, or configure the readonly property. but for now, it's just true or false.
10
11
import { Button, Card, Form, Switch, Typography } from "antd";
12
import { List } from "immutable";
13
import { useEffect, useState } from "react";
14
import { useIntl } from "react-intl";
15
16
import { redux, useTypedRedux } from "@cocalc/frontend/app-framework";
17
import { Icon } from "@cocalc/frontend/components";
18
import { labels } from "@cocalc/frontend/i18n";
19
import { Datastore } from "@cocalc/frontend/projects/actions";
20
import {
21
KUCALC_COCALC_COM,
22
KUCALC_ON_PREMISES,
23
} from "@cocalc/util/db-schema/site-defaults";
24
import { ConfigurationActions } from "./actions";
25
26
interface Props {
27
actions: ConfigurationActions;
28
datastore?: Datastore | List<string>; // List<string> is not used yet
29
project_id: string;
30
close?: Function;
31
}
32
33
export function DatastoreConfig({
34
actions,
35
datastore,
36
project_id,
37
close,
38
}: Props) {
39
const intl = useIntl();
40
const customize_kucalc = useTypedRedux("customize", "kucalc");
41
const customize_datastore = useTypedRedux("customize", "datastore");
42
const [need_save, set_need_save] = useState<boolean>(false);
43
44
// by default, we inherit the datastore configuration
45
// as of this, we also only support true/false
46
const inherit = typeof datastore === "boolean" ? datastore : true;
47
const [next_val, set_next_val] = useState<boolean>(inherit);
48
49
useEffect(() => {
50
// needed because of realtime collaboration, multiple frames, modal, etc!
51
set_next_val(inherit);
52
}, [inherit]);
53
54
function on_inherit_change(inherit: boolean) {
55
set_next_val(inherit);
56
}
57
58
useEffect(() => {
59
set_need_save(next_val != inherit);
60
}, [next_val, inherit]);
61
62
function save() {
63
actions.set_datastore(next_val);
64
close?.();
65
}
66
67
// this selector only make sense for cocalc.com or onprem with datastore enabled
68
const showDatastore =
69
customize_kucalc === KUCALC_COCALC_COM ||
70
(customize_kucalc === KUCALC_ON_PREMISES && customize_datastore);
71
72
if (!showDatastore) return null;
73
74
function render_control() {
75
return (
76
<Form layout="inline">
77
<Form.Item label="Inherit settings:" style={{ marginBottom: 0 }}>
78
<Switch
79
checked={next_val}
80
onChange={(val) => on_inherit_change(val)}
81
/>
82
</Form.Item>
83
<Form.Item>
84
<Button
85
disabled={!need_save}
86
type={need_save ? "primary" : "default"}
87
onClick={save}
88
>
89
Save
90
</Button>
91
</Form.Item>
92
</Form>
93
);
94
}
95
96
return (
97
<>
98
<br />
99
<Card
100
title={
101
<>
102
<Icon name="database" />{" "}
103
{intl.formatMessage(labels.cloud_storage_remote_filesystems)}
104
</>
105
}
106
>
107
<p>
108
If enabled, all student projects will have{" "}
109
<Typography.Text strong>read-only</Typography.Text> access to the same
110
cloud stores and remote file systems as this instructor project. To
111
configure them, please check{" "}
112
<a
113
onClick={() => {
114
redux.getProjectActions(project_id).set_active_tab("settings");
115
close?.();
116
}}
117
>
118
this project's settings
119
</a>{" "}
120
for more details. Any changes to the configuration of this project
121
will be reflected after the next start of a student project.
122
</p>
123
{render_control()}
124
</Card>
125
</>
126
);
127
}
128
129