Skip to content

Commit

Permalink
fix the case for clone query editor
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark committed Oct 4, 2023
1 parent a89d915 commit 989b447
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 6 additions & 4 deletions superset-frontend/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions superset-frontend/src/SqlLab/actions/sqlLab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 989b447

Please sign in to comment.