Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sqllab): Mistitled for new tab after rename #25523

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions superset-frontend/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -625,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
22 changes: 16 additions & 6 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 Expand Up @@ -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,
Expand Down
Loading