Chore: friday typings 5 (#73844)

* fix some event.target as stuff

* segment async story

* segmentinput story

* SegmentSelect

* fixing some tests

* more test fixes

* undo change to SilencesFilter
This commit is contained in:
Ashley Harrison 2023-08-29 09:14:15 +01:00 committed by GitHub
parent eea4adea29
commit 0853819ff7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 156 additions and 246 deletions

View File

@ -1038,29 +1038,10 @@ exports[`better eslint`] = {
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "1"]
],
"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"],
[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/SegmentInput.story.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"],
[0, 0, 0, "Do not use any type assertions.", "2"],
[0, 0, 0, "Do not use any type assertions.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Do not use any type assertions.", "5"],
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
[0, 0, 0, "Unexpected any. Specify a different type.", "7"]
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"packages/grafana-ui/src/components/Segment/SegmentSelect.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"]
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"packages/grafana-ui/src/components/Select/SelectBase.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@ -1099,17 +1080,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"]
],
"packages/grafana-ui/src/components/SingleStatShared/SingleStatBaseOptions.test.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.", "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"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"]
],
"packages/grafana-ui/src/components/SingleStatShared/SingleStatBaseOptions.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
@ -1683,9 +1653,6 @@ exports[`better eslint`] = {
"public/app/features/alerting/components/OptionElement.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/alerting/getAlertingValidationMessage.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/alerting/getAlertingValidationMessage.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
@ -1765,9 +1732,6 @@ exports[`better eslint`] = {
"public/app/features/alerting/unified/components/alert-groups/GroupBy.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/features/alerting/unified/components/alert-groups/MatcherFilter.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/features/alerting/unified/components/contact-points/ContactPoints.v2.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
@ -2332,8 +2296,7 @@ exports[`better eslint`] = {
],
"public/app/features/dashboard/utils/getPanelMenu.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Do not use any type assertions.", "2"]
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/features/dashboard/utils/panelMerge.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
@ -2543,10 +2506,7 @@ exports[`better eslint`] = {
"public/app/features/live/centrifuge/LiveDataStream.test.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.", "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.", "2"]
],
"public/app/features/live/centrifuge/LiveDataStream.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
@ -2651,13 +2611,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"],
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "1"]
],
"public/app/features/playlist/PlaylistSrv.test.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.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"]
],
"public/app/features/plugins/admin/components/GetStartedWithPlugin/GetStartedWithDataSource.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
@ -3615,9 +3568,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Do not use any type assertions.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Do not use any type assertions.", "5"],
[0, 0, 0, "Do not use any type assertions.", "6"],
[0, 0, 0, "Do not use any type assertions.", "7"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"]
[0, 0, 0, "Do not use any type assertions.", "6"]
],
"public/app/plugins/datasource/grafana/components/SearchEditor.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
@ -3658,35 +3609,7 @@ exports[`better eslint`] = {
[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"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
[0, 0, 0, "Unexpected any. Specify a different type.", "9"],
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
[0, 0, 0, "Unexpected any. Specify a different type.", "11"],
[0, 0, 0, "Unexpected any. Specify a different type.", "12"],
[0, 0, 0, "Unexpected any. Specify a different type.", "13"],
[0, 0, 0, "Unexpected any. Specify a different type.", "14"],
[0, 0, 0, "Unexpected any. Specify a different type.", "15"],
[0, 0, 0, "Unexpected any. Specify a different type.", "16"],
[0, 0, 0, "Unexpected any. Specify a different type.", "17"],
[0, 0, 0, "Unexpected any. Specify a different type.", "18"],
[0, 0, 0, "Unexpected any. Specify a different type.", "19"],
[0, 0, 0, "Unexpected any. Specify a different type.", "20"],
[0, 0, 0, "Unexpected any. Specify a different type.", "21"],
[0, 0, 0, "Unexpected any. Specify a different type.", "22"],
[0, 0, 0, "Unexpected any. Specify a different type.", "23"],
[0, 0, 0, "Unexpected any. Specify a different type.", "24"],
[0, 0, 0, "Unexpected any. Specify a different type.", "25"],
[0, 0, 0, "Unexpected any. Specify a different type.", "26"],
[0, 0, 0, "Unexpected any. Specify a different type.", "27"],
[0, 0, 0, "Unexpected any. Specify a different type.", "28"],
[0, 0, 0, "Unexpected any. Specify a different type.", "29"],
[0, 0, 0, "Unexpected any. Specify a different type.", "30"],
[0, 0, 0, "Unexpected any. Specify a different type.", "31"],
[0, 0, 0, "Unexpected any. Specify a different type.", "32"],
[0, 0, 0, "Unexpected any. Specify a different type.", "33"],
[0, 0, 0, "Unexpected any. Specify a different type.", "34"]
[0, 0, 0, "Unexpected any. Specify a different type.", "6"]
],
"public/app/plugins/datasource/graphite/datasource.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@ -3944,14 +3867,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
[0, 0, 0, "Unexpected any. Specify a different type.", "7"],
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
[0, 0, 0, "Unexpected any. Specify a different type.", "9"],
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
[0, 0, 0, "Unexpected any. Specify a different type.", "11"],
[0, 0, 0, "Unexpected any. Specify a different type.", "12"],
[0, 0, 0, "Unexpected any. Specify a different type.", "13"],
[0, 0, 0, "Unexpected any. Specify a different type.", "14"],
[0, 0, 0, "Unexpected any. Specify a different type.", "15"],
[0, 0, 0, "Unexpected any. Specify a different type.", "16"]
[0, 0, 0, "Unexpected any. Specify a different type.", "9"]
],
"public/app/plugins/datasource/influxdb/specs/mocks.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
@ -4002,10 +3918,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/plugins/datasource/loki/datasource.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/plugins/datasource/loki/datasource.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
@ -4608,8 +4520,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "2"]
],
"public/app/plugins/panel/flamegraph/components/FlameGraph/dataTransform.test.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.", "0"]
],
"public/app/plugins/panel/gauge/GaugeMigrations.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
@ -4673,9 +4584,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/plugins/panel/geomap/migrations.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/plugins/panel/geomap/migrations.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
@ -4694,10 +4602,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/plugins/panel/graph/GraphMigrations.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/plugins/panel/graph/GraphMigrations.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
@ -4957,8 +4861,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/plugins/panel/graph/specs/histogram.test.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.", "0"]
],
"public/app/plugins/panel/graph/specs/series_override_ctrl.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
@ -5242,19 +5145,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "15"],
[0, 0, 0, "Unexpected any. Specify a different type.", "16"]
],
"public/app/plugins/panel/table-old/specs/renderer.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/plugins/panel/table-old/specs/transformers.test.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.", "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"]
],
"public/app/plugins/panel/table-old/transformers.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],

