Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>
  • Loading branch information
huyaboo committed Apr 16, 2024
1 parent cff410a commit 541cbdd
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/plugins/vis_type_timeline/server/lib/fetch_data_source_id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataSourceAttributes>({
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<DataSourceAttributes>({
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;
};

0 comments on commit 541cbdd

Please sign in to comment.