mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
fix: wrap the UserAvatar component in forwardRef (#8461)
This fixes another one of the warnings we have in our tests and is probably a sane change to make anyway.
This commit is contained in:
parent
fe09ae214f
commit
cb0a26941b
@ -1,8 +1,16 @@
|
|||||||
import { styled } from '@mui/material';
|
import { styled } from '@mui/material';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import type { IGroupUser } from 'interfaces/group';
|
import type { IGroupUser } from 'interfaces/group';
|
||||||
import { useMemo } from 'react';
|
import {
|
||||||
import { UserAvatar } from 'component/common/UserAvatar/UserAvatar'; // usage
|
type ForwardRefExoticComponent,
|
||||||
|
type FunctionComponent,
|
||||||
|
type RefAttributes,
|
||||||
|
useMemo,
|
||||||
|
} from 'react';
|
||||||
|
import {
|
||||||
|
type IUserAvatarProps,
|
||||||
|
UserAvatar,
|
||||||
|
} from 'component/common/UserAvatar/UserAvatar';
|
||||||
import { objectId } from 'utils/objectId';
|
import { objectId } from 'utils/objectId';
|
||||||
import millify from 'millify';
|
import millify from 'millify';
|
||||||
|
|
||||||
@ -14,6 +22,12 @@ const StyledAvatars = styled('div')(({ theme }) => ({
|
|||||||
justifyContent: 'start',
|
justifyContent: 'start',
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
export type AvatarComponentType =
|
||||||
|
| FunctionComponent<IUserAvatarProps>
|
||||||
|
| ForwardRefExoticComponent<
|
||||||
|
IUserAvatarProps & RefAttributes<HTMLDivElement>
|
||||||
|
>;
|
||||||
|
|
||||||
export const AvatarComponent = styled(UserAvatar)(({ theme }) => ({
|
export const AvatarComponent = styled(UserAvatar)(({ theme }) => ({
|
||||||
outline: `${theme.spacing(0.25)} solid ${theme.palette.background.paper}`,
|
outline: `${theme.spacing(0.25)} solid ${theme.palette.background.paper}`,
|
||||||
margin: 0,
|
margin: 0,
|
||||||
@ -21,7 +35,7 @@ export const AvatarComponent = styled(UserAvatar)(({ theme }) => ({
|
|||||||
'&:hover': {
|
'&:hover': {
|
||||||
outlineColor: theme.palette.primary.main,
|
outlineColor: theme.palette.primary.main,
|
||||||
},
|
},
|
||||||
}));
|
})) as AvatarComponentType;
|
||||||
|
|
||||||
type User = {
|
type User = {
|
||||||
name: string;
|
name: string;
|
||||||
@ -32,7 +46,7 @@ type User = {
|
|||||||
type AvatarGroupProps = {
|
type AvatarGroupProps = {
|
||||||
users: User[];
|
users: User[];
|
||||||
avatarLimit?: number;
|
avatarLimit?: number;
|
||||||
AvatarComponent?: typeof UserAvatar;
|
AvatarComponent?: AvatarComponentType;
|
||||||
className?: string;
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -44,7 +58,7 @@ export const AvatarGroup = ({ ...props }: AvatarGroupProps) => (
|
|||||||
);
|
);
|
||||||
|
|
||||||
type AvatarGroupInnerProps = Omit<AvatarGroupProps, 'AvatarComponent'> & {
|
type AvatarGroupInnerProps = Omit<AvatarGroupProps, 'AvatarComponent'> & {
|
||||||
AvatarComponent: typeof UserAvatar;
|
AvatarComponent: AvatarComponentType;
|
||||||
};
|
};
|
||||||
|
|
||||||
const MAX_OVERFLOW_DISPLAY_NUMBER = 99;
|
const MAX_OVERFLOW_DISPLAY_NUMBER = 99;
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
||||||
import type { ProjectSchemaOwners } from 'openapi';
|
import type { ProjectSchemaOwners } from 'openapi';
|
||||||
import type { UserAvatar } from '../UserAvatar/UserAvatar';
|
import {
|
||||||
import { AvatarGroup } from '../AvatarGroup/AvatarGroup';
|
type AvatarComponentType,
|
||||||
|
AvatarGroup,
|
||||||
|
} from '../AvatarGroup/AvatarGroup';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
users: ProjectSchemaOwners;
|
users: ProjectSchemaOwners;
|
||||||
avatarLimit?: number;
|
avatarLimit?: number;
|
||||||
AvatarComponent?: typeof UserAvatar;
|
AvatarComponent?: AvatarComponentType;
|
||||||
className?: string;
|
className?: string;
|
||||||
};
|
};
|
||||||
export const AvatarGroupFromOwners: React.FC<Props> = ({ users, ...props }) => {
|
export const AvatarGroupFromOwners: React.FC<Props> = ({ users, ...props }) => {
|
||||||
|
@ -6,7 +6,7 @@ import {
|
|||||||
type Theme,
|
type Theme,
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import type { IUser } from 'interfaces/user';
|
import type { IUser } from 'interfaces/user';
|
||||||
import type { FC } from 'react';
|
import { forwardRef } from 'react';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import { HtmlTooltip } from '../HtmlTooltip/HtmlTooltip';
|
import { HtmlTooltip } from '../HtmlTooltip/HtmlTooltip';
|
||||||
const StyledAvatar = styled(Avatar)(({ theme }) => ({
|
const StyledAvatar = styled(Avatar)(({ theme }) => ({
|
||||||
@ -60,15 +60,8 @@ const TooltipMainContent = styled('div')(({ theme }) => ({
|
|||||||
fontSize: theme.typography.body1.fontSize,
|
fontSize: theme.typography.body1.fontSize,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const UserAvatar: FC<IUserAvatarProps> = ({
|
export const UserAvatar = forwardRef<HTMLDivElement, IUserAvatarProps>(
|
||||||
user,
|
({ user, src, className, sx, children, disableTooltip, ...props }, ref) => {
|
||||||
src,
|
|
||||||
className,
|
|
||||||
sx,
|
|
||||||
children,
|
|
||||||
disableTooltip,
|
|
||||||
...props
|
|
||||||
}) => {
|
|
||||||
let fallback: string | undefined;
|
let fallback: string | undefined;
|
||||||
if (!children && user) {
|
if (!children && user) {
|
||||||
fallback = user?.name || user?.email || user?.username;
|
fallback = user?.name || user?.email || user?.username;
|
||||||
@ -83,6 +76,7 @@ export const UserAvatar: FC<IUserAvatarProps> = ({
|
|||||||
|
|
||||||
const Avatar = (
|
const Avatar = (
|
||||||
<StyledAvatar
|
<StyledAvatar
|
||||||
|
ref={ref}
|
||||||
className={className}
|
className={className}
|
||||||
sx={sx}
|
sx={sx}
|
||||||
{...props}
|
{...props}
|
||||||
@ -109,7 +103,9 @@ export const UserAvatar: FC<IUserAvatarProps> = ({
|
|||||||
<TooltipSecondaryContent>
|
<TooltipSecondaryContent>
|
||||||
{tooltip.secondary}
|
{tooltip.secondary}
|
||||||
</TooltipSecondaryContent>
|
</TooltipSecondaryContent>
|
||||||
<TooltipMainContent>{tooltip.main}</TooltipMainContent>
|
<TooltipMainContent>
|
||||||
|
{tooltip.main}
|
||||||
|
</TooltipMainContent>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@ -119,4 +115,5 @@ export const UserAvatar: FC<IUserAvatarProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Avatar;
|
return Avatar;
|
||||||
};
|
},
|
||||||
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user