mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 11:44:26 -06:00
improve some grafana-ui types (#56318)
This commit is contained in:
parent
ae5e8bc53b
commit
7ac7f844f4
@ -1279,9 +1279,6 @@ exports[`better eslint`] = {
|
|||||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||||
[0, 0, 0, "Do not use any type assertions.", "1"]
|
[0, 0, 0, "Do not use any type assertions.", "1"]
|
||||||
],
|
],
|
||||||
"packages/grafana-ui/src/components/FilterInput/FilterInput.tsx:5381": [
|
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
|
||||||
],
|
|
||||||
"packages/grafana-ui/src/components/FormattedValueDisplay/FormattedValueDisplay.tsx:5381": [
|
"packages/grafana-ui/src/components/FormattedValueDisplay/FormattedValueDisplay.tsx:5381": [
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||||
],
|
],
|
||||||
@ -1887,36 +1884,16 @@ exports[`better eslint`] = {
|
|||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
[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.", "2"]
|
||||||
],
|
],
|
||||||
"packages/grafana-ui/src/utils/reactUtils.ts:5381": [
|
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
|
||||||
],
|
|
||||||
"packages/grafana-ui/src/utils/storybook/ThemedDocsContainer.tsx:5381": [
|
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
|
||||||
],
|
|
||||||
"packages/grafana-ui/src/utils/storybook/withTheme.tsx:5381": [
|
"packages/grafana-ui/src/utils/storybook/withTheme.tsx:5381": [
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
[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.", "1"]
|
||||||
],
|
],
|
||||||
"packages/grafana-ui/src/utils/table.ts:5381": [
|
"packages/grafana-ui/src/utils/table.ts:5381": [
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
|
|
||||||
],
|
],
|
||||||
"packages/grafana-ui/src/utils/useAsyncDependency.ts:5381": [
|
"packages/grafana-ui/src/utils/useAsyncDependency.ts:5381": [
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||||
],
|
],
|
||||||
"packages/grafana-ui/src/utils/useCombinedRefs.ts:5381": [
|
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
|
|
||||||
],
|
|
||||||
"packages/grafana-ui/src/utils/useDelayedSwitch.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.", "3"]
|
|
||||||
],
|
|
||||||
"packages/grafana-ui/src/utils/validate.ts:5381": [
|
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
|
||||||
],
|
|
||||||
"packages/jaeger-ui-components/src/ScrollManager.tsx:5381": [
|
"packages/jaeger-ui-components/src/ScrollManager.tsx:5381": [
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||||
|
@ -16,8 +16,8 @@ export interface Props extends Omit<HTMLProps<HTMLInputElement>, 'onChange'> {
|
|||||||
|
|
||||||
export const FilterInput = React.forwardRef<HTMLInputElement, Props>(
|
export const FilterInput = React.forwardRef<HTMLInputElement, Props>(
|
||||||
({ value, width, onChange, escapeRegex = true, ...restProps }, ref) => {
|
({ value, width, onChange, escapeRegex = true, ...restProps }, ref) => {
|
||||||
const innerRef = React.useRef<HTMLInputElement>(null);
|
const innerRef = React.useRef<HTMLInputElement | null>(null);
|
||||||
const combinedRef = useCombinedRefs(ref, innerRef) as React.Ref<HTMLInputElement>;
|
const combinedRef = useCombinedRefs<HTMLInputElement>(ref, innerRef);
|
||||||
|
|
||||||
const suffix =
|
const suffix =
|
||||||
value !== '' ? (
|
value !== '' ? (
|
||||||
|
@ -24,7 +24,7 @@ export function getChildId(children: ReactElement): string | undefined {
|
|||||||
* @param itemToRender
|
* @param itemToRender
|
||||||
* @param props props to be passed to the function if item provided as such
|
* @param props props to be passed to the function if item provided as such
|
||||||
*/
|
*/
|
||||||
export function renderOrCallToRender<TProps = any>(
|
export function renderOrCallToRender<TProps = {}>(
|
||||||
itemToRender: ((props?: TProps) => React.ReactNode) | React.ReactNode,
|
itemToRender: ((props?: TProps) => React.ReactNode) | React.ReactNode,
|
||||||
props?: TProps
|
props?: TProps
|
||||||
): React.ReactNode {
|
): React.ReactNode {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
// This is a temporary workaround to allow theme switching storybook docs
|
// This is a temporary workaround to allow theme switching storybook docs
|
||||||
// see https://github.com/storybookjs/storybook/issues/10523 for further details
|
// see https://github.com/storybookjs/storybook/issues/10523 for further details
|
||||||
import { DocsContainer } from '@storybook/addon-docs';
|
import { DocsContainer, DocsContextProps } from '@storybook/addon-docs';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useDarkMode } from 'storybook-dark-mode';
|
import { useDarkMode } from 'storybook-dark-mode';
|
||||||
|
|
||||||
import { GrafanaLight, GrafanaDark } from '../../../.storybook/storybookTheme';
|
import { GrafanaLight, GrafanaDark } from '../../../.storybook/storybookTheme';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
context: any;
|
context: DocsContextProps;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ThemedDocsContainer: React.FC<Props> = ({ children, context }) => {
|
export const ThemedDocsContainer: React.FC<Props> = ({ children, context }) => {
|
||||||
|
@ -6,7 +6,7 @@ import { Field, LinkModel } from '@grafana/data';
|
|||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export const getCellLinks = (field: Field, row: Row<any>) => {
|
export const getCellLinks = (field: Field, row: Row<any>) => {
|
||||||
let links: Array<LinkModel<any>> | undefined;
|
let links: Array<LinkModel<unknown>> | undefined;
|
||||||
if (field.getLinks) {
|
if (field.getLinks) {
|
||||||
links = field.getLinks({
|
links = field.getLinks({
|
||||||
valueRowIndex: row.index,
|
valueRowIndex: row.index,
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
export function useCombinedRefs<T>(...refs: any) {
|
export function useCombinedRefs<T>(
|
||||||
const targetRef = React.useRef<T>(null);
|
...refs: Array<React.MutableRefObject<T | null> | React.ForwardedRef<T | null> | ((instance: T | null) => void)>
|
||||||
|
) {
|
||||||
|
const targetRef = React.useRef<T | null>(null);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
refs.forEach((ref: any) => {
|
refs.forEach((ref) => {
|
||||||
if (!ref) {
|
if (!ref) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -22,13 +22,13 @@ export function useDelayedSwitch(value: boolean, options: DelayOptions = {}): bo
|
|||||||
const onStartTime = useRef<Date | undefined>();
|
const onStartTime = useRef<Date | undefined>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let timeout: number | undefined;
|
let timeout: ReturnType<typeof setTimeout> | undefined;
|
||||||
if (value) {
|
if (value) {
|
||||||
// If toggling to "on" state we always setTimeout no matter how long we have been "off".
|
// If toggling to "on" state we always setTimeout no matter how long we have been "off".
|
||||||
timeout = setTimeout(() => {
|
timeout = setTimeout(() => {
|
||||||
onStartTime.current = new Date();
|
onStartTime.current = new Date();
|
||||||
setDelayedValue(value);
|
setDelayedValue(value);
|
||||||
}, delay) as any;
|
}, delay);
|
||||||
} else {
|
} else {
|
||||||
// If toggling to "off" state we check how much time we were already "on".
|
// If toggling to "off" state we check how much time we were already "on".
|
||||||
const timeSpent = onStartTime.current ? Date.now() - onStartTime.current.valueOf() : 0;
|
const timeSpent = onStartTime.current ? Date.now() - onStartTime.current.valueOf() : 0;
|
||||||
@ -40,7 +40,7 @@ export function useDelayedSwitch(value: boolean, options: DelayOptions = {}): bo
|
|||||||
// We already spent enough time "on" so change right away.
|
// We already spent enough time "on" so change right away.
|
||||||
turnOff();
|
turnOff();
|
||||||
} else {
|
} else {
|
||||||
timeout = setTimeout(turnOff, duration - timeSpent) as any;
|
timeout = setTimeout(turnOff, duration - timeSpent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return () => {
|
return () => {
|
||||||
|
@ -7,12 +7,12 @@ export enum EventsWithValidation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const validate = (value: string, validationRules: ValidationRule[]) => {
|
export const validate = (value: string, validationRules: ValidationRule[]) => {
|
||||||
const errors = validationRules.reduce((acc, currRule) => {
|
const errors = validationRules.reduce<string[]>((acc, currRule) => {
|
||||||
if (!currRule.rule(value)) {
|
if (!currRule.rule(value)) {
|
||||||
return acc.concat(currRule.errorMessage);
|
return acc.concat(currRule.errorMessage);
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, [] as string[]);
|
}, []);
|
||||||
return errors.length > 0 ? errors : null;
|
return errors.length > 0 ? errors : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user