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/menu.tsx
Views: 687
/*1Cloud file system menu.2*/34import { Button, Dropdown } from "antd";5import type { MenuProps } from "antd";6import { A, Icon } from "@cocalc/frontend/components";7import { useMemo, useState } from "react";8import openSupportTab from "@cocalc/frontend/support/open";9import { User } from "@cocalc/frontend/users";1011function getItems(cloudFilesystem, show): MenuProps["items"] {12const help = {13key: "help",14icon: <Icon name="question-circle" />,15label: "Help",16children: [17{18key: "help-ops",19icon: <Icon name="question-circle" />,20label: "Filesystem Commands",21},22{23key: "documentation",24icon: <Icon name="question-circle" />,25label: (26<A href="https://doc.cocalc.com/compute_server.html">27Compute Server Documentation28</A>29),30},31{32key: "support",33icon: <Icon name="medkit" />,34label: "CoCalc Support",35},36{37key: "videos",38icon: <Icon name="youtube" style={{ color: "red" }} />,39label: (40<A href="https://www.youtube.com/playlist?list=PLOEk1mo1p5tJmEuAlou4JIWZFH7IVE2PZ">41Compute Server Videos42</A>43),44},45],46};47return [48{49danger: cloudFilesystem.mount,50key: "mount",51icon: <Icon name={cloudFilesystem.mount ? "stop" : "run"} />,52label: cloudFilesystem.mount ? "Disable Automount" : "Enable Automount",53},54{55key: "metrics",56icon: <Icon name={"graph"} />,57label: `${show.showMetrics ? "Hide" : "Show"} Metrics`,58},59{60type: "divider",61},62{63key: "edit-title-and-colors",64icon: <Icon name={"colors"} />,65label: "Title and Color",66},67{68key: "edit-bucket-storage-class",69icon: <Icon name="disk-snapshot" />,70label: "Bucket Storage Class",71},72// I think this leads to problems and corruption, and is also just really confusing to use.73// cocalc has timetravel, etc., and we should make a proper periodic backup-to-another-bucket74// functionality.75// {76// key: "edit-trash-config",77// icon: <Icon name={"trash"} />,78// label: cloudFilesystem.trash_days ? "Configure Trash" : "Enable Trash",79// },80{81key: "edit-lock",82icon: <Icon name={"lock"} />,83label: "Delete Protection",84},85{86type: "divider",87},88{89disabled: cloudFilesystem.mount,90key: "edit-mountpoint",91icon: <Icon name="folder-open" />,92label: "Change Mountpoint",93},94{95key: "edit-project",96disabled: cloudFilesystem.mount,97icon: <Icon name={"pencil"} />,98label: "Move to Another Project",99},100{101type: "divider",102},103{104key: "edit-mount-options",105icon: <Icon name={"database"} />,106label: "Mount and KeyDB Options",107},108{109disabled: cloudFilesystem.mount,110danger: true,111key: "delete",112icon: <Icon name="trash" />,113label: "Delete Filesystem",114},115{116type: "divider",117},118help,119];120}121122export default function Menu({123cloudFilesystem,124style,125setError,126size,127fontSize,128show,129}: {130cloudFilesystem;131style?;132setError;133size?;134fontSize?;135show?: {136setShowHelp;137setShowMount;138setShowEditMountpoint;139setShowEditTitleAndColor;140setShowDelete;141setShowEditLock;142setShowEditTrashDays;143setShowEditBucketStorageClass;144setShowEditMountOptions;145setShowEditProject;146setShowMetrics;147showMetrics;148};149}) {150const [open, setOpen] = useState<boolean>(false);151const { items, onClick } = useMemo(() => {152if (!open) {153return { onClick: () => {}, items: [] };154}155156return {157items: show != null ? getItems(cloudFilesystem, show) : [],158onClick: async (obj) => {159if (show == null) {160return;161}162setOpen(false);163let cmd = obj.key.startsWith("top-") ? obj.key.slice(4) : obj.key;164switch (cmd) {165case "mount":166show.setShowMount(true);167break;168case "metrics":169show.setShowMetrics(!show.showMetrics);170break;171case "edit-title-and-colors":172show.setShowEditTitleAndColor(true);173break;174case "edit-lock":175show.setShowEditLock(true);176break;177case "edit-mountpoint":178show.setShowEditMountpoint(true);179break;180case "edit-project":181show.setShowEditProject(true);182break;183case "edit-mount-options":184show.setShowEditMountOptions(true);185break;186case "edit-trash-config":187show.setShowEditTrashDays(true);188break;189case "edit-bucket-storage-class":190show.setShowEditBucketStorageClass(true);191break;192case "delete":193show.setShowDelete(true);194break;195case "help-ops":196show.setShowHelp(true);197break;198case "documentation":199case "videos":200// click opens new tab anyways201break;202case "support":203openSupportTab({204type: "question",205subject: `Cloud File System (Global Id: ${cloudFilesystem.id}; Project Specific Id: ${cloudFilesystem.project_specific_id})`,206body: `I am using a cloud file system, and have a question...`,207});208break;209210default:211setError(`not implemented -- '${cmd}'`);212}213},214};215}, [cloudFilesystem, open]);216217if (show == null) {218return (219<div>220Owner: <User account_id={cloudFilesystem.account_id} />221</div>222);223}224225return (226<div style={style}>227<Dropdown228menu={{ items, onClick }}229trigger={["click"]}230disabled={cloudFilesystem.deleting}231onOpenChange={setOpen}232>233<Button type="text" size={size}>234<Icon235name="ellipsis"236style={{ fontSize: fontSize ?? "15pt", color: "#000" }}237rotate="90"238/>239</Button>240</Dropdown>241</div>242);243}244245246