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/landing/executables-table.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Input, Table } from "antd";
7
import { debounce } from "lodash";
8
import { useMemo, useState } from "react";
9
10
import Code from "components/landing/code";
11
import { Text, Title } from "components/misc";
12
import executables, { Item } from "lib/landing/executables";
13
import { ComputeInventory } from "lib/landing/types";
14
import { SoftwareSpecTimestamp } from "./software-libraries";
15
16
const INFO_STYLE: React.CSSProperties = {
17
overflow: "auto",
18
maxHeight: "10em",
19
maxWidth: "40vw",
20
backgroundColor: "rgba(150, 150, 150, 0.1)",
21
fontSize: "10px",
22
border: "none",
23
borderRadius: "3px",
24
} as const;
25
26
const PRE_STYLE: React.CSSProperties = {
27
padding: "5px",
28
margin: 0,
29
overflow: "unset", // parent div will show scroll handles
30
} as const;
31
32
const COLUMNS = [
33
{
34
title: "Name",
35
key: "name",
36
dataIndex: "name",
37
responsive: ["md" as any],
38
render: (name) => (
39
<Text strong style={{ fontSize: "12pt" }}>
40
{name}
41
</Text>
42
),
43
},
44
{
45
title: "Path",
46
key: "path",
47
dataIndex: "path",
48
render: (path) => <Code>{path}</Code>,
49
},
50
{
51
title: "Information",
52
key: "output",
53
dataIndex: "output",
54
width: "40%",
55
render: (output) => {
56
return {
57
props: { style: { padding: "0 0 1em 0" } },
58
children: (
59
<div style={INFO_STYLE}>
60
<pre style={PRE_STYLE}>{output}</pre>
61
</div>
62
),
63
};
64
},
65
},
66
];
67
68
export default function ExecutablesTable({
69
executablesSpec,
70
timestamp,
71
}: {
72
executablesSpec: ComputeInventory["executables"];
73
timestamp: string;
74
}) {
75
const dataSource = executables(executablesSpec);
76
const [search, setSearch] = useState<string>("");
77
const onChange = useMemo(
78
() =>
79
debounce((e) => {
80
setSearch(e.target.value);
81
}, 300),
82
[],
83
);
84
85
let data: Item[];
86
if (!search) {
87
data = dataSource;
88
} else {
89
const s = search.toLowerCase();
90
data = [];
91
for (const x of dataSource) {
92
if (x.path.includes(s)) {
93
data.push(x);
94
}
95
}
96
}
97
98
return (
99
<div style={{ clear: "both" }}>
100
<Title level={2}>Showing {data.length} executables</Title>
101
<Input.Search
102
style={{ padding: "0 30px 15px 0", width: "50%", minWidth: "300px" }}
103
placeholder="Search..."
104
allowClear
105
onChange={onChange}
106
onPressEnter={(e) => setSearch((e.target as any).value)}
107
/>
108
<div style={{ overflowX: "auto", width: "100%" }}>
109
<Table
110
columns={COLUMNS}
111
bordered
112
pagination={false}
113
rowKey={"path"}
114
dataSource={data}
115
/>
116
</div>
117
<SoftwareSpecTimestamp timestamp={timestamp} />
118
</div>
119
);
120
}
121
122