From 93f7e456e5e06d6010e0f34de5297de17ebef3c2 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 14:26:33 -0700 Subject: [PATCH] [BUG] Support duplicate index pattern name (#5946) (#5960) * add key to index pattern options for support duplicate index pattern names --------- Signed-off-by: Eric (cherry picked from commit d6a4f305bccb40fc149e00eef58b289bde49fc9e) Signed-off-by: github-actions[bot] # Conflicts: # CHANGELOG.md Co-authored-by: github-actions[bot] --- .../datasource_selectable.test.tsx | 43 +++++++++++++++++++ .../datasource_selectable.tsx | 1 + 2 files changed, 44 insertions(+) diff --git a/src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.test.tsx b/src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.test.tsx index 3e6c99e420d6..63c2437cc7b3 100644 --- a/src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.test.tsx +++ b/src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.test.tsx @@ -181,4 +181,47 @@ describe('DataSourceSelectable', () => { ]; expect(optionTexts).toEqual(expectedIndexPatternSortedOrder); }); + + it('should allow display and selection of duplicated index patterns based on unique key', async () => { + const mockDataSourceOptionListWithDuplicates = [ + { + label: 'Index patterns', + options: [ + { label: 'duplicate-index-pattern', key: 'unique-key-1' }, + { label: 'unique-index-pattern-1', key: 'unique-key-2' }, + { label: 'duplicate-index-pattern', key: 'unique-key-3' }, + { label: 'unique-index-pattern-2', key: 'unique-key-4' }, + ], + }, + ] as any; + + const handleSelect = jest.fn(); + + render( + + ); + + const button = screen.getByLabelText('Open list of options'); + fireEvent.click(button); + + const optionsToSelect = screen.getAllByText('duplicate-index-pattern'); + fireEvent.click(optionsToSelect[1]); + + expect(handleSelect).toHaveBeenCalledWith( + expect.objectContaining([{ key: 'unique-key-3', label: 'duplicate-index-pattern' }]) + ); + }); }); diff --git a/src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.tsx b/src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.tsx index 1c6876815a0e..88abe18aa143 100644 --- a/src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.tsx +++ b/src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.tsx @@ -52,6 +52,7 @@ export const getSourceOptions = (dataSource: DataSourceType, dataSet: DataSetTyp ...optionContent, label: dataSet.title, value: dataSet.id, + key: dataSet.id, }; } return {