diff --git a/.betterer.results b/.betterer.results index 26340dde4ef..5253d0803ae 100644 --- a/.betterer.results +++ b/.betterer.results @@ -463,8 +463,7 @@ exports[`better eslint`] = { ], "packages/grafana-data/src/types/select.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"] + [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], "packages/grafana-data/src/types/templateVars.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -1063,16 +1062,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "1"] ], - "packages/grafana-ui/src/components/Segment/Segment.story.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"], - [0, 0, 0, "Unexpected any. Specify a different type.", "5"], - [0, 0, 0, "Unexpected any. Specify a different type.", "6"], - [0, 0, 0, "Unexpected any. Specify a different type.", "7"] - ], "packages/grafana-ui/src/components/Segment/SegmentAsync.story.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], diff --git a/packages/grafana-data/src/types/select.ts b/packages/grafana-data/src/types/select.ts index 52f5f097dc6..56ea31a3e2c 100644 --- a/packages/grafana-data/src/types/select.ts +++ b/packages/grafana-data/src/types/select.ts @@ -12,7 +12,7 @@ export interface SelectableValue { // Adds a simple native title attribute to each option. title?: string; // Optional component that will be shown together with other options. Does not get past any props. - component?: React.ComponentType; + component?: React.ComponentType; isDisabled?: boolean; [key: string]: any; } diff --git a/packages/grafana-ui/src/components/Segment/Segment.story.tsx b/packages/grafana-ui/src/components/Segment/Segment.story.tsx index 25f7624c033..c17f6729d3d 100644 --- a/packages/grafana-ui/src/components/Segment/Segment.story.tsx +++ b/packages/grafana-ui/src/components/Segment/Segment.story.tsx @@ -2,6 +2,7 @@ import { action } from '@storybook/addon-actions'; import { Meta, StoryFn } from '@storybook/react'; import React, { useState } from 'react'; +import { SelectableValue } from '@grafana/data'; import { Segment, Icon, SegmentSection } from '@grafana/ui'; import { SegmentSyncProps } from './Segment'; @@ -12,14 +13,25 @@ const AddButton = ( ); -const toOption = (value: any) => ({ label: value, value: value }); +function toOption(value: T) { + return { + label: `${value}`, + value: value, + }; +} const options = ['Option1', 'Option2', 'OptionWithLooongLabel', 'Option4'].map(toOption); const groupedOptions = [ { label: 'Names', options: ['Jane', 'Tom', 'Lisa'].map(toOption) }, { label: 'Prime', options: [2, 3, 5, 7, 11, 13].map(toOption) }, ]; -const SegmentFrame = ({ options, children }: any) => ( +const SegmentFrame = ({ + options, + children, +}: { + options: Array>; + children: React.ReactNode; +}) => ( <> {children} @@ -29,7 +41,7 @@ const SegmentFrame = ({ options, children }: any) => ( ); export const ArrayOptions = () => { - const [value, setValue] = useState(options[0]); + const [value, setValue] = useState>(options[0]); return ( = { }; export const ArrayOptionsWithPrimitiveValue = () => { - const [value, setValue] = useState('Option1'); + const [value, setValue] = useState('Option1'); return ( { }; export const ArrayOptionsWithPlaceholder = () => { - const [value, setValue] = useState(undefined); + const [value, setValue] = useState>(); return ( { }; export const GroupedArrayOptions = () => { - const [value, setValue] = useState(groupedOptions[0].options[0]); + const [value, setValue] = useState>(groupedOptions[0].options[0]); return ( - + { }; export const CustomOptionsAllowed = () => { - const [value, setValue] = useState(options[0]); + const [value, setValue] = useState>(options[0]); return ( { + onChange={(value) => { setValue(value); action('Segment value changed')(value); }} @@ -115,13 +127,15 @@ export const CustomOptionsAllowed = () => { ); }; -const CustomLabelComponent = ({ value }: any) =>
custom({value})
; +const CustomLabelComponent = ({ value }: SelectableValue) => ( +
custom({value})
+); export const CustomLabelField = () => { - const [value, setValue] = useState(groupedOptions[0].options[0].value); + const [value, setValue] = useState(groupedOptions[0].options[0].value); return ( - - + Component={} options={groupedOptions} onChange={({ value }) => { @@ -134,15 +148,15 @@ export const CustomLabelField = () => { }; export const HtmlAttributes = () => { - const [value, setValue] = useState(options[0]); + const [value, setValue] = useState>(groupedOptions[0].options[0]); return ( - + { + onChange={(value) => { setValue(value); action('Segment value changed')(value); }}