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