From e5bf1e930a5b6ba0b3300b02daf792d65d795202 Mon Sep 17 00:00:00 2001
From: Jason <jason.daurus@gmail.com>
Date: Tue, 14 Jun 2016 23:52:00 +0800
Subject: [web] FlowView and ContentView

---
 web/src/js/components/FlowView.jsx | 107 +++++++++++++++++++++++++++++++++++++
 1 file changed, 107 insertions(+)
 create mode 100644 web/src/js/components/FlowView.jsx

(limited to 'web/src/js/components/FlowView.jsx')

diff --git a/web/src/js/components/FlowView.jsx b/web/src/js/components/FlowView.jsx
new file mode 100644
index 00000000..be2cb460
--- /dev/null
+++ b/web/src/js/components/FlowView.jsx
@@ -0,0 +1,107 @@
+import React, { Component } from 'react'
+import _ from 'lodash'
+
+import Nav from './FlowView/Nav'
+import { Request, Response, Error } from './FlowView/Messages'
+import Details from './FlowView/Details'
+import Prompt from './prompt'
+
+export default class FlowView extends Component {
+
+    static allTabs = { Request, Response, Error, Details }
+
+    constructor(props, context) {
+        super(props, context)
+
+        this.state = { prompt: false }
+
+        this.closePrompt = this.closePrompt.bind(this)
+        this.selectTab = this.selectTab.bind(this)
+    }
+
+    getTabs() {
+        return ['request', 'response', 'error'].filter(k => this.props.flow[k]).concat(['details'])
+    }
+
+    nextTab(increment) {
+        const tabs = this.getTabs()
+        // JS modulo operator doesn't correct negative numbers, make sure that we are positive.
+        this.selectTab(tabs[(tabs.indexOf(this.props.tab) + increment + tabs.length) % tabs.length])
+    }
+
+    selectTab(panel) {
+        this.props.updateLocation(`/flows/${this.props.flow.id}/${panel}`)
+    }
+
+    closePrompt(edit) {
+        this.setState({ prompt: false })
+        if (edit) {
+            this.refs.tab.edit(edit)
+        }
+    }
+
+    promptEdit() {
+        let options
+
+        switch (this.props.tab) {
+
+            case 'request':
+                options = [
+                    'method',
+                    'url',
+                    { text: 'http version', key: 'v' },
+                    'header'
+                ]
+                break
+
+            case 'response':
+                options = [
+                    { text: 'http version', key: 'v' },
+                    'code',
+                    'message',
+                    'header'
+                ]
+                break
+
+            case 'details':
+                return
+
+            default:
+                throw 'Unknown tab for edit: ' + this.props.tab
+        }
+
+        this.setState({ prompt: { options, done: this.closePrompt } })
+    }
+
+    render() {
+        const tabs = this.getTabs()
+        let { flow, tab: active } = this.props
+
+        if (tabs.indexOf(active) < 0) {
+            if (active === 'response' && flow.error) {
+                active = 'error'
+            } else if (active === 'error' && flow.response) {
+                active = 'response'
+            } else {
+                active = tabs[0]
+            }
+        }
+
+        const Tab = FlowView.allTabs[_.capitalize(active)]
+
+        return (
+            <div className="flow-detail" onScroll={this.adjustHead}>
+                <Nav
+                    flow={flow}
+                    tabs={tabs}
+                    active={active}
+                    onSelectTab={this.selectTab}
+                />
+                <Tab flow={flow}/>
+                {this.state.prompt && (
+                    <Prompt {...this.state.prompt}/>
+                )}
+            </div>
+        )
+    }
+}
-- 
cgit v1.2.3


From f5c597a9e351b8dfb84f0fe3f09046e772482fc6 Mon Sep 17 00:00:00 2001
From: Jason <jason.daurus@gmail.com>
Date: Wed, 15 Jun 2016 00:46:59 +0800
Subject: [web] Editor & Prompt

---
 web/src/js/components/FlowView.jsx | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'web/src/js/components/FlowView.jsx')

diff --git a/web/src/js/components/FlowView.jsx b/web/src/js/components/FlowView.jsx
index be2cb460..23f8b3ea 100644
--- a/web/src/js/components/FlowView.jsx
+++ b/web/src/js/components/FlowView.jsx
@@ -4,7 +4,7 @@ import _ from 'lodash'
 import Nav from './FlowView/Nav'
 import { Request, Response, Error } from './FlowView/Messages'
 import Details from './FlowView/Details'
-import Prompt from './prompt'
+import Prompt from './Prompt'
 
 export default class FlowView extends Component {
 
@@ -97,7 +97,7 @@ export default class FlowView extends Component {
                     active={active}
                     onSelectTab={this.selectTab}
                 />
-                <Tab flow={flow}/>
+                <Tab ref="tab" flow={flow}/>
                 {this.state.prompt && (
                     <Prompt {...this.state.prompt}/>
                 )}
-- 
cgit v1.2.3

