mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove grafana-ui IconName type assertions (#54623)
This commit is contained in:
parent
4735de6aa4
commit
3cf8e9c72e
@ -1294,9 +1294,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/Alert/Alert.tsx:5381": [
|
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
|
||||||
],
|
|
||||||
"packages/grafana-ui/src/components/ButtonCascader/ButtonCascader.tsx:5381": [
|
"packages/grafana-ui/src/components/ButtonCascader/ButtonCascader.tsx:5381": [
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||||
],
|
],
|
||||||
@ -1396,9 +1393,6 @@ exports[`better eslint`] = {
|
|||||||
[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/components/Forms/RadioButtonGroup/RadioButtonGroup.tsx:5381": [
|
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
|
||||||
],
|
|
||||||
"packages/grafana-ui/src/components/Graph/Graph.test.tsx:5381": [
|
"packages/grafana-ui/src/components/Graph/Graph.test.tsx:5381": [
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||||
],
|
],
|
||||||
@ -1600,8 +1594,7 @@ exports[`better eslint`] = {
|
|||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "12"]
|
[0, 0, 0, "Unexpected any. Specify a different type.", "12"]
|
||||||
],
|
],
|
||||||
"packages/grafana-ui/src/components/Select/SelectMenu.tsx:5381": [
|
"packages/grafana-ui/src/components/Select/SelectMenu.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, "Do not use any type assertions.", "1"]
|
|
||||||
],
|
],
|
||||||
"packages/grafana-ui/src/components/Select/SelectOptionGroup.tsx:5381": [
|
"packages/grafana-ui/src/components/Select/SelectOptionGroup.tsx:5381": [
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||||
@ -1798,9 +1791,6 @@ exports[`better eslint`] = {
|
|||||||
[0, 0, 0, "Do not use any type assertions.", "2"],
|
[0, 0, 0, "Do not use any type assertions.", "2"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
|
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
|
||||||
],
|
],
|
||||||
"packages/grafana-ui/src/components/ToolbarButton/ToolbarButton.tsx:5381": [
|
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
|
||||||
],
|
|
||||||
"packages/grafana-ui/src/components/Tooltip/Tooltip.tsx:5381": [
|
"packages/grafana-ui/src/components/Tooltip/Tooltip.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, "Unexpected any. Specify a different type.", "1"]
|
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
|
||||||
|
@ -25,7 +25,7 @@ export interface Props extends HTMLAttributes<HTMLDivElement> {
|
|||||||
topSpacing?: number;
|
topSpacing?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getIconFromSeverity(severity: AlertVariant): string {
|
export function getIconFromSeverity(severity: AlertVariant): IconName {
|
||||||
switch (severity) {
|
switch (severity) {
|
||||||
case 'error':
|
case 'error':
|
||||||
case 'warning':
|
case 'warning':
|
||||||
@ -34,8 +34,6 @@ export function getIconFromSeverity(severity: AlertVariant): string {
|
|||||||
return 'info-circle';
|
return 'info-circle';
|
||||||
case 'success':
|
case 'success':
|
||||||
return 'check';
|
return 'check';
|
||||||
default:
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,20 +67,23 @@ export const Alert = React.forwardRef<HTMLDivElement, Props>(
|
|||||||
{...restProps}
|
{...restProps}
|
||||||
>
|
>
|
||||||
<div className={styles.icon}>
|
<div className={styles.icon}>
|
||||||
<Icon size="xl" name={getIconFromSeverity(severity) as IconName} />
|
<Icon size="xl" name={getIconFromSeverity(severity)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.body}>
|
<div className={styles.body}>
|
||||||
<div id={titleId} className={styles.title}>
|
<div id={titleId} className={styles.title}>
|
||||||
{title}
|
{title}
|
||||||
</div>
|
</div>
|
||||||
{children && <div className={styles.content}>{children}</div>}
|
{children && <div className={styles.content}>{children}</div>}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* If onRemove is specified, giving preference to onRemove */}
|
{/* If onRemove is specified, giving preference to onRemove */}
|
||||||
{onRemove && !buttonContent && (
|
{onRemove && !buttonContent && (
|
||||||
<div className={styles.close}>
|
<div className={styles.close}>
|
||||||
<IconButton aria-label="Close alert" name="times" onClick={onRemove} size="lg" type="button" />
|
<IconButton aria-label="Close alert" name="times" onClick={onRemove} size="lg" type="button" />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{onRemove && buttonContent && (
|
{onRemove && buttonContent && (
|
||||||
<div className={styles.buttonWrapper}>
|
<div className={styles.buttonWrapper}>
|
||||||
<Button aria-label="Close alert" variant="secondary" onClick={onRemove} type="button">
|
<Button aria-label="Close alert" variant="secondary" onClick={onRemove} type="button">
|
||||||
|
@ -5,7 +5,7 @@ import React, { useCallback, useEffect, useRef } from 'react';
|
|||||||
import { GrafanaTheme2, SelectableValue } from '@grafana/data';
|
import { GrafanaTheme2, SelectableValue } from '@grafana/data';
|
||||||
|
|
||||||
import { useStyles2 } from '../../../themes';
|
import { useStyles2 } from '../../../themes';
|
||||||
import { IconName } from '../../../types/icon';
|
import { toIconName } from '../../../types/icon';
|
||||||
import { Icon } from '../../Icon/Icon';
|
import { Icon } from '../../Icon/Icon';
|
||||||
|
|
||||||
import { RadioButtonSize, RadioButton } from './RadioButton';
|
import { RadioButtonSize, RadioButton } from './RadioButton';
|
||||||
@ -71,26 +71,27 @@ export function RadioButtonGroup<T>({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cx(styles.radioGroup, fullWidth && styles.fullWidth, className)}>
|
<div className={cx(styles.radioGroup, fullWidth && styles.fullWidth, className)}>
|
||||||
{options.map((o, i) => {
|
{options.map((opt, i) => {
|
||||||
const isItemDisabled = disabledOptions && o.value && disabledOptions.includes(o.value);
|
const isItemDisabled = disabledOptions && opt.value && disabledOptions.includes(opt.value);
|
||||||
|
const icon = opt.icon ? toIconName(opt.icon) : undefined;
|
||||||
return (
|
return (
|
||||||
<RadioButton
|
<RadioButton
|
||||||
size={size}
|
size={size}
|
||||||
disabled={isItemDisabled || disabled}
|
disabled={isItemDisabled || disabled}
|
||||||
active={value === o.value}
|
active={value === opt.value}
|
||||||
key={`o.label-${i}`}
|
key={`o.label-${i}`}
|
||||||
aria-label={o.ariaLabel}
|
aria-label={opt.ariaLabel}
|
||||||
onChange={handleOnChange(o)}
|
onChange={handleOnChange(opt)}
|
||||||
onClick={handleOnClick(o)}
|
onClick={handleOnClick(opt)}
|
||||||
id={`option-${o.value}-${internalId}`}
|
id={`option-${opt.value}-${internalId}`}
|
||||||
name={groupName.current}
|
name={groupName.current}
|
||||||
description={o.description}
|
description={opt.description}
|
||||||
fullWidth={fullWidth}
|
fullWidth={fullWidth}
|
||||||
ref={value === o.value ? activeButtonRef : undefined}
|
ref={value === opt.value ? activeButtonRef : undefined}
|
||||||
>
|
>
|
||||||
{o.icon && <Icon name={o.icon as IconName} className={styles.icon} />}
|
{icon && <Icon name={icon} className={styles.icon} />}
|
||||||
{o.imgUrl && <img src={o.imgUrl} alt={o.label} className={styles.img} />}
|
{opt.imgUrl && <img src={opt.imgUrl} alt={opt.label} className={styles.img} />}
|
||||||
{o.label} {o.component ? <o.component /> : null}
|
{opt.label} {opt.component ? <opt.component /> : null}
|
||||||
</RadioButton>
|
</RadioButton>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
@ -4,9 +4,8 @@ import React, { FC, RefCallback } from 'react';
|
|||||||
import { SelectableValue } from '@grafana/data';
|
import { SelectableValue } from '@grafana/data';
|
||||||
|
|
||||||
import { useTheme2 } from '../../themes/ThemeContext';
|
import { useTheme2 } from '../../themes/ThemeContext';
|
||||||
import { IconName } from '../../types';
|
|
||||||
import { CustomScrollbar } from '../CustomScrollbar/CustomScrollbar';
|
import { CustomScrollbar } from '../CustomScrollbar/CustomScrollbar';
|
||||||
import { Icon } from '../Icon/Icon';
|
import { Icon, toIconName } from '../Icon/Icon';
|
||||||
|
|
||||||
import { getSelectStyles } from './getSelectStyles';
|
import { getSelectStyles } from './getSelectStyles';
|
||||||
|
|
||||||
@ -52,6 +51,7 @@ export const SelectMenuOptions: FC<SelectMenuOptionProps<any>> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme2();
|
const theme = useTheme2();
|
||||||
const styles = getSelectStyles(theme);
|
const styles = getSelectStyles(theme);
|
||||||
|
const icon = data.icon ? toIconName(data.icon) : undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@ -66,7 +66,7 @@ export const SelectMenuOptions: FC<SelectMenuOptionProps<any>> = ({
|
|||||||
aria-label="Select option"
|
aria-label="Select option"
|
||||||
title={data.title}
|
title={data.title}
|
||||||
>
|
>
|
||||||
{data.icon && <Icon name={data.icon as IconName} className={styles.optionIcon} />}
|
{icon && <Icon name={icon} className={styles.optionIcon} />}
|
||||||
{data.imgUrl && <img className={styles.optionImage} src={data.imgUrl} alt={data.label || data.value} />}
|
{data.imgUrl && <img className={styles.optionImage} src={data.imgUrl} alt={data.label || data.value} />}
|
||||||
<div className={styles.optionBody}>
|
<div className={styles.optionBody}>
|
||||||
<span>{renderOptionLabel ? renderOptionLabel(data) : children}</span>
|
<span>{renderOptionLabel ? renderOptionLabel(data) : children}</span>
|
||||||
|
@ -7,7 +7,7 @@ import { selectors } from '@grafana/e2e-selectors';
|
|||||||
|
|
||||||
import { styleMixins, useStyles2 } from '../../themes';
|
import { styleMixins, useStyles2 } from '../../themes';
|
||||||
import { getFocusStyles, getMouseFocusStyles } from '../../themes/mixins';
|
import { getFocusStyles, getMouseFocusStyles } from '../../themes/mixins';
|
||||||
import { IconName } from '../../types/icon';
|
import { IconName, toIconName } from '../../types/icon';
|
||||||
import { getPropertiesForVariant } from '../Button';
|
import { getPropertiesForVariant } from '../Button';
|
||||||
import { Icon } from '../Icon/Icon';
|
import { Icon } from '../Icon/Icon';
|
||||||
import { Tooltip } from '../Tooltip/Tooltip';
|
import { Tooltip } from '../Tooltip/Tooltip';
|
||||||
@ -115,8 +115,10 @@ function renderIcon(icon: IconName | React.ReactNode) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isString(icon)) {
|
const iconName = isString(icon) && toIconName(icon);
|
||||||
return <Icon name={icon as IconName} size={'lg'} />;
|
|
||||||
|
if (iconName) {
|
||||||
|
return <Icon name={iconName} size="lg" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return icon;
|
return icon;
|
||||||
|
Loading…
Reference in New Issue
Block a user