From 4669b6ce11dd74e5d1020a1f124e8696b801d730 Mon Sep 17 00:00:00 2001 From: Diego Medina Date: Mon, 21 Mar 2022 17:58:23 -0400 Subject: [PATCH] fix: most Recently Selected Table Should Appear at the Top of the List on the Left Panel (#19258) --- .../src/SqlLab/actions/sqlLab.js | 20 +++++++++++-------- .../src/SqlLab/actions/sqlLab.test.js | 3 ++- .../src/SqlLab/reducers/sqlLab.js | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js index e13e4263a36c..02e07d5831e9 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.js @@ -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) { @@ -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([ diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.test.js b/superset-frontend/src/SqlLab/actions/sqlLab.test.js index 789ae986bfbe..5b20f5233564 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.test.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.test.js @@ -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'; @@ -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( diff --git a/superset-frontend/src/SqlLab/reducers/sqlLab.js b/superset-frontend/src/SqlLab/reducers/sqlLab.js index c3b2cd88f091..923caaf96152 100644 --- a/superset-frontend/src/SqlLab/reducers/sqlLab.js +++ b/superset-frontend/src/SqlLab/reducers/sqlLab.js @@ -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,