refactor(sqllab): nonblocking switch query editor (#29108)

This commit is contained in:
JUST.in DO IT
2024-06-12 15:07:34 -07:00
committed by GitHub
parent a88979631e
commit 31afb62e95
14 changed files with 188 additions and 101 deletions

View File

@@ -301,6 +301,9 @@ describe('getInitialState', () => {
name: expectedValue,
}),
);
expect(
getInitialState(apiDataWithLocalStorage).sqlLab.lastUpdatedActiveTab,
).toEqual(apiDataWithTabState.active_tab.id.toString());
});
it('skip unsaved changes for expired data', () => {

View File

@@ -110,6 +110,7 @@ export default function getInitialState({
};
});
const tabHistory = activeTab ? [activeTab.id.toString()] : [];
let lastUpdatedActiveTab = activeTab ? activeTab.id.toString() : '';
let tables = {} as Record<string, Table>;
let editorTabLastUpdatedAt = Date.now();
if (activeTab) {
@@ -217,6 +218,7 @@ export default function getInitialState({
if (sqlLab.tabHistory) {
tabHistory.push(...sqlLab.tabHistory);
}
lastUpdatedActiveTab = tabHistory.slice(tabHistory.length - 1)[0] || '';
}
}
} catch (error) {
@@ -250,6 +252,7 @@ export default function getInitialState({
editorTabLastUpdatedAt,
queryCostEstimates: {},
unsavedQueryEditor,
lastUpdatedActiveTab,
},
localStorageUsageInKilobytes: 0,
common,

View File

@@ -742,6 +742,9 @@ export default function sqlLabReducer(state = {}, action) {
[actions.SET_EDITOR_TAB_LAST_UPDATE]() {
return { ...state, editorTabLastUpdatedAt: action.timestamp };
},
[actions.SET_LAST_UPDATED_ACTIVE_TAB]() {
return { ...state, lastUpdatedActiveTab: action.queryEditorId };
},
};
if (action.type in actionHandlers) {
return actionHandlers[action.type]();