forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Anomaly Detection: Single Metric Viewer - add cases action (elas…
…tic#183423) ## Summary Related meta issue elastic#181272 This PR adds the 'Add to case' action in the Single Metric Viewer ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) --------- Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Dima Arnautov <[email protected]>
- Loading branch information
1 parent
2c7efb4
commit 2ec4ec3
Showing
19 changed files
with
562 additions
and
221 deletions.
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
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
54 changes: 54 additions & 0 deletions
54
x-pack/plugins/ml/public/cases/register_single_metric_viewer_attachment.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,54 @@ | ||
/* | ||
* 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 { CasesPublicSetup } from '@kbn/cases-plugin/public'; | ||
import { i18n } from '@kbn/i18n'; | ||
import type { CoreStart } from '@kbn/core/public'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import React from 'react'; | ||
import { PLUGIN_ICON } from '../../common/constants/app'; | ||
import { CASE_ATTACHMENT_TYPE_ID_SINGLE_METRIC_VIEWER } from '../../common/constants/cases'; | ||
import type { MlStartDependencies } from '../plugin'; | ||
import { getSingleMetricViewerComponent } from '../shared_components/single_metric_viewer'; | ||
import type { SingleMetricViewerServices } from '../embeddables/types'; | ||
import type { MlDependencies } from '../application/app'; | ||
|
||
export function registerSingleMetricViewerCasesAttachment( | ||
cases: CasesPublicSetup, | ||
coreStart: CoreStart, | ||
pluginStart: MlStartDependencies, | ||
mlServices: SingleMetricViewerServices | ||
) { | ||
const SingleMetricViewerComponent = getSingleMetricViewerComponent( | ||
coreStart, | ||
pluginStart as MlDependencies, | ||
mlServices | ||
); | ||
|
||
cases.attachmentFramework.registerPersistableState({ | ||
id: CASE_ATTACHMENT_TYPE_ID_SINGLE_METRIC_VIEWER, | ||
icon: PLUGIN_ICON, | ||
displayName: i18n.translate('xpack.ml.cases.registerSingleMetricViewer.displayName', { | ||
defaultMessage: 'Single metric viewer', | ||
}), | ||
getAttachmentViewObject: () => ({ | ||
event: ( | ||
<FormattedMessage | ||
id="xpack.ml.cases.singleMetricViewer.embeddableAddedEvent" | ||
defaultMessage="added single metric viewer" | ||
/> | ||
), | ||
timelineAvatar: PLUGIN_ICON, | ||
children: React.lazy(async () => { | ||
const { initComponent } = await import('./single_metric_viewer_attachment'); | ||
return { | ||
default: initComponent(pluginStart.fieldFormats, SingleMetricViewerComponent), | ||
}; | ||
}), | ||
}), | ||
}); | ||
} |
94 changes: 94 additions & 0 deletions
94
x-pack/plugins/ml/public/cases/single_metric_viewer_attachment.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,94 @@ | ||
/* | ||
* 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 { EuiDescriptionList } from '@elastic/eui'; | ||
import type { PersistableStateAttachmentViewProps } from '@kbn/cases-plugin/public/client/attachment_framework/types'; | ||
import moment from 'moment'; | ||
import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public'; | ||
import { FIELD_FORMAT_IDS } from '@kbn/field-formats-plugin/common'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import deepEqual from 'fast-deep-equal'; | ||
import { memoize } from 'lodash'; | ||
import React from 'react'; | ||
import type { SingleMetricViewerEmbeddableState } from '../embeddables/types'; | ||
import type { SingleMetricViewerSharedComponent } from '../shared_components/single_metric_viewer'; | ||
|
||
export const initComponent = memoize( | ||
( | ||
fieldFormats: FieldFormatsStart, | ||
SingleMetricViewerComponent: SingleMetricViewerSharedComponent | ||
) => { | ||
return React.memo( | ||
(props: PersistableStateAttachmentViewProps) => { | ||
const { persistableStateAttachmentState, caseData } = props; | ||
|
||
const inputProps = | ||
persistableStateAttachmentState as unknown as SingleMetricViewerEmbeddableState; | ||
|
||
const dataFormatter = fieldFormats.deserialize({ | ||
id: FIELD_FORMAT_IDS.DATE, | ||
}); | ||
|
||
const listItems = [ | ||
{ | ||
title: ( | ||
<FormattedMessage | ||
id="xpack.ml.cases.singleMetricViewer.description.jobIdLabel" | ||
defaultMessage="Job ID" | ||
/> | ||
), | ||
description: inputProps.jobIds.join(', '), | ||
}, | ||
{ | ||
title: ( | ||
<FormattedMessage | ||
id="xpack.ml.cases.singleMetricViewer.description.timeRangeLabel" | ||
defaultMessage="Time range" | ||
/> | ||
), | ||
description: `${dataFormatter.convert( | ||
inputProps.timeRange!.from | ||
)} - ${dataFormatter.convert(inputProps.timeRange!.to)}`, | ||
}, | ||
]; | ||
|
||
if (typeof inputProps.query?.query === 'string' && inputProps.query?.query !== '') { | ||
listItems.push({ | ||
title: ( | ||
<FormattedMessage | ||
id="xpack.ml.cases.singleMetricViewer.description.queryLabel" | ||
defaultMessage="Query" | ||
/> | ||
), | ||
description: inputProps.query?.query, | ||
}); | ||
} | ||
|
||
const { jobIds, timeRange, ...rest } = inputProps; | ||
const selectedJobId = jobIds[0]; | ||
|
||
return ( | ||
<> | ||
<EuiDescriptionList compressed type={'inline'} listItems={listItems} /> | ||
<SingleMetricViewerComponent | ||
bounds={{ min: moment(timeRange!.from), max: moment(timeRange!.to) }} | ||
lastRefresh={Date.now()} | ||
selectedJobId={selectedJobId} | ||
uuid={caseData.id} | ||
{...rest} | ||
/> | ||
</> | ||
); | ||
}, | ||
(prevProps, nextProps) => | ||
deepEqual( | ||
prevProps.persistableStateAttachmentState, | ||
nextProps.persistableStateAttachmentState | ||
) | ||
); | ||
} | ||
); |
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.