Skip to content

Commit

Permalink
Merge pull request #49 from commitdev/healthcheck-ui
Browse files Browse the repository at this point in the history
Added health check UI component
  • Loading branch information
jb55 committed Oct 31, 2019
2 parents 6b7e4f6 + e4d730e commit a767988
Show file tree
Hide file tree
Showing 4 changed files with 57 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
27 changes: 27 additions & 0 deletions templates/react/src/components/health-check/index.js
@@ -0,0 +1,27 @@
import React, { useState, useEffect } from 'react'
import axios from 'axios'
import StatusIcon from './status-icon'

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
27 changes: 27 additions & 0 deletions templates/react/src/components/health-check/status-icon.js
@@ -0,0 +1,27 @@
import React from 'react'
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 />
}

export default StatusIcon
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 a767988

Please sign in to comment.