Skip to content

Commit

Permalink
Merge branch '2.x' into bump-axios-2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwin-pc committed Mar 18, 2024
2 parents 2ec92c3 + 98dfac8 commit b62de4b
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface DataGridTableProps {
isContextView?: boolean;
isLoading?: boolean;
showPagination?: boolean;
scrollToTop?: () => void;
}

export const DataGridTable = ({
Expand All @@ -67,6 +68,7 @@ export const DataGridTable = ({
isContextView = false,
isLoading = false,
showPagination,
scrollToTop,
}: DataGridTableProps) => {
const services = getServices();
const [inspectedHit, setInspectedHit] = useState<OpenSearchSearchHit | undefined>();
Expand Down Expand Up @@ -179,6 +181,7 @@ export const DataGridTable = ({
isShortDots={isShortDots}
hideTimeColumn={hideTimeColumn}
defaultSortOrder={defaultSortOrder}
scrollToTop={scrollToTop}
/>
),
[
Expand All @@ -197,6 +200,7 @@ export const DataGridTable = ({
defaultSortOrder,
hideTimeColumn,
isShortDots,
scrollToTop,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface DefaultDiscoverTableProps {
hideTimeColumn: boolean;
defaultSortOrder: SortDirection;
showPagination?: boolean;
scrollToTop?: () => void;
}

export const LegacyDiscoverTable = ({
Expand All @@ -52,6 +53,7 @@ export const LegacyDiscoverTable = ({
hideTimeColumn,
defaultSortOrder,
showPagination,
scrollToTop,
}: DefaultDiscoverTableProps) => {
const displayedColumns = getLegacyDisplayedColumns(
columns,
Expand Down Expand Up @@ -173,7 +175,7 @@ export const LegacyDiscoverTable = ({
values={{ sampleSize }}
/>

<EuiButtonEmpty onClick={() => window.scrollTo(0, 0)}>
<EuiButtonEmpty onClick={scrollToTop}>
<FormattedMessage id="discover.backToTopLinkText" defaultMessage="Back to top." />
</EuiButtonEmpty>
</EuiCallOut>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
addColumn,
moveColumn,
removeColumn,
reorderColumn,
setColumns,
setSort,
useDispatch,
Expand All @@ -27,9 +26,10 @@ import { popularizeField } from '../../helpers/popularize_field';

interface Props {
rows?: OpenSearchSearchHit[];
scrollToTop?: () => void;
}

export const DiscoverTable = ({ rows }: Props) => {
export const DiscoverTable = ({ rows, scrollToTop }: Props) => {
const { services } = useOpenSearchDashboards<DiscoverViewServices>();
const {
uiSettings,
Expand Down Expand Up @@ -115,6 +115,7 @@ export const DiscoverTable = ({ rows }: Props) => {
displayTimeColumn={displayTimeColumn}
title={savedSearch?.id ? savedSearch.title : ''}
description={savedSearch?.id ? savedSearch.description : ''}
scrollToTop={scrollToTop}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import './discover_canvas.scss';

// eslint-disable-next-line import/no-default-export
export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewProps) {
const panelRef = useRef<HTMLDivElement>(null);
const { data$, refetch$, indexPattern } = useDiscoverContext();
const {
services: { uiSettings },
Expand Down Expand Up @@ -89,9 +90,15 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewPro
}, [dispatch, filteredColumns, indexPattern]);

const timeField = indexPattern?.timeFieldName ? indexPattern.timeFieldName : undefined;
const scrollToTop = () => {
if (panelRef.current) {
panelRef.current.scrollTop = 0;
}
};

return (
<EuiPanel
panelRef={panelRef}
hasBorder={false}
hasShadow={false}
color="transparent"
Expand All @@ -114,7 +121,7 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewPro
{fetchState.status === ResultStatus.READY && (
<EuiPanel hasShadow={false} paddingSize="none" className="dscCanvas_results">
<MemoizedDiscoverChartContainer {...fetchState} />
<MemoizedDiscoverTable rows={rows} />
<MemoizedDiscoverTable rows={rows} scrollToTop={scrollToTop} />
</EuiPanel>
)}
</EuiPanel>
Expand Down

0 comments on commit b62de4b

Please sign in to comment.