From a89d9157cf4ad3fa27026da93a2ec39ba5f22c17 Mon Sep 17 00:00:00 2001 From: justinpark Date: Wed, 4 Oct 2023 14:57:00 -0400 Subject: [PATCH 1/2] fix(sqllab): Mistitled for new tab after rename --- superset-frontend/src/SqlLab/actions/sqlLab.js | 7 ++++++- .../src/SqlLab/actions/sqlLab.test.js | 15 +++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js index 7c27a74a1e87e..1953770383b83 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.js @@ -607,7 +607,12 @@ export function addNewQueryEditor() { '-- Note: Unless you save your query, these tabs will NOT persist if you clear your cookies or change browsers.\n\n', ); - const name = newQueryTabName(queryEditors || []); + const name = newQueryTabName( + queryEditors?.map(qe => ({ + ...qe, + ...(qe.id === unsavedQueryEditor.id && unsavedQueryEditor), + })) || [], + ); return dispatch( addQueryEditor({ diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.test.js b/superset-frontend/src/SqlLab/actions/sqlLab.test.js index fc94a44645c7e..b5996df546ce0 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.test.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.test.js @@ -444,16 +444,23 @@ describe('async actions', () => { describe('addNewQueryEditor', () => { it('creates new query editor with new tab name', () => { - const store = mockStore(initialState); + const store = mockStore({ + ...initialState, + sqlLab: { + ...initialState.sqlLab, + unsavedQueryEditor: { + id: defaultQueryEditor.id, + name: 'Untitled Query 6', + }, + }, + }); const expectedActions = [ { type: actions.ADD_QUERY_EDITOR, queryEditor: { id: 'abcd', sql: expect.stringContaining('SELECT ...'), - name: `Untitled Query ${ - store.getState().sqlLab.queryEditors.length + 1 - }`, + name: `Untitled Query 7`, dbId: defaultQueryEditor.dbId, schema: defaultQueryEditor.schema, autorun: false, From 989b44787d73bdd67037750a7fb156dc750efffd Mon Sep 17 00:00:00 2001 From: justinpark Date: Wed, 4 Oct 2023 16:15:45 -0400 Subject: [PATCH 2/2] 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);