diff --git a/addon/web/client/src/App.tsx b/addon/web/client/src/App.tsx index a8b94fe..1cb368f 100644 --- a/addon/web/client/src/App.tsx +++ b/addon/web/client/src/App.tsx @@ -6,12 +6,11 @@ import scrollMonitor from 'scrollmonitor' import './App.css' import BreakPoint from './components/BreakPoint' -import EditFlow from './components/EditFlow' import FlowPreview from './components/FlowPreview' +import ViewFlow from './components/ViewFlow' import { FlowManager } from './flow' -import { isTextBody } from './utils' -import { parseMessage, SendMessageType, buildMessageMeta, Flow, MessageType, IResponse } from './message' +import { parseMessage, SendMessageType, buildMessageMeta, Flow, MessageType } from './message' interface IState { flows: Flow[] @@ -116,122 +115,6 @@ class App extends React.Component { }) } - renderFlow() { - const { flow, flowTab } = this.state - if (!flow) return null - - const request = flow.request - const response: IResponse = (flow.response || {}) as any - - return ( -
-
- { this.setState({ flow: null }) }}>x - { this.setState({ flowTab: 'Headers' }) }}>Headers - { this.setState({ flowTab: 'Preview' }) }}>Preview - { this.setState({ flowTab: 'Response' }) }}>Response - - { - flow.request.method = request.method - flow.request.url = request.url - flow.request.header = request.header - if (isTextBody(flow.request)) flow.request.body = request.body - this.setState({ flows: this.state.flows }) - }} - onChangeResponse={response => { - if (!flow.response) flow.response = {} as IResponse - - flow.response.statusCode = response.statusCode - flow.response.header = response.header - if (isTextBody(flow.response)) flow.response.body = response.body - this.setState({ flows: this.state.flows }) - }} - onMessage={msg => { - if (this.ws) this.ws.send(msg) - flow.waitIntercept = false - this.setState({ flows: this.state.flows }) - }} - /> - -
- -
- { - !(flowTab === 'Headers') ? null : -
-
-

General

-
-

Request URL: {request.url}

-

Request Method: {request.method}

-

Status Code: {`${response.statusCode || '(pending)'}`}

-
-
- - { - !(response.header) ? null : -
-

Response Headers

-
- { - Object.keys(response.header).map(key => { - return ( -

{key}: {response.header[key].join(' ')}

- ) - }) - } -
-
- } - -
-

Request Headers

-
- { - !(request.header) ? null : - Object.keys(request.header).map(key => { - return ( -

{key}: {request.header[key].join(' ')}

- ) - }) - } -
-
- - { - !(request.body && request.body.byteLength) ? null : -
-

Request Body

-
-

- { - !(flow.isTextRequest()) ? Not text : - flow.requestBody() - } -

-
-
- } - -
- } - - { - !(flowTab === 'Response') ? null : - !(response.body && response.body.byteLength) ?
No response
: - !(flow.isTextResponse()) ?
Not text response
: -
- {flow.responseBody()} -
- } -
- -
- ) - } - render() { const { flows } = this.state return ( @@ -292,7 +175,12 @@ class App extends React.Component { - {this.renderFlow()} + { this.setState({ flow: null }) }} + onReRenderFlows={() => { this.setState({ flows: this.state.flows }) }} + onMessage={msg => { if (this.ws) this.ws.send(msg) }} + />
{ if (this.pageBottom) return diff --git a/addon/web/client/src/components/ViewFlow.tsx b/addon/web/client/src/components/ViewFlow.tsx new file mode 100644 index 0000000..5929a8f --- /dev/null +++ b/addon/web/client/src/components/ViewFlow.tsx @@ -0,0 +1,146 @@ +import React from 'react' +import { Flow, IResponse } from '../message' +import { isTextBody } from '../utils' + +import EditFlow from './EditFlow' + +interface Iprops { + flow: Flow | null + onClose: () => void + onReRenderFlows: () => void + onMessage: (msg: ArrayBufferLike) => void +} + +interface IState { + flowTab: 'Headers' | 'Preview' | 'Response' +} + +class ViewFlow extends React.Component { + constructor(props: Iprops) { + super(props) + + this.state = { + flowTab: 'Headers', + } + } + + render() { + if (!this.props.flow) return null + + const flow = this.props.flow + const flowTab = this.state.flowTab + + const request = flow.request + const response: IResponse = (flow.response || {}) as any + + return ( +
+
+ { this.props.onClose() }}>x + { this.setState({ flowTab: 'Headers' }) }}>Headers + { this.setState({ flowTab: 'Preview' }) }}>Preview + { this.setState({ flowTab: 'Response' }) }}>Response + + { + flow.request.method = request.method + flow.request.url = request.url + flow.request.header = request.header + if (isTextBody(flow.request)) flow.request.body = request.body + this.props.onReRenderFlows() + }} + onChangeResponse={response => { + if (!flow.response) flow.response = {} as IResponse + + flow.response.statusCode = response.statusCode + flow.response.header = response.header + if (isTextBody(flow.response)) flow.response.body = response.body + this.props.onReRenderFlows() + }} + onMessage={msg => { + this.props.onMessage(msg) + flow.waitIntercept = false + this.props.onReRenderFlows() + }} + /> + +
+ +
+ { + !(flowTab === 'Headers') ? null : +
+
+

General

+
+

Request URL: {request.url}

+

Request Method: {request.method}

+

Status Code: {`${response.statusCode || '(pending)'}`}

+
+
+ + { + !(response.header) ? null : +
+

Response Headers

+
+ { + Object.keys(response.header).map(key => { + return ( +

{key}: {response.header[key].join(' ')}

+ ) + }) + } +
+
+ } + +
+

Request Headers

+
+ { + !(request.header) ? null : + Object.keys(request.header).map(key => { + return ( +

{key}: {request.header[key].join(' ')}

+ ) + }) + } +
+
+ + { + !(request.body && request.body.byteLength) ? null : +
+

Request Body

+
+

+ { + !(flow.isTextRequest()) ? Not text : + flow.requestBody() + } +

+
+
+ } + +
+ } + + { + !(flowTab === 'Response') ? null : + !(response.body && response.body.byteLength) ?
No response
: + !(flow.isTextResponse()) ?
Not text response
: +
+ {flow.responseBody()} +
+ } +
+ +
+ ) + } +} + +export default ViewFlow