mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
fix(sqllab): dedupe active_tab in tabHistory (#23265)
This commit is contained in:
parent
fae3ad0462
commit
b1526c14e0
@ -19,6 +19,14 @@
|
|||||||
import { t } from '@superset-ui/core';
|
import { t } from '@superset-ui/core';
|
||||||
import getToastsFromPyFlashMessages from 'src/components/MessageToasts/getToastsFromPyFlashMessages';
|
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({
|
export default function getInitialState({
|
||||||
defaultDbId,
|
defaultDbId,
|
||||||
common,
|
common,
|
||||||
@ -193,7 +201,7 @@ export default function getInitialState({
|
|||||||
offline: false,
|
offline: false,
|
||||||
queries,
|
queries,
|
||||||
queryEditors: Object.values(queryEditors),
|
queryEditors: Object.values(queryEditors),
|
||||||
tabHistory,
|
tabHistory: dedupeTabHistory(tabHistory),
|
||||||
tables,
|
tables,
|
||||||
queriesLastUpdate: Date.now(),
|
queriesLastUpdate: Date.now(),
|
||||||
user,
|
user,
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import getInitialState from './getInitialState';
|
import getInitialState, { dedupeTabHistory } from './getInitialState';
|
||||||
|
|
||||||
const apiData = {
|
const apiData = {
|
||||||
defaultDbId: 1,
|
defaultDbId: 1,
|
||||||
@ -51,4 +51,21 @@ describe('getInitialState', () => {
|
|||||||
.templateParams,
|
.templateParams,
|
||||||
).toBeUndefined();
|
).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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user