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/cloud-filesystem.tsx
Views: 687
import { Card } from "antd";1import { useState } from "react";2import type { CloudFilesystem as CloudFilesystemType } from "@cocalc/util/db-schema/cloud-filesystems";3import CloudFilesystemAvatar from "./avatar";4import CloudFilesystemCardTitle from "./card-title";5import ShowError from "@cocalc/frontend/components/error";6import { ProjectTitle } from "@cocalc/frontend/projects/project-title";7import DeleteCloudFilesystem from "./delete-filesystem";8import MountCloudFilesystem from "./mount-filesystem";9import EditMountpoint from "./edit-mountpoint";10import EditTitleAndColor from "./edit-title-and-color";11import EditLock from "./edit-lock";12import EditTrashDays from "./edit-trash-days";13import EditBucketStorageClass from "./edit-bucket-storage-class";14import EditMountOptions from "./edit-mount-options";15import EditProject from "./edit-project";16import { TimeAgo } from "@cocalc/frontend/components";17import { human_readable_size } from "@cocalc/util/misc";18import Metrics from "./metrics";19import { HelpModal } from "./help";2021interface Props {22cloudFilesystem: CloudFilesystemType;23style?;24refresh?;25showProject?: boolean;26editable?: boolean;27}2829export default function CloudFilesystem({30style,31refresh,32cloudFilesystem,33showProject,34editable,35}: Props) {36const [error, setError] = useState<string>("");37const { color, deleting } = cloudFilesystem;38const [showMetrics, setShowMetrics] = useState<boolean>(false);39const [showDelete, setShowDelete] = useState<boolean>(false);40const [showHelp, setShowHelp] = useState<boolean>(false);41const [showMount, setShowMount] = useState<boolean>(false);42const [showEditMountpoint, setShowEditMountpoint] = useState<boolean>(false);43const [showEditTitleAndColor, setShowEditTitleAndColor] =44useState<boolean>(false);45const [showEditLock, setShowEditLock] = useState<boolean>(false);46const [showEditTrashDays, setShowEditTrashDays] = useState<boolean>(false);47const [showEditBucketStorageClass, setShowEditBucketStorageClass] =48useState<boolean>(false);49const [showEditMountOptions, setShowEditMountOptions] =50useState<boolean>(false);51const [showEditProject, setShowEditProject] = useState<boolean>(false);52const show = editable53? {54setShowDelete,55setShowHelp,56setShowMount,57setShowEditMountpoint,58setShowEditTitleAndColor,59setShowEditLock,60setShowEditTrashDays,61setShowEditBucketStorageClass,62setShowEditMountOptions,63setShowEditProject,64setShowMetrics,65showMetrics,66}67: undefined;6869return (70<Card71style={{72opacity: deleting ? 0.5 : undefined,73width: "100%",74minWidth: "500px",75border: `0.5px solid ${color ?? "#f0f0f0"}`,76borderRight: `10px solid ${color ?? "#aaa"}`,77borderLeft: `10px solid ${color ?? "#aaa"}`,78...style,79}}80>81{editable && (82<>83{showDelete && (84<DeleteCloudFilesystem85cloudFilesystem={cloudFilesystem}86open={showDelete}87setOpen={setShowDelete}88refresh={refresh}89/>90)}91{showMount && (92<MountCloudFilesystem93cloudFilesystem={cloudFilesystem}94open={showMount}95setOpen={setShowMount}96refresh={refresh}97/>98)}99{showEditMountpoint && (100<EditMountpoint101cloudFilesystem={cloudFilesystem}102open={showEditMountpoint}103setOpen={setShowEditMountpoint}104refresh={refresh}105/>106)}107{showHelp && <HelpModal open setOpen={setShowHelp} />}108{showEditTitleAndColor && (109<EditTitleAndColor110cloudFilesystem={cloudFilesystem}111open={showEditTitleAndColor}112setOpen={setShowEditTitleAndColor}113refresh={refresh}114/>115)}116{showEditLock && (117<EditLock118cloudFilesystem={cloudFilesystem}119open={showEditLock}120setOpen={setShowEditLock}121refresh={refresh}122/>123)}124{showEditTrashDays && (125<EditTrashDays126cloudFilesystem={cloudFilesystem}127open={showEditTrashDays}128setOpen={setShowEditTrashDays}129refresh={refresh}130/>131)}132{showEditBucketStorageClass && (133<EditBucketStorageClass134cloudFilesystem={cloudFilesystem}135open={showEditBucketStorageClass}136setOpen={setShowEditBucketStorageClass}137refresh={refresh}138/>139)}140{showEditMountOptions && (141<EditMountOptions142cloudFilesystem={cloudFilesystem}143open={showEditMountOptions}144setOpen={setShowEditMountOptions}145refresh={refresh}146/>147)}148{showEditProject && (149<EditProject150cloudFilesystem={cloudFilesystem}151open={showEditProject}152setOpen={setShowEditProject}153refresh={refresh}154/>155)}156</>157)}158<Card.Meta159avatar={160<CloudFilesystemAvatar161cloudFilesystem={cloudFilesystem}162setShowMetrics={setShowMetrics}163showMetrics={showMetrics}164/>165}166title={167<CloudFilesystemCardTitle168cloudFilesystem={cloudFilesystem}169setError={setError}170refresh={refresh}171show={show}172/>173}174description={175<div style={{ color: "#666" }}>176<ShowError setError={setError} error={error} />177Cloud File System{" "}178<BytesUsed {...cloudFilesystem} show={show?.setShowMetrics} />,{" "}179<Compression {...cloudFilesystem} />{" "}180<BlockSize {...cloudFilesystem} />,{" "}181{cloudFilesystem.mount ? "mounted" : "which would mount"} at{" "}182<Mountpoint183{...cloudFilesystem}184show={show?.setShowEditMountpoint}185/>186,{" "}187<Bucket188{...cloudFilesystem}189show={show?.setShowEditBucketStorageClass}190/>191, <LastEdited {...cloudFilesystem} />.192{showProject && (193<ProjectTitle project_id={cloudFilesystem.project_id} />194)}195{showMetrics && <Metrics id={cloudFilesystem.id} />}196</div>197}198/>199</Card>200);201}202203export function Mountpoint({204mountpoint,205show,206}: {207mountpoint: string;208show?;209}) {210return (211<span212style={{ cursor: show != null ? "pointer" : undefined }}213onClick={show}214>215<code>~/{mountpoint}</code>216</span>217);218}219220function BlockSize({ block_size }) {221return <>block size {block_size ?? 4} MB</>;222}223224function Compression({ compression }) {225if (compression == "lz4") {226return <>with LZ4 compression and</>;227} else if (compression == "zlib") {228return <>with ZLIB compression and</>;229} else {230return <>with no compression and</>;231}232}233234function Bucket({ bucket_location, bucket_storage_class, show }) {235return (236<>237stored in a{" "}238<span style={{ cursor: "pointer" }} onClick={show}>239{(bucket_storage_class ?? "standard").split("-").join(" ")} bucket240</span>{" "}241in <Location bucket_location={bucket_location} />242</>243);244}245246function LastEdited({ last_edited }: { last_edited? }) {247if (!last_edited) {248return <>not used</>;249}250const d = new Date(last_edited);251const recent = d >= new Date(Date.now() - 5 * 60 * 1000);252return <>last edited {recent ? "recently" : <TimeAgo date={d} />}</>;253}254255function Location({ bucket_location }) {256if (!bucket_location) {257return <>unknown-region</>;258}259if (bucket_location.includes("-")) {260return <>{bucket_location}</>;261} else {262return <>the {bucket_location.toUpperCase()} multiregion</>;263}264}265266function BytesUsed({ bytes_used, show }: { bytes_used?; show }) {267return (268<span style={{ cursor: "pointer" }} onClick={() => show(true)}>269storing{" "}270<span style={{ color: "#666", fontWeight: "bold" }}>271{human_readable_size(bytes_used ?? 0)}272</span>273</span>274);275}276277278