Skip to content

Commit

Permalink
healthcheck-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
mihailistov committed Oct 18, 2019
1 parent 9a9f97f commit 2fae53b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions templates/react/package.json
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"@material-ui/core": "^4.5.1",
"@material-ui/icons": "^4.5.1",
"axios": "^0.19.0",
"react": "^16.10.2",
"react-dom": "^16.10.2",
"react-redux": "^7.1.1",
Expand Down
50 changes: 50 additions & 0 deletions templates/react/src/components/health-check/index.js
@@ -0,0 +1,50 @@
import React, { useState, useEffect } from 'react'
import axios from 'axios'
import { withStyles } from '@material-ui/core/styles'
import { red, green } from '@material-ui/core/colors'
import Radio from '@material-ui/core/Radio'

const radioStyle = (customColor) => ({
root: {
color: customColor,
'&$checked': {
color: customColor,
},
},
checked: {},
})

const CustomRadio = (customColor) => (
withStyles(radioStyle(customColor))(props => <Radio checked={true} color="default" {...props} />)
)

const GreenRadio = CustomRadio(green[600])
const RedRadio = CustomRadio(red[600])

function StatusIcon(props) {
return props.value === 200 ? <GreenRadio /> : <RedRadio />
}

function HealthCheck() {
const [data, setData] = useState({ status: {} })

useEffect(() => {
const fetchData = async () => {
const result = await axios(
'http://127.0.0.1:8080/v1/health',
)

setData(result)
}

fetchData()
}, [])

return (
<div>
API Health Status: <StatusIcon value={data.status}/>
</div>
)
}

export default HealthCheck
2 changes: 2 additions & 0 deletions templates/react/src/views/home.js
@@ -1,9 +1,11 @@
import React from 'react';
import HealthCheck from '../components/health-check'

export default function Home() {
return (
<div>
Home
<HealthCheck />
</div>
);
}

0 comments on commit 2fae53b

Please sign in to comment.