Merge pull request #1012 from gzzhanghao/router

[web] eliminate common.Router.getParams
This commit is contained in:
Maximilian Hils 2016-03-09 18:54:34 +01:00
commit b413a052f9
3 changed files with 14 additions and 20 deletions

View File

@ -543,9 +543,6 @@ var Router = exports.Router = {
// For whatever reason, react-router always returns the same object, which makes comparing // For whatever reason, react-router always returns the same object, which makes comparing
// the current props with nextProps impossible. As a workaround, we just clone the query object. // the current props with nextProps impossible. As a workaround, we just clone the query object.
return _lodash2.default.clone(this.context.location.query); return _lodash2.default.clone(this.context.location.query);
},
getParams: function getParams() {
return this.props.routeParams;
} }
}; };
@ -3363,12 +3360,12 @@ var MainView = _react2.default.createClass({
} }
}, },
onUpdate: function onUpdate(flow) { onUpdate: function onUpdate(flow) {
if (flow.id === this.getParams().flowId) { if (flow.id === this.props.routeParams.flowId) {
this.forceUpdate(); this.forceUpdate();
} }
}, },
onRemove: function onRemove(flow_id, index) { onRemove: function onRemove(flow_id, index) {
if (flow_id === this.getParams().flowId) { if (flow_id === this.props.routeParams.flowId) {
var flow_to_select = this.state.view.list[Math.min(index, this.state.view.list.length - 1)]; var flow_to_select = this.state.view.list[Math.min(index, this.state.view.list.length - 1)];
this.selectFlow(flow_to_select); this.selectFlow(flow_to_select);
} }
@ -3381,7 +3378,7 @@ var MainView = _react2.default.createClass({
}, },
selectFlow: function selectFlow(flow) { selectFlow: function selectFlow(flow) {
if (flow) { if (flow) {
var tab = this.getParams().detailTab || "request"; var tab = this.props.routeParams.detailTab || "request";
this.updateLocation("/flows/" + flow.id + "/" + tab); this.updateLocation("/flows/" + flow.id + "/" + tab);
this.refs.flowTable.scrollIntoView(flow); this.refs.flowTable.scrollIntoView(flow);
} else { } else {
@ -3391,14 +3388,14 @@ var MainView = _react2.default.createClass({
selectFlowRelative: function selectFlowRelative(shift) { selectFlowRelative: function selectFlowRelative(shift) {
var flows = this.state.view.list; var flows = this.state.view.list;
var index; var index;
if (!this.getParams().flowId) { if (!this.props.routeParams.flowId) {
if (shift < 0) { if (shift < 0) {
index = flows.length - 1; index = flows.length - 1;
} else { } else {
index = 0; index = 0;
} }
} else { } else {
var currFlowId = this.getParams().flowId; var currFlowId = this.props.routeParams.flowId;
var i = flows.length; var i = flows.length;
while (i--) { while (i--) {
if (flows[i].id === currFlowId) { if (flows[i].id === currFlowId) {
@ -3498,7 +3495,7 @@ var MainView = _react2.default.createClass({
e.preventDefault(); e.preventDefault();
}, },
getSelected: function getSelected() { getSelected: function getSelected() {
return this.context.flowStore.get(this.getParams().flowId); return this.context.flowStore.get(this.props.routeParams.flowId);
}, },
render: function render() { render: function render() {
var selected = this.getSelected(); var selected = this.getSelected();
@ -3508,7 +3505,7 @@ var MainView = _react2.default.createClass({
details = [_react2.default.createElement(_common.Splitter, { key: "splitter" }), _react2.default.createElement(_index2.default, { details = [_react2.default.createElement(_common.Splitter, { key: "splitter" }), _react2.default.createElement(_index2.default, {
key: "flowDetails", key: "flowDetails",
ref: "flowDetails", ref: "flowDetails",
tab: this.getParams().detailTab, tab: this.props.routeParams.detailTab,
flow: selected })]; flow: selected })];
} else { } else {
details = null; details = null;

View File

@ -53,9 +53,6 @@ export var Router = {
// For whatever reason, react-router always returns the same object, which makes comparing // For whatever reason, react-router always returns the same object, which makes comparing
// the current props with nextProps impossible. As a workaround, we just clone the query object. // the current props with nextProps impossible. As a workaround, we just clone the query object.
return _.clone(this.context.location.query); return _.clone(this.context.location.query);
},
getParams: function() {
return this.props.routeParams;
} }
}; };

View File

@ -75,12 +75,12 @@ var MainView = React.createClass({
} }
}, },
onUpdate: function (flow) { onUpdate: function (flow) {
if (flow.id === this.getParams().flowId) { if (flow.id === this.props.routeParams.flowId) {
this.forceUpdate(); this.forceUpdate();
} }
}, },
onRemove: function (flow_id, index) { onRemove: function (flow_id, index) {
if (flow_id === this.getParams().flowId) { if (flow_id === this.props.routeParams.flowId) {
var flow_to_select = this.state.view.list[Math.min(index, this.state.view.list.length - 1)]; var flow_to_select = this.state.view.list[Math.min(index, this.state.view.list.length - 1)];
this.selectFlow(flow_to_select); this.selectFlow(flow_to_select);
} }
@ -93,7 +93,7 @@ var MainView = React.createClass({
}, },
selectFlow: function (flow) { selectFlow: function (flow) {
if (flow) { if (flow) {
var tab = this.getParams().detailTab || "request"; var tab = this.props.routeParams.detailTab || "request";
this.updateLocation(`/flows/${flow.id}/${tab}`); this.updateLocation(`/flows/${flow.id}/${tab}`);
this.refs.flowTable.scrollIntoView(flow); this.refs.flowTable.scrollIntoView(flow);
} else { } else {
@ -103,14 +103,14 @@ var MainView = React.createClass({
selectFlowRelative: function (shift) { selectFlowRelative: function (shift) {
var flows = this.state.view.list; var flows = this.state.view.list;
var index; var index;
if (!this.getParams().flowId) { if (!this.props.routeParams.flowId) {
if (shift < 0) { if (shift < 0) {
index = flows.length - 1; index = flows.length - 1;
} else { } else {
index = 0; index = 0;
} }
} else { } else {
var currFlowId = this.getParams().flowId; var currFlowId = this.props.routeParams.flowId;
var i = flows.length; var i = flows.length;
while (i--) { while (i--) {
if (flows[i].id === currFlowId) { if (flows[i].id === currFlowId) {
@ -212,7 +212,7 @@ var MainView = React.createClass({
e.preventDefault(); e.preventDefault();
}, },
getSelected: function () { getSelected: function () {
return this.context.flowStore.get(this.getParams().flowId); return this.context.flowStore.get(this.props.routeParams.flowId);
}, },
render: function () { render: function () {
var selected = this.getSelected(); var selected = this.getSelected();
@ -224,7 +224,7 @@ var MainView = React.createClass({
<FlowView <FlowView
key="flowDetails" key="flowDetails"
ref="flowDetails" ref="flowDetails"
tab={this.getParams().detailTab} tab={this.props.routeParams.detailTab}
flow={selected}/> flow={selected}/>
]; ];
} else { } else {