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.tsx
Views: 687
import {1Cloud as CloudType,2State,3} from "@cocalc/util/db-schema/compute-servers";4import { CLOUDS_BY_NAME } from "@cocalc/util/compute/cloud/clouds";5import { Select, Space, Spin, Tooltip } from "antd";6import { useEffect, useState } from "react";7import { setServerCloud } from "./api";8import { useStore } from "@cocalc/frontend/app-framework";9import DisplayCloud from "./display-cloud";1011interface Props {12cloud: CloudType;13state?: State;14editable?: boolean;15height?: number | string;16setError?;17id?: number;18setCloud?: (cloud: CloudType) => void;19style?;20onChange?;21}2223export default function Cloud({24cloud,25state,26editable,27height,28setError,29id,30setCloud,31style,32}: Props) {33const [newCloud, setNewCloud] = useState<CloudType>(cloud);34const [saving, setSaving] = useState<boolean>(false);35const customize = useStore("customize");36useEffect(() => {37setNewCloud(cloud);38}, [cloud]);3940const label = (41<DisplayCloud42cloud={cloud}43height={height}44style={!editable ? style : undefined}45/>46);47if (!editable) {48return label;49}5051const options: { value: string; label: JSX.Element; key: string }[] = [];52for (const cloud in CLOUDS_BY_NAME) {53if (customize?.get(`compute_servers_${cloud}_enabled`)) {54options.push({55key: cloud,56value: cloud,57label: <Cloud editable={false} cloud={cloud as CloudType} />,58});59}60}6162if (state != "deprovisioned" && setCloud == null) {63return (64<Tooltip65title="You must first deprovision the compute server VM before you can change the66cloud provider."67>68<span>{label}</span>69</Tooltip>70);71}7273return (74<Space>75<Select76value={newCloud}77style={{ width: 180, ...style }}78onChange={async (value) => {79if (value == newCloud) {80// nothing to do81return;82}83setNewCloud(value);84if (setCloud != null) {85setCloud(value);86}87if (id) {88// save to backend89try {90setSaving(true);91await setServerCloud({ cloud: value, id });92} catch (err) {93setError(`${err}`);94} finally {95setSaving(false);96}97}98}}99options={options}100/>101{saving && <Spin />}102</Space>103);104}105106107