From e17a4285450ccf44ba780d01e6c579b0753fae9a Mon Sep 17 00:00:00 2001 From: Nikolay Bogdanov Date: Tue, 12 Jul 2016 10:18:25 +0300 Subject: [PATCH] Make app.navigate accept options Option {replace: true} is used now in app.navigate to replace existing history record with the new route. Implements blueprint react-router Change-Id: I8f8fc62073194d45e2c35368e613d8e24fcf24b4 --- static/app.js | 4 ++-- static/component_mixins.js | 2 +- static/views/cluster_page_tabs/history_tab.js | 6 +++--- static/views/cluster_page_tabs/logs_tab.js | 2 +- static/views/cluster_page_tabs/network_tab.js | 15 ++++----------- static/views/cluster_page_tabs/nodes_tab.js | 7 ++----- .../nodes_tab_screens/node_list_screen.js | 2 +- static/views/cluster_page_tabs/settings_tab.js | 5 +---- static/views/dialogs.js | 15 +++++++++------ static/views/login_page.js | 2 +- static/views/welcome_page.js | 2 +- static/views/wizard.js | 2 +- 12 files changed, 27 insertions(+), 37 deletions(-) diff --git a/static/app.js b/static/app.js index 9d7a35481..8e2b980e0 100644 --- a/static/app.js +++ b/static/app.js @@ -243,8 +243,8 @@ class App { this.page = this.rootComponent.setPage(Page, options); } - navigate(url, options) { - return this.router.navigate(url.replace(/^\//, '#'), options); + navigate(url, {replace} = {replace: false}) { + return this.router.navigate(url.replace(/^\//, '#'), {trigger: true, replace: !!replace}); } logout() { diff --git a/static/component_mixins.js b/static/component_mixins.js index 807c66831..87d7f8bed 100644 --- a/static/component_mixins.js +++ b/static/component_mixins.js @@ -62,7 +62,7 @@ export var unsavedChangesMixin = { applyChanges: this.applyChanges, revertChanges: this.revertChanges }).then(() => { - app.navigate(href, {trigger: true}); + app.navigate(href); }); } } diff --git a/static/views/cluster_page_tabs/history_tab.js b/static/views/cluster_page_tabs/history_tab.js index 828ae4334..2469527d7 100644 --- a/static/views/cluster_page_tabs/history_tab.js +++ b/static/views/cluster_page_tabs/history_tab.js @@ -43,7 +43,7 @@ HistoryTab = React.createClass({ if (!transactionId || !_.includes(subtabs, transactionId)) { app.navigate( '/cluster/' + cluster.id + '/history' + (defaultSubtab ? '/' + defaultSubtab : ''), - {trigger: true, replace: true} + {replace: true} ); } return {activeTransactionId: transactionId || null}; @@ -70,7 +70,7 @@ HistoryTab = React.createClass({ () => { app.navigate( '/cluster/' + this.props.cluster.id + '/history', - {trigger: true, replace: true} + {replace: true} ); } ); @@ -83,7 +83,7 @@ HistoryTab = React.createClass({ if (_.isNull(this.props.activeTransactionId) && transaction) { app.navigate( '/cluster/' + cluster.id + '/history/' + transaction.id, - {trigger: true, replace: true} + {replace: true} ); } if (this.props.activeTransactionId !== activeTransactionId) { diff --git a/static/views/cluster_page_tabs/logs_tab.js b/static/views/cluster_page_tabs/logs_tab.js index bf902a1aa..d50f13b9e 100644 --- a/static/views/cluster_page_tabs/logs_tab.js +++ b/static/views/cluster_page_tabs/logs_tab.js @@ -92,7 +92,7 @@ var LogsTab = React.createClass({ _.extend({}, this.props.selectedLogs) : _.omit(this.props.selectedLogs, 'node'); logOptions.level = logOptions.level.toLowerCase(); app.navigate('/cluster/' + this.props.cluster.id + '/logs/' + - utils.serializeTabOptions(logOptions), {trigger: false, replace: true}); + utils.serializeTabOptions(logOptions), {replace: true}); params = params || {}; this.fetchLogs(params) .then((data) => { diff --git a/static/views/cluster_page_tabs/network_tab.js b/static/views/cluster_page_tabs/network_tab.js index 51382b0d0..3e2324d01 100644 --- a/static/views/cluster_page_tabs/network_tab.js +++ b/static/views/cluster_page_tabs/network_tab.js @@ -532,10 +532,7 @@ var NetworkTab = React.createClass({ // check if current subroute is valid if (!subroute || !_.includes(subtabs, subroute)) { - app.navigate( - '/cluster/' + cluster.id + '/network/' + subtabs[0], - {trigger: true, replace: true} - ); + app.navigate('/cluster/' + cluster.id + '/network/' + subtabs[0], {replace: true}); } return {activeNetworkSectionName: subroute, showAllNetworks}; } @@ -890,8 +887,7 @@ var NetworkTab = React.createClass({ this.updateInitialConfiguration(); var defaultSubtab = this.constructor.getSubtabs(this.props)[0]; app.navigate( - '/cluster/' + this.props.cluster.id + '/network/' + defaultSubtab, - {trigger: true, replace: true} + '/cluster/' + this.props.cluster.id + '/network/' + defaultSubtab, {replace: true} ); }); }); @@ -927,7 +923,7 @@ var NetworkTab = React.createClass({ if (!this.props.showAllNetworks) { app.navigate( '/cluster/' + this.props.cluster.id + '/network/group/' + newNodeNetworkGroupId, - {trigger: true, replace: true} + {replace: true} ); } }); @@ -940,10 +936,7 @@ var NetworkTab = React.createClass({ : this.props.cluster.get('nodeNetworkGroups').find({is_default: true}).id ); - app.navigate( - navigationUrl, - {trigger: true, replace: true} - ); + app.navigate(navigationUrl, {replace: true}); }, render() { var isLocked = this.isLocked(); diff --git a/static/views/cluster_page_tabs/nodes_tab.js b/static/views/cluster_page_tabs/nodes_tab.js index ffca9575f..b941a5c97 100644 --- a/static/views/cluster_page_tabs/nodes_tab.js +++ b/static/views/cluster_page_tabs/nodes_tab.js @@ -69,7 +69,7 @@ var NodesTab = React.createClass({ }, checkScreenExists(screen) { if (!this.getScreenConstructor(screen || this.state.screen)) { - app.navigate('/cluster/' + this.props.cluster.id + '/nodes', {trigger: true, replace: true}); + app.navigate('/cluster/' + this.props.cluster.id + '/nodes', {replace: true}); return false; } return true; @@ -88,10 +88,7 @@ var NodesTab = React.createClass({ }); }, () => { - app.navigate( - '/cluster/' + this.props.cluster.id + '/nodes', - {trigger: true, replace: true} - ); + app.navigate('/cluster/' + this.props.cluster.id + '/nodes', {replace: true}); } ); }, diff --git a/static/views/cluster_page_tabs/nodes_tab_screens/node_list_screen.js b/static/views/cluster_page_tabs/nodes_tab_screens/node_list_screen.js index 18d06ac50..199b6771e 100644 --- a/static/views/cluster_page_tabs/nodes_tab_screens/node_list_screen.js +++ b/static/views/cluster_page_tabs/nodes_tab_screens/node_list_screen.js @@ -722,7 +722,7 @@ ManagementPanel = React.createClass({ changeScreen(url, passNodeIds) { url = url ? '/' + url : ''; if (passNodeIds) url += '/' + utils.serializeTabOptions({nodes: this.props.nodes.map('id')}); - app.navigate('/cluster/' + this.props.cluster.id + '/nodes' + url, {trigger: true}); + app.navigate('/cluster/' + this.props.cluster.id + '/nodes' + url); }, goToConfigurationScreen(action, conflict) { if (conflict) { diff --git a/static/views/cluster_page_tabs/settings_tab.js b/static/views/cluster_page_tabs/settings_tab.js index 7978d1b55..11c85b00a 100644 --- a/static/views/cluster_page_tabs/settings_tab.js +++ b/static/views/cluster_page_tabs/settings_tab.js @@ -61,10 +61,7 @@ var SettingsTab = React.createClass({ if (activeTab === 'settings') { var subroute = tabOptions[0]; if (!subroute || !_.includes(subtabs, subroute)) { - app.navigate( - '/cluster/' + cluster.id + '/settings/' + subtabs[0], - {trigger: true, replace: true} - ); + app.navigate('/cluster/' + cluster.id + '/settings/' + subtabs[0], {replace: true}); } return {activeSettingsSectionName: subroute}; } diff --git a/static/views/dialogs.js b/static/views/dialogs.js index 561b48a3b..6b87bf2f8 100644 --- a/static/views/dialogs.js +++ b/static/views/dialogs.js @@ -861,7 +861,7 @@ export var RemoveClusterDialog = React.createClass({ () => { this.close(); dispatcher.trigger('updateNodeStats updateNotifications'); - app.navigate('/clusters', {trigger: true}); + app.navigate('/clusters'); }, this.showError ); @@ -1037,11 +1037,14 @@ export var ShowNodeInfoDialog = React.createClass({ }, goToConfigurationScreen(url) { this.close(); - app.navigate( - '/cluster/' + this.props.node.get('cluster') + '/nodes/' + url + '/' + - utils.serializeTabOptions({nodes: this.props.node.id}), - {trigger: true} - ); + app.navigate([ + '/cluster/', + this.props.node.get('cluster'), + '/nodes/', + url, + '/', + utils.serializeTabOptions({nodes: this.props.node.id}) + ].join('')); }, showSummary(group) { var meta = this.props.node.get('meta'); diff --git a/static/views/login_page.js b/static/views/login_page.js index c52defd42..46a9013e3 100644 --- a/static/views/login_page.js +++ b/static/views/login_page.js @@ -84,7 +84,7 @@ var LoginForm = React.createClass({ nextUrl = app.router.returnUrl; delete app.router.returnUrl; } - app.navigate(nextUrl, {trigger: true}); + app.navigate(nextUrl); }); }, componentDidMount() { diff --git a/static/views/welcome_page.js b/static/views/welcome_page.js index b5f50703f..8440161ce 100644 --- a/static/views/welcome_page.js +++ b/static/views/welcome_page.js @@ -40,7 +40,7 @@ var WelcomePage = React.createClass({ }); this.saveSettings(this.getStatisticsSettingsToSave()) .then( - () => app.navigate('/', {trigger: true}), + () => app.navigate('/'), (response) => { this.setState({actionInProgress: false}); utils.showErrorDialog({response}); diff --git a/static/views/wizard.js b/static/views/wizard.js index 728474cde..182d8e680 100644 --- a/static/views/wizard.js +++ b/static/views/wizard.js @@ -693,7 +693,7 @@ var CreateClusterWizard = React.createClass({ () => { this.props.clusters.add(cluster); this.close(); - app.navigate('/cluster/' + this.cluster.id, {trigger: true}); + app.navigate('/cluster/' + this.cluster.id); }, (response) => { this.stopHandlingKeys = false;