aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/views/App.js
blob: 5a2d91336b6266862b6fa61ee573e88d539e834e (plain) (blame)
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
import React, {Component} from 'react';
import Header from "./Header";
import MainPane from "./MainPane";
import Footer from "./Footer";
import {BrowserRouter as Router, Route, Switch} from "react-router-dom";
import Services from "./Services";
import Filters from "./Filters";
import Rules from "./Rules";
import Config from "./Config";

class App extends Component {

    constructor(props) {
        super(props);
        this.state = {
            servicesWindowOpen: false,
            filterWindowOpen: false,
            rulesWindowOpen: false,
            configWindowOpen: false,
            configDone: false
        };

		fetch('/api/services')
		.then(response => {
			if( response.status === 503){
				this.setState({configWindowOpen: true});
			} else if (response.status === 200){
				this.setState({configDone: true});
			}
		});


    }

    render() {
        let modal;
        if (this.state.servicesWindowOpen) {
            modal = <Services onHide={() => this.setState({servicesWindowOpen: false})}/>;
        }
        if (this.state.filterWindowOpen) {
            modal = <Filters onHide={() => this.setState({filterWindowOpen: false})}/>;
        }
        if (this.state.rulesWindowOpen) {
            modal = <Rules onHide={() => this.setState({rulesWindowOpen: false})}/>;
        }
        if (this.state.configWindowOpen) {
            modal = <Config onHide={() => this.setState({configWindowOpen: false})}
						onDone={() => this.setState({configDone: true})}/>;
        }

        return (
            <div className="app">
                <Router>
                    <Header onOpenServices={() => this.setState({servicesWindowOpen: true})}
                            onOpenFilters={() => this.setState({filterWindowOpen: true})}
                            onOpenRules={() => this.setState({rulesWindowOpen: true})} 
                            onOpenConfig={() => this.setState({configWindowOpen: true})} 
							onConfigDone={this.state.configDone}
					/>
                    <Switch>
                        <Route path="/connections/:id" children={<MainPane/>}/>
                        <Route path="/" children={<MainPane/>}/>
                    </Switch>
                    {modal}
                    <Footer/>
                </Router>

            </div>
        );
    }
}

export default App;