Skip to content

Commit

Permalink
update function name and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark committed Jun 3, 2024
1 parent a9c0459 commit c453f8e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
11 changes: 10 additions & 1 deletion superset-frontend/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,16 @@ function migrateQuery(queryId, queryEditorId, dispatch) {
);
}

export function migrateQueryEditorFromLocalStorage(queryEditor) {
/**
* Persist QueryEditor from local storage to backend tab state.
* This ensures that when new tabs are created, query editors are
* asynchronously stored in local storage and periodically synchronized
* with the backend.
* When switching to persistence mode, the QueryEditors previously
* stored in local storage will also be synchronized to the backend
* through syncQueryEditor.
*/
export function syncQueryEditor(queryEditor) {
return function (dispatch, getState) {
const { tables, queries } = getState().sqlLab;
const localStorageTables = tables.filter(
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/SqlLab/actions/sqlLab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ describe('async actions', () => {
});
});

describe('migrateQueryEditorFromLocalStorage', () => {
describe('syncQueryEditor', () => {
it('updates the tab state in the backend', () => {
expect.assertions(3);

Expand Down Expand Up @@ -1073,7 +1073,7 @@ describe('async actions', () => {
},
];
return store
.dispatch(actions.migrateQueryEditorFromLocalStorage(oldQueryEditor))
.dispatch(actions.syncQueryEditor(oldQueryEditor))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import { useUpdateSqlEditorTabMutation } from 'src/hooks/apiResources/sqlEditorTabs';
import { useDebounceValue } from 'src/hooks/useDebounceValue';
import {
migrateQueryEditorFromLocalStorage,
syncQueryEditor,
setEditorTabLastUpdate,
} from 'src/SqlLab/actions/sqlLab';
import useEffectEvent from 'src/hooks/useEffectEvent';
Expand Down Expand Up @@ -99,7 +99,7 @@ const EditorAutoSync: React.FC = () => {
const firstUnsavedQueryEditor = getUnsavedNewQueryEditor();

if (firstUnsavedQueryEditor) {
dispatch(migrateQueryEditorFromLocalStorage(firstUnsavedQueryEditor));
dispatch(syncQueryEditor(firstUnsavedQueryEditor));
}
timer = setTimeout(saveUnsavedQueryEditor, INTERVAL);
}
Expand Down

0 comments on commit c453f8e

Please sign in to comment.