Skip to content

Commit

Permalink
update error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Su <[email protected]>
  • Loading branch information
zhongnansu committed Mar 23, 2023
1 parent 0767a48 commit 8fc0dfc
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/plugins/data/common/index_patterns/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,20 @@ export const getIndexPatternTitle = async (
getDataSource: (id: string) => Promise<SavedObject<DataSourceAttributes>>
): Promise<string> => {
const DELIMITER = '.';
let dataSourceTitle;
// If an index-pattern references datasource, prepend data source name with index pattern name for display purpose
if (Array.isArray(references) && references[0] && references[0].type === 'data-source') {
const {
attributes: { title: dataSourceTitle },
} = await getDataSource(references[0].id);
const dataSourceId = references[0].id;
try {
const {
attributes: { title },
error,
} = await getDataSource(dataSourceId);
dataSourceTitle = error ? dataSourceId : title;
} catch (e) {
dataSourceTitle = dataSourceId;
}

return dataSourceTitle.concat(DELIMITER).concat(indexPatternTitle);
} else {
// if index pattern doesn't reference datasource, return as it is.
Expand Down

0 comments on commit 8fc0dfc

Please sign in to comment.