Skip to content

Commit

Permalink
[Dataset Quality]Migrate telemetry tests and remove flyout code (elas…
Browse files Browse the repository at this point in the history
…tic#190584)

## Summary

closes elastic#184572

After the merge of the 1st
[PR](elastic#189532) around Flyout
migration, this PR covers the remaining bits.

- [x] Adding same telemetry to the page which was present in the flyout
- [x] Create a Locator and use it in the Table to connect the main page
with Details page
- [x] Update locator in Unified Doc Viewer
- [x] Migrate all kind of tests which were present for flyout to the
page
- [x] Remove everything which was once called Dataset Quality Flyout.
- [x] Make build green - Yellow is also acceptable

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
achyutjhunjhunwala and kibanamachine authored Aug 27, 2024
1 parent 32dd373 commit 8431033
Show file tree
Hide file tree
Showing 83 changed files with 1,176 additions and 4,291 deletions.
11 changes: 0 additions & 11 deletions packages/deeplinks/observability/locators/dataset_quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,11 @@ type TimeRangeConfig = {
refresh: RefreshInterval;
};

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
type DatasetConfig = {
rawName: string;
type: string;
name: string;
namespace: string;
};

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
type Filters = {
timeRange: TimeRangeConfig;
};

export interface DataQualityLocatorParams extends SerializableRecord {
filters?: Filters;
flyout?: {
dataset: DatasetConfig;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { SerializableRecord } from '@kbn/utility-types';

export const DATA_QUALITY_DETAILS_LOCATOR_ID = 'DATA_QUALITY_DETAILS_LOCATOR';

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
type RefreshInterval = {
pause: boolean;
value: number;
};

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
type TimeRangeConfig = {
from: string;
to: string;
refresh: RefreshInterval;
};

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
type DegradedFieldsTable = {
page?: number;
rowsPerPage?: number;
sort?: {
field: string;
direction: 'asc' | 'desc';
};
};

export interface DataQualityDetailsLocatorParams extends SerializableRecord {
dataStream: string;
timeRange?: TimeRangeConfig;
breakdownField?: string;
degradedFields?: {
table?: DegradedFieldsTable;
};
}
1 change: 1 addition & 0 deletions packages/deeplinks/observability/locators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

export * from './dataset_quality';
export * from './dataset_quality_details';
export * from './logs_explorer';
export * from './observability_logs_explorer';
export * from './observability_onboarding';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import {
import { i18n } from '@kbn/i18n';
import { orderBy } from 'lodash';
import { getRouterLinkProps } from '@kbn/router-utils';
import { DATA_QUALITY_LOCATOR_ID, DataQualityLocatorParams } from '@kbn/deeplinks-observability';
import {
DATA_QUALITY_DETAILS_LOCATOR_ID,
DataQualityDetailsLocatorParams,
} from '@kbn/deeplinks-observability';
import { BrowserUrlService } from '@kbn/share-plugin/public';
import { getUnifiedDocViewerServices } from '../../plugin';

Expand All @@ -39,13 +42,6 @@ interface DegradedField {
values: string[];
}

interface ParamsForLocator {
dataStreamType: string;
dataStreamName: string;
dataStreamNamespace: string;
rawName: string;
}

interface TableOptions {
page: {
index: number;
Expand Down Expand Up @@ -117,7 +113,7 @@ export const LogsOverviewDegradedFields = ({ rawDoc }: { rawDoc: DataTableRecord
const columns = getDegradedFieldsColumns();
const tableData = getDataFormattedForTable(ignoredFieldValues);

const paramsForLocator = getParamsForLocator(sourceFields);
const dataStream = getDataStreamRawName(sourceFields);

const accordionId = useGeneratedHtmlId({
prefix: qualityIssuesAccordionTitle,
Expand Down Expand Up @@ -194,9 +190,7 @@ export const LogsOverviewDegradedFields = ({ rawDoc }: { rawDoc: DataTableRecord
buttonContent={accordionTitle}
paddingSize="m"
initialIsOpen={false}
extraAction={
<DatasetQualityLink urlService={urlService} paramsForLocator={paramsForLocator} />
}
extraAction={<DatasetQualityLink urlService={urlService} dataStream={dataStream} />}
data-test-subj="unifiedDocViewLogsOverviewDegradedFieldsAccordion"
>
<EuiBasicTable
Expand Down Expand Up @@ -246,67 +240,53 @@ const getDataFormattedForTable = (
}));
};

const getParamsForLocator = (
const getDataStreamRawName = (
sourceFields: DataTableRecord['raw']['fields']
): ParamsForLocator | undefined => {
): string | undefined => {
if (sourceFields) {
const dataStreamTypeArr = sourceFields['data_stream.type'];
const dataStreamType = dataStreamTypeArr ? dataStreamTypeArr[0] : undefined;
const dataStreamNameArr = sourceFields['data_stream.dataset'];
const dataStreamName = dataStreamNameArr ? dataStreamNameArr[0] : undefined;
const dataStreamNamespaceArr = sourceFields['data_stream.namespace'];
const dataStreamNamespace = dataStreamNamespaceArr ? dataStreamNamespaceArr[0] : undefined;
let rawName;
let dataStream;

if (dataStreamType && dataStreamName && dataStreamNamespace) {
rawName = `${dataStreamType}-${dataStreamName}-${dataStreamNamespace}`;
dataStream = `${dataStreamType}-${dataStreamName}-${dataStreamNamespace}`;
}

if (rawName) {
return {
dataStreamType,
dataStreamName,
dataStreamNamespace,
rawName,
};
}
return dataStream;
}
};

const DatasetQualityLink = React.memo(
({
urlService,
paramsForLocator,
dataStream,
}: {
urlService: BrowserUrlService;
paramsForLocator?: ParamsForLocator;
dataStream: string | undefined;
}) => {
const locator = urlService.locators.get<DataQualityLocatorParams>(DATA_QUALITY_LOCATOR_ID);
const locatorParams: DataQualityLocatorParams = paramsForLocator
? {
flyout: {
dataset: {
rawName: paramsForLocator.rawName,
type: paramsForLocator.dataStreamType,
name: paramsForLocator.dataStreamName,
namespace: paramsForLocator.dataStreamNamespace,
},
},
}
: {};

const datasetQualityUrl = locator?.getRedirectUrl(locatorParams);
if (!dataStream) {
return null;
}
const locator = urlService.locators.get<DataQualityDetailsLocatorParams>(
DATA_QUALITY_DETAILS_LOCATOR_ID
);

const datasetQualityUrl = locator?.getRedirectUrl({ dataStream });

const navigateToDatasetQuality = () => {
locator?.navigate(locatorParams);
locator?.navigate({ dataStream });
};

const datasetQualityLinkProps = getRouterLinkProps({
href: datasetQualityUrl,
onClick: navigateToDatasetQuality,
});

return paramsForLocator ? (
return (
<EuiHeaderLink
{...datasetQualityLinkProps}
color="primary"
Expand All @@ -316,6 +296,6 @@ const DatasetQualityLink = React.memo(
>
{datasetQualityLinkTitle}
</EuiHeaderLink>
) : null;
);
}
);
6 changes: 5 additions & 1 deletion x-pack/plugins/data_quality/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ export const PLUGIN_NAME = i18n.translate('xpack.dataQuality.name', {
defaultMessage: 'Data Set Quality',
});

export { DATA_QUALITY_URL_STATE_KEY, datasetQualityUrlSchemaV1 } from './url_schema';
export {
DATA_QUALITY_URL_STATE_KEY,
datasetQualityUrlSchemaV1,
datasetQualityDetailsUrlSchemaV1,
} from './url_schema';
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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 { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/common';
import { ManagementAppLocatorParams } from '@kbn/management-plugin/common/locator';
import { LocatorPublic } from '@kbn/share-plugin/common';
import { DataQualityDetailsLocatorParams } from '@kbn/deeplinks-observability';
import { datasetQualityDetailsUrlSchemaV1, DATA_QUALITY_URL_STATE_KEY } from '../url_schema';
import { deepCompactObject } from '../utils/deep_compact_object';

interface LocatorPathConstructionParams {
locatorParams: DataQualityDetailsLocatorParams;
useHash: boolean;
managementLocator: LocatorPublic<ManagementAppLocatorParams>;
}

export const constructDatasetQualityDetailsLocatorPath = async (
params: LocatorPathConstructionParams
) => {
const { locatorParams, useHash, managementLocator } = params;

const pageState = datasetQualityDetailsUrlSchemaV1.urlSchemaRT.encode(
deepCompactObject({
v: 1,
...locatorParams,
})
);

const managementPath = await managementLocator.getLocation({
sectionId: 'data',
appId: 'data_quality/details',
});

const path = setStateToKbnUrl(
DATA_QUALITY_URL_STATE_KEY,
pageState,
{ useHash, storeInHashQuery: false },
`${managementPath.app}${managementPath.path}`
);

return {
app: '',
path,
state: {},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface LocatorPathConstructionParams {

export const constructDatasetQualityLocatorPath = async (params: LocatorPathConstructionParams) => {
const {
locatorParams: { filters, flyout },
locatorParams: { filters },
useHash,
managementLocator,
} = params;
Expand All @@ -29,7 +29,6 @@ export const constructDatasetQualityLocatorPath = async (params: LocatorPathCons
deepCompactObject({
v: 1,
filters,
flyout,
})
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 type { LocatorDefinition } from '@kbn/share-plugin/public';
import {
DataQualityDetailsLocatorParams,
DATA_QUALITY_DETAILS_LOCATOR_ID,
} from '@kbn/deeplinks-observability';
import { DataQualityLocatorDependencies } from './types';
import { constructDatasetQualityDetailsLocatorPath } from './construct_dataset_quality_details_locator_path';

export class DatasetQualityDetailsLocatorDefinition
implements LocatorDefinition<DataQualityDetailsLocatorParams>
{
public readonly id = DATA_QUALITY_DETAILS_LOCATOR_ID;

constructor(protected readonly deps: DataQualityLocatorDependencies) {}

public readonly getLocation = async (params: DataQualityDetailsLocatorParams) => {
const { useHash, managementLocator } = this.deps;
return await constructDatasetQualityDetailsLocatorPath({
useHash,
managementLocator,
locatorParams: params,
});
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
* 2.0.
*/

import type { LocatorDefinition, LocatorPublic } from '@kbn/share-plugin/public';
import type { LocatorDefinition } from '@kbn/share-plugin/public';
import { DataQualityLocatorParams, DATA_QUALITY_LOCATOR_ID } from '@kbn/deeplinks-observability';
import { DataQualityLocatorDependencies } from './types';
import { constructDatasetQualityLocatorPath } from './construct_dataset_quality_locator_path';

export type DatasetQualityLocator = LocatorPublic<DataQualityLocatorParams>;

export class DatasetQualityLocatorDefinition
implements LocatorDefinition<DataQualityLocatorParams>
{
Expand Down
7 changes: 1 addition & 6 deletions x-pack/plugins/data_quality/common/locators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
* 2.0.
*/

import { DatasetQualityLocator } from './dataset_quality_locator';

export * from './dataset_quality_locator';
export * from './dataset_quality_details_locator';
export * from './types';

export interface DataQualityLocators {
datasetQualityLocator: DatasetQualityLocator;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,7 @@
*/

import * as rt from 'io-ts';
import { degradedFieldRT, tableRT, timeRangeRT } from './common';

const integrationRT = rt.strict({
name: rt.string,
title: rt.string,
version: rt.string,
});

const datasetRT = rt.intersection([
rt.strict({
rawName: rt.string,
type: rt.string,
name: rt.string,
namespace: rt.string,
}),
rt.exact(
rt.partial({
integration: integrationRT,
title: rt.string,
})
),
]);

export const flyoutRT = rt.exact(
rt.partial({
dataset: datasetRT,
insightsTimeRange: timeRangeRT,
breakdownField: rt.string,
degradedFields: degradedFieldRT,
})
);
import { tableRT, timeRangeRT } from './common';

export const filtersRT = rt.exact(
rt.partial({
Expand All @@ -54,7 +24,6 @@ export const urlSchemaRT = rt.exact(
rt.partial({
v: rt.literal(1),
table: tableRT,
flyout: flyoutRT,
filters: filtersRT,
})
);
Expand Down
Loading

0 comments on commit 8431033

Please sign in to comment.