refactor(sql_lab): SQL Lab Persistent Saved State (#17771)

* a lot of console logs

* testing

* test

* added saved_query to remoteId

* created useEffect so that title properly changes in modal

* Update superset-frontend/src/SqlLab/actions/sqlLab.js

Co-authored-by: Lyndsi Kay Williams <55605634+lyndsiWilliams@users.noreply.github.com>

Co-authored-by: Lyndsi Kay Williams <55605634+lyndsiWilliams@users.noreply.github.com>
This commit is contained in:
AAfghahi
2022-01-18 13:10:31 -05:00
committed by GitHub
parent 5bfe2d47b0
commit 88db2cc0ab
6 changed files with 52 additions and 8 deletions

View File

@@ -636,12 +636,13 @@ export function switchQueryEditor(queryEditor, displayLimit) {
title: json.label,
sql: json.sql,
selectedText: null,
latestQueryId: json.latest_query ? json.latest_query.id : null,
latestQueryId: json.latest_query?.id,
autorun: json.autorun,
dbId: json.database_id,
templateParams: json.template_params,
schema: json.schema,
queryLimit: json.query_limit,
remoteId: json.saved_query?.id,
validationResult: {
id: null,
errors: [],
@@ -864,19 +865,38 @@ export function saveQuery(query) {
stringify: false,
})
.then(result => {
const savedQuery = convertQueryToClient(result.json.item);
dispatch({
type: QUERY_EDITOR_SAVED,
query,
result: convertQueryToClient(result.json.item),
result: savedQuery,
});
dispatch(addSuccessToast(t('Your query was saved')));
dispatch(queryEditorSetTitle(query, query.title));
return savedQuery;
})
.catch(() =>
dispatch(addDangerToast(t('Your query could not be saved'))),
);
}
export const addSavedQueryToTabState =
(queryEditor, savedQuery) => dispatch => {
const sync = isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE)
? SupersetClient.put({
endpoint: `/tabstateview/${queryEditor.id}`,
postPayload: { saved_query_id: savedQuery.remoteId },
})
: Promise.resolve();
return sync
.catch(() => {
dispatch(addDangerToast(t('Your query was not properly saved')));
})
.then(() => {
dispatch(addSuccessToast(t('Your query was saved')));
});
};
export function updateSavedQuery(query) {
return dispatch =>
SupersetClient.put({