Created
March 20, 2020 18:42
-
-
Save mmontes11/ab7ead943896e72a21ab3adecdac3a32 to your computer and use it in GitHub Desktop.
Frontend realtime component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect } from "react"; | |
import PropTypes from "prop-types"; | |
import { handleDataParams } from "hocs/dataParams"; | |
import store from "config/store"; | |
import RealTimeParamsPanel from "containers/RealTimeParamsPanel"; | |
import { startRealTimeData, finishRealTimeData, resetData } from "actions/data"; | |
import { reset } from "actions/common"; | |
import Charts from "containers/Charts"; | |
import { REALTIME } from "constants/chartTypes"; | |
import { THING, TYPE } from "constants/params"; | |
const RealTime = ({ onParamsSelected, onReset }) => { | |
useEffect(() => () => store.dispatch(finishRealTimeData()), []); | |
return ( | |
<div className="container is-fluid section"> | |
<div className="columns is-centered"> | |
<div className="column is-three-quarters"> | |
<RealTimeParamsPanel onParamsSelected={onParamsSelected} onReset={onReset} /> | |
<Charts chartType={REALTIME} /> | |
</div> | |
</div> | |
</div> | |
); | |
}; | |
RealTime.propTypes = { | |
onParamsSelected: PropTypes.func.isRequired, | |
onReset: PropTypes.func.isRequired, | |
}; | |
const withDataParams = handleDataParams({ | |
path: "real-time", | |
pathParams: [ | |
{ | |
id: THING, | |
}, | |
{ | |
id: TYPE, | |
}, | |
], | |
queryParams: [], | |
getData: () => { | |
store.dispatch(resetData()); | |
store.dispatch(startRealTimeData()); | |
}, | |
reset: () => { | |
store.dispatch(reset()); | |
store.dispatch(finishRealTimeData()); | |
}, | |
}); | |
export default withDataParams(RealTime); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment