Skip to content

Commit 87d7f2c

Browse files
author
jan hof
committed
implemented dynamic config forms
1 parent 078b4c1 commit 87d7f2c

File tree

9 files changed

+307
-17555
lines changed

9 files changed

+307
-17555
lines changed

package-lock.json

Lines changed: 222 additions & 17553 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"@coreui/react": "^3.2.3",
3232
"@coreui/react-chartjs": "^1.0.1",
3333
"@coreui/utils": "^1.3.1",
34+
"@rjsf/core": "^2.4.0",
35+
"@types/react-jsonschema-form": "^1.7.4",
3436
"@types/socket.io-client": "^1.4.34",
3537
"axios": "^0.21.0",
3638
"classnames": "^2.2.6",
@@ -39,18 +41,21 @@
3941
"enzyme-adapter-react-16": "^1.15.3",
4042
"http-proxy-middleware": "^1.0.6",
4143
"node-sass": "^4.14.1",
44+
"nvm": "0.0.4",
4245
"prop-types": "^15.7.2",
4346
"react": "^16.13.1",
4447
"react-addons-update": "^15.6.2",
4548
"react-app-polyfill": "^1.0.6",
4649
"react-dom": "^16.13.1",
50+
"react-jsonschema-form": "^1.8.1",
4751
"react-redux": "7.2.1",
4852
"react-router-dom": "^5.2.0",
4953
"redux": "4.0.5",
5054
"socket.io-client": "^2.3.1",
5155
"ws": "^7.3.1"
5256
},
5357
"devDependencies": {
58+
"@types/react-router-dom": "^5.1.6",
5459
"@typescript-eslint/eslint-plugin": "^4.6.0",
5560
"@typescript-eslint/parser": "^4.6.0",
5661
"auto-changelog": "2.2.0",

src/containers/TheSidebar.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ import {
1515
import CIcon from '@coreui/icons-react'
1616

1717
// sidebar nav config
18-
import navigation from './_nav'
18+
import useNavigation from '../hooks/navigationFetcher'
1919

2020
const TheSidebar = () => {
2121
const dispatch = useDispatch()
2222
const show = useSelector(state => state.sidebarShow)
23+
const [navigation, setNavigation] = useNavigation();
2324

2425
return (
2526
<CSidebar

src/hooks/configHook.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Axios from "axios";
2+
import { JSONSchema6 } from "json-schema";
3+
import { useEffect, useState } from "react";
4+
5+
const useConfig = (namespace: string) => {
6+
const [config, setConfig] = useState<JSONSchema6>();
7+
8+
useEffect(() => {
9+
Axios.get("/api/webinterface/service/" + namespace).then((res) =>
10+
setConfig(res.data)
11+
);
12+
}, []);
13+
14+
return [config, setConfig];
15+
};
16+
17+
export default useConfig;

src/hooks/navigationFetcher.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Axios from "axios";
2+
import { useEffect, useState } from "react";
3+
4+
function useNavigation() {
5+
const [navigation, setNavigation] = useState();
6+
7+
useEffect(() => {
8+
Axios.get("/api/webinterface/nav").then((res) => setNavigation(res.data));
9+
}, []);
10+
11+
return [navigation, setNavigation];
12+
}
13+
14+
export default useNavigation;

src/hooks/websocketFetcher.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ function useWebsocketUrl() {
55
const [websocketUrl, setWebsocketUrl] = useState<string>();
66

77
useEffect(() => {
8-
Axios.get("/api/websocket").then((res) => setWebsocketUrl(res.data));
8+
Axios.get("/api/webinterface/websocket").then((res) =>
9+
setWebsocketUrl(res.data)
10+
);
911
}, []);
1012

1113
return [websocketUrl, setWebsocketUrl];

src/routes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import React from 'react';
22

33
const Dashboard = React.lazy(() => import('./views/dashboard/Dashboard'));
4+
const ServiceDetails = React.lazy(() => import('./views/service/ServiceDetails'));
45

56
const routes = [
67
{ path: '/', exact: true, name: 'Home' },
78
{ path: '/dashboard', name: 'Dashboard', component: Dashboard },
9+
{ path: '/service/:namespace', name: 'Services', component: ServiceDetails },
810
];
911

1012
export default routes;

src/views/dashboard/Dashboard.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { freeSet } from "@coreui/icons";
1414
import io from "socket.io-client";
1515
import Axios from "axios";
1616
import useWebsocketUrl from "../../hooks/websocketFetcher";
17+
import { useHistory } from "react-router-dom";
1718

1819
let ws: SocketIOClient.Socket;
1920

@@ -37,6 +38,7 @@ const Dashboard = () => {
3738

3839
//useServiceFetcher(setServices);
3940
const [websocketUrl, setWebsocketUrl] = useWebsocketUrl();
41+
const router = useHistory();
4042

4143
useEffect(() => {
4244
ws = io(websocketUrl as string);

src/views/service/ServiceDetails.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { CRow } from "@coreui/react";
2+
import React, { ReactPropTypes } from "react";
3+
import Form from "react-jsonschema-form";
4+
import { RouteComponentProps } from "react-router-dom";
5+
import { JSONSchema6 } from "json-schema";
6+
import useConfig from "../../hooks/configHook";
7+
8+
type ServiceDetailsProps = {
9+
namespace: string;
10+
};
11+
12+
const schema: JSONSchema6 = {
13+
title: "Todo",
14+
type: "object",
15+
required: ["title"],
16+
properties: {
17+
title: { type: "string", title: "Title", default: "A new task" },
18+
done: { type: "boolean", title: "Done?", default: false },
19+
},
20+
};
21+
22+
const ServiceDetails = (props: RouteComponentProps<ServiceDetailsProps>) => {
23+
const [config, setConfig] = useConfig(props.match.params.namespace);
24+
25+
return (
26+
<>
27+
<CRow>
28+
{config && (
29+
<Form
30+
schema={config as JSONSchema6}
31+
onChange={() => console.log("changed")}
32+
onSubmit={() => console.log("submitted")}
33+
onError={() => console.log("errors")}
34+
/>
35+
)}
36+
</CRow>
37+
</>
38+
);
39+
};
40+
export default ServiceDetails;

0 commit comments

Comments
 (0)