diff --git a/client/actions/addInterface.js b/client/actions/addInterface.js index 4675fb63..7437eb20 100644 --- a/client/actions/addInterface.js +++ b/client/actions/addInterface.js @@ -7,8 +7,10 @@ import { GET_INTERFACE_REQ_PARAMS, GET_INTERFACE_RES_PARAMS, PUSH_INTERFACE_NAME, - PUSH_INTERFACE_METHOD + PUSH_INTERFACE_METHOD, + FETCH_INTERFACE_PROJECT } from '../constants/action-types.js' +import axios from 'axios' export function pushInputValue (value) { return { @@ -72,3 +74,10 @@ export function pushInterfaceMethod (value) { payload: value } } + +export function fetchInterfaceProject(id) { + return { + type: FETCH_INTERFACE_PROJECT, + payload: axios.get('/project/get', { params: {id}}) + } +} diff --git a/client/constants/action-types.js b/client/constants/action-types.js index 68173e59..12a7d58b 100644 --- a/client/constants/action-types.js +++ b/client/constants/action-types.js @@ -14,6 +14,7 @@ export const DELETE_INTERFACE_SEQ_HEADER = 'DELETE_INTERFACE_SEQ_HEADER' export const GET_INTERFACE_REQ_PARAMS = 'GET_INTERFACE_REQ_PARAMS' export const GET_INTERFACE_RES_PARAMS = 'GET_INTERFACE_RES_PARAMS' export const PUSH_INTERFACE_METHOD = 'PUSH_INTERFACE_METHOD' +export const FETCH_INTERFACE_PROJECT = 'FETCH_INTERFACE_PROJECT' // group export const FETCH_GROUP_LIST = 'FETCH_GROUP_LIST' diff --git a/client/containers/AddInterface/AddInterface.js b/client/containers/AddInterface/AddInterface.js index ce5b446e..14789991 100644 --- a/client/containers/AddInterface/AddInterface.js +++ b/client/containers/AddInterface/AddInterface.js @@ -17,7 +17,9 @@ import { getReqParams, addReqHeader, pushInputValue, - pushInterfaceName + pushInterfaceName, + fetchInterfaceProject, + pushInterfaceMethod } from '../../actions/addInterface.js' const success = () => { @@ -41,7 +43,9 @@ const success = () => { getResParams, addReqHeader, pushInputValue, - pushInterfaceName + pushInterfaceName, + fetchInterfaceProject, + pushInterfaceMethod } ) @@ -106,12 +110,14 @@ class AddInterface extends Component { editState (data) { const props = this.props - const { path, title, req_params_other, res_body, req_headers} = data + const { path, title, req_params_other, res_body, req_headers, project_id, method } = data props.pushInputValue(path) + props.pushInterfaceMethod(method) props.pushInterfaceName(title) props.getReqParams(req_params_other) props.getResParams(res_body) props.addReqHeader(req_headers) + props.fetchInterfaceProject(project_id) } initInterfaceData (interfaceId) { diff --git a/client/containers/AddInterface/InterfaceTest/InterfaceTest.js b/client/containers/AddInterface/InterfaceTest/InterfaceTest.js index 78a21744..9fd40912 100644 --- a/client/containers/AddInterface/InterfaceTest/InterfaceTest.js +++ b/client/containers/AddInterface/InterfaceTest/InterfaceTest.js @@ -1,34 +1,55 @@ import React, { Component } from 'react' -// import PropTypes from 'prop-types' -// import { connect } from 'react-redux' -import { Button } from 'antd' +import PropTypes from 'prop-types' +import { connect } from 'react-redux' +import { Button, Input } from 'antd' import { autobind } from 'core-decorators'; import crossRequest from 'cross-request'; +import { withRouter } from 'react-router'; +import URL from 'url'; import { } from '../../../actions/group.js' import './InterfaceTest.scss' -// @connect( -// state => ({ -// }), -// { -// } -// ) +@connect( + state => ({ + reqParams: state.addInterface.reqParams, + method: state.addInterface.method, + url: state.addInterface.url, + seqGroup: state.addInterface.seqGroup, + interfaceName: state.addInterface.interfaceName, + interfaceProject: state.addInterface.project + }), + { + } +) +@withRouter export default class InterfaceTest extends Component { static propTypes = { + reqParams: PropTypes.string, + method: PropTypes.string, + url: PropTypes.string, + interfaceName: PropTypes.string, + seqGroup: PropTypes.array, + match: PropTypes.object, + interfaceProject: PropTypes.object } state = { - res: {} + res: {}, + header: {} } constructor(props) { super(props) } + componentWillMount() { + + } + @autobind testInterface() { crossRequest({ @@ -46,12 +67,51 @@ export default class InterfaceTest extends Component { render () { + const { method, url, seqGroup, interfaceName, interfaceProject } = this.props; + const { prd_host, basepath, protocol } = interfaceProject; + const reqParams = JSON.parse(this.props.reqParams); + let query = {}; + + if (method === 'GET') { + Object.keys(reqParams).forEach(key => { + const value = typeof reqParams[key] === 'object' ? JSON.stringify(reqParams) : reqParams.toString(); + query[key] = value; + }) + } + + const href = URL.format({ + protocol: protocol || 'http', + host: prd_host, + pathname: URL.resolve(basepath, url), + query + }); + return (