Skip to content

Commit

Permalink
[Dataset quality] Keeping timeframe selected when navigating to datas…
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrdyn authored Oct 1, 2024
1 parent 5bc33cd commit 1d3ab69
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ export const getDatasetQualityTableColumns = ({
const { integration, name, rawName } = dataStreamStat;

return (
<DatasetQualityDetailsLink urlService={urlService} dataStream={rawName}>
<DatasetQualityDetailsLink
urlService={urlService}
dataStream={rawName}
timeRange={timeRange}
>
<EuiFlexGroup alignItems="center" gutterSize="s">
<EuiFlexItem grow={false}>
<IntegrationIcon integration={integration} />
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
<DatasetQualityDetailsLink
urlService={urlServiceMock}
dataStream={dataStream.rawName}
timeRange={timeRange}
>
{dataStream.title}
</DatasetQualityDetailsLink>
);

expect(mockDataQualityDetailsLocator.getRedirectUrl).toHaveBeenCalledWith({
dataStream: dataStream.rawName,
timeRange,
});
expect(wrapper.prop('href')).toBe(DATA_QUALITY_DETAILS_LOCATOR_ID);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataQualityDetailsLocatorParams>(
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({
Expand Down

0 comments on commit 1d3ab69

Please sign in to comment.