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/compute/cloud-filesystem/mount-filesystem.tsx
Views: 687
import { Alert, Button, Modal, Spin } from "antd";1import { useEffect, useRef, useState } from "react";23import { A } from "@cocalc/frontend/components/A";4import ShowError from "@cocalc/frontend/components/error";5import { Icon } from "@cocalc/frontend/components/icon";6import { checkInAll } from "@cocalc/frontend/compute/check-in";7import { CancelText } from "@cocalc/frontend/i18n/components";8import type { CloudFilesystem } from "@cocalc/util/db-schema/cloud-filesystems";9import { editCloudFilesystem } from "./api";10import { Mountpoint } from "./cloud-filesystem";11import { editModalStyle } from "./util";1213interface Props {14cloudFilesystem: CloudFilesystem;15open?: boolean;16setOpen;17refresh;18}1920// Actually toggles Mount status21export default function MountCloudFilesystem({22cloudFilesystem,23open,24setOpen,25refresh,26}: Props) {27const [mounting, setMounting] = useState<boolean>(false);28const [error, setError] = useState<string>("");29const buttonRef = useRef<any>(null);3031useEffect(() => {32if (!cloudFilesystem.mount) {33// only focus for mounting (the non-dangerous one)34setTimeout(() => {35buttonRef.current?.focus();36}, 300);37}38}, []);3940const doToggleMount = async () => {41try {42setMounting(true);43await editCloudFilesystem({44id: cloudFilesystem.id,45mount: !cloudFilesystem.mount,46});47checkInAll(cloudFilesystem.project_id);48refresh();49setOpen(false);50} catch (err) {51setError(`${err}`);52} finally {53setMounting(false);54}55};56const icon = cloudFilesystem.mount ? "stop" : "run";57const verb = cloudFilesystem.mount58? "Unmount and Disable Automount"59: "Mount and Enable Automount";6061return (62<Modal63styles={{ body: editModalStyle(cloudFilesystem) }}64centered65title={66<>67<Icon name={icon} /> {verb} "{cloudFilesystem.title}"{" "}68{cloudFilesystem.mount ? "from" : "at"}{" "}69<Mountpoint {...cloudFilesystem} />?70</>71}72open={open}73onCancel={() => setOpen(false)}74footer={[75<Button key="cancel" onClick={() => setOpen(false)}>76<CancelText />77</Button>,78<Button79ref={buttonRef}80key="ok"81type={cloudFilesystem.mount ? "default" : "primary"}82danger={cloudFilesystem.mount}83disabled={mounting}84onClick={doToggleMount}85>86<Icon name={icon} /> {verb}{" "}87{mounting ? <Spin style={{ marginLeft: "15px" }} /> : undefined}88</Button>,89]}90>91<div>92<p>93Are you sure you want to{" "}94{cloudFilesystem.mount ? "unmount" : "automount"} this cloud95filesystem?96{cloudFilesystem.mount97? " The file system may be currently mounted so make sure no applications have anything in this filesystem open to avoid data loss. "98: " "}99{cloudFilesystem.mount ? "Unmounting" : "Automatic mounting"}{" "}100typically takes about <b>15 seconds</b>.101</p>102<Alert103showIcon104style={{ margin: "10px 0" }}105type="warning"106message={<b>Cloud File Systems Only Visible From Compute Servers</b>}107description={108<>109Currently cloud file systems can only be used from compute110servers, i.e., from a Jupyter notebook or terminal that is set to111use a compute server or from the file browser set to explore a112compute server.113</>114}115/>116{!cloudFilesystem.mount && (117<p style={{ color: "#666" }}>118<b>WARNING:</b> When a cloud file system is first created or has not119been used for a while, it can take several minutes to automount in a120running project while{" "}121<A href="https://cloud.google.com/iam/docs/access-change-propagation">122security policies123</A>{" "}124propagate.125</p>126)}127</div>128<ShowError error={error} setError={setError} />129</Modal>130);131}132133134