-
Notifications
You must be signed in to change notification settings - Fork 780
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UI] module name validation
- Loading branch information
Showing
37 changed files
with
5,173 additions
and
4,054 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,16 @@ | ||
import { | ||
createBrowserRouter, | ||
RouterProvider, | ||
} from "react-router-dom" | ||
import routes from "./routes" | ||
import Page404 from "./components/pages/Page404" | ||
import { createBrowserRouter, RouterProvider } from "react-router-dom"; | ||
import routes from "./routes"; | ||
import Page404 from "./components/pages/Page404"; | ||
import AppLayout from "./components/layouts/AppLayout"; | ||
|
||
export default function App() { | ||
const router = createBrowserRouter([ | ||
{ | ||
element: <AppLayout />, | ||
errorElement: <Page404 />, | ||
children: routes | ||
children: routes, | ||
}, | ||
]) | ||
]); | ||
|
||
return ( | ||
<RouterProvider router={router} /> | ||
) | ||
} | ||
return <RouterProvider router={router} />; | ||
} |
225 changes: 123 additions & 102 deletions
225
cyclops-ui/src/components/k8s-resources/ConfigMap.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,121 +1,142 @@ | ||
import React, {useEffect, useState} from 'react'; | ||
import {Divider, Row, Alert, Descriptions} from 'antd'; | ||
import axios from 'axios'; | ||
import React, { useEffect, useState } from "react"; | ||
import { Divider, Row, Alert, Descriptions } from "antd"; | ||
import axios from "axios"; | ||
import ReactAce from "react-ace"; | ||
|
||
interface Props { | ||
name: string; | ||
namespace: string; | ||
name: string; | ||
namespace: string; | ||
} | ||
|
||
const ConfigMap = ({name, namespace}: Props) => { | ||
const [configMap, setConfigMap] = useState({}); | ||
const [error, setError] = useState({ | ||
message: "", | ||
description: "", | ||
}); | ||
const ConfigMap = ({ name, namespace }: Props) => { | ||
const [configMap, setConfigMap] = useState({}); | ||
const [error, setError] = useState({ | ||
message: "", | ||
description: "", | ||
}); | ||
|
||
function fetchConfigMap() { | ||
axios.get(`/api/resources`,{ | ||
params: { | ||
group: ``, | ||
version: `v1`, | ||
kind: `ConfigMap`, | ||
name: name, | ||
namespace: namespace | ||
} | ||
}).then(res => { | ||
setConfigMap(res.data) | ||
}).catch(error => { | ||
console.log(error) | ||
if (error.response === undefined) { | ||
setError({ | ||
message: String(error), | ||
description: "Check if Cyclops backend is available on: " + window.__RUNTIME_CONFIG__.REACT_APP_CYCLOPS_CTRL_HOST | ||
}) | ||
} else { | ||
setError(error.response.data); | ||
} | ||
}) | ||
} | ||
|
||
useEffect(() => { | ||
fetchConfigMap() | ||
const interval = setInterval(() => fetchConfigMap(), ) | ||
return () => { | ||
clearInterval(interval); | ||
function fetchConfigMap() { | ||
axios | ||
.get(`/api/resources`, { | ||
params: { | ||
group: ``, | ||
version: `v1`, | ||
kind: `ConfigMap`, | ||
name: name, | ||
namespace: namespace, | ||
}, | ||
}) | ||
.then((res) => { | ||
setConfigMap(res.data); | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
if (error.response === undefined) { | ||
setError({ | ||
message: String(error), | ||
description: | ||
"Check if Cyclops backend is available on: " + | ||
window.__RUNTIME_CONFIG__.REACT_APP_CYCLOPS_CTRL_HOST, | ||
}); | ||
} else { | ||
setError(error.response.data); | ||
} | ||
}, []); | ||
}); | ||
} | ||
|
||
useEffect(() => { | ||
fetchConfigMap(); | ||
const interval = setInterval(() => fetchConfigMap()); | ||
return () => { | ||
clearInterval(interval); | ||
}; | ||
}, []); | ||
|
||
const configMapData = (configMap: any) => { | ||
if (configMap.data) { | ||
return <Descriptions style={{width: "100%"}} bordered> | ||
{Object.entries<string>(configMap.data).map(([key, dataValue]) => ( | ||
<Descriptions.Item key={key} labelStyle={{width: "20%"}} label={key} span={24} > | ||
{configMapDataValues(key, dataValue)} | ||
</Descriptions.Item> | ||
))} | ||
</Descriptions> | ||
} | ||
const configMapData = (configMap: any) => { | ||
if (configMap.data) { | ||
return ( | ||
<Descriptions style={{ width: "100%" }} bordered> | ||
{Object.entries<string>(configMap.data).map(([key, dataValue]) => ( | ||
<Descriptions.Item | ||
key={key} | ||
labelStyle={{ width: "20%" }} | ||
label={key} | ||
span={24} | ||
> | ||
{configMapDataValues(key, dataValue)} | ||
</Descriptions.Item> | ||
))} | ||
</Descriptions> | ||
); | ||
} | ||
}; | ||
|
||
const configMapDataValues = (key: string, data: string) => { | ||
const lines = data.split('\n').length; | ||
const configMapDataValues = (key: string, data: string) => { | ||
const lines = data.split("\n").length; | ||
|
||
if (lines > 1) { | ||
return <ReactAce | ||
setOptions={{ useWorker: false }} | ||
value={data} | ||
readOnly={true} | ||
width="100%" | ||
mode={configMapDataExtension(key)} | ||
height={calculateEditorHeight(lines)} | ||
/> | ||
} else { | ||
return data | ||
} | ||
if (lines > 1) { | ||
return ( | ||
<ReactAce | ||
setOptions={{ useWorker: false }} | ||
value={data} | ||
readOnly={true} | ||
width="100%" | ||
mode={configMapDataExtension(key)} | ||
height={calculateEditorHeight(lines)} | ||
/> | ||
); | ||
} else { | ||
return data; | ||
} | ||
}; | ||
|
||
const calculateEditorHeight = (lines: number) => { | ||
if (lines > 20) { | ||
return '320px' | ||
} else { | ||
return `${lines * 16}px` | ||
} | ||
}; | ||
const calculateEditorHeight = (lines: number) => { | ||
if (lines > 20) { | ||
return "320px"; | ||
} else { | ||
return `${lines * 16}px`; | ||
} | ||
}; | ||
|
||
const configMapDataExtension = (filename: string) => { | ||
const ext = filename.split('.').pop(); | ||
switch (ext) { | ||
case "json": | ||
return "json" | ||
default: | ||
return "json" | ||
} | ||
const configMapDataExtension = (filename: string) => { | ||
const ext = filename.split(".").pop(); | ||
switch (ext) { | ||
case "json": | ||
return "json"; | ||
default: | ||
return "json"; | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
{ | ||
error.message.length !== 0 && <Alert | ||
message={error.message} | ||
description={error.description} | ||
type="error" | ||
closable | ||
afterClose={() => {setError({ | ||
message: "", | ||
description: "", | ||
})}} | ||
style={{marginBottom: '20px'}} | ||
/> | ||
} | ||
<Row> | ||
<Divider style={{fontSize: '120%'}} orientationMargin="0" orientation={"left"}>Data:</Divider> | ||
{configMapData(configMap)} | ||
</Row> | ||
</div> | ||
); | ||
} | ||
return ( | ||
<div> | ||
{error.message.length !== 0 && ( | ||
<Alert | ||
message={error.message} | ||
description={error.description} | ||
type="error" | ||
closable | ||
afterClose={() => { | ||
setError({ | ||
message: "", | ||
description: "", | ||
}); | ||
}} | ||
style={{ marginBottom: "20px" }} | ||
/> | ||
)} | ||
<Row> | ||
<Divider | ||
style={{ fontSize: "120%" }} | ||
orientationMargin="0" | ||
orientation={"left"} | ||
> | ||
Data: | ||
</Divider> | ||
{configMapData(configMap)} | ||
</Row> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ConfigMap; |
Oops, something went wrong.