You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2023/10/19 13:06:09 UTC
[superset] 01/09: fix(sqllab): Mistitled for new tab after rename (#25523)
This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/superset.git
commit d7cbdca081ed69a7fc740272d714a6deaa0f6bac
Author: JUST.in DO IT <ju...@airbnb.com>
AuthorDate: Fri Oct 13 11:17:45 2023 -0400
fix(sqllab): Mistitled for new tab after rename (#25523)
(cherry picked from commit a520124a78286aea0f9a7ad491d041bbca2c3596)
---
superset-frontend/src/SqlLab/actions/sqlLab.js | 17 ++++++++++++-----
.../src/SqlLab/actions/sqlLab.test.js | 22 ++++++++++++++++------
2 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js
index 5d9ecdacdf..fbfba6783e 100644
--- a/superset-frontend/src/SqlLab/actions/sqlLab.js
+++ b/superset-frontend/src/SqlLab/actions/sqlLab.js
@@ -596,7 +596,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({
@@ -614,10 +619,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 fc94a44645..25f80aa1c3 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);
@@ -444,16 +447,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,