Skip to content

Commit 926b840

Browse files
committed
templates store ui
1 parent 43888cf commit 926b840

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

cyclops-ui/src/components/layouts/Sidebar.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import { Button, Menu, MenuProps } from "antd";
3-
import { AppstoreAddOutlined, HddOutlined, BugFilled } from "@ant-design/icons";
3+
import {AppstoreAddOutlined, HddOutlined, BugFilled, SnippetsOutlined} from "@ant-design/icons";
44
import { useLocation } from "react-router";
55
import PathConstants from "../../routes/PathConstants";
66
import { Link } from "react-router-dom";
@@ -19,6 +19,11 @@ const SideNav = () => {
1919
icon: <HddOutlined />,
2020
key: "nodes",
2121
},
22+
{
23+
label: <Link to={PathConstants.TEMPLATES}> Templates</Link>,
24+
icon: <SnippetsOutlined />,
25+
key: "templates",
26+
},
2227
];
2328

2429
return (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import React, { useEffect, useState } from "react";
2+
import {Col, Table, Typography, Alert, Row} from "antd";
3+
import axios from "axios";
4+
import Title from "antd/es/typography/Title";
5+
6+
const TemplateStore = () => {
7+
const [templates, setTemplates] = useState([]);
8+
const [error, setError] = useState({
9+
message: "",
10+
description: "",
11+
});
12+
13+
useEffect(() => {
14+
axios
15+
.get(`/api/templates/store`)
16+
.then((res) => {
17+
setTemplates(res.data);
18+
})
19+
.catch((error) => {
20+
if (error?.response?.data) {
21+
setError({
22+
message: error.response.data.message || String(error),
23+
description: error.response.data.description || "Check if Cyclops backend is available on: " + window.__RUNTIME_CONFIG__.REACT_APP_CYCLOPS_CTRL_HOST,
24+
});
25+
} else {
26+
setError({
27+
message: String(error),
28+
description:
29+
"Check if Cyclops backend is available on: " + window.__RUNTIME_CONFIG__.REACT_APP_CYCLOPS_CTRL_HOST,
30+
});
31+
}
32+
});
33+
}, []);
34+
35+
return (
36+
<div>
37+
{error.message.length !== 0 && (
38+
<Alert
39+
message={error.message}
40+
description={error.description}
41+
type="error"
42+
closable
43+
afterClose={() => {
44+
setError({
45+
message: "",
46+
description: "",
47+
});
48+
}}
49+
style={{ marginBottom: "20px" }}
50+
/>
51+
)}
52+
<Row gutter={[40, 0]}>
53+
<Col span={18}>
54+
<Title level={2}>Templates: {templates.length}</Title>
55+
</Col>
56+
</Row>
57+
<Col span={24} style={{ overflowX: "auto" }}>
58+
<Table dataSource={templates}>
59+
<Table.Column title="Name" dataIndex="name" width={"30%"} />
60+
<Table.Column title="Repo" dataIndex={["ref", "repo"]} width={"30%"} />
61+
<Table.Column
62+
title="Path"
63+
dataIndex={["ref", "path"]}
64+
width={"20%"}
65+
render={function (value: any, record: any, index: number) {
66+
if (!value.startsWith('/')) {
67+
return '/' + value;
68+
}
69+
return value;
70+
}}
71+
/>
72+
<Table.Column title="Version" dataIndex={["ref", "version"]} width={"10%"} />
73+
</Table>
74+
</Col>
75+
</div>
76+
);
77+
};
78+
79+
export default TemplateStore;

cyclops-ui/src/routes/PathConstants.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const PathConstants = {
77
MODULE_ROLLBACK: "/modules/:moduleName/rollback",
88
NODES: "/nodes",
99
NODE_GET: "/nodes/:nodeName",
10+
TEMPLATES: "/templates",
1011
};
1112

1213
export default PathConstants;

cyclops-ui/src/routes/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const Nodes = React.lazy(() => import("../components/pages/nodes"));
1313
const NodeDetails = React.lazy(
1414
() => import("../components/pages/node_details")
1515
);
16+
const Templates = React.lazy(() => import("../components/pages/TemplateStore"));
1617

1718
const routes = [
1819
{ path: PathConstants.HOME, element: <Home /> },
@@ -23,6 +24,7 @@ const routes = [
2324
{ path: PathConstants.MODULE_ROLLBACK, element: <ModuleHistory /> },
2425
{ path: PathConstants.NODES, element: <Nodes /> },
2526
{ path: PathConstants.NODE_GET, element: <NodeDetails /> },
27+
{ path: PathConstants.TEMPLATES, element: <Templates /> },
2628
];
2729

2830
export default routes;

0 commit comments

Comments
 (0)