From e0229045f29dcbe56365dc797ad63ea93b44c08c Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Wed, 4 Dec 2019 13:55:23 +0100 Subject: [PATCH] UI: Use SelectableValue as Segment value (#20867) * Use SelectableValue for segment value * Update cloudwatch components to use new segment props --- .../src/components/Segment/Segment.story.tsx | 35 ++++++++++--------- .../src/components/Segment/Segment.tsx | 13 ++++--- .../components/Segment/SegmentAsync.story.tsx | 34 +++++++++--------- .../src/components/Segment/SegmentAsync.tsx | 9 ++--- .../src/components/Segment/SegmentSelect.tsx | 7 ++-- .../src/components/Segment/types.ts | 5 +-- .../cloudwatch/components/Dimensions.tsx | 12 ++++--- .../cloudwatch/components/QueryEditor.tsx | 12 +++---- .../cloudwatch/components/Stats.tsx | 7 ++-- 9 files changed, 74 insertions(+), 60 deletions(-) diff --git a/packages/grafana-ui/src/components/Segment/Segment.story.tsx b/packages/grafana-ui/src/components/Segment/Segment.story.tsx index 9de2b52933d..be31b41171e 100644 --- a/packages/grafana-ui/src/components/Segment/Segment.story.tsx +++ b/packages/grafana-ui/src/components/Segment/Segment.story.tsx @@ -18,8 +18,9 @@ const toOption = (value: any) => ({ label: value, value: value }); SegmentStories.add('Array Options', () => { const options = ['Option1', 'Option2', 'OptionWithLooongLabel', 'Option4'].map(toOption); + options[0].label = 'Option1 Label'; return ( - + {(value, updateValue) => ( <>
@@ -29,9 +30,9 @@ SegmentStories.add('Array Options', () => { ) => { - updateValue(value); - action('Segment value changed')(value); + onChange={item => { + updateValue(item); + action('Segment value changed')(item.value); }} /> { return ( - + {(value, updateValue) => ( <>
@@ -63,9 +64,9 @@ SegmentStories.add('Grouped Array Options', () => { ) => { - updateValue(value); - action('Segment value changed')(value); + onChange={item => { + updateValue(item); + action('Segment value changed')(item.value); }} /> { SegmentStories.add('With custom options allowed', () => { const options = ['Option1', 'Option2', 'OptionWithLooongLabel', 'Option4'].map(toOption); return ( - + {(value, updateValue) => ( <>
@@ -94,9 +95,9 @@ SegmentStories.add('With custom options allowed', () => { allowCustomValue value={value} options={options} - onChange={(value: SelectableValue) => { - updateValue(value); - action('Segment value changed')(value); + onChange={item => { + updateValue(item); + action('Segment value changed')(item.value); }} /> { ); }); -const CustomLabelComponent = ({ value }: any) =>
custom({value})
; +const CustomLabelComponent = ({ value: { value } }: any) =>
custom({value})
; SegmentStories.add('Custom Label Field', () => { return ( - + {(value, setValue) => ( <>
@@ -126,9 +127,9 @@ SegmentStories.add('Custom Label Field', () => { } options={groupedOptions} - onChange={(value: SelectableValue) => { - setValue(value); - action('Segment value changed')(value); + onChange={item => { + setValue(item); + action('Segment value changed')(item.value); }} /> ({ const [Label, width, expanded, setExpanded] = useExpandableLabel(false); if (!expanded) { - return