From 9b4d2a5ffa9cefbec89614d247514e528192c99e Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 18 Mar 2019 15:06:57 -0700 Subject: [PATCH] remove the error collector --- .../StatsPicker/StatsPicker.story.tsx | 21 ++++++++++++++----- .../components/StatsPicker/StatsPicker.tsx | 14 ++++++------- .../src/utils/statsCalculator.test.ts | 18 +++++++++------- .../grafana-ui/src/utils/statsCalculator.ts | 18 ++++++++++------ 4 files changed, 45 insertions(+), 26 deletions(-) diff --git a/packages/grafana-ui/src/components/StatsPicker/StatsPicker.story.tsx b/packages/grafana-ui/src/components/StatsPicker/StatsPicker.story.tsx index d37ac92f583..c8ea6eb0f50 100644 --- a/packages/grafana-ui/src/components/StatsPicker/StatsPicker.story.tsx +++ b/packages/grafana-ui/src/components/StatsPicker/StatsPicker.story.tsx @@ -6,6 +6,15 @@ import { withCenteredStory } from '../../utils/storybook/withCenteredStory'; import { StatsPicker } from './StatsPicker'; import { text, boolean } from '@storybook/addon-knobs'; +const getKnobs = () => { + return { + placeholder: text('Placeholder Text', ''), + defaultStat: text('Default Stat', ''), + allowMultiple: boolean('Allow Multiple', false), + initialStats: text('Initial Stats', ''), + }; +}; + interface State { stats: string[]; } @@ -19,12 +28,16 @@ export class WrapperWithState extends PureComponent { } toStatsArray = (txt: string): string[] => { + if (!txt) { + return []; + } return txt.split(',').map(v => v.trim()); }; componentDidUpdate(prevProps: any) { const { initialReducers } = this.props; if (initialReducers !== prevProps.initialReducers) { + console.log('Changing initial reducers'); this.setState({ stats: this.toStatsArray(initialReducers) }); } } @@ -48,13 +61,11 @@ export class WrapperWithState extends PureComponent { } } -const story = storiesOf('UI/TableReducePicker', module); +const story = storiesOf('UI/StatsPicker', module); story.addDecorator(withCenteredStory); story.add('picker', () => { - const placeholder = text('Placeholder Text', ''); - const defaultStat = text('Default Stat', ''); - const allowMultiple = boolean('Allow Multiple', false); - const initialStats = text('Initial Stats', ''); + const { placeholder, defaultStat, allowMultiple, initialStats } = getKnobs(); + return (
{ checkInput = () => { const { stats, allowMultiple, defaultStat, onChange } = this.props; - // Check that the selected reducers are all real - const notFound: string[] = []; - const current = getStatsCalculators(stats, notFound); - if (notFound.length > 0) { - console.warn('Unknown reducers', notFound, stats); - onChange(current.map(reducer => reducer.value)); + const current = getStatsCalculators(stats); + if (current.length !== stats.length) { + const found = current.map(v => v.value); + const notFound = difference(stats, found); + console.warn('Unknown stats', notFound, stats); + onChange(current.map(stat => stat.value)); } // Make sure there is only one @@ -65,7 +66,6 @@ export class StatsPicker extends PureComponent { render() { const { width, stats, allowMultiple, defaultStat, placeholder } = this.props; const current = getStatsCalculators(stats); - return (