yapi/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js

128 lines
3.7 KiB
JavaScript
Raw Normal View History

2017-08-18 11:33:37 +08:00
import React, { Component } from 'react'
import { connect } from 'react-redux';
import PropTypes from 'prop-types'
import { withRouter } from 'react-router'
2017-08-18 17:31:48 +08:00
import { fetchInterfaceColList, setColData, fetchCaseData } from '../../../../reducer/modules/interfaceCol'
2017-08-22 09:41:20 +08:00
import { Postman } from '../../../../components'
2017-08-18 11:33:37 +08:00
@connect(
state => {
return {
interfaceColList: state.interfaceCol.interfaceColList,
currColId: state.interfaceCol.currColId,
currCaseId: state.interfaceCol.currCaseId,
2017-08-18 17:31:48 +08:00
currCase: state.interfaceCol.currCase,
2017-08-22 09:41:20 +08:00
isShowCol: state.interfaceCol.isShowCol,
currProject: state.project.currProject
2017-08-18 11:33:37 +08:00
}
},
{
fetchInterfaceColList,
2017-08-18 17:31:48 +08:00
fetchCaseData,
2017-08-18 11:33:37 +08:00
setColData
}
)
@withRouter
export default class InterfaceCaseContent extends Component {
static propTypes = {
match: PropTypes.object,
interfaceColList: PropTypes.array,
fetchInterfaceColList: PropTypes.func,
2017-08-18 17:31:48 +08:00
fetchCaseData: PropTypes.func,
2017-08-18 11:33:37 +08:00
setColData: PropTypes.func,
history: PropTypes.object,
currColId: PropTypes.number,
currCaseId: PropTypes.number,
2017-08-18 17:31:48 +08:00
currCase: PropTypes.object,
2017-08-22 09:41:20 +08:00
isShowCol: PropTypes.bool,
currProject: PropTypes.object
2017-08-18 11:33:37 +08:00
}
constructor(props) {
super(props)
}
2017-08-18 21:11:09 +08:00
getColId(colList, currCaseId) {
let currColId = 0;
colList.forEach(col => {
col.caseList.forEach(caseItem => {
if (+caseItem._id === currCaseId) {
currColId = col._id;
}
})
})
return currColId;
}
2017-08-18 11:33:37 +08:00
async componentWillMount() {
const result = await this.props.fetchInterfaceColList(this.props.match.params.id)
2017-08-18 17:31:48 +08:00
let { currCaseId } = this.props;
2017-08-18 11:33:37 +08:00
const params = this.props.match.params;
const { actionId } = params;
currCaseId = +actionId || +currCaseId || result.payload.data.data[0].caseList[0]._id;
2017-08-18 21:11:09 +08:00
let currColId = this.getColId(result.payload.data.data, currCaseId);
2017-08-18 17:31:48 +08:00
this.props.history.push('/project/' + params.id + '/interface/case/' + currCaseId)
this.props.fetchCaseData(currCaseId)
2017-08-18 21:11:09 +08:00
this.props.setColData({currCaseId: +currCaseId, currColId, isShowCol: false})
2017-08-18 17:31:48 +08:00
}
componentWillReceiveProps(nextProps) {
const oldCaseId = this.props.match.params.actionId
const newCaseId = nextProps.match.params.actionId
if (oldCaseId !== newCaseId) {
2017-08-18 21:11:09 +08:00
let currColId = this.getColId(this.props.interfaceColList, newCaseId);
2017-08-18 17:31:48 +08:00
this.props.fetchCaseData(newCaseId);
2017-08-18 21:11:09 +08:00
this.props.setColData({currCaseId: +newCaseId, currColId, isShowCol: false})
2017-08-18 11:33:37 +08:00
}
}
2017-08-23 15:50:07 +08:00
// updateCase = () => {
// const project_id = this.props.match.params.id;
// const {
// currDomain: domain,
// pathname: path,
// method,
// pathParam: req_params,
// query: req_query,
// headers: req_headers,
// bodyType: req_body_type,
// bodyForm: req_body_form,
// bodyOther: req_body_other
// } = this.postman.state;
// const res = await axios.post('/api/col/add_case', {
// casename: caseName,
// col_id: colId,
// project_id,
// domain,
// path,
// method,
// req_params,
// req_query,
// req_headers,
// req_body_type,
// req_body_form,
// req_body_other
// });
// if (res.data.errcode) {
// message.error(res.data.errmsg)
// } else {
// message.success('添加成功')
// this.setState({saveCaseModalVisible: false})
// }
// }
2017-08-18 11:33:37 +08:00
render() {
2017-08-23 11:41:46 +08:00
const { currCase, currProject } = this.props;
2017-08-23 14:59:24 +08:00
const data = Object.assign({}, currCase, currProject, {_id: currCase._id});
2017-08-18 17:31:48 +08:00
return (
<div>
2017-08-22 09:41:20 +08:00
<h1 style={{marginLeft: 8}}>{currCase.casename}</h1>
<div>
2017-08-23 15:50:07 +08:00
<Postman data={data} saveTip="更新保存用例" save={false} />
2017-08-22 09:41:20 +08:00
</div>
2017-08-18 17:31:48 +08:00
</div>
)
2017-08-18 11:33:37 +08:00
}
}