CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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