Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added health check UI component #49

Merged
merged 2 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions templates/react/package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import HealthCheck from '../components/health-check'

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