|
| 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; |
0 commit comments