feature: frontend split component and list all node

This commit is contained in:
RouxAntoine 2023-07-24 08:23:26 +02:00
parent 2983242dde
commit 59c65f4e8b
Signed by: antoine
GPG Key ID: 098FB66FC0475E70
9 changed files with 163 additions and 69 deletions

View File

@ -0,0 +1,4 @@
backoffice.configuration.kubernetes.api.kubeconfig=/Users/antoine/.kube/config.kubeconfig
#backoffice.configuration.kubernetes.api.url=https://kubernetes.localdomain:6443
#backoffice.configuration.kubernetes.api.ca-cert=/Users/antoine/Documents/virtualization/kubeadm/ca.crt

View File

@ -0,0 +1,4 @@
backoffice.configuration.api-prefix=/api
#backoffice.configuration.kubernetes.api.url=https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT
#backoffice.configuration.kubernetes.api.ca-cert=/run/secrets/kubernetes.io/serviceaccount/ca.crt

View File

@ -1,6 +1,9 @@
<html> <html>
<head> <head>
<title>backoffice</title> <title>backoffice</title>
<meta name="viewport" content="initial-scale=1, width=device-width" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"/>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"/>
</head> </head>
<body> <body>
<div id="react_container"></div> <div id="react_container"></div>
@ -8,11 +11,17 @@
<!-- Note: when deploying, replace "development.js" with "production.min.js". --> <!-- Note: when deploying, replace "development.js" with "production.min.js". -->
<script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script> <script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script> <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/@mui/material@5.14.1/umd/material-ui.development.js" crossorigin></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script> <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<!-- Load our React component. --> <!-- Load our React component. -->
<script src="http://localhost:35729/livereload.js"></script> <script src="http://localhost:35729/livereload.js"></script>
<script type="text/babel" src="src/RootHeader.js" data-presets="es2015,react"></script>
<script type="text/babel" src="src/ListData.js" data-presets="es2015,react"></script>
<script type="text/babel" src="src/NodesComponent.js" data-presets="es2015,react"></script>
<script type="text/babel" src="src/RootBody.js" data-presets="es2015,react"></script>
<script type="text/babel" src="src/RootFooter.js" data-presets="es2015,react"></script>
<script type="text/babel" src="src/App.js" data-presets="es2015,react"></script> <script type="text/babel" src="src/App.js" data-presets="es2015,react"></script>
</body> </body>
</html> </html>

View File

@ -2,72 +2,47 @@
// import {useState, useEffect} from 'react'; // import {useState, useEffect} from 'react';
function formatDate(date) { const ColorModeContext = React.createContext({ toggleColorMode: () => {} });
return date.toLocaleString();
}
function currentDate() {
return new Date();
}
function RootHeader() {
return (
<header>
</header>
);
}
function RootFooter() {
return (
<footer></footer>
);
}
function Result({criteria}) {
const [res, setRes] = React.useState([]);
React.useEffect(() => {
console.log("hey")
setRes([...res, "toto"]);
}, [criteria]);
return (
<div>
{
res.map((r) =>
<div key={r}>{r}</div>
)
}
</div>
)
}
function SearchInput() {
const [criteria, setCriteria] = React.useState("")
// searchByCriteria(criteria);
return (
<input
value={criteria}
onChange={e => setCriteria(e.target.value)}
/>
)
}
function RootBody(props) {
return (
<div>
<div>coucou 2</div>
<SearchInput/>
<Result/>
<div>{formatDate(props.date)}</div>
</div>
);
}
function App() { function App() {
const prefersDarkMode = MaterialUI.useMediaQuery('(prefers-color-scheme: dark)');
const preferredBrowserColorMode = prefersDarkMode ? 'dark' : 'light';
const persistedColorMode = localStorage.getItem("colorMode")
const [mode, setMode] = React.useState(persistedColorMode || preferredBrowserColorMode);
const colorMode = React.useMemo(() => {
return {
toggleColorMode: () => {
return setMode((prevMode) => {
let newColorMode = prevMode === 'light' ? 'dark' : 'light';
localStorage.setItem("colorMode", newColorMode);
return newColorMode;
});
},
};
}, [],
);
const theme = React.useMemo(() => {
return MaterialUI.createTheme({
palette: {
mode: mode,
},
});
}, [mode]);
return ( return (
<div> <div>
<ColorModeContext.Provider value={colorMode}>
<MaterialUI.ThemeProvider theme={theme}>
<MaterialUI.CssBaseline enableColorScheme/>
<RootHeader/> <RootHeader/>
<RootBody date={currentDate()}/> <RootBody/>
<RootFooter/> <RootFooter/>
</MaterialUI.ThemeProvider>
</ColorModeContext.Provider>
</div> </div>
); );
} }

View File

@ -0,0 +1,13 @@
'use strict';
function ListData({datas}) {
return (
<div>
{
datas.map((data, index) =>
<div key={index}>{data.name}</div>
)
}
</div>
)
}

View File

@ -0,0 +1,18 @@
'use strict';
function Nodes({criteria}) {
const [nodes, setNodes] = React.useState([]);
React.useEffect(() => {
fetch("/api/v1/nodes")
.then(response => response.json())
.then(value => setNodes(value));
}, []);
return (
<div>
<div>nodes</div>
<ListData datas={nodes}/>
</div>
);
}

View File

@ -0,0 +1,20 @@
'use strict';
function FilterInput({onChange}) {
return (
<input
onChange={onChange}
/>
)
}
function RootBody() {
const [criteria, setCriteria] = React.useState("")
return (
<div>
<Nodes criteria={criteria}/>
<FilterInput onChange={e => setCriteria(e.target.value)}/>
</div>
);
}

View File

@ -0,0 +1,7 @@
'use strict';
function RootFooter() {
return (
<footer></footer>
);
}

View File

@ -0,0 +1,44 @@
'use strict';
function currentDate() {
return new Date();
}
function formatDate(date) {
return date.toLocaleString();
}
function ColoredApp() {
const theme = MaterialUI.useTheme();
const colorMode = React.useContext(ColorModeContext);
return (
<MaterialUI.Box
sx={{
display: 'flex',
width: '100%',
alignItems: 'center',
justifyContent: 'center',
bgcolor: 'background.default',
color: 'text.primary',
borderRadius: 1,
p: 3,
}}
>
{theme.palette.mode} mode
<MaterialUI.IconButton sx={{ml: 1}} onClick={colorMode.toggleColorMode} color="inherit">
{theme.palette.mode === 'dark' ? <span className="material-icons">brightness_7</span> : <span className="material-icons">brightness_4</span>}
</MaterialUI.IconButton>
</MaterialUI.Box>
);
}
function RootHeader() {
return (
<header>
<ColoredApp/>
{formatDate(currentDate())}
</header>
);
}