aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/components/flowdetail.jsx.js
blob: 744901be6d7987b137434ca7fb834ab7247ce783 (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/** @jsx React.DOM */

var FlowDetailNav = React.createClass({
    render: function(){

        var items = ["request", "response", "details"].map(function(e){
            var str = e.charAt(0).toUpperCase() + e.slice(1);
            var className = this.props.active === e ? "active" : "";
            var onClick = function(){
                this.props.selectTab(e);
                return false;
            }.bind(this);
            return <a key={e}
                      href="#" 
                      className={className}
                      onClick={onClick}>{str}</a>;
        }.bind(this));
        return (
            <nav ref="head" className="nav-tabs nav-tabs-sm">
                {items}
            </nav>
        );
    } 
});

var Headers = React.createClass({
    render: function(){
        var rows = this.props.message.headers.map(function(header){
            return (
                <tr>
                    <td className="header-name">{header[0]}</td>
                    <td className="header-value">{header[1]}</td>
                </tr>
            );
        })
        return (
            <table className="header-table">
                <tbody>
                    {rows}
                </tbody>
            </table>
        );
    }
})

var FlowDetailRequest = React.createClass({
    render: function(){
        var flow = this.props.flow;
        var url = <code>{ RequestUtils.pretty_url(flow.request) }</code>;
        var content = null;
        if(flow.request.contentLength > 0){
            content = "Request Content Size: "+ formatSize(flow.request.contentLength);
        } else {
            content = <div className="alert alert-info">No Content</div>;
        }

        //TODO: Styling

        return (
            <section>
                {url}
                <Headers message={flow.request}/>
                <hr/>
                {content}
            </section>
        );
    }
});

var FlowDetailResponse = React.createClass({
    render: function(){
        return <section>response</section>;
    }
});

var FlowDetailConnectionInfo = React.createClass({
    render: function(){
        return <section>details</section>;
    }
});

var tabs = {
    request: FlowDetailRequest,
    response: FlowDetailResponse,
    details: FlowDetailConnectionInfo
};

var FlowDetail = React.createClass({
    mixins: [StickyHeadMixin],
    render: function(){
        var flow = JSON.stringify(this.props.flow, null, 2);
        var Tab = tabs[this.props.active];
        return (
            <div className="flow-detail" onScroll={this.adjustHead}>
                <FlowDetailNav ref="head" active={this.props.active} selectTab={this.props.selectTab}/>
                <Tab flow={this.props.flow}/>
            </div>
            );
    } 
});