From 7da321a260d120f46086bb8a3181b8058a41f431 Mon Sep 17 00:00:00 2001 From: zwjamnsss Date: Fri, 18 Aug 2017 21:11:09 +0800 Subject: [PATCH] feat: col menu --- .../InterfaceCol/InterfaceCaseContent.js | 18 ++++++++++++++++-- .../Interface/InterfaceCol/InterfaceColMenu.js | 16 +++++++++------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js b/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js index b1594346..99e34e26 100644 --- a/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js +++ b/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js @@ -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}) } } diff --git a/client/containers/Project/Interface/InterfaceCol/InterfaceColMenu.js b/client/containers/Project/Interface/InterfaceCol/InterfaceColMenu.js index e106e596..4ceef6b9 100644 --- a/client/containers/Project/Interface/InterfaceCol/InterfaceColMenu.js +++ b/client/containers/Project/Interface/InterfaceCol/InterfaceColMenu.js @@ -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 (
@@ -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) => (