From 1d3ab6989d1e42d0a85ffe1f7f3db316fcd011ea Mon Sep 17 00:00:00 2001 From: Yngrid Coello Date: Tue, 1 Oct 2024 13:36:54 +0200 Subject: [PATCH] [Dataset quality] Keeping timeframe selected when navigating to dataset details (#194263) https://github.com/user-attachments/assets/1042bc36-29df-4833-be53-96ee142a4d6a --- .../dataset_quality/table/columns.tsx | 6 +- .../dataset_quality_details_link.test.tsx | 70 +++++++++++++++++++ .../table/dataset_quality_details_link.tsx | 13 ++-- 3 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/table/dataset_quality_details_link.test.tsx diff --git a/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/table/columns.tsx b/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/table/columns.tsx index 68ec09897f7c2..99fdc25382bf2 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/table/columns.tsx +++ b/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/table/columns.tsx @@ -186,7 +186,11 @@ export const getDatasetQualityTableColumns = ({ const { integration, name, rawName } = dataStreamStat; return ( - + diff --git a/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/table/dataset_quality_details_link.test.tsx b/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/table/dataset_quality_details_link.test.tsx new file mode 100644 index 0000000000000..ca9dc9764e4b4 --- /dev/null +++ b/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/table/dataset_quality_details_link.test.tsx @@ -0,0 +1,70 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { DATA_QUALITY_DETAILS_LOCATOR_ID } from '@kbn/deeplinks-observability'; +import { BrowserUrlService } from '@kbn/share-plugin/public'; +import { shallow } from 'enzyme'; +import React from 'react'; +import { DatasetQualityDetailsLink } from './dataset_quality_details_link'; + +const createMockLocator = (id: string) => ({ + navigate: jest.fn(), + getRedirectUrl: jest.fn().mockReturnValue(id), +}); + +describe('DatasetQualityDetailsLink', () => { + const mockDataQualityDetailsLocator = createMockLocator(DATA_QUALITY_DETAILS_LOCATOR_ID); + + const urlServiceMock = { + locators: { + get: jest.fn((id) => { + switch (id) { + case DATA_QUALITY_DETAILS_LOCATOR_ID: + return mockDataQualityDetailsLocator; + default: + throw new Error(`Unknown locator id: ${id}`); + } + }), + }, + } as any as BrowserUrlService; + + const dataStream = { + title: 'My data stream', + rawName: 'logs-my.data.stream-default', + }; + + const timeRange = { + from: 'now-7d/d', + refresh: { + pause: true, + value: 60000, + }, + to: 'now', + }; + + afterEach(() => { + jest.clearAllMocks(); + }); + + it('renders a link to dataset quality details', () => { + const wrapper = shallow( + + {dataStream.title} + + ); + + expect(mockDataQualityDetailsLocator.getRedirectUrl).toHaveBeenCalledWith({ + dataStream: dataStream.rawName, + timeRange, + }); + expect(wrapper.prop('href')).toBe(DATA_QUALITY_DETAILS_LOCATOR_ID); + }); +}); diff --git a/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/table/dataset_quality_details_link.tsx b/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/table/dataset_quality_details_link.tsx index ac73f269d9f5a..ec6c34ce1a772 100644 --- a/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/table/dataset_quality_details_link.tsx +++ b/x-pack/plugins/observability_solution/dataset_quality/public/components/dataset_quality/table/dataset_quality_details_link.tsx @@ -5,31 +5,34 @@ * 2.0. */ -import React from 'react'; -import { BrowserUrlService } from '@kbn/share-plugin/public'; +import { EuiHeaderLink } from '@elastic/eui'; import { DATA_QUALITY_DETAILS_LOCATOR_ID, DataQualityDetailsLocatorParams, } from '@kbn/deeplinks-observability'; import { getRouterLinkProps } from '@kbn/router-utils'; -import { EuiHeaderLink } from '@elastic/eui'; +import { BrowserUrlService } from '@kbn/share-plugin/public'; +import React from 'react'; +import { TimeRangeConfig } from '../../../../common/types'; export const DatasetQualityDetailsLink = React.memo( ({ urlService, dataStream, + timeRange, children, }: { urlService: BrowserUrlService; dataStream: string; + timeRange: TimeRangeConfig; children: React.ReactNode; }) => { const locator = urlService.locators.get( DATA_QUALITY_DETAILS_LOCATOR_ID ); - const datasetQualityUrl = locator?.getRedirectUrl({ dataStream }); + const datasetQualityUrl = locator?.getRedirectUrl({ dataStream, timeRange }); const navigateToDatasetQuality = () => { - locator?.navigate({ dataStream }); + locator?.navigate({ dataStream, timeRange }); }; const datasetQualityLinkDetailsProps = getRouterLinkProps({