Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/course/configuration/datastore-config.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45// This configures the datastore configuration for student and the shared project.6// basically: if it is "true", the datastore config of the teacher project is looked up when the project starts7// and used to configure it in read-only mode. In the future, a natural extension is to explicitly list the datastores8// that should be inherited, or configure the readonly property. but for now, it's just true or false.910import { Button, Card, Form, Switch, Typography } from "antd";11import { List } from "immutable";12import { useEffect, useState } from "react";13import { useIntl } from "react-intl";1415import { redux, useTypedRedux } from "@cocalc/frontend/app-framework";16import { Icon } from "@cocalc/frontend/components";17import { labels } from "@cocalc/frontend/i18n";18import { Datastore } from "@cocalc/frontend/projects/actions";19import {20KUCALC_COCALC_COM,21KUCALC_ON_PREMISES,22} from "@cocalc/util/db-schema/site-defaults";23import { ConfigurationActions } from "./actions";2425interface Props {26actions: ConfigurationActions;27datastore?: Datastore | List<string>; // List<string> is not used yet28project_id: string;29close?: Function;30}3132export function DatastoreConfig({33actions,34datastore,35project_id,36close,37}: Props) {38const intl = useIntl();39const customize_kucalc = useTypedRedux("customize", "kucalc");40const customize_datastore = useTypedRedux("customize", "datastore");41const [need_save, set_need_save] = useState<boolean>(false);4243// by default, we inherit the datastore configuration44// as of this, we also only support true/false45const inherit = typeof datastore === "boolean" ? datastore : true;46const [next_val, set_next_val] = useState<boolean>(inherit);4748useEffect(() => {49// needed because of realtime collaboration, multiple frames, modal, etc!50set_next_val(inherit);51}, [inherit]);5253function on_inherit_change(inherit: boolean) {54set_next_val(inherit);55}5657useEffect(() => {58set_need_save(next_val != inherit);59}, [next_val, inherit]);6061function save() {62actions.set_datastore(next_val);63close?.();64}6566// this selector only make sense for cocalc.com or onprem with datastore enabled67const showDatastore =68customize_kucalc === KUCALC_COCALC_COM ||69(customize_kucalc === KUCALC_ON_PREMISES && customize_datastore);7071if (!showDatastore) return null;7273function render_control() {74return (75<Form layout="inline">76<Form.Item label="Inherit settings:" style={{ marginBottom: 0 }}>77<Switch78checked={next_val}79onChange={(val) => on_inherit_change(val)}80/>81</Form.Item>82<Form.Item>83<Button84disabled={!need_save}85type={need_save ? "primary" : "default"}86onClick={save}87>88Save89</Button>90</Form.Item>91</Form>92);93}9495return (96<>97<br />98<Card99title={100<>101<Icon name="database" />{" "}102{intl.formatMessage(labels.cloud_storage_remote_filesystems)}103</>104}105>106<p>107If enabled, all student projects will have{" "}108<Typography.Text strong>read-only</Typography.Text> access to the same109cloud stores and remote file systems as this instructor project. To110configure them, please check{" "}111<a112onClick={() => {113redux.getProjectActions(project_id).set_active_tab("settings");114close?.();115}}116>117this project's settings118</a>{" "}119for more details. Any changes to the configuration of this project120will be reflected after the next start of a student project.121</p>122{render_control()}123</Card>124</>125);126}127128129