-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Dataset quality] Added dataQuality locator (#184588)
Closes #183406 ## π Summary This PR adds a basic locator to dataQuality plugin, where timeRange filters can be shared ## π₯ Demo https://github.com/elastic/kibana/assets/1313018/47dabe6f-fe89-4075-8688-1e53332cdd9a --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
863c4f3
commit 9a6dacb
Showing
14 changed files
with
364 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
x-pack/plugins/data_quality/common/locators/construct_dataset_quality_locator_path.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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 { datasetQualityUrlSchemaV1, DATA_QUALITY_URL_STATE_KEY } from '../url_schema'; | ||
import { deepCompactObject } from '../utils/deep_compact_object'; | ||
import { DataQualityLocatorParams } from './types'; | ||
|
||
interface LocatorPathConstructionParams { | ||
locatorParams: DataQualityLocatorParams; | ||
useHash: boolean; | ||
managementLocator: LocatorPublic<ManagementAppLocatorParams>; | ||
} | ||
|
||
export const constructDatasetQualityLocatorPath = async (params: LocatorPathConstructionParams) => { | ||
const { | ||
locatorParams: { filters }, | ||
useHash, | ||
managementLocator, | ||
} = params; | ||
|
||
const pageState = datasetQualityUrlSchemaV1.urlSchemaRT.encode( | ||
deepCompactObject({ | ||
v: 1, | ||
filters, | ||
}) | ||
); | ||
|
||
const managementPath = await managementLocator.getLocation({ | ||
sectionId: 'data', | ||
appId: 'data_quality', | ||
}); | ||
|
||
const path = setStateToKbnUrl( | ||
DATA_QUALITY_URL_STATE_KEY, | ||
pageState, | ||
{ useHash, storeInHashQuery: false }, | ||
`${managementPath.app}${managementPath.path}` | ||
); | ||
|
||
return { | ||
app: '', | ||
path, | ||
state: {}, | ||
}; | ||
}; |
33 changes: 33 additions & 0 deletions
33
x-pack/plugins/data_quality/common/locators/dataset_quality_locator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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, LocatorPublic } from '@kbn/share-plugin/public'; | ||
import { | ||
DataQualityLocatorDependencies, | ||
DataQualityLocatorParams, | ||
DATA_QUALITY_LOCATOR_ID, | ||
} from './types'; | ||
import { constructDatasetQualityLocatorPath } from './construct_dataset_quality_locator_path'; | ||
|
||
export type DatasetQualityLocator = LocatorPublic<DataQualityLocatorParams>; | ||
|
||
export class DatasetQualityLocatorDefinition | ||
implements LocatorDefinition<DataQualityLocatorParams> | ||
{ | ||
public readonly id = DATA_QUALITY_LOCATOR_ID; | ||
|
||
constructor(protected readonly deps: DataQualityLocatorDependencies) {} | ||
|
||
public readonly getLocation = async (params: DataQualityLocatorParams) => { | ||
const { useHash, managementLocator } = this.deps; | ||
return await constructDatasetQualityLocatorPath({ | ||
useHash, | ||
managementLocator, | ||
locatorParams: params, | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* 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 { DatasetQualityLocator } from './dataset_quality_locator'; | ||
|
||
export * from './dataset_quality_locator'; | ||
export * from './types'; | ||
|
||
export interface DataQualityLocators { | ||
datasetQualityLocator: DatasetQualityLocator; | ||
} |
77 changes: 77 additions & 0 deletions
77
x-pack/plugins/data_quality/common/locators/locators.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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 { DatasetQualityLocatorDefinition } from './dataset_quality_locator'; | ||
import { DataQualityLocatorDependencies } from './types'; | ||
|
||
const createMockLocator = (id: string, section: string) => ({ | ||
id, | ||
navigate: jest.fn(), | ||
getRedirectUrl: jest.fn(), | ||
getLocation: jest.fn().mockReturnValue({ app: id, path: `/${section}`, state: {} }), | ||
getUrl: jest.fn(), | ||
navigateSync: jest.fn(), | ||
useUrl: jest.fn(), | ||
telemetry: jest.fn(), | ||
inject: jest.fn(), | ||
extract: jest.fn(), | ||
migrations: jest.fn(), | ||
}); | ||
|
||
const setup = async () => { | ||
const dep: DataQualityLocatorDependencies = { | ||
useHash: false, | ||
managementLocator: createMockLocator('management', 'data/data_quality'), | ||
}; | ||
|
||
const datasetQualityLocator = new DatasetQualityLocatorDefinition(dep); | ||
|
||
return { | ||
datasetQualityLocator, | ||
}; | ||
}; | ||
|
||
describe('Data quality Locators', () => { | ||
const timeRange = { to: 'now', from: 'now-30m' }; | ||
|
||
describe('Dataset Quality Locator', () => { | ||
it('should create a link with correct path and no state', async () => { | ||
const { datasetQualityLocator } = await setup(); | ||
const location = await datasetQualityLocator.getLocation({}); | ||
|
||
expect(location).toMatchObject({ | ||
app: '', | ||
path: 'management/data/data_quality?pageState=(v:1)', | ||
state: {}, | ||
}); | ||
}); | ||
|
||
it('should create a link with correct timeRange', async () => { | ||
const refresh = { | ||
pause: false, | ||
value: 0, | ||
}; | ||
const locatorParams = { | ||
filters: { | ||
timeRange: { | ||
...timeRange, | ||
refresh, | ||
}, | ||
}, | ||
}; | ||
const { datasetQualityLocator } = await setup(); | ||
|
||
const location = await datasetQualityLocator.getLocation(locatorParams); | ||
|
||
expect(location).toMatchObject({ | ||
app: '', | ||
path: 'management/data/data_quality?pageState=(filters:(timeRange:(from:now-30m,refresh:(pause:!f,value:0),to:now)),v:1)', | ||
state: {}, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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 { ManagementAppLocatorParams } from '@kbn/management-plugin/common/locator'; | ||
import { LocatorPublic } from '@kbn/share-plugin/common'; | ||
import { SerializableRecord } from '@kbn/utility-types'; | ||
|
||
export const DATA_QUALITY_LOCATOR_ID = 'DATA_QUALITY_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 Filters = { | ||
timeRange: TimeRangeConfig; | ||
}; | ||
|
||
export interface DataQualityLocatorParams extends SerializableRecord { | ||
filters?: Filters; | ||
} | ||
|
||
export interface DataQualityLocatorDependencies { | ||
useHash: boolean; | ||
managementLocator: LocatorPublic<ManagementAppLocatorParams>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../../..', | ||
roots: ['<rootDir>/x-pack/plugins/data_quality'], | ||
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/x-pack/plugins/data_quality', | ||
coverageReporters: ['text', 'html'], | ||
collectCoverageFrom: ['<rootDir>/x-pack/plugins/datas_quality/{common,public}/**/*.{ts,tsx}'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
"datasetQuality", | ||
"management", | ||
"features", | ||
"share", | ||
], | ||
"optionalPlugins": [], | ||
"requiredBundles": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.