mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
refactor(sqllab): nonblocking switch query editor (#29108)
This commit is contained in:
@@ -102,6 +102,7 @@ export const CREATE_DATASOURCE_SUCCESS = 'CREATE_DATASOURCE_SUCCESS';
|
||||
export const CREATE_DATASOURCE_FAILED = 'CREATE_DATASOURCE_FAILED';
|
||||
|
||||
export const SET_EDITOR_TAB_LAST_UPDATE = 'SET_EDITOR_TAB_LAST_UPDATE';
|
||||
export const SET_LAST_UPDATED_ACTIVE_TAB = 'SET_LAST_UPDATED_ACTIVE_TAB';
|
||||
|
||||
export const addInfoToast = addInfoToastAction;
|
||||
export const addSuccessToast = addSuccessToastAction;
|
||||
@@ -611,29 +612,17 @@ export function cloneQueryToNewTab(query, autorun) {
|
||||
};
|
||||
}
|
||||
|
||||
export function setActiveQueryEditor(queryEditor) {
|
||||
return function (dispatch) {
|
||||
const sync = isFeatureEnabled(FeatureFlag.SqllabBackendPersistence)
|
||||
? SupersetClient.post({
|
||||
endpoint: encodeURI(`/tabstateview/${queryEditor.id}/activate`),
|
||||
})
|
||||
: Promise.resolve();
|
||||
export function setLastUpdatedActiveTab(queryEditorId) {
|
||||
return {
|
||||
type: SET_LAST_UPDATED_ACTIVE_TAB,
|
||||
queryEditorId,
|
||||
};
|
||||
}
|
||||
|
||||
return sync
|
||||
.then(() => dispatch({ type: SET_ACTIVE_QUERY_EDITOR, queryEditor }))
|
||||
.catch(response => {
|
||||
if (response.status !== 404) {
|
||||
return dispatch(
|
||||
addDangerToast(
|
||||
t(
|
||||
'An error occurred while setting the active tab. Please contact ' +
|
||||
'your administrator.',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return dispatch({ type: REMOVE_QUERY_EDITOR, queryEditor });
|
||||
});
|
||||
export function setActiveQueryEditor(queryEditor) {
|
||||
return {
|
||||
type: SET_ACTIVE_QUERY_EDITOR,
|
||||
queryEditor,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -674,51 +663,42 @@ export function setTables(tableSchemas) {
|
||||
return { type: SET_TABLES, tables };
|
||||
}
|
||||
|
||||
export function switchQueryEditor(queryEditor, displayLimit) {
|
||||
export function fetchQueryEditor(queryEditor, displayLimit) {
|
||||
return function (dispatch) {
|
||||
if (
|
||||
isFeatureEnabled(FeatureFlag.SqllabBackendPersistence) &&
|
||||
queryEditor &&
|
||||
!queryEditor.loaded
|
||||
) {
|
||||
SupersetClient.get({
|
||||
endpoint: encodeURI(`/tabstateview/${queryEditor.id}`),
|
||||
SupersetClient.get({
|
||||
endpoint: encodeURI(`/tabstateview/${queryEditor.id}`),
|
||||
})
|
||||
.then(({ json }) => {
|
||||
const loadedQueryEditor = {
|
||||
id: json.id.toString(),
|
||||
loaded: true,
|
||||
name: json.label,
|
||||
sql: json.sql,
|
||||
selectedText: null,
|
||||
latestQueryId: json.latest_query?.id,
|
||||
autorun: json.autorun,
|
||||
dbId: json.database_id,
|
||||
templateParams: json.template_params,
|
||||
catalog: json.catalog,
|
||||
schema: json.schema,
|
||||
queryLimit: json.query_limit,
|
||||
remoteId: json.saved_query?.id,
|
||||
hideLeftBar: json.hide_left_bar,
|
||||
};
|
||||
dispatch(loadQueryEditor(loadedQueryEditor));
|
||||
dispatch(setTables(json.table_schemas || []));
|
||||
if (json.latest_query && json.latest_query.resultsKey) {
|
||||
dispatch(fetchQueryResults(json.latest_query, displayLimit));
|
||||
}
|
||||
})
|
||||
.then(({ json }) => {
|
||||
const loadedQueryEditor = {
|
||||
id: json.id.toString(),
|
||||
loaded: true,
|
||||
name: json.label,
|
||||
sql: json.sql,
|
||||
selectedText: null,
|
||||
latestQueryId: json.latest_query?.id,
|
||||
autorun: json.autorun,
|
||||
dbId: json.database_id,
|
||||
templateParams: json.template_params,
|
||||
catalog: json.catalog,
|
||||
schema: json.schema,
|
||||
queryLimit: json.query_limit,
|
||||
remoteId: json.saved_query?.id,
|
||||
hideLeftBar: json.hide_left_bar,
|
||||
};
|
||||
dispatch(loadQueryEditor(loadedQueryEditor));
|
||||
dispatch(setTables(json.table_schemas || []));
|
||||
dispatch(setActiveQueryEditor(loadedQueryEditor));
|
||||
if (json.latest_query && json.latest_query.resultsKey) {
|
||||
dispatch(fetchQueryResults(json.latest_query, displayLimit));
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response.status !== 404) {
|
||||
return dispatch(
|
||||
addDangerToast(t('An error occurred while fetching tab state')),
|
||||
);
|
||||
}
|
||||
return dispatch({ type: REMOVE_QUERY_EDITOR, queryEditor });
|
||||
});
|
||||
} else {
|
||||
dispatch(setActiveQueryEditor(queryEditor));
|
||||
}
|
||||
.catch(response => {
|
||||
if (response.status !== 404) {
|
||||
return dispatch(
|
||||
addDangerToast(t('An error occurred while fetching tab state')),
|
||||
);
|
||||
}
|
||||
return dispatch({ type: REMOVE_QUERY_EDITOR, queryEditor });
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user