Skip to content
Snippets Groups Projects
Unverified Commit e9a42ba7 authored by Douglas Fabris's avatar Douglas Fabris Committed by GitHub
Browse files

chore: Reduce complexity to infer IconName type (#29881)

parent e6b9a72d
No related branches found
No related tags found
No related merge requests found
Showing
with 48 additions and 48 deletions
import type { Icon } from '@rocket.chat/fuselage';
import type { TranslationKey } from '@rocket.chat/ui-contexts'; import type { TranslationKey } from '@rocket.chat/ui-contexts';
import type { ComponentProps } from 'react'; import type { Keys as IconName } from '@rocket.chat/icons';
import { settings } from '../../../settings/client'; import { settings } from '../../../settings/client';
export type FormattingButton = export type FormattingButton =
| { | {
label: TranslationKey; label: TranslationKey;
icon: ComponentProps<typeof Icon>['name']; icon: IconName;
pattern: string; pattern: string;
// text?: () => string | undefined; // text?: () => string | undefined;
command?: string; command?: string;
......
import type { IUIActionButton, IUActionButtonWhen } from '@rocket.chat/apps-engine/definition/ui/IUIActionButtonDescriptor'; import type { IUIActionButton, IUActionButtonWhen } from '@rocket.chat/apps-engine/definition/ui/IUIActionButtonDescriptor';
import type { UserStatus } from '@rocket.chat/core-typings'; import type { UserStatus } from '@rocket.chat/core-typings';
import type { TranslationKey, LocationPathname } from '@rocket.chat/ui-contexts'; import type { TranslationKey, LocationPathname } from '@rocket.chat/ui-contexts';
import type { Icon } from '@rocket.chat/fuselage'; import type { Keys as IconName } from '@rocket.chat/icons';
import type { ComponentProps } from 'react';
import { sdk } from '../../../utils/client/lib/SDKClient'; import { sdk } from '../../../utils/client/lib/SDKClient';
...@@ -18,7 +17,7 @@ export interface IAppAccountBoxItem extends IUIActionButton { ...@@ -18,7 +17,7 @@ export interface IAppAccountBoxItem extends IUIActionButton {
export type AccountBoxItem = { export type AccountBoxItem = {
name: TranslationKey; name: TranslationKey;
icon: ComponentProps<typeof Icon>['name']; icon: IconName;
href: LocationPathname; href: LocationPathname;
sideNav?: string; sideNav?: string;
condition: () => boolean; condition: () => boolean;
......
import type { ComponentProps, ContextType } from 'react'; import type { ContextType } from 'react';
import mem from 'mem'; import mem from 'mem';
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var'; import { ReactiveVar } from 'meteor/reactive-var';
import { Tracker } from 'meteor/tracker'; import { Tracker } from 'meteor/tracker';
import type { Icon } from '@rocket.chat/fuselage';
import type { IMessage, IUser, ISubscription, IRoom, SettingValue, Serialized, ITranslatedMessage } from '@rocket.chat/core-typings'; import type { IMessage, IUser, ISubscription, IRoom, SettingValue, Serialized, ITranslatedMessage } from '@rocket.chat/core-typings';
import type { TranslationKey } from '@rocket.chat/ui-contexts'; import type { TranslationKey } from '@rocket.chat/ui-contexts';
import type { Keys as IconName } from '@rocket.chat/icons';
import { Messages, ChatRoom, Subscriptions } from '../../../models/client'; import { Messages, ChatRoom, Subscriptions } from '../../../models/client';
import { roomCoordinator } from '../../../../client/lib/rooms/roomCoordinator'; import { roomCoordinator } from '../../../../client/lib/rooms/roomCoordinator';
...@@ -48,7 +48,7 @@ type MessageActionConditionProps = { ...@@ -48,7 +48,7 @@ type MessageActionConditionProps = {
export type MessageActionConfig = { export type MessageActionConfig = {
id: string; id: string;
icon: ComponentProps<typeof Icon>['name']; icon: IconName;
variant?: 'danger' | 'success' | 'warning'; variant?: 'danger' | 'success' | 'warning';
label: TranslationKey; label: TranslationKey;
order?: number; order?: number;
......
import type { Icon } from '@rocket.chat/fuselage';
import { Button, Modal } from '@rocket.chat/fuselage'; import { Button, Modal } from '@rocket.chat/fuselage';
import type { Keys as IconName } from '@rocket.chat/icons';
import { useTranslation } from '@rocket.chat/ui-contexts'; import { useTranslation } from '@rocket.chat/ui-contexts';
import type { FC, ComponentProps, ReactElement, ReactNode } from 'react'; import type { FC, ComponentProps, ReactElement, ReactNode } from 'react';
import React from 'react'; import React from 'react';
...@@ -15,14 +15,14 @@ type GenericModalProps = RequiredModalProps & { ...@@ -15,14 +15,14 @@ type GenericModalProps = RequiredModalProps & {
cancelText?: ReactNode; cancelText?: ReactNode;
confirmText?: ReactNode; confirmText?: ReactNode;
title?: string | ReactElement; title?: string | ReactElement;
icon?: ComponentProps<typeof Icon>['name'] | ReactElement | null; icon?: IconName | ReactElement | null;
confirmDisabled?: boolean; confirmDisabled?: boolean;
tagline?: ReactNode; tagline?: ReactNode;
onCancel?: () => Promise<void> | void; onCancel?: () => Promise<void> | void;
onClose?: () => Promise<void> | void; onClose?: () => Promise<void> | void;
} & Omit<ComponentProps<typeof Modal>, 'title'>; } & Omit<ComponentProps<typeof Modal>, 'title'>;
const iconMap: Record<string, ComponentProps<typeof Icon>['name']> = { const iconMap: Record<string, IconName> = {
danger: 'modal-warning', danger: 'modal-warning',
warning: 'modal-warning', warning: 'modal-warning',
info: 'info', info: 'info',
......
import type { Icon } from '@rocket.chat/fuselage';
import { States, StatesIcon, StatesTitle, StatesSubtitle, StatesActions, StatesAction } from '@rocket.chat/fuselage'; import { States, StatesIcon, StatesTitle, StatesSubtitle, StatesActions, StatesAction } from '@rocket.chat/fuselage';
import type { Keys as IconName } from '@rocket.chat/icons';
import { useTranslation } from '@rocket.chat/ui-contexts'; import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ComponentProps } from 'react';
import React from 'react'; import React from 'react';
type GenericNoResultsProps = { type GenericNoResultsProps = {
icon?: ComponentProps<typeof Icon>['name']; icon?: IconName;
title?: string; title?: string;
description?: string; description?: string;
buttonTitle?: string; buttonTitle?: string;
......
import { Icon, Button } from '@rocket.chat/fuselage'; import { Icon, Button } from '@rocket.chat/fuselage';
import type { Keys as IconName } from '@rocket.chat/icons';
import type { ComponentProps, ReactElement, ReactNode } from 'react'; import type { ComponentProps, ReactElement, ReactNode } from 'react';
import React from 'react'; import React from 'react';
type InfoPanelActionProps = Omit<ComponentProps<typeof Button>, 'label'> & { type InfoPanelActionProps = Omit<ComponentProps<typeof Button>, 'label'> & {
icon?: ComponentProps<typeof Icon>['name']; icon?: IconName;
label: ReactNode; label: ReactNode;
}; };
......
import { Box, Icon } from '@rocket.chat/fuselage'; import { Box, Icon } from '@rocket.chat/fuselage';
import type { ComponentProps, FC, ReactNode } from 'react'; import type { Keys as IconName } from '@rocket.chat/icons';
import type { FC, ReactNode } from 'react';
import React from 'react'; import React from 'react';
type InfoPanelTitleProps = { type InfoPanelTitleProps = {
...@@ -7,7 +8,7 @@ type InfoPanelTitleProps = { ...@@ -7,7 +8,7 @@ type InfoPanelTitleProps = {
icon: ReactNode; icon: ReactNode;
}; };
const isValidIcon = (icon: ReactNode): icon is ComponentProps<typeof Icon>['name'] => typeof icon === 'string'; const isValidIcon = (icon: ReactNode): icon is IconName => typeof icon === 'string';
const InfoPanelTitle: FC<InfoPanelTitleProps> = ({ title, icon }) => ( const InfoPanelTitle: FC<InfoPanelTitleProps> = ({ title, icon }) => (
<Box display='flex' flexShrink={0} alignItems='center' fontScale='h4' color='default' withTruncatedText> <Box display='flex' flexShrink={0} alignItems='center' fontScale='h4' color='default' withTruncatedText>
......
import { Box, Icon, Tag } from '@rocket.chat/fuselage'; import { Box, Icon, Tag } from '@rocket.chat/fuselage';
import type { IconProps } from '@rocket.chat/fuselage'; import type { Keys as IconName } from '@rocket.chat/icons';
import type { FC, ReactElement } from 'react'; import type { FC, ReactElement } from 'react';
import React, { memo } from 'react'; import React, { memo } from 'react';
...@@ -8,7 +8,7 @@ import SidebarGenericItem from './SidebarGenericItem'; ...@@ -8,7 +8,7 @@ import SidebarGenericItem from './SidebarGenericItem';
type SidebarNavigationItemProps = { type SidebarNavigationItemProps = {
permissionGranted?: (() => boolean) | boolean; permissionGranted?: (() => boolean) | boolean;
pathSection: string; pathSection: string;
icon?: IconProps['name']; icon?: IconName;
label?: string; label?: string;
tag?: string; tag?: string;
currentPath?: string; currentPath?: string;
......
import type { Icon } from '@rocket.chat/fuselage';
import { Box, Button, Modal } from '@rocket.chat/fuselage'; import { Box, Button, Modal } from '@rocket.chat/fuselage';
import type { Keys as IconName } from '@rocket.chat/icons';
import { useTranslation } from '@rocket.chat/ui-contexts'; import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ReactNode, ReactElement, ComponentProps } from 'react'; import type { ReactNode, ReactElement, ComponentProps } from 'react';
import React from 'react'; import React from 'react';
...@@ -12,7 +12,7 @@ type UpsellModalProps = { ...@@ -12,7 +12,7 @@ type UpsellModalProps = {
title: string | ReactElement; title: string | ReactElement;
subtitle?: string | ReactElement; subtitle?: string | ReactElement;
description?: string | ReactElement; description?: string | ReactElement;
icon?: ComponentProps<typeof Icon>['name']; icon?: IconName;
img: ComponentProps<typeof Modal.HeroImage>['src']; img: ComponentProps<typeof Modal.HeroImage>['src'];
onCancel?: () => void; onCancel?: () => void;
onClose?: () => void; onClose?: () => void;
......
import { Button, Icon } from '@rocket.chat/fuselage'; import { Button, Icon } from '@rocket.chat/fuselage';
import type { Keys as IconName } from '@rocket.chat/icons';
import type { ReactElement, ComponentProps } from 'react'; import type { ReactElement, ComponentProps } from 'react';
import React from 'react'; import React from 'react';
type UserInfoActionProps = { type UserInfoActionProps = {
icon: ComponentProps<typeof Icon>['name']; icon: IconName;
} & ComponentProps<typeof Button>; } & ComponentProps<typeof Button>;
const UserInfoAction = ({ icon, label, ...props }: UserInfoActionProps): ReactElement => ( const UserInfoAction = ({ icon, label, ...props }: UserInfoActionProps): ReactElement => (
......
import type { IMessage } from '@rocket.chat/core-typings'; import type { IMessage } from '@rocket.chat/core-typings';
import type { IconProps } from '@rocket.chat/fuselage';
import { Box, ButtonGroup } from '@rocket.chat/fuselage'; import { Box, ButtonGroup } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks'; import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import type { Keys as IconName } from '@rocket.chat/icons';
import type { TranslationKey } from '@rocket.chat/ui-contexts'; import type { TranslationKey } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react'; import type { ReactElement } from 'react';
import React from 'react'; import React from 'react';
...@@ -10,7 +10,7 @@ import { actionLinks } from '../../../lib/actionLinks'; ...@@ -10,7 +10,7 @@ import { actionLinks } from '../../../lib/actionLinks';
import MessageAction from './actions/MessageAction'; import MessageAction from './actions/MessageAction';
type MessageActionOptions = { type MessageActionOptions = {
icon: IconProps['name']; icon: IconName;
i18nLabel?: TranslationKey; i18nLabel?: TranslationKey;
label?: string; label?: string;
methodId: string; methodId: string;
......
import type { IconProps } from '@rocket.chat/fuselage';
import { Icon, Button } from '@rocket.chat/fuselage'; import { Icon, Button } from '@rocket.chat/fuselage';
import type { Keys as IconName } from '@rocket.chat/icons';
import type { TranslationKey } from '@rocket.chat/ui-contexts'; import type { TranslationKey } from '@rocket.chat/ui-contexts';
import { useTranslation } from '@rocket.chat/ui-contexts'; import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react'; import type { ReactElement } from 'react';
import React from 'react'; import React from 'react';
const resolveLegacyIcon = (legacyIcon: IconProps['name'] | `icon-${IconProps['name'] | 'videocam'}`): IconProps['name'] => { const resolveLegacyIcon = (legacyIcon: IconName | `icon-${IconName | 'videocam'}`): IconName => {
if (legacyIcon === 'icon-videocam') { if (legacyIcon === 'icon-videocam') {
return 'video'; return 'video';
} }
return legacyIcon?.replace(/^icon-/, '') as IconProps['name']; return legacyIcon?.replace(/^icon-/, '') as IconName;
}; };
type MessageActionProps = { type MessageActionProps = {
icon: IconProps['name']; icon: IconName;
i18nLabel?: TranslationKey; i18nLabel?: TranslationKey;
label?: string; label?: string;
methodId: string; methodId: string;
......
import type { UiKitBannerPayload } from '@rocket.chat/core-typings'; import type { UiKitBannerPayload } from '@rocket.chat/core-typings';
import { Emitter } from '@rocket.chat/emitter'; import { Emitter } from '@rocket.chat/emitter';
import type { Icon } from '@rocket.chat/fuselage'; import type { Keys as IconName } from '@rocket.chat/icons';
import type { ComponentProps } from 'react';
export type LegacyBannerPayload = { export type LegacyBannerPayload = {
id: string; id: string;
...@@ -9,7 +8,7 @@ export type LegacyBannerPayload = { ...@@ -9,7 +8,7 @@ export type LegacyBannerPayload = {
title?: string | (() => string); title?: string | (() => string);
text?: string | (() => string); text?: string | (() => string);
html?: string | (() => string); html?: string | (() => string);
icon?: ComponentProps<typeof Icon>['name']; icon?: IconName;
modifiers?: ('large' | 'danger')[]; modifiers?: ('large' | 'danger')[];
timer?: number; timer?: number;
action?: () => Promise<void> | void; action?: () => Promise<void> | void;
......
import type { IconProps } from '@rocket.chat/fuselage'; import type { Keys as IconName } from '@rocket.chat/icons';
import type { LocationPathname } from '@rocket.chat/ui-contexts'; import type { LocationPathname } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react'; import type { ReactElement } from 'react';
export type Item = { export type Item = {
i18nLabel: string; i18nLabel: string;
href?: LocationPathname | `https://go.rocket.chat/i/${string}`; href?: LocationPathname | `https://go.rocket.chat/i/${string}`;
icon?: IconProps['name']; icon?: IconName;
tag?: 'Alpha' | 'Beta'; tag?: 'Alpha' | 'Beta';
permissionGranted?: () => boolean; permissionGranted?: () => boolean;
pathSection?: string; pathSection?: string;
......
import type { IconProps } from '@rocket.chat/fuselage';
import { IconButton, Sidebar } from '@rocket.chat/fuselage'; import { IconButton, Sidebar } from '@rocket.chat/fuselage';
import { useMutableCallback, usePrefersReducedMotion } from '@rocket.chat/fuselage-hooks'; import { useMutableCallback, usePrefersReducedMotion } from '@rocket.chat/fuselage-hooks';
import type { Keys as IconName } from '@rocket.chat/icons';
import type { FC, ReactElement } from 'react'; import type { FC, ReactElement } from 'react';
import React, { memo, useState } from 'react'; import React, { memo, useState } from 'react';
...@@ -8,7 +8,7 @@ type CondensedProps = { ...@@ -8,7 +8,7 @@ type CondensedProps = {
title: ReactElement | string; title: ReactElement | string;
titleIcon?: ReactElement; titleIcon?: ReactElement;
avatar: ReactElement | boolean; avatar: ReactElement | boolean;
icon?: IconProps['name']; icon?: IconName;
actions?: ReactElement; actions?: ReactElement;
href?: string; href?: string;
unread?: boolean; unread?: boolean;
......
import type { IconProps } from '@rocket.chat/fuselage';
import { Sidebar, IconButton } from '@rocket.chat/fuselage'; import { Sidebar, IconButton } from '@rocket.chat/fuselage';
import { useMutableCallback, usePrefersReducedMotion } from '@rocket.chat/fuselage-hooks'; import { useMutableCallback, usePrefersReducedMotion } from '@rocket.chat/fuselage-hooks';
import type { Keys as IconName } from '@rocket.chat/icons';
import type { VFC } from 'react'; import type { VFC } from 'react';
import React, { memo, useState } from 'react'; import React, { memo, useState } from 'react';
import { useShortTimeAgo } from '../../hooks/useTimeAgo'; import { useShortTimeAgo } from '../../hooks/useTimeAgo';
type ExtendedProps = { type ExtendedProps = {
icon?: IconProps['name']; icon?: IconName;
title?: React.ReactNode; title?: React.ReactNode;
avatar?: React.ReactNode | boolean; avatar?: React.ReactNode | boolean;
actions?: React.ReactNode; actions?: React.ReactNode;
......
import type { UIKitActionEvent, UiKitBannerProps } from '@rocket.chat/core-typings'; import type { UIKitActionEvent, UiKitBannerProps } from '@rocket.chat/core-typings';
import { Banner, Icon } from '@rocket.chat/fuselage'; import { Banner, Icon } from '@rocket.chat/fuselage';
import { kitContext, bannerParser, UiKitBanner as renderUiKitBannerBlocks } from '@rocket.chat/fuselage-ui-kit'; import { kitContext, bannerParser, UiKitBanner as renderUiKitBannerBlocks } from '@rocket.chat/fuselage-ui-kit';
import type { Keys as IconName } from '@rocket.chat/icons';
import type { LayoutBlock } from '@rocket.chat/ui-kit'; import type { LayoutBlock } from '@rocket.chat/ui-kit';
import type { FC, ComponentProps, ReactElement, ContextType } from 'react'; import type { FC, ReactElement, ContextType } from 'react';
import React, { useMemo } from 'react'; import React, { useMemo } from 'react';
import { useUIKitHandleAction } from '../../UIKit/hooks/useUIKitHandleAction'; import { useUIKitHandleAction } from '../../UIKit/hooks/useUIKitHandleAction';
...@@ -19,7 +20,7 @@ const UiKitBanner: FC<UiKitBannerProps> = ({ payload }) => { ...@@ -19,7 +20,7 @@ const UiKitBanner: FC<UiKitBannerProps> = ({ payload }) => {
const icon = useMemo(() => { const icon = useMemo(() => {
if (state.icon) { if (state.icon) {
return <Icon name={state.icon as ComponentProps<typeof Icon>['name']} size={20} />; return <Icon name={state.icon as IconName} size={20} />;
} }
return null; return null;
......
import type { Icon } from '@rocket.chat/fuselage'; import type { Keys as IconName } from '@rocket.chat/icons';
import type { ComponentProps, ReactNode } from 'react'; import type { ReactNode } from 'react';
import { useMemo } from 'react'; import { useMemo } from 'react';
export type Action = { export type Action = {
label: ReactNode; label: ReactNode;
icon?: ComponentProps<typeof Icon>['name']; icon?: IconName;
action: () => void; action: () => void;
}; };
......
import type { IconProps } from '@rocket.chat/fuselage';
import { Button, Icon } from '@rocket.chat/fuselage'; import { Button, Icon } from '@rocket.chat/fuselage';
import type { Keys as IconName } from '@rocket.chat/icons';
import type { FC, HtmlHTMLAttributes } from 'react'; import type { FC, HtmlHTMLAttributes } from 'react';
import React from 'react'; import React from 'react';
type AgentInfoActionProps = { type AgentInfoActionProps = {
icon: IconProps['name']; icon: IconName;
label?: string; label?: string;
title?: string; title?: string;
} & Omit<HtmlHTMLAttributes<HTMLElement>, 'is'>; } & Omit<HtmlHTMLAttributes<HTMLElement>, 'is'>;
......
import type { IMessage } from '@rocket.chat/core-typings'; import type { IMessage } from '@rocket.chat/core-typings';
import type { Icon } from '@rocket.chat/fuselage';
import { Box, MessageDivider, Throbber } from '@rocket.chat/fuselage'; import { Box, MessageDivider, Throbber } from '@rocket.chat/fuselage';
import type { Keys as IconName } from '@rocket.chat/icons';
import { useTranslation, useUserPreference } from '@rocket.chat/ui-contexts'; import { useTranslation, useUserPreference } from '@rocket.chat/ui-contexts';
import type { UseQueryResult } from '@tanstack/react-query'; import type { UseQueryResult } from '@tanstack/react-query';
import type { ReactElement, ComponentProps, ReactNode } from 'react'; import type { ReactElement, ReactNode } from 'react';
import React, { useCallback } from 'react'; import React, { useCallback } from 'react';
import { Virtuoso } from 'react-virtuoso'; import { Virtuoso } from 'react-virtuoso';
...@@ -29,7 +29,7 @@ import { useRoomSubscription } from '../../contexts/RoomContext'; ...@@ -29,7 +29,7 @@ import { useRoomSubscription } from '../../contexts/RoomContext';
import { useTabBarClose } from '../../contexts/ToolboxContext'; import { useTabBarClose } from '../../contexts/ToolboxContext';
type MessageListTabProps = { type MessageListTabProps = {
iconName: ComponentProps<typeof Icon>['name']; iconName: IconName;
title: ReactNode; title: ReactNode;
emptyResultMessage: string; emptyResultMessage: string;
context: MessageActionContext; context: MessageActionContext;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment