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/edit-mount-options.tsx
Views: 687
import { Button, InputNumber, Modal, Spin } from "antd";1import { useState } from "react";23import ShowError from "@cocalc/frontend/components/error";4import { Icon } from "@cocalc/frontend/components/icon";5import { CancelText } from "@cocalc/frontend/i18n/components";6import type { CloudFilesystem } from "@cocalc/util/db-schema/cloud-filesystems";7import { MAX_PORT, MIN_PORT } from "@cocalc/util/db-schema/cloud-filesystems";8import { editCloudFilesystem } from "./api";9import { MountAndKeyDBOptions } from "./create";10import { editModalStyle } from "./util";1112interface Props {13cloudFilesystem: CloudFilesystem;14open?: boolean;15setOpen;16refresh;17}1819export default function EditMountOptions({20cloudFilesystem,21open,22setOpen,23refresh,24}: Props) {25const [changing, setChanging] = useState<boolean>(false);26const [error, setError] = useState<string>("");27const [configuration, setConfiguration] = useState<{28keydb_options: string;29mount_options: string;30port: number | null;31}>({32keydb_options: cloudFilesystem.keydb_options ?? "",33mount_options: cloudFilesystem.mount_options ?? "",34port: cloudFilesystem.port,35});3637const changed = !(38cloudFilesystem.keydb_options == configuration.keydb_options &&39cloudFilesystem.mount_options == configuration.mount_options &&40cloudFilesystem.port == configuration.port41);4243const doEdit = async () => {44if (!changed) {45// no op46setOpen(false);47return;48}49try {50setChanging(true);51await editCloudFilesystem({52id: cloudFilesystem.id,53...configuration,54});55refresh();56setOpen(false);57} catch (err) {58setError(`${err}`);59} finally {60setChanging(false);61}62};6364return (65<Modal66style={{ maxWidth: "100%" }}67styles={{ body: editModalStyle(cloudFilesystem) }}68width={750}69centered70title={71<>72<Icon name={"disk-snapshot"} /> Edit the Mount and KeyDB Options for73the cloud file system "{cloudFilesystem.title?.trim()}"74</>75}76open={open}77onCancel={() => setOpen(false)}78footer={[79<Button key="cancel" onClick={() => setOpen(false)}>80<CancelText />81</Button>,82<Button83key="ok"84type="primary"85disabled={changing || !changed}86onClick={doEdit}87>88Change{" "}89{changing ? <Spin style={{ marginLeft: "15px" }} /> : undefined}90</Button>,91]}92>93<MountAndKeyDBOptions94showHeader={false}95configuration={configuration}96setConfiguration={setConfiguration}97disabled={cloudFilesystem.mount}98/>99<h6>KeyDB Port</h6>100<p>101The KeyDB server will listen on port {configuration.port}. You can102change this to a different port between {MIN_PORT} and {MAX_PORT}, in103case it conflicts with some other software you are using.104</p>105<div style={{ textAlign: "center" }}>106<InputNumber107disabled={cloudFilesystem.mount}108size="large"109style={{ width: "200px" }}110min={MIN_PORT}111max={MAX_PORT}112value={configuration.port}113onChange={(port) => setConfiguration({ ...configuration, port })}114/>115</div>116117<ShowError118style={{ marginTop: "15px" }}119error={error}120setError={setError}121/>122<h6>Advanced</h6>123<pre style={{ overflowY: "scroll", maxHeight: "100px" }}>124{JSON.stringify(cloudFilesystem, undefined, 2)}125</pre>126</Modal>127);128}129130131