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/custom-software/info-bar.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
// in "Files", this shows some information and action buttons related to the custom software environment
7
8
import { Map as iMap } from "immutable";
9
import {
10
CUSTOM_SOFTWARE_HELP_URL as help_url,
11
title_style,
12
props2img,
13
RESET_ICON,
14
} from "./util";
15
import { ComputeImages } from "./init";
16
import { path_split, trunc, trunc_middle } from "@cocalc/util/misc";
17
import { open_new_tab } from "../misc";
18
import { Icon, Tip, HiddenXSSM, VisibleMDLG, VisibleXSSM } from "../components";
19
import { Button } from "antd";
20
import { Available as AvailableFeatures } from "../project_configuration";
21
import { serverURL } from "../project/named-server-panel";
22
import LinkRetry from "../components/link-retry";
23
24
interface Props {
25
project_id: string;
26
images: ComputeImages;
27
project_map: iMap<string, any>;
28
actions: any;
29
available_features: AvailableFeatures;
30
show_custom_software_reset: boolean;
31
project_is_running: boolean;
32
}
33
34
export const CustomSoftwareInfo: React.FC<Props> = (props: Props) => {
35
const {
36
project_id,
37
actions,
38
available_features,
39
show_custom_software_reset,
40
project_is_running,
41
} = props;
42
43
function render_path(path) {
44
if (!project_is_running) return null;
45
if (path.length === 0) return null;
46
47
const onClick = path.endsWith("/")
48
? () => actions.open_directory(path)
49
: () => actions.open_file({ path: path });
50
51
// boil down what user sees as the launch button description
52
const display_path = path.endsWith("/")
53
? path.slice(0, -1)
54
: path_split(path).tail;
55
56
return (
57
<Button onClick={onClick} >
58
<Tip title={`Open '${path}'`} placement={"bottom"}>
59
<Icon name={"rocket"} />{" "}
60
<VisibleMDLG>{trunc_middle(display_path, 40)}</VisibleMDLG>
61
</Tip>
62
</Button>
63
);
64
}
65
66
function reset() {
67
actions.toggle_custom_software_reset(!show_custom_software_reset);
68
}
69
70
function render_jupyter(): JSX.Element | null {
71
if (available_features == null) return null;
72
73
const href_jupyterlab = serverURL(project_id, "jupyterlab");
74
const href_jupyterclassic = serverURL(project_id, "jupyter");
75
76
const have_jupyterlab = available_features.jupyter_lab || false;
77
const have_jupyterclassic = available_features.jupyter_notebook || false;
78
79
return (
80
<>
81
{have_jupyterclassic ? (
82
<LinkRetry mode="button" href={href_jupyterclassic}>
83
<Tip
84
title={"Start the classical Jupyter server"}
85
placement={"bottom"}
86
>
87
<Icon name={"ipynb"} /> <HiddenXSSM>Jupyter</HiddenXSSM>
88
</Tip>
89
</LinkRetry>
90
) : undefined}
91
{have_jupyterlab ? (
92
<LinkRetry mode="button" href={href_jupyterlab}>
93
<Tip title={"Start Jupyter Lab server"} placement={"bottom"}>
94
<Icon name={"ipynb"} /> <VisibleMDLG>JupyterLab</VisibleMDLG>
95
<VisibleXSSM>Lab</VisibleXSSM>
96
</Tip>
97
</LinkRetry>
98
) : undefined}
99
100
<Button onClick={reset}>
101
<Icon name={RESET_ICON} /> <VisibleMDLG>Reset...</VisibleMDLG>
102
</Button>
103
104
<Button onClick={() => open_new_tab(help_url)}>
105
<Icon name={"question-circle"} />
106
</Button>
107
</>
108
);
109
}
110
111
function img_info(img) {
112
const disp = img.get("display", "");
113
const id = img.get("id", "");
114
return `${disp} (${id})`;
115
}
116
117
const img = props2img(props);
118
if (img == null) return null;
119
const path = img.get("path", "");
120
121
return (
122
<>
123
<div style={{ whiteSpace: "nowrap" }}>
124
{render_path(path)}
125
{render_jupyter()}
126
</div>
127
<div style={title_style}>
128
<Tip title={img_info(img)} placement={"bottom"}>
129
{trunc(img.get("display", ""), 100)}
130
</Tip>
131
</div>
132
</>
133
);
134
};
135
136