diff --git a/CHANGELOG.md b/CHANGELOG.md index bf4a8925..d84ea60f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - refactor: Add data source info in discover url when navigating([#347](https://github.com/opensearch-project/dashboards-assistant/pull/347)) - feat: only display ai actions that compatible with the datasource([#350](https://github.com/opensearch-project/dashboards-assistant/pull/350)) - feat: take index pattern and query assistant input to text2viz app([#349](https://github.com/opensearch-project/dashboards-assistant/pull/349)) +- feat: Hide incompatible index patterns ([#354] (https://github.com/opensearch-project/dashboards-assistant/pull/354)) ### 📈 Features/Enhancements 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 (