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(sql lab): most recently selected table should appear at the top of the list on the left panel #19258

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
20 changes: 12 additions & 8 deletions superset-frontend/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,8 @@ export function queryEditorSetSelectedText(queryEditor, sql) {
return { type: QUERY_EDITOR_SET_SELECTED_TEXT, queryEditor, sql };
}

export function mergeTable(table, query) {
return { type: MERGE_TABLE, table, query };
export function mergeTable(table, query, prepend) {
return { type: MERGE_TABLE, table, query, prepend };
}

function getTableMetadata(table, query, dispatch) {
Expand Down Expand Up @@ -1076,12 +1076,16 @@ export function addTable(query, database, tableName, schemaName) {
name: tableName,
};
dispatch(
mergeTable({
...table,
isMetadataLoading: true,
isExtraMetadataLoading: true,
expanded: true,
}),
mergeTable(
{
...table,
isMetadataLoading: true,
isExtraMetadataLoading: true,
expanded: true,
},
null,
true,
),
);

return Promise.all([
Expand Down
3 changes: 2 additions & 1 deletion superset-frontend/src/SqlLab/actions/sqlLab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ describe('async actions', () => {

describe('addTable', () => {
it('updates the table schema state in the backend', () => {
expect.assertions(5);
expect.assertions(6);

const database = { disable_data_preview: true };
const tableName = 'table';
Expand All @@ -743,6 +743,7 @@ describe('async actions', () => {
expect(store.getActions().map(a => a.type)).toEqual(
expectedActionTypes,
);
expect(store.getActions()[0].prepend).toBeTruthy();
expect(fetchMock.calls(updateTableSchemaEndpoint)).toHaveLength(1);
expect(fetchMock.calls(getTableMetadataEndpoint)).toHaveLength(1);
expect(fetchMock.calls(getExtraTableMetadataEndpoint)).toHaveLength(
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/SqlLab/reducers/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default function sqlLabReducer(state = {}, action) {
}
// for new table, associate Id of query for data preview
at.dataPreviewQueryId = null;
let newState = addToArr(state, 'tables', at);
let newState = addToArr(state, 'tables', at, Boolean(action.prepend));
if (action.query) {
newState = alterInArr(newState, 'tables', at, {
dataPreviewQueryId: action.query.id,
Expand Down