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/description.tsx
Views: 687
import Configuration from "./configuration";1import Cloud from "./cloud";2import { User } from "@cocalc/frontend/users";3import type { Data, State } from "@cocalc/util/db-schema/compute-servers";4import { TimeAgo } from "@cocalc/frontend/components";5import { CopyToClipBoard } from "@cocalc/frontend/components";6import { useTypedRedux } from "@cocalc/frontend/app-framework";7import { A } from "@cocalc/frontend/components/A";8import { Icon } from "@cocalc/frontend/components/icon";9import { Button, Input, Tooltip } from "antd";10import { useState } from "react";1112interface Props {13cloud?;14configuration;15account_id?: string;16short?;17data?: Data;18state?: State;19}2021export default function Description({22cloud,23configuration,24data,25account_id,26short,27state,28}: Props) {29return (30<div>31{!short && (32<>33{account_id != null && (34<>35<User account_id={account_id} />36's37</>38)}{" "}39compute server{" "}40{cloud != null && (41<>42hosted on <Cloud height={15} cloud={cloud} />43</>44)}45.{" "}46</>47)}48<Configuration configuration={configuration} />49{state == "running" && data != null && (50<RuntimeInfo data={data} configuration={configuration} />51)}52</div>53);54}5556// TODO: "Stop then start the compute server for changes to ssh keys to take effect." is only57// because I haven't implemented something better through an api, similar to how sync works.58// It would not be hard.59function RuntimeInfo({ configuration, data }) {60const [showToken, setShowToken] = useState<boolean>(false);61return (62<div style={{ display: "flex", textAlign: "center" }}>63{data?.externalIp && (64<Tooltip65title={66<>67Setup{" "}68<A href="https://doc.cocalc.com/account/ssh.html">69ssh keys in your account or project70</A>71, then <code>ssh user@{data?.externalIp}</code> to connect to the72remote compute server Docker container, and{" "}73<code>ssh root@{data?.externalIp}</code> to connect to the host74VM. Stop then start the compute server for changes to ssh keys to75take effect.76</>77}78placement="left"79>80<div style={{ flex: 0.7, display: "flex" }}>81<CopyToClipBoard value={data?.externalIp} size="small" />82</div>83</Tooltip>84)}85<div style={{ flex: 1, display: "flex" }}>86{data?.externalIp && configuration.dns ? (87<DnsLink {...configuration} />88) : (89<ExternalIpLink90externalIp={data?.externalIp}91authToken={configuration.authToken}92/>93)}94{configuration.authToken && (95<div style={{ display: "flex", margin: "-1px 0 0 5px" }}>96{!showToken && (97<Button98style={{ color: "#666" }}99type="text"100size="small"101onClick={() => setShowToken(!showToken)}102>103Token...104</Button>105)}106{showToken && (107<Input.Password108readOnly109size="small"110value={configuration.authToken}111style={{ width: "125px", marginLeft: "5px", fontSize: "10px" }}112/>113)}114</div>115)}116</div>117{data?.lastStartTimestamp && (118<div style={{ flex: 0.7, textAlign: "center" }}>119Started: <TimeAgo date={data?.lastStartTimestamp} />120</div>121)}122</div>123);124}125126function DnsLink({ dns, authToken }) {127const compute_servers_dns = useTypedRedux("customize", "compute_servers_dns");128if (!compute_servers_dns || !dns) {129return null;130}131const auth = getQuery(authToken);132return (133<A href={`https://${dns}.${compute_servers_dns}${auth}`}>134<Icon name="external-link" /> https://{dns}.{compute_servers_dns}135</A>136);137}138139function ExternalIpLink({ externalIp, authToken }) {140if (!externalIp) {141return null;142}143const auth = getQuery(authToken);144return (145<A href={`https://${externalIp}${auth}`}>146<Icon name="external-link" /> https://{externalIp}147</A>148);149}150151export function getQuery(authToken) {152return authToken ? `?auth_token=${authToken}` : "";153}154155156