Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide incompatible index patterns #354

Merged
31 changes: 22 additions & 9 deletions public/components/visualization/source_selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import React, { useCallback, useMemo, useState, useEffect, useRef } from 'react';
import { i18n } from '@osd/i18n';

import { EuiComboBoxOptionOption } from '@elastic/eui';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new import seems is not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I'll delete it

import { useOpenSearchDashboards } from '../../../../../src/plugins/opensearch_dashboards_react/public';
import {
DataSource,
Expand Down Expand Up @@ -139,13 +139,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)
);
}
}
);
Expand All @@ -171,10 +167,27 @@ export const SourceSelector = ({
dataSources.dataSourceService.reload();
}, [dataSources.dataSourceService]);

const options = useMemo(() => {
if (dataSourceOptions[0] && dataSourceOptions[0].options.length > 0) {
return dataSourceOptions;
}
return [
{
label: 'Index patterns',
options: [
{
label: 'No supported index patterns',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i18n

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I forgot it

disabled: true,
},
],
},
];
}, [dataSourceOptions]);

return (
<DataSourceSelectable
dataSources={currentDataSources}
dataSourceOptionList={dataSourceOptions}
dataSourceOptionList={options}
setDataSourceOptionList={onSetDataSourceOptions}
onDataSourceSelect={onDataSourceSelect}
selectedSources={selectedSources}
Expand Down
Loading