View File

@ -14,11 +14,10 @@ const AddButton = (
</span>
);
const toOption = (value: any) => ({ label: value, value: value });
const toOption = <T,>(value: T): SelectableValue<T> => ({ label: String(value), value: value });
const options = ['Option1', 'Option2', 'OptionWithLooongLabel', 'Option4'].map(toOption);
const loadOptions = (options: any): Promise<Array<SelectableValue<string>>> =>
new Promise((res) => setTimeout(() => res(options), 2000));
const loadOptions = <T,>(options: T): Promise<T> => new Promise((res) => setTimeout(() => res(options), 2000));
const loadOptionsErr = (): Promise<Array<SelectableValue<string>>> =>
new Promise((_, rej) => setTimeout(() => rej(Error('Could not find data')), 2000));
@ -37,7 +36,7 @@ const SegmentFrame = ({ loadOptions, children }: any) => (
);
export const ArrayOptions = () => {
const [value, setValue] = useState<any>(options[0]);
const [value, setValue] = useState(options[0]);
return (
<SegmentFrame loadOptions={() => loadOptions(options)}>
<SegmentAsync
@ -73,7 +72,10 @@ export const ArrayOptionsWithPrimitiveValue = () => {
);
};
const groupedOptions: any = [
const groupedOptions: Array<{
label: string;
options: Array<SelectableValue<string | number>>;
}> = [
{ label: 'Names', options: ['Jane', 'Tom', 'Lisa'].map(toOption) },
{ label: 'Prime', options: [2, 3, 5, 7, 11, 13].map(toOption) },
];
@ -82,7 +84,7 @@ export const GroupedArrayOptions = () => {
const [value, setValue] = useState(groupedOptions[0].options[0]);
return (
<SegmentFrame loadOptions={() => loadOptions(groupedOptions)}>
<SegmentAsync
<SegmentAsync<string | number>
value={value}
loadOptions={() => loadOptions(groupedOptions)}
onChange={(item) => {
@ -111,13 +113,15 @@ export const CustomOptionsAllowed = () => {
);
};
const CustomLabelComponent = ({ value }: any) => <div className="gf-form-label">custom({value})</div>;
const CustomLabelComponent = ({ value }: { value: unknown }) => (
<div className="gf-form-label">custom({String(value)})</div>
);
export const CustomLabel = () => {
const [value, setValue] = useState(groupedOptions[0].options[0].value);
return (
<SegmentFrame loadOptions={() => loadOptions(groupedOptions)}>
<SegmentAsync
<SegmentAsync<string | number>
Component={<CustomLabelComponent value={value} />}
loadOptions={() => loadOptions(groupedOptions)}
onChange={({ value }) => {
@ -146,7 +150,7 @@ export const CustomStateMessageHandler = () => {
return '';
};
const [value, setValue] = useState<any>(options[0]);
const [value, setValue] = useState(options[0].value);
return (
<>
<SegmentFrame loadOptions={() => loadOptions(groupedOptions)}>
@ -187,7 +191,7 @@ export const CustomStateMessageHandler = () => {
};
export const HtmlAttributes = () => {
const [value, setValue] = useState<any>(options[0]);
const [value, setValue] = useState(options[0]);
return (
<SegmentFrame loadOptions={() => loadOptions(options)}>
<SegmentAsync

View File

@ -6,20 +6,20 @@ import { SegmentInput, Icon, SegmentSection } from '@grafana/ui';
import { SegmentInputProps } from './SegmentInput';
const SegmentFrame = ({ children }: any) => (
const SegmentFrame = ({ children }: React.PropsWithChildren) => (
<>
<SegmentSection label="Segment Name">{children}</SegmentSection>
</>
);
export const BasicInput = () => {
const [value, setValue] = useState('some text');
const [value, setValue] = useState<string | number>('some text');
return (
<SegmentFrame>
<SegmentInput
value={value}
onChange={(text) => {
setValue(text as string);
setValue(text);
action('Segment value changed')(text);
}}
/>
@ -33,14 +33,14 @@ const meta: Meta<typeof SegmentInput> = {
};
export const BasicInputWithPlaceholder = () => {
const [value, setValue] = useState('');
const [value, setValue] = useState<string | number>('');
return (
<SegmentFrame>
<SegmentInput
placeholder="add text"
value={value}
onChange={(text) => {
setValue(text as string);
setValue(text);
action('Segment value changed')(text);
}}
/>
@ -49,7 +49,7 @@ export const BasicInputWithPlaceholder = () => {
};
export const BasicInputWithHtmlAttributes = () => {
const [value, setValue] = useState('some text');
const [value, setValue] = useState<string | number>('some text');
return (
<SegmentFrame>
<SegmentInput
@ -57,7 +57,7 @@ export const BasicInputWithHtmlAttributes = () => {
id="segment-input"
value={value}
onChange={(text) => {
setValue(text as string);
setValue(text);
action('Segment value changed')(text);
}}
/>
@ -65,7 +65,11 @@ export const BasicInputWithHtmlAttributes = () => {
);
};
const InputComponent = ({ initialValue }: any) => {
interface InputComponentProps {
initialValue: string | number;
}
const InputComponent = ({ initialValue }: InputComponentProps) => {
const [value, setValue] = useState(initialValue);
return (
<SegmentInput
@ -73,7 +77,7 @@ const InputComponent = ({ initialValue }: any) => {
autofocus
value={value}
onChange={(text) => {
setValue(text as string);
setValue(text);
action('Segment value changed')(text);
}}
/>
@ -81,10 +85,10 @@ const InputComponent = ({ initialValue }: any) => {
};
export const InputWithAutoFocus = () => {
const [inputComponents, setInputComponents] = useState<any>([]);
const [inputComponents, setInputComponents] = useState<Array<(props: InputComponentProps) => JSX.Element>>([]);
return (
<SegmentFrame>
{inputComponents.map((InputComponent: any, i: number) => (
{inputComponents.map((InputComponent, i) => (
<InputComponent initialValue="test" key={i} />
))}
<button

View File

@ -76,9 +76,9 @@ export function SegmentSelect<T>({
if (ref && ref.current) {
// https://github.com/JedWatson/react-select/issues/188#issuecomment-279240292
// Unfortunately there's no other way of retrieving the value (not yet) created new option
const input = ref.current.querySelector('input[id^="react-select-"]') as HTMLInputElement;
const input = ref.current.querySelector<HTMLInputElement>('input[id^="react-select-"]');
if (input && (input.value || allowEmptyValue)) {
onChange({ value: input.value as any, label: input.value });
onChange({ value: input.value as T, label: input.value });
} else {
onClickOutside();
}

View File

@ -34,10 +34,10 @@ describe('sharedSingleStatMigrationHandler', () => {
},
title: 'Usage',
type: 'bargauge',
};
} as PanelModel;
sharedSingleStatMigrationHandler(panel as any);
expect((panel as any).fieldConfig).toMatchInlineSnapshot(`
sharedSingleStatMigrationHandler(panel);
expect(panel.fieldConfig).toMatchInlineSnapshot(`
{
"defaults": {
"color": {
@ -105,11 +105,11 @@ describe('sharedSingleStatMigrationHandler', () => {
},
},
},
};
} as PanelModel;
sharedSingleStatMigrationHandler(panel as any);
sharedSingleStatMigrationHandler(panel);
expect((panel as any).fieldConfig).toMatchInlineSnapshot(`
expect(panel.fieldConfig).toMatchInlineSnapshot(`
{
"defaults": {
"mappings": undefined,
@ -141,10 +141,10 @@ describe('sharedSingleStatMigrationHandler', () => {
},
title: 'Usage',
type: 'bargauge',
};
} as PanelModel;
sharedSingleStatMigrationHandler(panel as any);
expect((panel as any).fieldConfig).toMatchInlineSnapshot(`
sharedSingleStatMigrationHandler(panel);
expect(panel.fieldConfig).toMatchInlineSnapshot(`
{
"defaults": {
"mappings": undefined,
@ -174,10 +174,10 @@ describe('sharedSingleStatMigrationHandler', () => {
},
title: 'Usage',
type: 'bargauge',
};
} as PanelModel;
sharedSingleStatMigrationHandler(panel as any);
expect((panel as any).fieldConfig.defaults.displayName).toBe('newTitle');
sharedSingleStatMigrationHandler(panel);
expect(panel.fieldConfig.defaults.displayName).toBe('newTitle');
});
it('change from angular singlestat with no enabled gauge', () => {
@ -242,8 +242,8 @@ describe('sharedSingleStatMigrationHandler', () => {
},
title: 'Usage',
type: 'bargauge',
} as unknown as PanelModel;
sharedSingleStatMigrationHandler(panel as any);
} as PanelModel;
sharedSingleStatMigrationHandler(panel);
expect(panel.fieldConfig.defaults.unit).toBe('percentunit');
expect(panel.fieldConfig.defaults.min).toBe(0);
expect(panel.fieldConfig.defaults.max).toBe(1);

View File

@ -4,6 +4,7 @@ import {
DataTransformerConfig,
DataSourceInstanceSettings,
DataSourceRef,
DataQuery,
} from '@grafana/data';
import { DataSourceSrv } from '@grafana/runtime';
@ -81,9 +82,9 @@ describe('getAlertingValidationMessage', () => {
},
reload: jest.fn(),
};
const targets: any[] = [
{ refId: 'A', query: 'some query', datasource: 'alertingDatasource' },
{ refId: 'B', query: 'some query', datasource: 'datasource' },
const targets: DataQuery[] = [
{ refId: 'A', datasource: { type: 'alertingDatasource' } },
{ refId: 'B', datasource: { type: 'datasource' } },
];
const transformations: DataTransformerConfig[] = [];

View File

@ -23,7 +23,7 @@ export const MatcherFilter = ({ className, onFilterChange, defaultQueryString }:
debounce((e: FormEvent<HTMLInputElement>) => {
logInfo(LogMessages.filterByLabel);
const target = e.target as HTMLInputElement;
const target = e.currentTarget;
onFilterChange(target.value);
}, 600),
[onFilterChange]

View File

@ -188,10 +188,12 @@ export function getPanelMenu(
iconClassName: 'info-circle',
onClick: (e: React.MouseEvent<HTMLElement>) => {
const currentTarget = e.currentTarget;
const target = e.target as HTMLElement;
const closestMenuItem = target.closest('[role="menuitem"]');
const target = e.target;
if (target === currentTarget || closestMenuItem === currentTarget) {
if (
target === currentTarget ||
(target instanceof HTMLElement && target.closest('[role="menuitem"]') === currentTarget)
) {
onInspectPanel();
}
},

View File

@ -253,7 +253,7 @@ describe('LiveDataStream', () => {
describe('happy path with a single subscriber in `append` mode', () => {
let deps: ReturnType<typeof createDeps>;
let liveDataStream: LiveDataStream<any>;
let liveDataStream: LiveDataStream;
const valuesCollection = new ValuesCollection<DataQueryResponse>();
beforeAll(() => {
@ -494,7 +494,7 @@ describe('LiveDataStream', () => {
describe('happy path with a single subscriber in `replace` mode', () => {
let deps: ReturnType<typeof createDeps>;
let liveDataStream: LiveDataStream<any>;
let liveDataStream: LiveDataStream;
const valuesCollection = new ValuesCollection<DataQueryResponse>();
beforeAll(() => {
@ -850,7 +850,7 @@ describe('LiveDataStream', () => {
describe('happy path with multiple subscribers', () => {
let deps: ReturnType<typeof createDeps>;
let liveDataStream: LiveDataStream<any>;
let liveDataStream: LiveDataStream;
const valuesCollections = {
withTimeBFilter: new ValuesCollection<DataQueryResponse>(),
withTimeAFilter: new ValuesCollection<DataQueryResponse>(),

View File

@ -1,4 +1,5 @@
// @ts-ignore
import { Store } from 'redux';
import configureMockStore from 'redux-mock-store';
import { locationService } from '@grafana/runtime';
@ -31,10 +32,9 @@ jest.mock('./api', () => ({
const mockStore = configureMockStore();
setStore(
// eslint-disable-next-line
mockStore({
location: {},
}) as any
}) as Store
);
function createPlaylistSrv(): PlaylistSrv {
@ -42,7 +42,7 @@ function createPlaylistSrv(): PlaylistSrv {
return new PlaylistSrv();
}
const mockWindowLocation = (): [jest.MockInstance<any, any>, () => void] => {
const mockWindowLocation = (): [jest.Mock, () => void] => {
const oldLocation = window.location;
const hrefMock = jest.fn();
@ -51,8 +51,7 @@ const mockWindowLocation = (): [jest.MockInstance<any, any>, () => void] => {
//@ts-ignore
delete window.location;
// eslint-disable-next-line
window.location = {} as any;
window.location = {} as Location;
// Only mocking href as that is all this test needs, but otherwise there is lots of things missing, so keep that
// in mind if this is reused.
@ -68,7 +67,7 @@ const mockWindowLocation = (): [jest.MockInstance<any, any>, () => void] => {
describe('PlaylistSrv', () => {
let srv: PlaylistSrv;
let hrefMock: jest.MockInstance<any, any>;
let hrefMock: jest.Mock;
let unmockLocation: () => void;
const initialUrl = 'http://localhost/playlist';

View File

@ -220,11 +220,11 @@ export class UnthemedQueryEditor extends PureComponent<Props, State> {
if (e.key !== 'Enter') {
return;
}
this.checkAndUpdateValue('buffer', (e.target as any).value);
this.checkAndUpdateValue('buffer', e.currentTarget.value);
};
handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {
this.checkAndUpdateValue('buffer', e.target.value);
this.checkAndUpdateValue('buffer', e.currentTarget.value);
};
renderMeasurementsQuery() {

View File

@ -3,6 +3,7 @@ import { of } from 'rxjs';
import { createFetchResponse } from 'test/helpers/createFetchResponse';
import { AbstractLabelMatcher, AbstractLabelOperator, getFrameDisplayName, dateTime } from '@grafana/data';
import { BackendSrvRequest } from '@grafana/runtime';
import { backendSrv } from 'app/core/services/backend_srv'; // will use the version in __mocks__
import { TemplateSrv } from 'app/features/templating/template_srv';
@ -120,10 +121,10 @@ describe('graphiteDatasource', () => {
};
let response: any;
let requestOptions: any;
let requestOptions: BackendSrvRequest;
beforeEach(() => {
fetchMock.mockImplementation((options: any) => {
fetchMock.mockImplementation((options) => {
requestOptions = options;
return of(
createFetchResponse([
@ -142,8 +143,8 @@ describe('graphiteDatasource', () => {
});
it('X-Dashboard and X-Panel headers to be set!', () => {
expect(requestOptions.headers['X-Dashboard-Id']).toBe(5);
expect(requestOptions.headers['X-Panel-Id']).toBe(3);
expect(requestOptions.headers?.['X-Dashboard-Id']).toBe(5);
expect(requestOptions.headers?.['X-Panel-Id']).toBe(3);
});
it('should generate the correct query', () => {
@ -226,10 +227,10 @@ describe('graphiteDatasource', () => {
];
beforeEach(async () => {
fetchMock.mockImplementation((options: any) => {
fetchMock.mockImplementation((options) => {
return of(createFetchResponse(response));
});
await ctx.ds.annotationEvents(options.range, options.targets[0]).then((data: any) => {
await ctx.ds.annotationEvents(options.range, options.targets[0]).then((data) => {
results = data;
});
});
@ -254,11 +255,11 @@ describe('graphiteDatasource', () => {
];
beforeEach(async () => {
fetchMock.mockImplementation((options: any) => {
fetchMock.mockImplementation((options) => {
return of(createFetchResponse(response));
});
await ctx.ds.annotationEvents(options.range, options.targets[0]).then((data: any) => {
await ctx.ds.annotationEvents(options.range, options.targets[0]).then((data) => {
results = data;
});
});
@ -272,10 +273,10 @@ describe('graphiteDatasource', () => {
});
it('and tags response is invalid', async () => {
fetchMock.mockImplementation((options: any) => {
fetchMock.mockImplementation((options) => {
return of(createFetchResponse('zzzzzzz'));
});
await ctx.ds.annotationEvents(options.range, options.targets[0]).then((data: any) => {
await ctx.ds.annotationEvents(options.range, options.targets[0]).then((data) => {
results = data;
});
expect(results).toEqual([]);
@ -411,86 +412,86 @@ describe('graphiteDatasource', () => {
describe('querying for template variables', () => {
let results: any;
let requestOptions: any;
let requestOptions: BackendSrvRequest;
beforeEach(() => {
fetchMock.mockImplementation((options: any) => {
fetchMock.mockImplementation((options) => {
requestOptions = options;
return of(createFetchResponse(['backend_01', 'backend_02']));
});
});
it('should generate tags query', () => {
ctx.ds.metricFindQuery('tags()').then((data: any) => {
ctx.ds.metricFindQuery('tags()').then((data) => {
results = data;
});
expect(requestOptions.url).toBe('/api/datasources/proxy/1/tags/autoComplete/tags');
expect(requestOptions.params.expr).toEqual([]);
expect(requestOptions.params?.expr).toEqual([]);
expect(results).not.toBe(null);
});
it('should generate tags query with a filter expression', () => {
ctx.ds.metricFindQuery('tags(server=backend_01)').then((data: any) => {
ctx.ds.metricFindQuery('tags(server=backend_01)').then((data) => {
results = data;
});
expect(requestOptions.url).toBe('/api/datasources/proxy/1/tags/autoComplete/tags');
expect(requestOptions.params.expr).toEqual(['server=backend_01']);
expect(requestOptions.params?.expr).toEqual(['server=backend_01']);
expect(results).not.toBe(null);
});
it('should generate tags query for an expression with whitespace after', () => {
ctx.ds.metricFindQuery('tags(server=backend_01 )').then((data: any) => {
ctx.ds.metricFindQuery('tags(server=backend_01 )').then((data) => {
results = data;
});
expect(requestOptions.url).toBe('/api/datasources/proxy/1/tags/autoComplete/tags');
expect(requestOptions.params.expr).toEqual(['server=backend_01']);
expect(requestOptions.params?.expr).toEqual(['server=backend_01']);
expect(results).not.toBe(null);
});
it('should generate tag values query for one tag', () => {
ctx.ds.metricFindQuery('tag_values(server)').then((data: any) => {
ctx.ds.metricFindQuery('tag_values(server)').then((data) => {
results = data;
});
expect(requestOptions.url).toBe('/api/datasources/proxy/1/tags/autoComplete/values');
expect(requestOptions.params.tag).toBe('server');
expect(requestOptions.params.expr).toEqual([]);
expect(requestOptions.params?.tag).toBe('server');
expect(requestOptions.params?.expr).toEqual([]);
expect(results).not.toBe(null);
});
it('should generate tag values query for a tag and expression', () => {
ctx.ds.metricFindQuery('tag_values(server,server=~backend*)').then((data: any) => {
ctx.ds.metricFindQuery('tag_values(server,server=~backend*)').then((data) => {
results = data;
});
expect(requestOptions.url).toBe('/api/datasources/proxy/1/tags/autoComplete/values');
expect(requestOptions.params.tag).toBe('server');
expect(requestOptions.params.expr).toEqual(['server=~backend*']);
expect(requestOptions.params?.tag).toBe('server');
expect(requestOptions.params?.expr).toEqual(['server=~backend*']);
expect(results).not.toBe(null);
});
it('should generate tag values query for a tag with whitespace after', () => {
ctx.ds.metricFindQuery('tag_values(server )').then((data: any) => {
ctx.ds.metricFindQuery('tag_values(server )').then((data) => {
results = data;
});
expect(requestOptions.url).toBe('/api/datasources/proxy/1/tags/autoComplete/values');
expect(requestOptions.params.tag).toBe('server');
expect(requestOptions.params.expr).toEqual([]);
expect(requestOptions.params?.tag).toBe('server');
expect(requestOptions.params?.expr).toEqual([]);
expect(results).not.toBe(null);
});
it('should generate tag values query for a tag and expression with whitespace after', () => {
ctx.ds.metricFindQuery('tag_values(server , server=~backend* )').then((data: any) => {
ctx.ds.metricFindQuery('tag_values(server , server=~backend* )').then((data) => {
results = data;
});
expect(requestOptions.url).toBe('/api/datasources/proxy/1/tags/autoComplete/values');
expect(requestOptions.params.tag).toBe('server');
expect(requestOptions.params.expr).toEqual(['server=~backend*']);
expect(requestOptions.params?.tag).toBe('server');
expect(requestOptions.params?.expr).toEqual(['server=~backend*']);
expect(results).not.toBe(null);
});
@ -513,7 +514,7 @@ describe('graphiteDatasource', () => {
});
it('should interpolate $__searchFilter with searchFilter', () => {
ctx.ds.metricFindQuery('app.$__searchFilter', { searchFilter: 'backend' }).then((data: any) => {
ctx.ds.metricFindQuery('app.$__searchFilter', { searchFilter: 'backend' }).then((data) => {
results = data;
});
@ -524,7 +525,7 @@ describe('graphiteDatasource', () => {
});
it('should interpolate $__searchFilter with default when searchFilter is missing', () => {
ctx.ds.metricFindQuery('app.$__searchFilter', {}).then((data: any) => {
ctx.ds.metricFindQuery('app.$__searchFilter', {}).then((data) => {
results = data;
});
@ -535,18 +536,18 @@ describe('graphiteDatasource', () => {
});
it('should request expanded metrics', () => {
ctx.ds.metricFindQuery('expand(*.servers.*)').then((data: any) => {
ctx.ds.metricFindQuery('expand(*.servers.*)').then((data) => {
results = data;
});
expect(requestOptions.url).toBe('/api/datasources/proxy/1/metrics/expand');
expect(requestOptions.params.query).toBe('*.servers.*');
expect(requestOptions.params?.query).toBe('*.servers.*');
expect(results).not.toBe(null);
});
it('should fetch from /metrics/find endpoint when queryType is default or query is string', async () => {
const stringQuery = 'query';
ctx.ds.metricFindQuery(stringQuery).then((data: any) => {
ctx.ds.metricFindQuery(stringQuery).then((data) => {
results = data;
});
expect(requestOptions.url).toBe('/api/datasources/proxy/1/metrics/find');
@ -564,7 +565,7 @@ describe('graphiteDatasource', () => {
});
it('should fetch from /render endpoint when queryType is value', async () => {
fetchMock.mockImplementation((options: any) => {
fetchMock.mockImplementation((options) => {
requestOptions = options;
return of(
createFetchResponse([
@ -591,7 +592,7 @@ describe('graphiteDatasource', () => {
});
it('should return values of a query when queryType is GraphiteQueryType.Value', async () => {
fetchMock.mockImplementation((options: any) => {
fetchMock.mockImplementation((options) => {
requestOptions = options;
return of(
createFetchResponse([
@ -621,7 +622,7 @@ describe('graphiteDatasource', () => {
});
it('should return metric names when queryType is GraphiteQueryType.MetricName', async () => {
fetchMock.mockImplementation((options: any) => {
fetchMock.mockImplementation((options) => {
requestOptions = options;
return of(
createFetchResponse([
@ -731,10 +732,9 @@ describe('graphiteDatasource', () => {
});
});
function accessScenario(name: string, url: string, fn: any) {
function accessScenario(name: string, url: string, fn: ({ headers }: { headers: Record<string, unknown> }) => void) {
describe('access scenario ' + name, () => {
const ctx: any = {
// @ts-ignore
const ctx = {
templateSrv: new TemplateSrv(),
instanceSettings: { url: 'url', name: 'graphiteProd', jsonData: {} },
};
@ -756,12 +756,12 @@ function accessScenario(name: string, url: string, fn: any) {
});
}
accessScenario('with proxy access', '/api/datasources/proxy/1', (httpOptions: any) => {
accessScenario('with proxy access', '/api/datasources/proxy/1', (httpOptions) => {
expect(httpOptions.headers['X-Dashboard-Id']).toBe(1);
expect(httpOptions.headers['X-Panel-Id']).toBe(2);
});
accessScenario('with direct access', 'http://localhost:8080', (httpOptions: any) => {
accessScenario('with direct access', 'http://localhost:8080', (httpOptions) => {
expect(httpOptions.headers['X-Dashboard-Id']).toBe(undefined);
expect(httpOptions.headers['X-Panel-Id']).toBe(undefined);
});

View File

@ -8,7 +8,7 @@ import { backendSrv } from 'app/core/services/backend_srv'; // will use the vers
import { BROWSER_MODE_DISABLED_MESSAGE } from '../constants';
import InfluxDatasource from '../datasource';
import { InfluxVersion } from '../types';
import { InfluxQuery, InfluxVersion } from '../types';
//@ts-ignore
const templateSrv = new TemplateSrvStub();
@ -34,18 +34,21 @@ describe('InfluxDataSource', () => {
describe('When issuing metricFindQuery', () => {
const query = 'SELECT max(value) FROM measurement WHERE $timeFilter';
const queryOptions: any = {
const queryOptions = {
range: {
from: '2018-01-01T00:00:00Z',
to: '2018-01-02T00:00:00Z',
},
};
let requestQuery: any, requestMethod: any, requestData: any, response: any;
let requestQuery: any;
let requestMethod: string | undefined;
let requestData: any;
let response: any;
beforeEach(async () => {
fetchMock.mockImplementation((req: any) => {
fetchMock.mockImplementation((req) => {
requestMethod = req.method;
requestQuery = req.params.q;
requestQuery = req.params?.q;
requestData = req.data;
return of({
data: {
@ -160,11 +163,14 @@ describe('InfluxDataSource', () => {
describe('When issuing metricFindQuery', () => {
const query = 'SELECT max(value) FROM measurement';
const queryOptions: any = {};
let requestMethod: any, requestQueryParameter: any, queryEncoded: any, requestQuery: any;
const queryOptions = {};
let requestMethod: string | undefined;
let requestQueryParameter: Record<string, any> | undefined;
let queryEncoded: any;
let requestQuery: any;
beforeEach(async () => {
fetchMock.mockImplementation((req: any) => {
fetchMock.mockImplementation((req) => {
requestMethod = req.method;
requestQueryParameter = req.params;
requestQuery = req.data;
@ -280,7 +286,7 @@ describe('InfluxDataSource', () => {
adhocFilters,
};
function influxChecks(query: any) {
function influxChecks(query: InfluxQuery) {
expect(templateSrv.replace).toBeCalledTimes(10);
expect(query.alias).toBe(text);
expect(query.measurement).toBe(textWithFormatRegex);
@ -291,7 +297,7 @@ describe('InfluxDataSource', () => {
expect(query.tags![0].value).toBe(textWithFormatRegex);
expect(query.groupBy![0].params![0]).toBe(textWithFormatRegex);
expect(query.select![0][0].params![0]).toBe(textWithFormatRegex);
expect(query.adhocFilters[0].key).toBe(adhocFilters[0].key);
expect(query.adhocFilters?.[0].key).toBe(adhocFilters[0].key);
}
describe('when interpolating query variables for dashboard->explore', () => {

View File

@ -1233,7 +1233,7 @@ describe('LokiDatasource', () => {
});
it('keeps all labels when no labels are loaded', async () => {
ds.getResource = () => Promise.resolve({ data: [] } as any);
ds.getResource = <T>() => Promise.resolve({ data: [] } as T);
const queries = await ds.importFromAbstractQueries([
{
refId: 'A',
@ -1247,7 +1247,7 @@ describe('LokiDatasource', () => {
});
it('filters out non existing labels', async () => {
ds.getResource = () => Promise.resolve({ data: ['foo'] } as any);
ds.getResource = <T>() => Promise.resolve({ data: ['foo'] } as T);
const queries = await ds.importFromAbstractQueries([
{
refId: 'A',

View File

@ -168,8 +168,10 @@ const FlameGraph = ({
// hide context menu if outside the flame graph canvas is clicked
useEffect(() => {
const handleOnClick = (e: MouseEvent) => {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
if ((e.target as HTMLElement).parentElement?.id !== 'flameGraphCanvasContainer_clickOutsideCheck') {
if (
e.target instanceof HTMLElement &&
e.target.parentElement?.id !== 'flameGraphCanvasContainer_clickOutsideCheck'
) {
setClickedItemData(undefined);
}
};

View File

@ -148,7 +148,7 @@ function diffFlamebearerToDataFrameDTO(levels: number[][], names: string[]) {
if (i > 0) {
const prevNodesInLevel = nodeLevels[i].slice(0, -1);
const currentNodeStart =
prevNodesInLevel.reduce((acc: number, n: any) => n.offsetTotal + n.valTotal + acc, 0) + node.offsetTotal;
prevNodesInLevel.reduce((acc, n) => n.offsetTotal + n.valTotal + acc, 0) + node.offsetTotal;
const prevLevel = nodeLevels[i - 1];
let prevLevelOffset = 0;

View File

@ -12,7 +12,7 @@ describe('Worldmap Migrations', () => {
});
it('simple worldmap', () => {
const old: any = {
const old = {
angular: simpleWorldmapConfig,
};
const panel = {} as PanelModel;

View File

@ -1,4 +1,4 @@
import { PanelModel, FieldConfigSource, DataQuery } from '@grafana/data';
import { PanelModel, DataQuery } from '@grafana/data';
import { graphPanelMigrationHandler } from './GraphMigrations';
@ -119,7 +119,7 @@ describe('Graph Panel Migrations', () => {
} as Omit<PanelModel, 'fieldConfig'>;
const result = graphPanelMigrationHandler(panel as PanelModel);
const fieldSource = (panel as any).fieldConfig as FieldConfigSource;
const fieldSource = (panel as PanelModel).fieldConfig;
expect(result.dataLinks).toBeUndefined();
expect(fieldSource.defaults.links).toHaveLength(1);
@ -145,7 +145,7 @@ describe('Graph Panel Migrations', () => {
} as unknown as PanelModel;
graphPanelMigrationHandler(panel as PanelModel);
const fieldConfig = (panel as any).fieldConfig as FieldConfigSource;
const fieldConfig = (panel as PanelModel).fieldConfig;
expect(fieldConfig.defaults.links).toHaveLength(1);
});
});

View File

@ -2,7 +2,7 @@ import { convertValuesToHistogram, getSeriesValues } from '../histogram';
describe('Graph Histogam Converter', () => {
describe('Values to histogram converter', () => {
let values: any;
let values: number[];
let bucketSize = 10;
beforeEach(() => {

View File

@ -9,12 +9,12 @@ import { ColumnRender } from '../types';
const utc: TimeZone = 'utc';
const sanitize = (value: any): string => {
const sanitize = (): string => {
return 'sanitized';
};
const templateSrv = {
replace: (value: any, scopedVars: ScopedVars) => {
replace: (value: string, scopedVars: ScopedVars) => {
if (scopedVars) {
// For testing variables replacement in link
each(scopedVars, (val, key) => {

View File

@ -1,7 +1,9 @@
import TableModel from 'app/core/TableModel';
import { tableDataFormatFilterer, timeSeriesFormatFilterer, transformDataToTable, transformers } from '../transformers';
describe('when transforming time series table', () => {
let table: any;
let table: TableModel;
describe('given 2 time series', () => {
const time = new Date().getTime();
@ -419,7 +421,7 @@ describe('when transforming time series table', () => {
describe('timeSeriesFormatFilterer', () => {
describe('when called with an object that contains datapoints property', () => {
it('then it should return same object in array', () => {
const data: any = { datapoints: [] };
const data = { datapoints: [] };
const result = timeSeriesFormatFilterer(data);
@ -429,7 +431,7 @@ describe('timeSeriesFormatFilterer', () => {
describe('when called with an object that does not contain datapoints property', () => {
it('then it should return empty array', () => {
const data: any = { prop: [] };
const data = { prop: [] };
const result = timeSeriesFormatFilterer(data);
@ -440,7 +442,7 @@ describe('timeSeriesFormatFilterer', () => {
describe('when called with an array of series with both timeseries and table data', () => {
it('then it should return an array with timeseries', () => {
const time = new Date().getTime();
const data: any[] = [
const data = [
{
target: 'series1',
datapoints: [
@ -484,7 +486,7 @@ describe('timeSeriesFormatFilterer', () => {
describe('tableDataFormatFilterer', () => {
describe('when called with an object that contains columns property', () => {
it('then it should return same object in array', () => {
const data: any = { columns: [] };
const data = { columns: [] };
const result = tableDataFormatFilterer(data);
@ -494,7 +496,7 @@ describe('tableDataFormatFilterer', () => {
describe('when called with an object that does not contain columns property', () => {
it('then it should return empty array', () => {
const data: any = { prop: [] };
const data = { prop: [] };
const result = tableDataFormatFilterer(data);
@ -505,7 +507,7 @@ describe('tableDataFormatFilterer', () => {
describe('when called with an array of series with both timeseries and table data', () => {
it('then it should return an array with table data', () => {
const time = new Date().getTime();
const data: any[] = [
const data = [
{
target: 'series1',
datapoints: [