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/next/components/share/path-actions.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
import { Icon } from "@cocalc/frontend/components/icon";
7
import Link from "next/link";
8
// import ExternalLink from "./external-link";
9
// import rawURL from "lib/share/raw-url";
10
import downloadURL from "lib/share/download-url";
11
import { r_join } from "@cocalc/frontend/components/r_join";
12
import SiteName from "./site-name";
13
import Edit from "./edit";
14
15
interface Props {
16
id: string;
17
path: string;
18
url?: string;
19
relativePath: string;
20
isDir?: boolean;
21
exclude?: Set<string>;
22
project_id: string;
23
image?: string;
24
description?: string;
25
has_site_license?: boolean;
26
}
27
28
export default function PathActions({
29
id,
30
path,
31
url,
32
relativePath,
33
isDir,
34
exclude,
35
project_id,
36
image,
37
description,
38
has_site_license,
39
}: Props) {
40
const include = (action: string) => !exclude?.has(action);
41
const v: JSX.Element[] = [];
42
if (include("edit")) {
43
if (url && isDir) {
44
// TODO!
45
// have to implement git clone...
46
} else {
47
v.push(
48
<Edit
49
key="edit"
50
id={id}
51
path={path}
52
url={url}
53
relativePath={relativePath}
54
image={image}
55
project_id={project_id}
56
description={description}
57
has_site_license={has_site_license}
58
/>,
59
);
60
}
61
}
62
if (!url && include("hosted")) {
63
v.push(
64
<Link key="hosted" href={`/share/public_paths/${id}`}>
65
Hosted by <SiteName />
66
</Link>,
67
);
68
}
69
if (!url && !isDir && include("download")) {
70
v.push(
71
<a key="download" href={downloadURL(id, path, relativePath)}>
72
<Icon name="cloud-download" /> Download
73
</a>,
74
);
75
}
76
/*
77
if (!url && include("raw")) {
78
v.push(
79
<ExternalLink key="raw" href={rawURL({ id, path, relativePath })}>
80
Raw
81
</ExternalLink>,
82
);
83
}
84
if (!url && include("embed")) {
85
v.push(
86
<Link
87
key="embed"
88
href={`/share/public_paths/embed/${id}${
89
relativePath ? "/" + relativePath : ""
90
}`}
91
>
92
Embed
93
</Link>,
94
);
95
}
96
*/
97
98
return <div style={{ marginTop: "5px" }}>{r_join(v, " | ")}</div>;
99
}
100
101