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);