-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[ML] Persist URL state for Anomaly detection jobs using metric function #83507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3794a7e
e35b174
16d30cb
df2dc85
8c094c6
53dc467
607d788
1b10541
e3adf61
104f440
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,14 @@ | |
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
| import React from 'react'; | ||
| import React, { useCallback, useEffect } from 'react'; | ||
| import { EuiFlexItem, EuiFormRow, EuiSelect } from '@elastic/eui'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { mlJobService } from '../../../services/job_service'; | ||
| import { getFunctionDescription, isMetricDetector } from '../../get_function_description'; | ||
| import { useToastNotificationService } from '../../../services/toast_notification_service'; | ||
| import { ML_JOB_AGGREGATION } from '../../../../../common/constants/aggregation_types'; | ||
| import type { CombinedJob } from '../../../../../common/types/anomaly_detection_jobs'; | ||
|
|
||
| const plotByFunctionOptions = [ | ||
| { | ||
|
|
@@ -30,11 +35,70 @@ const plotByFunctionOptions = [ | |
| export const PlotByFunctionControls = ({ | ||
| functionDescription, | ||
| setFunctionDescription, | ||
| selectedDetectorIndex, | ||
| selectedJobId, | ||
| selectedEntities, | ||
| }: { | ||
| functionDescription: undefined | string; | ||
| setFunctionDescription: (func: string) => void; | ||
| selectedDetectorIndex: number; | ||
| selectedJobId: string; | ||
| selectedEntities: Record<string, any>; | ||
| }) => { | ||
| const toastNotificationService = useToastNotificationService(); | ||
|
|
||
| const getFunctionDescriptionToPlot = useCallback( | ||
| async ( | ||
| _selectedDetectorIndex: number, | ||
| _selectedEntities: Record<string, any>, | ||
| _selectedJobId: string, | ||
| _selectedJob: CombinedJob | ||
|
Comment on lines
+52
to
+55
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you don't need it and can access these arguments from the component scope
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think doing that will require the callback to depend on those arguments, and since they are the same as the original effect we're splitting it from, I don't see the benefits of either moving it outside of the effect or using the arguments from component scope. |
||
| ) => { | ||
| const functionToPlot = await getFunctionDescription( | ||
| { | ||
| selectedDetectorIndex: _selectedDetectorIndex, | ||
| selectedEntities: _selectedEntities, | ||
| selectedJobId: _selectedJobId, | ||
| selectedJob: _selectedJob, | ||
| }, | ||
| toastNotificationService | ||
| ); | ||
| setFunctionDescription(functionToPlot); | ||
| }, | ||
| [setFunctionDescription, toastNotificationService] | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| if (functionDescription !== undefined) { | ||
| return; | ||
| } | ||
| const selectedJob = mlJobService.getJob(selectedJobId); | ||
| if ( | ||
| // set if only entity controls are picked | ||
| selectedEntities !== undefined && | ||
| functionDescription === undefined && | ||
| isMetricDetector(selectedJob, selectedDetectorIndex) | ||
| ) { | ||
| const detector = selectedJob.analysis_config.detectors[selectedDetectorIndex]; | ||
| if (detector?.function === ML_JOB_AGGREGATION.METRIC) { | ||
| getFunctionDescriptionToPlot( | ||
| selectedDetectorIndex, | ||
| selectedEntities, | ||
| selectedJobId, | ||
| selectedJob | ||
| ); | ||
| } | ||
| } | ||
| }, [ | ||
| setFunctionDescription, | ||
| selectedDetectorIndex, | ||
| selectedEntities, | ||
| selectedJobId, | ||
| functionDescription, | ||
| ]); | ||
|
|
||
| if (functionDescription === undefined) return null; | ||
|
|
||
| return ( | ||
| <EuiFlexItem grow={false}> | ||
| <EuiFormRow | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it be a more specific type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated here 607d788
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qn895 can't find it in the commit hash you've mentioned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why Github is being weird but it's
https://github.com/elastic/kibana/pull/83507/commits/607d7880884564514d8fb34b4972bc4ab644ea75