You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2023/03/22 21:33:49 UTC
[superset] branch master updated: fix(sqllab): dedupe active_tab in tabHistory (#23265)
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new b1526c14e0 fix(sqllab): dedupe active_tab in tabHistory (#23265)
b1526c14e0 is described below
commit b1526c14e076781d008b04c8e80090414e229c3b
Author: JUST.in DO IT <ju...@airbnb.com>
AuthorDate: Wed Mar 22 14:33:41 2023 -0700
fix(sqllab): dedupe active_tab in tabHistory (#23265)
---
.../src/SqlLab/reducers/getInitialState.js | 10 +++++++++-
.../src/SqlLab/reducers/getInitialState.test.ts | 19 ++++++++++++++++++-
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/superset-frontend/src/SqlLab/reducers/getInitialState.js b/superset-frontend/src/SqlLab/reducers/getInitialState.js
index 2d00d3e0d6..1d50c1067c 100644
--- a/superset-frontend/src/SqlLab/reducers/getInitialState.js
+++ b/superset-frontend/src/SqlLab/reducers/getInitialState.js
@@ -19,6 +19,14 @@
import { t } from '@superset-ui/core';
import getToastsFromPyFlashMessages from 'src/components/MessageToasts/getToastsFromPyFlashMessages';
+export function dedupeTabHistory(tabHistory) {
+ return tabHistory.reduce(
+ (result, tabId) =>
+ result.slice(-1)[0] === tabId ? result : result.concat(tabId),
+ [],
+ );
+}
+
export default function getInitialState({
defaultDbId,
common,
@@ -193,7 +201,7 @@ export default function getInitialState({
offline: false,
queries,
queryEditors: Object.values(queryEditors),
- tabHistory,
+ tabHistory: dedupeTabHistory(tabHistory),
tables,
queriesLastUpdate: Date.now(),
user,
diff --git a/superset-frontend/src/SqlLab/reducers/getInitialState.test.ts b/superset-frontend/src/SqlLab/reducers/getInitialState.test.ts
index 94a0c6a85e..e1896d882d 100644
--- a/superset-frontend/src/SqlLab/reducers/getInitialState.test.ts
+++ b/superset-frontend/src/SqlLab/reducers/getInitialState.test.ts
@@ -17,7 +17,7 @@
* under the License.
*/
-import getInitialState from './getInitialState';
+import getInitialState, { dedupeTabHistory } from './getInitialState';
const apiData = {
defaultDbId: 1,
@@ -51,4 +51,21 @@ describe('getInitialState', () => {
.templateParams,
).toBeUndefined();
});
+
+ describe('dedupeTabHistory', () => {
+ it('should dedupe the tab history', () => {
+ [
+ { value: [], expected: [] },
+ { value: [12, 3, 4, 5, 6], expected: [12, 3, 4, 5, 6] },
+ { value: [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], expected: [1, 2] },
+ {
+ value: [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3],
+ expected: [1, 2, 3],
+ },
+ { value: [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3], expected: [2, 3] },
+ ].forEach(({ value, expected }) => {
+ expect(dedupeTabHistory(value)).toEqual(expected);
+ });
+ });
+ });
});