var MainView = React.createClass({ mixins: [Navigation, State], getInitialState: function () { this.onQueryChange(Query.FILTER, function () { this.state.view.recalculate(this.getViewFilt(), this.getViewSort()); }.bind(this)); this.onQueryChange(Query.HIGHLIGHT, function () { this.state.view.recalculate(this.getViewFilt(), this.getViewSort()); }.bind(this)); return { flows: [] }; }, getViewFilt: function () { var filt = Filt.parse(this.getQuery()[Query.FILTER] || ""); var highlight = (this.getQuery()[Query.HIGHLIGHT] || "").split("&") .map(decodeURIComponent) .map(function (filtstr) { return filtstr.trim() !== "" ? Filt.parse(filtstr) : false; }); return function filter_and_highlight(flow) { flow._highlight = []; for (var i = 0; i < highlight.length; i++) { if (highlight[i] && highlight[i](flow)) { flow._highlight.push(FadedHighlightColors[i]); } } return filt(flow); }; }, getViewSort: function () { }, componentWillReceiveProps: function (nextProps) { if (nextProps.flowStore !== this.props.flowStore) { this.closeView(); this.openView(nextProps.flowStore); } }, openView: function (store) { var view = new StoreView(store, this.getViewFilt(), this.getViewSort()); this.setState({ view: view }); view.addListener("recalculate", this.onRecalculate); view.addListener("add update remove", this.onUpdate); }, onRecalculate: function () { this.forceUpdate(); var selected = this.getSelected(); if (selected) { this.refs.flowTable.scrollIntoView(selected); } }, onUpdate: function (flow) { if (flow.id === this.getParams().flowId) { this.forceUpdate(); } }, closeView: function () { this.state.view.close(); }, componentWillMount: function () { this.openView(this.props.flowStore); }, componentWillUnmount: function () { this.closeView(); }, selectFlow: function (flow) { if (flow) { this.replaceWith( "flow", { flowId: flow.id, detailTab: this.getParams().detailTab || "request" } ); this.refs.flowTable.scrollIntoView(flow); } else { this.replaceWith("flows", {}); } }, selectFlowRelative: function (shift) { var flows = this.state.view.list; var index; if (!this.getParams().flowId) { if (shift > 0) { index = flows.length - 1; } else { index = 0; } } else { var currFlowId = this.getParams().flowId; var i = flows.length; while (i--) { if (flows[i].id === currFlowId) { index = i; break; } } index = Math.min( Math.max(0, index + shift), flows.length - 1); } this.selectFlow(flows[index]); }, onKeyDown: function (e) { switch (e.keyCode) { case Key.K: case Key.UP: this.selectFlowRelative(-1); break; case Key.J: case Key.DOWN: this.selectFlowRelative(+1); break; case Key.SPACE: case Key.PAGE_DOWN: this.selectFlowRelative(+10); break; case Key.PAGE_UP: this.selectFlowRelative(-10); break; case Key.END: this.selectFlowRelative(+1e10); break; case Key.HOME: this.selectFlowRelative(-1e10); break; case Key.ESC: this.selectFlow(null); break; case Key.H: case Key.LEFT: if (this.refs.flowDetails) { this.refs.flowDetails.nextTab(-1); } break; case Key.L: case Key.TAB: case Key.RIGHT: if (this.refs.flowDetails) { this.refs.flowDetails.nextTab(+1); } break; default: console.debug("keydown", e.keyCode); return; } e.preventDefault(); }, getSelected: function () { return this.props.flowStore.get(this.getParams().flowId); }, render: function () { var selected = this.getSelected(); var details; if (selected) { details = [ , ]; } else { details = null; } return (
{details}
); } });