Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
db8673c
[ML] Change placement of annotation footer buttons
qn895 Nov 11, 2020
3d854a2
[ML] Fix performance issue with annotation/renderFocusChart on SMV
qn895 Nov 11, 2020
b5166e6
[ML] Add AnnotationUpdatesService and MlAnnotationComponent
qn895 Nov 12, 2020
528a8de
[ML] Update type definition
qn895 Nov 12, 2020
81e20c4
[ML] Add to AnnotationUpdatesService context, update tests
qn895 Nov 16, 2020
bafde0d
[ML] Update snapshots for AnnotationsTable
qn895 Nov 16, 2020
927b38d
Merge remote upstream into ml-annotations-smv-improvements
qn895 Nov 16, 2020
c4ebb5e
Merge remote-tracking branch 'upstream/master' into ml-annotations-sm…
qn895 Nov 16, 2020
d3d4ce4
Merge remote-tracking branch 'upstream/master' into ml-annotations-sm…
qn895 Nov 16, 2020
eb1da71
Merge remote-tracking branch 'upstream/master' into ml-annotations-sm…
qn895 Nov 16, 2020
6eff2c8
[ML] Delete MlAnnotationComponent
qn895 Nov 16, 2020
1365c52
[ML] Update updateBtn to grab by id
qn895 Nov 17, 2020
0cf7ad0
[ML] Rename update$, isAnnotationInitialized$
qn895 Nov 17, 2020
2165da7
[ML] Add MlAnnotationUpdatesContext.Provider, rename file
qn895 Nov 17, 2020
d2cb370
Merge upstream/main into ml-annotations-smv-improvements
qn895 Nov 17, 2020
3575d6a
Update test types
qn895 Nov 17, 2020
f179e79
Merge remote-tracking branch 'upstream/master' into ml-annotations-sm…
qn895 Nov 17, 2020
588bedd
[ML] Remove console log
qn895 Nov 18, 2020
b67515d
Merge remote-tracking branch 'upstream/master' into ml-annotations-sm…
qn895 Nov 18, 2020
9b8020b
[ML] Move annotationUpdatesService to beforeEach
qn895 Nov 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
import { CommonProps } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { distinctUntilChanged } from 'rxjs/operators';
import {
ANNOTATION_MAX_LENGTH_CHARS,
ANNOTATION_EVENT_USER,
Expand All @@ -37,6 +36,7 @@ import {
annotation$,
annotationsRefreshed,
AnnotationState,
AnnotationUpdatesService,
} from '../../../services/annotations_service';
import { AnnotationDescriptionList } from '../annotation_description_list';
import { DeleteAnnotationModal } from '../delete_annotation_modal';
Expand All @@ -48,6 +48,7 @@ import {
} from '../../../../../common/types/annotations';
import { PartitionFieldsType } from '../../../../../common/types/anomalies';
import { PARTITION_FIELDS } from '../../../../../common/constants/anomalies';
import { MlAnnotationComponent } from '../annotations_service';

interface ViewableDetector {
index: number;
Expand Down Expand Up @@ -356,16 +357,16 @@ export class AnnotationFlyoutUI extends Component<CommonProps & Props> {
</EuiFormRow>
</EuiFlyoutBody>
<EuiFlyoutFooter>
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiButtonEmpty iconType="cross" onClick={this.cancelEditingHandler} flush="left">
<EuiButtonEmpty onClick={this.cancelEditingHandler} flush="left">
<FormattedMessage
id="xpack.ml.timeSeriesExplorer.annotationFlyout.cancelButtonLabel"
defaultMessage="Cancel"
/>
</EuiButtonEmpty>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiFlexItem grow={false} style={{ marginLeft: 'auto' }}>
{isExistingAnnotation && (
<EuiButtonEmpty color="danger" onClick={this.deleteConfirmHandler}>
<FormattedMessage
Expand Down Expand Up @@ -402,18 +403,16 @@ export class AnnotationFlyoutUI extends Component<CommonProps & Props> {
}
}

export const AnnotationFlyout: FC<any> = (props) => {
const annotationProp = useObservable(
annotation$.pipe(
distinctUntilChanged((prev, curr) => {
// prevent re-rendering
return prev !== null && curr !== null;
})
)
);
interface AnnotationFlyoutContainerProps extends CommonProps, Props {
annotationUpdatesService: AnnotationUpdatesService;
}

export const AnnotationFlyoutContainer: FC<any> = (props: AnnotationFlyoutContainerProps) => {
const { annotationUpdatesService, ...restProps } = props;
const annotationProp = useObservable<AnnotationState>(annotationUpdatesService.update$());

const cancelEditingHandler = useCallback(() => {
annotation$.next(null);
annotationUpdatesService.setValue(null);
}, []);

if (annotationProp === undefined || annotationProp === null) {
Expand Down Expand Up @@ -441,7 +440,22 @@ export const AnnotationFlyout: FC<any> = (props) => {
</h2>
</EuiTitle>
</EuiFlyoutHeader>
<AnnotationFlyoutUI {...props} />
<AnnotationFlyoutUI {...restProps} />
</EuiFlyout>
);
};

export const AnnotationFlyout: FC<any> = (props) => {
return (
<MlAnnotationComponent>
{(annotationUpdatesService) => {
return (
<AnnotationFlyoutContainer
annotationUpdatesService={annotationUpdatesService}
{...props}
/>
);
}}
</MlAnnotationComponent>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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, useMemo } from 'react';
import { AnnotationUpdatesService } from '../../../services/annotations_service';

interface MlAnnotationWrapperProps {
children: (annotationUpdatesService: AnnotationUpdatesService) => React.ReactElement;
}

export const MlAnnotationComponent: FC<MlAnnotationWrapperProps> = ({ children }) => {
const service = useMemo(() => new AnnotationUpdatesService(), []);
return <>{children(service)}</>;
};
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 { MlAnnotationComponent } from './annotation_service';
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { BehaviorSubject } from 'rxjs';

import { BehaviorSubject, Observable } from 'rxjs';
import { distinctUntilChanged } from 'rxjs/operators';
import { Annotation } from '../../../common/types/annotations';

/*
Expand Down Expand Up @@ -79,3 +79,20 @@ export const annotation$ = new BehaviorSubject<AnnotationState>(null);
*/
export const annotationsRefresh$ = new BehaviorSubject(Date.now());
export const annotationsRefreshed = () => annotationsRefresh$.next(Date.now());

export class AnnotationUpdatesService {
private _annotation$: BehaviorSubject<AnnotationState> = annotation$;

public update$(): Observable<AnnotationState> {
return this._annotation$.asObservable().pipe(
distinctUntilChanged((prev, curr) => {
// prevent re-rendering
return prev !== null && curr !== null;
})
);
}

public setValue(annotation: AnnotationState) {
this._annotation$.next(annotation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React from 'react';
import { Annotation } from '../../../../../common/types/annotations';
import { CombinedJob } from '../../../../../common/types/anomaly_detection_jobs';
import { ChartTooltipService } from '../../../components/chart_tooltip';
import { AnnotationUpdatesService } from '../../../services/annotations_service';

interface Props {
selectedJob: CombinedJob;
Expand Down Expand Up @@ -45,6 +46,7 @@ interface TimeseriesChartProps {
zoomFromFocusLoaded: object;
zoomToFocusLoaded: object;
tooltipService: object;
annotationUpdatesService: AnnotationUpdatesService;
}

declare class TimeseriesChart extends React.Component<Props, any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
getSeverityWithLow,
getMultiBucketImpactLabel,
} from '../../../../../common/util/anomaly_utils';
import { annotation$ } from '../../../services/annotations_service';
import { formatValue } from '../../../formatters/format_value';
import {
LINE_CHART_ANOMALY_RADIUS,
Expand Down Expand Up @@ -1798,7 +1797,9 @@ class TimeseriesChartIntl extends Component {
}

export const TimeseriesChart = (props) => {
const annotationProp = useObservable(annotation$);
const { annotationService } = props;
const annotationProp = useObservable(annotationService.update$());

if (annotationProp === undefined) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useMlKibana, useNotifications } from '../../../contexts/kibana';
import { getBoundsRoundedToInterval } from '../../../util/time_buckets';
import { ANNOTATION_EVENT_USER } from '../../../../../common/constants/annotations';
import { getControlsForDetector } from '../../get_controls_for_detector';
import { MlAnnotationComponent } from '../../../components/annotations/annotations_service';

interface TimeSeriesChartWithTooltipsProps {
bounds: any;
Expand Down Expand Up @@ -119,22 +120,29 @@ export const TimeSeriesChartWithTooltips: FC<TimeSeriesChartWithTooltipsProps> =

return (
<div className="ml-timeseries-chart" data-test-subj="mlSingleMetricViewerChart">
<MlTooltipComponent>
{(tooltipService) => (
<TimeseriesChart
{...chartProps}
annotationData={annotationData}
bounds={bounds}
detectorIndex={detectorIndex}
renderFocusChartOnly={renderFocusChartOnly}
selectedJob={selectedJob}
showAnnotations={showAnnotations}
showForecast={showForecast}
showModelBounds={showModelBounds}
tooltipService={tooltipService}
/>
)}
</MlTooltipComponent>
<MlAnnotationComponent>
{(annotationService) => {
return (
<MlTooltipComponent>
{(tooltipService) => (
<TimeseriesChart
{...chartProps}
annotationService={annotationService}
annotationData={annotationData}
bounds={bounds}
detectorIndex={detectorIndex}
renderFocusChartOnly={renderFocusChartOnly}
selectedJob={selectedJob}
showAnnotations={showAnnotations}
showForecast={showForecast}
showModelBounds={showModelBounds}
tooltipService={tooltipService}
/>
)}
</MlTooltipComponent>
);
}}
</MlAnnotationComponent>
</div>
);
};