Skip to content

Commit

Permalink
templates store ui
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-cvit committed Apr 3, 2024
1 parent 43888cf commit 926b840
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cyclops-ui/src/components/layouts/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { Button, Menu, MenuProps } from "antd";
import { AppstoreAddOutlined, HddOutlined, BugFilled } from "@ant-design/icons";
import {AppstoreAddOutlined, HddOutlined, BugFilled, SnippetsOutlined} from "@ant-design/icons";
import { useLocation } from "react-router";
import PathConstants from "../../routes/PathConstants";
import { Link } from "react-router-dom";
Expand All @@ -19,6 +19,11 @@ const SideNav = () => {
icon: <HddOutlined />,
key: "nodes",
},
{
label: <Link to={PathConstants.TEMPLATES}> Templates</Link>,
icon: <SnippetsOutlined />,
key: "templates",
},
];

return (
Expand Down
79 changes: 79 additions & 0 deletions cyclops-ui/src/components/pages/TemplateStore.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React, { useEffect, useState } from "react";
import {Col, Table, Typography, Alert, Row} from "antd";
import axios from "axios";
import Title from "antd/es/typography/Title";

const TemplateStore = () => {
const [templates, setTemplates] = useState([]);
const [error, setError] = useState({
message: "",
description: "",
});

useEffect(() => {
axios
.get(`/api/templates/store`)
.then((res) => {
setTemplates(res.data);
})
.catch((error) => {
if (error?.response?.data) {
setError({
message: error.response.data.message || String(error),
description: error.response.data.description || "Check if Cyclops backend is available on: " + window.__RUNTIME_CONFIG__.REACT_APP_CYCLOPS_CTRL_HOST,
});
} else {
setError({
message: String(error),
description:
"Check if Cyclops backend is available on: " + window.__RUNTIME_CONFIG__.REACT_APP_CYCLOPS_CTRL_HOST,
});
}
});
}, []);

return (
<div>
{error.message.length !== 0 && (
<Alert
message={error.message}
description={error.description}
type="error"
closable
afterClose={() => {
setError({
message: "",
description: "",
});
}}
style={{ marginBottom: "20px" }}
/>
)}
<Row gutter={[40, 0]}>
<Col span={18}>
<Title level={2}>Templates: {templates.length}</Title>
</Col>
</Row>
<Col span={24} style={{ overflowX: "auto" }}>
<Table dataSource={templates}>
<Table.Column title="Name" dataIndex="name" width={"30%"} />
<Table.Column title="Repo" dataIndex={["ref", "repo"]} width={"30%"} />
<Table.Column
title="Path"
dataIndex={["ref", "path"]}
width={"20%"}
render={function (value: any, record: any, index: number) {
if (!value.startsWith('/')) {
return '/' + value;
}
return value;
}}
/>
<Table.Column title="Version" dataIndex={["ref", "version"]} width={"10%"} />
</Table>
</Col>
</div>
);
};

export default TemplateStore;
1 change: 1 addition & 0 deletions cyclops-ui/src/routes/PathConstants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const PathConstants = {
MODULE_ROLLBACK: "/modules/:moduleName/rollback",
NODES: "/nodes",
NODE_GET: "/nodes/:nodeName",
TEMPLATES: "/templates",
};

export default PathConstants;
2 changes: 2 additions & 0 deletions cyclops-ui/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Nodes = React.lazy(() => import("../components/pages/nodes"));
const NodeDetails = React.lazy(
() => import("../components/pages/node_details")
);
const Templates = React.lazy(() => import("../components/pages/TemplateStore"));

const routes = [
{ path: PathConstants.HOME, element: <Home /> },
Expand All @@ -23,6 +24,7 @@ const routes = [
{ path: PathConstants.MODULE_ROLLBACK, element: <ModuleHistory /> },
{ path: PathConstants.NODES, element: <Nodes /> },
{ path: PathConstants.NODE_GET, element: <NodeDetails /> },
{ path: PathConstants.TEMPLATES, element: <Templates /> },
];

export default routes;

0 comments on commit 926b840

Please sign in to comment.