-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReportLoader.jsx
78 lines (70 loc) · 2.18 KB
/
ReportLoader.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React from 'react';
import {connect} from 'react-redux'
import {load} from '../actions/report';
import Button from '@mui/material/Button';
import Container from '@mui/material/Container';
import Box from '@mui/material/Box';
import Alert from '@mui/material/Alert';
class ReportLoaderComponent extends React.Component {
click_load_report() {
const test = 'test/fixtures/cpp_project/report.json';
this.props.dispatch(load({filename: test}));
}
render_error_message() {
if (this.props.state_props.report.error) {
return (
<Alert severity="error">error: {this.props.state_props.report.error.message}</Alert>
);
}
return null;
}
render_loader() {
const bundled = '%%___static_report___%%.json';
if (document.querySelector(`script[type="text/localfs"][data-path="${bundled}"]`)) {
if (this.props.state_props.report.error) {
return this.render_error_message();
}
if (!this.loaded_report) {
this.loaded_report = true;
setTimeout(() => this.props.dispatch(load({filename: bundled})));
}
return <Container maxWidth="sm"><p>loading</p></Container>
}
const info = 'Hello looks like you want to load a report :)';
return (
<Container maxWidth="sm">
<Box
alignItems="center"
sx={{ marginTop: '8rem' }}
>
<Alert severity="info">{info}</Alert>
{this.render_error_message()}
<Button onClick={this.click_load_report.bind(this)}>Load Report</Button>
</Box>
</Container>
);
}
render() {
if (!this.props.component || !this.props.state_props.report.worker) {
return this.render_loader();
}
const Component = this.props.component;
return (
<Component
{...this.props.router_props}
report={this.props.state_props.report}
/>
);
}
}
const mapStateToProps = (state) => {
// select stuff
return {state_props: state};
}
export const ReportLoader = connect(
mapStateToProps,
)(ReportLoaderComponent);
export const wrap_report_loader = (Component) => (
(props) => <ReportLoader router_props={props} component={Component} />
);
export default ReportLoader;