feat: add separate endpoint to fetch function names for autocomplete (#12840)

* WIP

* Add unit test for API

* Add spec

* Fix unit test

* Fix unit test

* Fix test

* Fix test

* Add period to error message
This commit is contained in:
Beto Dealmeida
2021-02-02 18:01:01 -08:00
committed by GitHub
parent 8553543ab0
commit ab3f4bd94b
10 changed files with 113 additions and 11 deletions

View File

@@ -57,6 +57,8 @@ export const QUERY_EDITOR_SET_QUERY_LIMIT = 'QUERY_EDITOR_SET_QUERY_LIMIT';
export const QUERY_EDITOR_SET_TEMPLATE_PARAMS =
'QUERY_EDITOR_SET_TEMPLATE_PARAMS';
export const QUERY_EDITOR_SET_SELECTED_TEXT = 'QUERY_EDITOR_SET_SELECTED_TEXT';
export const QUERY_EDITOR_SET_FUNCTION_NAMES =
'QUERY_EDITOR_SET_FUNCTION_NAMES';
export const QUERY_EDITOR_PERSIST_HEIGHT = 'QUERY_EDITOR_PERSIST_HEIGHT';
export const MIGRATE_QUERY_EDITOR = 'MIGRATE_QUERY_EDITOR';
export const MIGRATE_TAB_HISTORY = 'MIGRATE_TAB_HISTORY';
@@ -1300,3 +1302,23 @@ export function createCtasDatasource(vizOptions) {
});
};
}
export function queryEditorSetFunctionNames(queryEditor, dbId) {
return function (dispatch) {
return SupersetClient.get({
endpoint: encodeURI(`/api/v1/database/${dbId}/function_names/`),
})
.then(({ json }) =>
dispatch({
type: QUERY_EDITOR_SET_FUNCTION_NAMES,
queryEditor,
functionNames: json.function_names,
}),
)
.catch(() =>
dispatch(
addDangerToast(t('An error occurred while fetching function names.')),
),
);
};
}