Skip to content

Commit

Permalink
[BUG] Support duplicate index pattern name (#5946) (#5960)
Browse files Browse the repository at this point in the history
* add key to index pattern options for support duplicate index pattern names

---------

Signed-off-by: Eric <menwe@amazon.com>
(cherry picked from commit d6a4f30)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent e36cc3f commit 93f7e45
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<DataSourceSelectable
dataSources={[
({
getDataSet: jest.fn().mockResolvedValue([]),
getType: jest.fn().mockReturnValue('DEFAULT_INDEX_PATTERNS'),
getName: jest.fn().mockReturnValue('Index patterns'),
} as unknown) as DataSourceType,
]}
dataSourceOptionList={mockDataSourceOptionListWithDuplicates}
selectedSources={selectedSourcesMock}
onDataSourceSelect={handleSelect}
setDataSourceOptionList={setDataSourceOptionListMock}
onGetDataSetError={onFetchDataSetErrorMock}
/>
);

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' }])
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const getSourceOptions = (dataSource: DataSourceType, dataSet: DataSetTyp
...optionContent,
label: dataSet.title,
value: dataSet.id,
key: dataSet.id,
};
}
return {
Expand Down

0 comments on commit 93f7e45

Please sign in to comment.