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] Add switch to enable model plot annotations independently (elast…
- Loading branch information
Showing
8 changed files
with
137 additions
and
9 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
65 changes: 65 additions & 0 deletions
65
...ob_details_step/components/advanced_section/components/annotations/annotations_switch.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,65 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* 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, { FC, useState, useContext, useEffect } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiCallOut, EuiSpacer, EuiSwitch } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { JobCreatorContext } from '../../../../../job_creator_context'; | ||
import { Description } from './description'; | ||
|
||
export const AnnotationsSwitch: FC = () => { | ||
const { jobCreator, jobCreatorUpdate, jobCreatorUpdated } = useContext(JobCreatorContext); | ||
const [annotationsEnabled, setAnnotationsEnabled] = useState(jobCreator.modelChangeAnnotations); | ||
const [showCallOut, setShowCallout] = useState( | ||
jobCreator.modelPlot && !jobCreator.modelChangeAnnotations | ||
); | ||
|
||
useEffect(() => { | ||
jobCreator.modelChangeAnnotations = annotationsEnabled; | ||
jobCreatorUpdate(); | ||
}, [annotationsEnabled]); | ||
|
||
useEffect(() => { | ||
setShowCallout(jobCreator.modelPlot && !annotationsEnabled); | ||
}, [jobCreatorUpdated, annotationsEnabled]); | ||
|
||
function toggleAnnotations() { | ||
setAnnotationsEnabled(!annotationsEnabled); | ||
} | ||
|
||
return ( | ||
<> | ||
<Description> | ||
<EuiSwitch | ||
name="switch" | ||
checked={annotationsEnabled} | ||
onChange={toggleAnnotations} | ||
data-test-subj="mlJobWizardSwitchAnnotations" | ||
label={i18n.translate( | ||
'xpack.ml.newJob.wizard.jobDetailsStep.advancedSection.enableModelPlotAnnotations.title', | ||
{ | ||
defaultMessage: 'Enable model change annotations', | ||
} | ||
)} | ||
/> | ||
</Description> | ||
{showCallOut && ( | ||
<EuiCallOut | ||
title={ | ||
<FormattedMessage | ||
id="xpack.ml.newJob.wizard.jobDetailsStep.advancedSection.annotationsSwitchCallout.title" | ||
defaultMessage="If you enable model plot with this configuration, we recommend you also enable annotations." | ||
/> | ||
} | ||
color="primary" | ||
iconType="help" | ||
/> | ||
)} | ||
<EuiSpacer /> | ||
</> | ||
); | ||
}; |
34 changes: 34 additions & 0 deletions
34
...nents/job_details_step/components/advanced_section/components/annotations/description.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,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* 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, { memo, FC } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { EuiDescribedFormGroup, EuiFormRow } from '@elastic/eui'; | ||
|
||
export const Description: FC = memo(({ children }) => { | ||
const title = i18n.translate( | ||
'xpack.ml.newJob.wizard.jobDetailsStep.advancedSection.enableModelPlotAnnotations.title', | ||
{ | ||
defaultMessage: 'Enable model change annotations', | ||
} | ||
); | ||
return ( | ||
<EuiDescribedFormGroup | ||
title={<h3>{title}</h3>} | ||
description={ | ||
<FormattedMessage | ||
id="xpack.ml.newJob.wizard.jobDetailsStep.advancedSection.enableModelPlotAnnotations.description" | ||
defaultMessage="Select to generate annotations when the model changes significantly. For example, when step changes, periodicity or trends are detected." | ||
/> | ||
} | ||
> | ||
<EuiFormRow label={title}> | ||
<>{children}</> | ||
</EuiFormRow> | ||
</EuiDescribedFormGroup> | ||
); | ||
}); |
7 changes: 7 additions & 0 deletions
7
...s/components/job_details_step/components/advanced_section/components/annotations/index.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,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { AnnotationsSwitch } from './annotations_switch'; |
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