Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(queryAssist): allow dataset with DATA_SOURCE type #7890

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,25 @@
*/
const getAvailableLanguagesForDataSource = (() => {
const availableLanguagesByDataSource: Map<string | undefined, string[]> = new Map();
const pendingRequests: Map<string | undefined, Promise<string[]>> = new Map();

return async (http: HttpSetup, dataSourceId: string | undefined) => {
const cached = availableLanguagesByDataSource.get(dataSourceId);
if (cached !== undefined) return cached;
const languages = await http

const pendingRequest = pendingRequests.get(dataSourceId);

Check warning on line 31 in src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx#L31

Added line #L31 was not covered by tests
if (pendingRequest !== undefined) return pendingRequest;

const languagesPromise = http

Check warning on line 34 in src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx#L34

Added line #L34 was not covered by tests
.get<{ configuredLanguages: string[] }>(API.QUERY_ASSIST.LANGUAGES, {
query: { dataSourceId },
})
.then((response) => response.configuredLanguages)
.catch(() => []);
.catch(() => [])
.finally(() => pendingRequests.delete(dataSourceId));
pendingRequests.set(dataSourceId, languagesPromise);

Check warning on line 41 in src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx#L39-L41

Added lines #L39 - L41 were not covered by tests

const languages = await languagesPromise;

Check warning on line 43 in src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx#L43

Added line #L43 was not covered by tests
availableLanguagesByDataSource.set(dataSourceId, languages);
return languages;
};
Expand All @@ -47,7 +57,11 @@
switchMap(async (query) => {
// currently query assist tool relies on opensearch API to get index
// mappings, external data source types (e.g. s3) are not supported
if (query.dataset?.dataSource?.type !== DEFAULT_DATA.SOURCE_TYPES.OPENSEARCH) return [];
if (
query.dataset?.dataSource?.type !== DEFAULT_DATA.SOURCE_TYPES.OPENSEARCH &&
query.dataset?.dataSource?.type !== 'DATA_SOURCE'
)
return [];

Check warning on line 64 in src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx#L64

Added line #L64 was not covered by tests

const dataSourceId = query.dataset?.dataSource?.id;
return getAvailableLanguagesForDataSource(http, dataSourceId);
Expand Down
Loading