diff --git a/client/containers/AddInterface/InterfaceTest/InterfaceTest.js b/client/containers/AddInterface/InterfaceTest/InterfaceTest.js index fe031b1d..c381eb6f 100644 --- a/client/containers/AddInterface/InterfaceTest/InterfaceTest.js +++ b/client/containers/AddInterface/InterfaceTest/InterfaceTest.js @@ -50,7 +50,6 @@ export default class InterfaceTest extends Component { params: {}, paramsNotJson: false, headers: {}, - search: '', currDomain: '' } @@ -59,15 +58,15 @@ export default class InterfaceTest extends Component { } componentWillMount() { - this.interfacePropsToState() + this.getInterfaceState() } componentWillReceiveProps(nextProps) { - this.interfacePropsToState(nextProps) + this.getInterfaceState(nextProps) } @autobind - interfacePropsToState(nextProps) { + getInterfaceState(nextProps) { const props = nextProps || this.props; const { method, url, seqGroup, interfaceProject } = props; const { prd_host, basepath, protocol, env } = interfaceProject; @@ -105,6 +104,7 @@ export default class InterfaceTest extends Component { }) this.setState({ + method, domains, pathname, query, @@ -118,8 +118,7 @@ export default class InterfaceTest extends Component { @autobind testInterface() { - const { method } = this.props; - const { pathname, query, headers, params, currDomain } = this.state; + const { headers, params, currDomain, method, pathname, query } = this.state; const urlObj = URL.parse(currDomain); const href = URL.format({ @@ -156,8 +155,12 @@ export default class InterfaceTest extends Component { @autobind changeDomain(value) { - const domain = this.state.domains[value]; - this.setState({ currDomain: domain }); + this.setState({ currDomain: value }); + } + + @autobind + selectDomain(value) { + this.setState({ currDomain: value }); } @autobind @@ -171,6 +174,7 @@ export default class InterfaceTest extends Component { changeQuery(e, key) { const query = JSON.parse(JSON.stringify(this.state.query)); query[key] = e.target.value; + this.setState({ query }); } @@ -181,6 +185,21 @@ export default class InterfaceTest extends Component { this.setState({ params }); } + @autobind + changeMethod(value) { + this.setState({ method: value }); + } + + @autobind + changePath(e) { + const path = e.target.value; + const urlObj = URL.parse(path, true); + this.setState({ + query: urlObj.query, + pathname: urlObj.pathname + }) + } + hasCrossRequestPlugin() { const dom = document.getElementById('y-request'); return dom.getAttribute('key') === 'yapi'; @@ -188,12 +207,10 @@ export default class InterfaceTest extends Component { render () { - const { interfaceName, method } = this.props; - const { domains, pathname, query, headers, params, paramsNotJson } = this.state; - const search = URL.format({ - query - }); + const { interfaceName } = this.props; + const { method, domains, pathname, query, headers, params, paramsNotJson, currDomain } = this.state; const hasPlugin = this.hasCrossRequestPlugin(); + const search = decodeURIComponent(URL.format({query})); return ( @@ -217,6 +234,8 @@ export default class InterfaceTest extends Component { }