From 541cbdd38e89da3372b09e476f2c79ab5b771822 Mon Sep 17 00:00:00 2001 From: Huy Nguyen <73027756+huyaboo@users.noreply.github.com> Date: Tue, 16 Apr 2024 18:14:31 +0000 Subject: [PATCH] Address comments Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com> --- .../server/lib/fetch_data_source_id.ts | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/plugins/vis_type_timeline/server/lib/fetch_data_source_id.ts b/src/plugins/vis_type_timeline/server/lib/fetch_data_source_id.ts index 85de50a62606..e3d0d76d23e7 100644 --- a/src/plugins/vis_type_timeline/server/lib/fetch_data_source_id.ts +++ b/src/plugins/vis_type_timeline/server/lib/fetch_data_source_id.ts @@ -12,31 +12,31 @@ export const fetchDataSourceIdByName = async ( config: OpenSearchFunctionConfig, client: SavedObjectsClientContract ) => { - if (config.data_source_name) { - if (!getDataSourceEnabled().enabled) { - throw new Error('To query from multiple data sources, first enable the data source feature'); - } + if (!config.data_source_name) { + return undefined; + } - const dataSources = await client.find({ - type: 'data-source', - perPage: 100, - search: `"${config.data_source_name}"`, - searchFields: ['title'], - fields: ['id', 'title'], - }); + if (!getDataSourceEnabled().enabled) { + throw new Error('To query from multiple data sources, first enable the data source feature'); + } - const possibleDataSourceIds = dataSources.saved_objects.filter( - (obj) => obj.attributes.title === config.data_source_name - ); + const dataSources = await client.find({ + type: 'data-source', + perPage: 100, + search: `"${config.data_source_name}"`, + searchFields: ['title'], + fields: ['id', 'title'], + }); - if (possibleDataSourceIds.length !== 1) { - throw new Error( - `Expected exactly 1 result for data_source_name "${config.data_source_name}" but got ${possibleDataSourceIds.length} results` - ); - } + const possibleDataSourceIds = dataSources.saved_objects.filter( + (obj) => obj.attributes.title === config.data_source_name + ); - return possibleDataSourceIds.pop()?.id; + if (possibleDataSourceIds.length !== 1) { + throw new Error( + `Expected exactly 1 result for data_source_name "${config.data_source_name}" but got ${possibleDataSourceIds.length} results` + ); } - return undefined; + return possibleDataSourceIds.pop()?.id; };