Skip to content

Commit

Permalink
fix: most Recently Selected Table Should Appear at the Top of the Lis…
Browse files Browse the repository at this point in the history
…t on the Left Panel (#19258)
  • Loading branch information
diegomedina248 committed Mar 21, 2022
1 parent 29cba2b commit 4669b6c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
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

0 comments on commit 4669b6c

Please sign in to comment.