From c5607a6dac0bf8af4d73b61a78bd6367490b8dda Mon Sep 17 00:00:00 2001 From: Nathan L Smith Date: Wed, 10 Jun 2020 17:09:49 -0500 Subject: [PATCH] [APM] Don't show annotations on charts with no data Hide the annotations plot and legend when a chart has annotations but doesn't have any values in the series. Fixes #66981. --- .../charts/CustomPlot/CustomPlot.stories.tsx | 37 +++++++++++++++++++ .../shared/charts/CustomPlot/index.js | 4 +- .../charts/CustomPlot/test/CustomPlot.test.js | 20 ++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 x-pack/plugins/apm/public/components/shared/charts/CustomPlot/CustomPlot.stories.tsx diff --git a/x-pack/plugins/apm/public/components/shared/charts/CustomPlot/CustomPlot.stories.tsx b/x-pack/plugins/apm/public/components/shared/charts/CustomPlot/CustomPlot.stories.tsx new file mode 100644 index 00000000000000..48e83763cb9df6 --- /dev/null +++ b/x-pack/plugins/apm/public/components/shared/charts/CustomPlot/CustomPlot.stories.tsx @@ -0,0 +1,37 @@ +/* + * 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 { storiesOf } from '@storybook/react'; +import React from 'react'; +// @ts-ignore +import CustomPlot from './'; + +storiesOf('shared/charts/CustomPlot', module).add( + 'with annotations but no data', + () => { + const annotations = [ + { + type: 'version', + id: '2020-06-10 04:36:31', + '@timestamp': 1591763925012, + text: '2020-06-10 04:36:31', + }, + { + type: 'version', + id: '2020-06-10 15:23:01', + '@timestamp': 1591802689233, + text: '2020-06-10 15:23:01', + }, + ]; + return ; + }, + { + info: { + source: false, + text: + "When a chart has no data but does have annotations, the annotations shouldn't show up at all.", + }, + } +); diff --git a/x-pack/plugins/apm/public/components/shared/charts/CustomPlot/index.js b/x-pack/plugins/apm/public/components/shared/charts/CustomPlot/index.js index 050cb0639ee88a..e1ffec3a8d97f5 100644 --- a/x-pack/plugins/apm/public/components/shared/charts/CustomPlot/index.js +++ b/x-pack/plugins/apm/public/components/shared/charts/CustomPlot/index.js @@ -168,7 +168,7 @@ export class InnerCustomPlot extends PureComponent { tickFormatX={this.props.tickFormatX} /> - {this.state.showAnnotations && !isEmpty(annotations) && ( + {this.state.showAnnotations && !isEmpty(annotations) && !noHits && ( { this.setState(({ showAnnotations }) => ({ diff --git a/x-pack/plugins/apm/public/components/shared/charts/CustomPlot/test/CustomPlot.test.js b/x-pack/plugins/apm/public/components/shared/charts/CustomPlot/test/CustomPlot.test.js index d906e7f5093c23..ad1d73f2b766b0 100644 --- a/x-pack/plugins/apm/public/components/shared/charts/CustomPlot/test/CustomPlot.test.js +++ b/x-pack/plugins/apm/public/components/shared/charts/CustomPlot/test/CustomPlot.test.js @@ -255,12 +255,28 @@ describe('when response has no data', () => { const onHover = jest.fn(); const onMouseLeave = jest.fn(); const onSelectionEnd = jest.fn(); + const annotations = [ + { + type: 'version', + id: '2020-06-10 04:36:31', + '@timestamp': 1591763925012, + text: '2020-06-10 04:36:31', + }, + { + type: 'version', + id: '2020-06-10 15:23:01', + '@timestamp': 1591802689233, + text: '2020-06-10 15:23:01', + }, + ]; + let wrapper; beforeEach(() => { const series = getEmptySeries(1451606400000, 1451610000000); wrapper = mount( { expect(wrapper.find('Tooltip').length).toEqual(0); }); + it('should not show annotations', () => { + expect(wrapper.find('AnnotationsPlot')).toHaveLength(0); + }); + it('should have correct markup', () => { expect(toJson(wrapper)).toMatchSnapshot(); });