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

93 lines
2.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
}
}
render() {
2017-08-22 10:02:50 +08:00
const { currCase } = this.props;
const data = currCase;
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>
<Postman data={data} />
</div>
2017-08-18 17:31:48 +08:00
</div>
)
2017-08-18 11:33:37 +08:00
}
}