From 989b44787d73bdd67037750a7fb156dc750efffd Mon Sep 17 00:00:00 2001 From: justinpark Date: Wed, 4 Oct 2023 16:15:45 -0400 Subject: [PATCH] fix the case for clone query editor --- superset-frontend/src/SqlLab/actions/sqlLab.js | 10 ++++++---- superset-frontend/src/SqlLab/actions/sqlLab.test.js | 7 +++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js index 1953770383b83..ac26f1fc6ca38 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.js @@ -630,10 +630,12 @@ export function addNewQueryEditor() { export function cloneQueryToNewTab(query, autorun) { return function (dispatch, getState) { const state = getState(); - const { queryEditors, tabHistory } = state.sqlLab; - const sourceQueryEditor = queryEditors.find( - qe => qe.id === tabHistory[tabHistory.length - 1], - ); + const { queryEditors, unsavedQueryEditor, tabHistory } = state.sqlLab; + const sourceQueryEditor = { + ...queryEditors.find(qe => qe.id === tabHistory[tabHistory.length - 1]), + ...(tabHistory[tabHistory.length - 1] === unsavedQueryEditor.id && + unsavedQueryEditor), + }; const queryEditor = { name: t('Copy of %s', sourceQueryEditor.name), dbId: query.dbId ? query.dbId : null, diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.test.js b/superset-frontend/src/SqlLab/actions/sqlLab.test.js index b5996df546ce0..25f80aa1c386a 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.test.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.test.js @@ -389,8 +389,11 @@ describe('async actions', () => { const state = { sqlLab: { tabHistory: [id], - queryEditors: [{ id, name: 'Dummy query editor' }], - unsavedQueryEditor: {}, + queryEditors: [{ id, name: 'out of updated title' }], + unsavedQueryEditor: { + id, + name: 'Dummy query editor', + }, }, }; const store = mockStore(state);