mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-25 18:03:50 +00:00
[web] minor fixes and cleanup
This commit is contained in:
parent
f870ccd949
commit
42895f4fec
@ -1,17 +1,20 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import ReactDOM from 'react-dom'
|
import ReactDOM from 'react-dom'
|
||||||
|
import { connect } from 'react-redux'
|
||||||
import shallowEqual from 'shallowequal'
|
import shallowEqual from 'shallowequal'
|
||||||
import AutoScroll from './helpers/AutoScroll'
|
import AutoScroll from './helpers/AutoScroll'
|
||||||
import { calcVScroll } from './helpers/VirtualScroll'
|
import { calcVScroll } from './helpers/VirtualScroll'
|
||||||
import FlowTableHead from './FlowTable/FlowTableHead'
|
import FlowTableHead from './FlowTable/FlowTableHead'
|
||||||
import FlowRow from './FlowTable/FlowRow'
|
import FlowRow from './FlowTable/FlowRow'
|
||||||
import Filt from "../filt/filt"
|
import Filt from "../filt/filt"
|
||||||
|
import * as flowsActions from '../ducks/flows'
|
||||||
|
|
||||||
|
|
||||||
class FlowTable extends React.Component {
|
class FlowTable extends React.Component {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
onSelect: PropTypes.func.isRequired,
|
selectFlow: PropTypes.func.isRequired,
|
||||||
flows: PropTypes.array.isRequired,
|
flows: PropTypes.array.isRequired,
|
||||||
rowHeight: PropTypes.number,
|
rowHeight: PropTypes.number,
|
||||||
highlight: PropTypes.string,
|
highlight: PropTypes.string,
|
||||||
@ -107,7 +110,7 @@ class FlowTable extends React.Component {
|
|||||||
flow={flow}
|
flow={flow}
|
||||||
selected={flow === selected}
|
selected={flow === selected}
|
||||||
highlighted={isHighlighted(flow)}
|
highlighted={isHighlighted(flow)}
|
||||||
onSelect={this.props.onSelect}
|
onSelect={this.props.selectFlow}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
<tr style={{ height: vScroll.paddingBottom }}></tr>
|
<tr style={{ height: vScroll.paddingBottom }}></tr>
|
||||||
@ -118,4 +121,15 @@ class FlowTable extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AutoScroll(FlowTable)
|
FlowTable = AutoScroll(FlowTable)
|
||||||
|
|
||||||
|
export default connect(
|
||||||
|
state => ({
|
||||||
|
flows: state.flows.view,
|
||||||
|
highlight: state.flows.highlight,
|
||||||
|
selected: state.flows.byId[state.flows.selected[0]],
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
selectFlow: flowsActions.select,
|
||||||
|
}
|
||||||
|
)(FlowTable)
|
||||||
|
@ -3,93 +3,47 @@ import { connect } from 'react-redux'
|
|||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
|
||||||
import Nav from './FlowView/Nav'
|
import Nav from './FlowView/Nav'
|
||||||
import { Request, Response, ErrorView as Error } from './FlowView/Messages'
|
import { ErrorView as Error, Request, Response } from './FlowView/Messages'
|
||||||
import Details from './FlowView/Details'
|
import Details from './FlowView/Details'
|
||||||
|
|
||||||
import { selectTab } from '../ducks/ui/flow'
|
import { selectTab } from '../ducks/ui/flow'
|
||||||
|
|
||||||
class FlowView extends Component {
|
export const allTabs = { Request, Response, Error, Details }
|
||||||
|
|
||||||
static allTabs = { Request, Response, Error, Details }
|
function FlowView({ flow, tabName, selectTab }) {
|
||||||
|
|
||||||
constructor(props, context) {
|
// only display available tab names
|
||||||
super(props, context)
|
const tabs = ['request', 'response', 'error'].filter(k => flow[k])
|
||||||
this.onPromptFinish = this.onPromptFinish.bind(this)
|
tabs.push("details")
|
||||||
}
|
|
||||||
|
|
||||||
onPromptFinish(edit) {
|
if (tabs.indexOf(tabName) < 0) {
|
||||||
this.props.setPrompt(false)
|
if (tabName === 'response' && flow.error) {
|
||||||
if (edit && this.tabComponent) {
|
tabName = 'error'
|
||||||
this.tabComponent.edit(edit)
|
} else if (tabName === 'error' && flow.response) {
|
||||||
|
tabName = 'response'
|
||||||
|
} else {
|
||||||
|
tabName = tabs[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getPromptOptions() {
|
const Tab = allTabs[_.capitalize(tabName)]
|
||||||
switch (this.props.tab) {
|
|
||||||
|
|
||||||
case 'request':
|
return (
|
||||||
return [
|
<div className="flow-detail">
|
||||||
'method',
|
<Nav
|
||||||
'url',
|
tabs={tabs}
|
||||||
{ text: 'http version', key: 'v' },
|
active={tabName}
|
||||||
'header'
|
onSelectTab={selectTab}
|
||||||
]
|
/>
|
||||||
break
|
<Tab flow={flow}/>
|
||||||
|
</div>
|
||||||
case 'response':
|
)
|
||||||
return [
|
|
||||||
{ text: 'http version', key: 'v' },
|
|
||||||
'code',
|
|
||||||
'message',
|
|
||||||
'header'
|
|
||||||
]
|
|
||||||
break
|
|
||||||
|
|
||||||
case 'details':
|
|
||||||
return
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw 'Unknown tab for edit: ' + this.props.tab
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
let { flow, tab: active, updateFlow } = this.props
|
|
||||||
const tabs = ['request', 'response', 'error'].filter(k => flow[k]).concat(['details'])
|
|
||||||
|
|
||||||
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">
|
|
||||||
<Nav
|
|
||||||
flow={flow}
|
|
||||||
tabs={tabs}
|
|
||||||
active={active}
|
|
||||||
onSelectTab={this.props.selectTab}
|
|
||||||
/>
|
|
||||||
<Tab ref={ tab => this.tabComponent = tab } flow={flow} updateFlow={updateFlow} />
|
|
||||||
{this.props.promptOpen && (
|
|
||||||
<div>fixme</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
state => ({
|
state => ({
|
||||||
promptOpen: state.ui.promptOpen,
|
flow: state.flows.byId[state.flows.selected[0]],
|
||||||
tab: state.ui.flow.tab
|
tabName: state.ui.flow.tab,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
selectTab,
|
selectTab,
|
||||||
|
@ -120,30 +120,6 @@ export class Request extends Component {
|
|||||||
</section>
|
</section>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
edit(k) {
|
|
||||||
throw "unimplemented"
|
|
||||||
/*
|
|
||||||
switch (k) {
|
|
||||||
case 'm':
|
|
||||||
this.refs.requestLine.refs.method.focus()
|
|
||||||
break
|
|
||||||
case 'u':
|
|
||||||
this.refs.requestLine.refs.url.focus()
|
|
||||||
break
|
|
||||||
case 'v':
|
|
||||||
this.refs.requestLine.refs.httpVersion.focus()
|
|
||||||
break
|
|
||||||
case 'h':
|
|
||||||
this.refs.headers.edit()
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
throw new Error(`Unimplemented: ${k}`)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Request = Message(Request)
|
Request = Message(Request)
|
||||||
@ -189,28 +165,6 @@ export class Response extends Component {
|
|||||||
</section>
|
</section>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
edit(k) {
|
|
||||||
throw "unimplemented"
|
|
||||||
/*
|
|
||||||
switch (k) {
|
|
||||||
case 'c':
|
|
||||||
this.refs.responseLine.refs.status_code.focus()
|
|
||||||
break
|
|
||||||
case 'm':
|
|
||||||
this.refs.responseLine.refs.msg.focus()
|
|
||||||
break
|
|
||||||
case 'v':
|
|
||||||
this.refs.responseLine.refs.httpVersion.focus()
|
|
||||||
break
|
|
||||||
case 'h':
|
|
||||||
this.refs.headers.edit()
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
throw new Error(`'Unimplemented: ${k}`)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Response = Message(Response)
|
Response = Message(Response)
|
||||||
|
@ -1,54 +1,27 @@
|
|||||||
import React, { Component } from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import Splitter from './common/Splitter'
|
import Splitter from './common/Splitter'
|
||||||
import FlowTable from './FlowTable'
|
import FlowTable from './FlowTable'
|
||||||
import FlowView from './FlowView'
|
import FlowView from './FlowView'
|
||||||
import * as flowsActions from '../ducks/flows'
|
|
||||||
|
|
||||||
class MainView extends Component {
|
MainView.propTypes = {
|
||||||
|
hasSelection: PropTypes.bool.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
static propTypes = {
|
function MainView({ hasSelection }) {
|
||||||
highlight: PropTypes.string,
|
return (
|
||||||
sort: PropTypes.object,
|
<div className="main-view">
|
||||||
}
|
<FlowTable/>
|
||||||
|
{hasSelection && <Splitter key="splitter"/>}
|
||||||
render() {
|
{hasSelection && <FlowView key="flowDetails"/>}
|
||||||
const { flows, selectedFlow, highlight } = this.props
|
</div>
|
||||||
return (
|
)
|
||||||
<div className="main-view">
|
|
||||||
<FlowTable
|
|
||||||
ref="flowTable"
|
|
||||||
flows={flows}
|
|
||||||
selected={selectedFlow}
|
|
||||||
highlight={highlight}
|
|
||||||
onSelect={this.props.selectFlow}
|
|
||||||
/>
|
|
||||||
{selectedFlow && [
|
|
||||||
<Splitter key="splitter"/>,
|
|
||||||
<FlowView
|
|
||||||
key="flowDetails"
|
|
||||||
ref="flowDetails"
|
|
||||||
tab={this.props.tab}
|
|
||||||
updateFlow={data => this.props.updateFlow(selectedFlow, data)}
|
|
||||||
flow={selectedFlow}
|
|
||||||
/>
|
|
||||||
]}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
state => ({
|
state => ({
|
||||||
flows: state.flows.view,
|
hasSelection: !!state.flows.byId[state.flows.selected[0]]
|
||||||
filter: state.flows.filter,
|
|
||||||
highlight: state.flows.highlight,
|
|
||||||
selectedFlow: state.flows.byId[state.flows.selected[0]],
|
|
||||||
tab: state.ui.flow.tab,
|
|
||||||
}),
|
}),
|
||||||
{
|
{}
|
||||||
selectFlow: flowsActions.select,
|
|
||||||
updateFlow: flowsActions.update,
|
|
||||||
}
|
|
||||||
)(MainView)
|
)(MainView)
|
||||||
|
@ -20,7 +20,7 @@ class ProxyAppMain extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { showEventLog, location, filter, highlight } = this.props
|
const { showEventLog } = this.props
|
||||||
return (
|
return (
|
||||||
<div id="container" tabIndex="0">
|
<div id="container" tabIndex="0">
|
||||||
<Header/>
|
<Header/>
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import shallowEqual from 'shallowequal'
|
|
||||||
|
|
||||||
window._ = _;
|
window._ = _;
|
||||||
window.React = React;
|
window.React = React;
|
||||||
@ -126,13 +125,9 @@ export function getDiff(obj1, obj2) {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
export const pure = renderFn => class extends React.Component {
|
export const pure = renderFn => class extends React.PureComponent {
|
||||||
static displayName = renderFn.name
|
static displayName = renderFn.name
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps) {
|
|
||||||
return !shallowEqual(this.props, nextProps)
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return renderFn(this.props)
|
return renderFn(this.props)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user