-
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 Dataset Quality Locator (#177000)
closes #170611 ## 📝 Summary This PR adds the infrastructure work for the locators needed to create the navigation link from the Logs Explorer to the Dataset Quality Page, but the links themselves are to be added with a later ticket. ## 💡For Reviewers To be abled to test this PR you can add the below code [here](https://github.com/elastic/kibana/blob/main/x-pack/plugins/observability_solution/observability_logs_explorer/public/components/logs_explorer_top_nav_menu.tsx#L150) to make the link visible in the Logs Explorer Page. `<ConnectedDatasetQualityLink /> <VerticalRule />` ## 🎥 Demo https://github.com/elastic/kibana/assets/11225826/1f3ce10a-3b8c-4027-b72d-1ed71b782fa5
- Loading branch information
1 parent
03e8e9c
commit 9a47387
Showing
13 changed files
with
283 additions
and
4 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
packages/deeplinks/observability/locators/dataset_quality.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 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 DATASET_QUALITY_LOCATOR_ID = 'DATASET_QUALITY_LOCATOR'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
type RefreshInterval = { | ||
isPaused: boolean; | ||
interval: 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 DatasetQualityLocatorParams extends SerializableRecord { | ||
filters?: Filters; | ||
} |
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
29 changes: 29 additions & 0 deletions
29
...rvability_solution/observability_logs_explorer/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,29 @@ | ||
/* | ||
* 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 { | ||
DatasetQualityLocatorParams, | ||
DATASET_QUALITY_LOCATOR_ID, | ||
} from '@kbn/deeplinks-observability/locators'; | ||
import { DatasetQualityLocatorDependencies } from './types'; | ||
import { constructDatasetQualityLocatorPath } from './utils'; | ||
|
||
export type DatasetQualityLocator = LocatorPublic<DatasetQualityLocatorParams>; | ||
|
||
export class DatasetQualityLocatorDefinition | ||
implements LocatorDefinition<DatasetQualityLocatorParams> | ||
{ | ||
public readonly id = DATASET_QUALITY_LOCATOR_ID; | ||
|
||
constructor(protected readonly deps: DatasetQualityLocatorDependencies) {} | ||
|
||
public readonly getLocation = async (params: DatasetQualityLocatorParams) => { | ||
const { useHash } = this.deps; | ||
return constructDatasetQualityLocatorPath({ useHash, 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
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
47 changes: 47 additions & 0 deletions
47
...servability_logs_explorer/common/locators/utils/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,47 @@ | ||
/* | ||
* 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 { DatasetQualityLocatorParams } from '@kbn/deeplinks-observability/locators'; | ||
import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/common'; | ||
import { OBSERVABILITY_LOGS_EXPLORER_APP_ID } from '@kbn/deeplinks-observability'; | ||
import { | ||
OBSERVABILITY_DATASET_QUALITY_URL_STATE_KEY, | ||
datasetQualityUrlSchemaV1, | ||
} from '../../url_schema'; | ||
import { deepCompactObject } from '../../utils/deep_compact_object'; | ||
|
||
interface LocatorPathConstructionParams { | ||
locatorParams: DatasetQualityLocatorParams; | ||
useHash: boolean; | ||
} | ||
|
||
export const constructDatasetQualityLocatorPath = async (params: LocatorPathConstructionParams) => { | ||
const { | ||
locatorParams: { filters }, | ||
useHash, | ||
} = params; | ||
|
||
const pageState = datasetQualityUrlSchemaV1.urlSchemaRT.encode( | ||
deepCompactObject({ | ||
v: 1, | ||
filters, | ||
}) | ||
); | ||
|
||
const path = setStateToKbnUrl( | ||
OBSERVABILITY_DATASET_QUALITY_URL_STATE_KEY, | ||
pageState, | ||
{ useHash, storeInHashQuery: false }, | ||
'/dataset-quality' | ||
); | ||
|
||
return { | ||
app: OBSERVABILITY_LOGS_EXPLORER_APP_ID, | ||
path, | ||
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 |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
*/ | ||
|
||
export * from './construct_locator_path'; | ||
export * from './construct_dataset_quality_locator_path'; |
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
102 changes: 102 additions & 0 deletions
102
...rvability_solution/observability_logs_explorer/public/components/dataset_quality_link.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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* 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 { EuiHeaderLink } from '@elastic/eui'; | ||
import { | ||
DatasetQualityLocatorParams, | ||
DATASET_QUALITY_LOCATOR_ID, | ||
} from '@kbn/deeplinks-observability/locators'; | ||
import { LogsExplorerPublicState } from '@kbn/logs-explorer-plugin/public'; | ||
import { getRouterLinkProps } from '@kbn/router-utils'; | ||
import { BrowserUrlService } from '@kbn/share-plugin/public'; | ||
import { MatchedStateFromActor } from '@kbn/xstate-utils'; | ||
import { useActor } from '@xstate/react'; | ||
import React from 'react'; | ||
import { datasetQualityLinkTitle } from '../../common/translations'; | ||
import { | ||
ObservabilityLogsExplorerService, | ||
useObservabilityLogsExplorerPageStateContext, | ||
} from '../state_machines/observability_logs_explorer/src'; | ||
import { useKibanaContextForPlugin } from '../utils/use_kibana'; | ||
|
||
export const ConnectedDatasetQualityLink = React.memo(() => { | ||
const { | ||
services: { | ||
share: { url }, | ||
}, | ||
} = useKibanaContextForPlugin(); | ||
const [pageState] = useActor(useObservabilityLogsExplorerPageStateContext()); | ||
|
||
if (pageState.matches({ initialized: 'validLogsExplorerState' })) { | ||
return <DatasetQualityLink urlService={url} pageState={pageState} />; | ||
} else { | ||
return <DatasetQualityLink urlService={url} />; | ||
} | ||
}); | ||
|
||
type InitializedPageState = MatchedStateFromActor< | ||
ObservabilityLogsExplorerService, | ||
{ initialized: 'validLogsExplorerState' } | ||
>; | ||
|
||
const constructLocatorParams = ( | ||
logsExplorerState: LogsExplorerPublicState | ||
): DatasetQualityLocatorParams => { | ||
const { time, refreshInterval } = logsExplorerState; | ||
const locatorParams: DatasetQualityLocatorParams = { | ||
filters: { | ||
timeRange: { | ||
from: time?.from || 'now-24h', | ||
to: time?.to || 'now', | ||
refresh: { | ||
isPaused: refreshInterval ? refreshInterval.pause : false, | ||
interval: refreshInterval ? refreshInterval.value : 60000, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
return locatorParams; | ||
}; | ||
|
||
export const DatasetQualityLink = React.memo( | ||
({ | ||
urlService, | ||
pageState, | ||
}: { | ||
urlService: BrowserUrlService; | ||
pageState?: InitializedPageState; | ||
}) => { | ||
const locator = urlService.locators.get<DatasetQualityLocatorParams>( | ||
DATASET_QUALITY_LOCATOR_ID | ||
); | ||
const locatorParams: DatasetQualityLocatorParams = pageState | ||
? constructLocatorParams(pageState.context.logsExplorerState) | ||
: {}; | ||
|
||
const datasetQualityUrl = locator?.useUrl(locatorParams); | ||
|
||
const navigateToDatasetQuality = () => { | ||
locator?.navigate(locatorParams); | ||
}; | ||
|
||
const datasetQualityLinkProps = getRouterLinkProps({ | ||
href: datasetQualityUrl, | ||
onClick: navigateToDatasetQuality, | ||
}); | ||
|
||
return ( | ||
<EuiHeaderLink | ||
{...datasetQualityLinkProps} | ||
color="primary" | ||
data-test-subj="logsExplorerDatasetQualityLink" | ||
> | ||
{datasetQualityLinkTitle} | ||
</EuiHeaderLink> | ||
); | ||
} | ||
); |
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