mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-21 05:19:42 +08:00
feat: col menu
This commit is contained in:
parent
2367517863
commit
7da321a260
@ -40,23 +40,37 @@ export default class InterfaceCaseContent extends Component {
|
||||
super(props)
|
||||
}
|
||||
|
||||
getColId(colList, currCaseId) {
|
||||
let currColId = 0;
|
||||
colList.forEach(col => {
|
||||
col.caseList.forEach(caseItem => {
|
||||
if (+caseItem._id === currCaseId) {
|
||||
currColId = col._id;
|
||||
}
|
||||
})
|
||||
})
|
||||
return currColId;
|
||||
}
|
||||
|
||||
async componentWillMount() {
|
||||
const result = await this.props.fetchInterfaceColList(this.props.match.params.id)
|
||||
let { currCaseId } = this.props;
|
||||
const params = this.props.match.params;
|
||||
const { actionId } = params;
|
||||
currCaseId = +actionId || +currCaseId || result.payload.data.data[0].caseList[0]._id;
|
||||
let currColId = this.getColId(result.payload.data.data, currCaseId);
|
||||
this.props.history.push('/project/' + params.id + '/interface/case/' + currCaseId)
|
||||
this.props.fetchCaseData(currCaseId)
|
||||
this.props.setColData({currCaseId: +currCaseId, isShowCol: false})
|
||||
this.props.setColData({currCaseId: +currCaseId, currColId, isShowCol: false})
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
const oldCaseId = this.props.match.params.actionId
|
||||
const newCaseId = nextProps.match.params.actionId
|
||||
if (oldCaseId !== newCaseId) {
|
||||
let currColId = this.getColId(this.props.interfaceColList, newCaseId);
|
||||
this.props.fetchCaseData(newCaseId);
|
||||
this.props.setColData({currCaseId: +newCaseId, isShowCol: false})
|
||||
this.props.setColData({currCaseId: +newCaseId, currColId, isShowCol: false})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,14 +61,11 @@ export default class InterfaceColMenu extends Component {
|
||||
}
|
||||
|
||||
async componentWillReceiveProps(nextProps) {
|
||||
const { isShowCol, currColId, currCaseId } = nextProps;
|
||||
const action = isShowCol ? 'col' : 'case';
|
||||
const actionId = isShowCol ? currColId : currCaseId;
|
||||
const { currColId } = nextProps;
|
||||
let expandedKeys = this.state.expandedKeys;
|
||||
if (expandedKeys.indexOf(action+'_'+actionId) === -1) {
|
||||
expandedKeys = expandedKeys.concat([action+'_'+actionId])
|
||||
if (expandedKeys.indexOf('col_'+currColId) === -1) {
|
||||
expandedKeys = expandedKeys.concat(['col_'+currColId])
|
||||
}
|
||||
console.log(expandedKeys)
|
||||
this.setState({expandedKeys})
|
||||
}
|
||||
|
||||
@ -88,6 +85,10 @@ export default class InterfaceColMenu extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
onExpand = (keys) => {
|
||||
this.setState({expandedKeys: keys})
|
||||
}
|
||||
|
||||
onSelect = (keys) => {
|
||||
if (keys.length) {
|
||||
const type = keys[0].split('_')[0];
|
||||
@ -111,6 +112,7 @@ export default class InterfaceColMenu extends Component {
|
||||
|
||||
render() {
|
||||
const { currColId, currCaseId, isShowCol } = this.props;
|
||||
console.log(this.state.expandedKeys)
|
||||
|
||||
return (
|
||||
<div>
|
||||
@ -126,7 +128,7 @@ export default class InterfaceColMenu extends Component {
|
||||
selectedKeys={[isShowCol ? 'col_'+currColId : 'case_'+currCaseId]}
|
||||
onSelect={this.onSelect}
|
||||
autoExpandParent
|
||||
onExpand={keys => this.setState({expandedKeys: keys})}
|
||||
onExpand={this.onExpand}
|
||||
>
|
||||
{
|
||||
this.props.interfaceColList.map((col) => (
|
||||
|
Loading…
Reference in New Issue
Block a user