aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/panels/MainPane.js
blob: bd25e0c76979bb321aa4597f08f3dc63fa1b1104 (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
import React, {Component} from 'react';
import './common.scss';
import './MainPane.scss';
import Connections from "../../views/Connections";
import ConnectionContent from "../ConnectionContent";
import {Route, Switch, withRouter} from "react-router-dom";
import PcapPane from "./PcapPane";
import backend from "../../backend";
import RulePane from "./RulePane";
import ServicePane from "./ServicePane";
import log from "../../log";

class MainPane extends Component {

    state = {};

    componentDidMount() {
        const match = this.props.location.pathname.match(/^\/connections\/([a-f0-9]{24})$/);
        if (match != null) {
            this.loading = true;
            backend.get(`/api/connections/${match[1]}`)
                .then(res => {
                    this.loading = false;
                    this.setState({selectedConnection: res.json});
                    log.debug(`Initial connection ${match[1]} loaded`);
                })
                .catch(error => log.error("Error loading initial connection", error));
        }
    }

    render() {
        return (
            <div className="main-pane">
                <div className="pane connections-pane">
                    {
                        !this.loading &&
                        <Connections onSelected={(c) => this.setState({selectedConnection: c})}
                                     initialConnection={this.state.selectedConnection}/>
                    }
                </div>
                <div className="pane details-pane">
                    <Switch>
                        <Route path="/pcaps" children={<PcapPane/>}/>
                        <Route path="/rules" children={<RulePane/>}/>
                        <Route path="/services" children={<ServicePane/>}/>
                        <Route exact path="/connections/:id"
                               children={<ConnectionContent connection={this.state.selectedConnection}/>}/>
                        <Route children={<ConnectionContent/>}/>
                    </Switch>
                </div>
            </div>
        );
    }
}

export default withRouter(MainPane);