Skip to content

Commit 6c4f705

Browse files
fix: remove old specs with changed ids (#167)
1 parent c780d98 commit 6c4f705

File tree

6 files changed

+38
-9
lines changed

6 files changed

+38
-9
lines changed

src/specs/area_series.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ export class AreaSeriesSpecComponent extends PureComponent<AreaSpecProps> {
2222
const { chartStore, children, ...config } = this.props;
2323
chartStore!.addSeriesSpec({ ...config });
2424
}
25-
componentDidUpdate() {
25+
componentDidUpdate(prevProps: AreaSpecProps) {
2626
const { chartStore, children, ...config } = this.props;
2727
chartStore!.addSeriesSpec({ ...config });
28+
if (prevProps.id !== this.props.id) {
29+
chartStore!.removeSeriesSpec(prevProps.id);
30+
}
2831
}
2932
componentWillUnmount() {
3033
const { chartStore, id } = this.props;

src/specs/bar_series.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ export class BarSeriesSpecComponent extends PureComponent<BarSpecProps> {
2222
const { chartStore, children, ...config } = this.props;
2323
chartStore!.addSeriesSpec({ ...config });
2424
}
25-
componentDidUpdate() {
25+
componentDidUpdate(prevProps: BarSpecProps) {
2626
const { chartStore, children, ...config } = this.props;
2727
chartStore!.addSeriesSpec({ ...config });
28+
if (prevProps.id !== this.props.id) {
29+
chartStore!.removeSeriesSpec(prevProps.id);
30+
}
2831
}
2932
componentWillUnmount() {
3033
const { chartStore, id } = this.props;

src/specs/line_series.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ export class LineSeriesSpecComponent extends PureComponent<LineSpecProps> {
2222
const { chartStore, children, ...config } = this.props;
2323
chartStore!.addSeriesSpec({ ...config });
2424
}
25-
componentDidUpdate() {
25+
componentDidUpdate(prevProps: LineSpecProps) {
2626
const { chartStore, children, ...config } = this.props;
2727
chartStore!.addSeriesSpec({ ...config });
28+
if (prevProps.id !== this.props.id) {
29+
chartStore!.removeSeriesSpec(prevProps.id);
30+
}
2831
}
2932
componentWillUnmount() {
3033
const { chartStore, id } = this.props;

stories/area_chart.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,21 @@ const dateFormatter = timeFormatter('HH:mm');
2020

2121
storiesOf('Area Chart', module)
2222
.add('basic', () => {
23+
const toggleSpec = boolean('toggle area spec', true);
24+
const data1 = KIBANA_METRICS.metrics.kibana_os_load[0].data;
25+
const data2 = data1.map((datum) => [datum[0], datum[1] - 1]);
26+
const data = toggleSpec ? data1 : data2;
27+
const specId = toggleSpec ? 'areas1' : 'areas2';
28+
2329
return (
2430
<Chart renderer="canvas" className={'story-chart'}>
2531
<AreaSeries
26-
id={getSpecId('areas')}
32+
id={getSpecId(specId)}
2733
xScaleType={ScaleType.Time}
2834
yScaleType={ScaleType.Linear}
2935
xAccessor={0}
3036
yAccessors={[1]}
31-
data={KIBANA_METRICS.metrics.kibana_os_load[0].data}
37+
data={data}
3238
yScaleToDataExtent={false}
3339
/>
3440
</Chart>

stories/bar_chart.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,22 @@ storiesOf('Bar Chart', module)
2626
.add('basic', () => {
2727
const darkmode = boolean('darkmode', false);
2828
const className = darkmode ? 'story-chart-dark' : 'story-chart';
29+
const toggleSpec = boolean('toggle bar spec', true);
30+
const data1 = [{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }];
31+
const data2 = data1.map((datum) => ({ ...datum, y: datum.y - 1 }));
32+
const data = toggleSpec ? data1 : data2;
33+
const specId = toggleSpec ? 'bars1' : 'bars2';
34+
2935
return (
3036
<Chart renderer="canvas" className={className}>
3137
<BarSeries
32-
id={getSpecId('bars')}
38+
id={getSpecId(specId)}
3339
name={'Simple bar series'}
3440
xScaleType={ScaleType.Linear}
3541
yScaleType={ScaleType.Linear}
3642
xAccessor="x"
3743
yAccessors={['y']}
38-
data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]}
44+
data={data}
3945
yScaleToDataExtent={false}
4046
/>
4147
</Chart>

stories/line_chart.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { boolean } from '@storybook/addon-knobs';
12
import { storiesOf } from '@storybook/react';
23
import React from 'react';
34
import {
@@ -15,19 +16,26 @@ import {
1516
} from '../src/';
1617
import { KIBANA_METRICS } from '../src/lib/series/utils/test_dataset_kibana';
1718
import { TSVB_DATASET } from '../src/lib/series/utils/test_dataset_tsvb';
19+
1820
const dateFormatter = timeFormatter(niceTimeFormatByDay(1));
1921

2022
storiesOf('Line Chart', module)
2123
.add('basic', () => {
24+
const toggleSpec = boolean('toggle line spec', true);
25+
const data1 = KIBANA_METRICS.metrics.kibana_os_load[0].data;
26+
const data2 = data1.map((datum) => [datum[0], datum[1] - 1]);
27+
const data = toggleSpec ? data1 : data2;
28+
const specId = toggleSpec ? 'lines1' : 'lines2';
29+
2230
return (
2331
<Chart renderer="canvas" className={'story-chart'}>
2432
<LineSeries
25-
id={getSpecId('lines')}
33+
id={getSpecId(specId)}
2634
xScaleType={ScaleType.Time}
2735
yScaleType={ScaleType.Linear}
2836
xAccessor={0}
2937
yAccessors={[1]}
30-
data={KIBANA_METRICS.metrics.kibana_os_load[0].data}
38+
data={data}
3139
yScaleToDataExtent={false}
3240
/>
3341
</Chart>

0 commit comments

Comments
 (0)