From 43a2e31e7b089cfb34567ec08707b1b06b47b025 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 21 Oct 2024 06:45:14 +0000 Subject: [PATCH] Hide incompatible index patterns (#354) * Display a message when there is no supported data source Signed-off-by: Kapian1234 * filter out incompatible index patterns Signed-off-by: Kapian1234 * Display a message when there is no supported data source Signed-off-by: Kapian1234 * remove log Signed-off-by: Kapian1234 * remove unused import Signed-off-by: Kapian1234 * add changelog Signed-off-by: Kapian1234 * modify changelog Signed-off-by: Kapian1234 * resolve some issues Signed-off-by: Kapian1234 --------- Signed-off-by: Kapian1234 Signed-off-by: Jincheng Wan <45655760+Kapian1234@users.noreply.github.com> (cherry picked from commit e3ec245e1853929a89a06465d8360e6f887d08a7) Signed-off-by: github-actions[bot] # Conflicts: # CHANGELOG.md --- .../visualization/source_selector.tsx | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/public/components/visualization/source_selector.tsx b/public/components/visualization/source_selector.tsx index 3cbb620d..9a2720fb 100644 --- a/public/components/visualization/source_selector.tsx +++ b/public/components/visualization/source_selector.tsx @@ -5,7 +5,6 @@ import React, { useCallback, useMemo, useState, useEffect, useRef } from 'react'; import { i18n } from '@osd/i18n'; - import { useOpenSearchDashboards } from '../../../../../src/plugins/opensearch_dashboards_react/public'; import { DataSource, @@ -139,13 +138,9 @@ export const SourceSelector = ({ } ); if (!res.exists) { - dataSourceIdToIndexPatternIds[key].forEach((indexPatternId) => { - indexPatternOptions.options.forEach((option) => { - if (option.value === indexPatternId) { - option.disabled = true; - } - }); - }); + indexPatternOptions.options = indexPatternOptions.options.filter( + (option) => !dataSourceIdToIndexPatternIds[key].includes(option.value) + ); } } ); @@ -171,10 +166,31 @@ export const SourceSelector = ({ dataSources.dataSourceService.reload(); }, [dataSources.dataSourceService]); + const options = useMemo(() => { + if (dataSourceOptions[0] && dataSourceOptions[0].options.length > 0) { + return dataSourceOptions; + } + return [ + { + label: i18n.translate('dashboardAssistant.datasource.selector.group.label', { + defaultMessage: 'Index patterns', + }), + options: [ + { + label: i18n.translate('dashboardAssistant.datasource.selector.emptyMessage.label', { + defaultMessage: 'No supported index patterns', + }), + disabled: true, + }, + ], + }, + ]; + }, [dataSourceOptions]); + return (