From c99fae5158143a77fa43b0f92ad7a18aba6d2240 Mon Sep 17 00:00:00 2001 From: Vladimir Chernitsyn Date: Mon, 15 Apr 2024 14:33:42 +0200 Subject: [PATCH] feat(UserCard): add UserCard support in UIFactory --- packages/ui/src/ui/UIFactory.tsx | 7 +++++++ packages/ui/src/ui/components/UserLink/UserLink.tsx | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/ui/UIFactory.tsx b/packages/ui/src/ui/UIFactory.tsx index dbd59200e..b0eb6a9c7 100644 --- a/packages/ui/src/ui/UIFactory.tsx +++ b/packages/ui/src/ui/UIFactory.tsx @@ -28,6 +28,7 @@ import YT from './config/yt-config'; import {PreparedAclSubject} from './utils/acl/acl-types'; import {PreparedRole} from './utils/acl'; import {UISettingsMonitoring} from '../shared/ui-settings'; +import {DefaultUserCard, type UserCardProps} from './components/UserLink/UserLink'; type HeaderItemOrPage = | { @@ -306,6 +307,8 @@ export interface UIFactory { disabled?: boolean; }): React.ReactNode; + renderUserCard(props: UserCardProps): React.ReactNode; + makeSupportContent( params: {login: string; cluster?: string; buttonToWrap?: React.ReactNode}, makeContent: (params: { @@ -555,6 +558,10 @@ const uiFactory: UIFactory = { return undefined; }, + renderUserCard(props: UserCardProps): React.ReactNode { + return ; + }, + makeSupportContent(_x, makeContent) { const {reportBugUrl} = uiSettings; if (!reportBugUrl) { diff --git a/packages/ui/src/ui/components/UserLink/UserLink.tsx b/packages/ui/src/ui/components/UserLink/UserLink.tsx index d5500dbd2..daf256f48 100644 --- a/packages/ui/src/ui/components/UserLink/UserLink.tsx +++ b/packages/ui/src/ui/components/UserLink/UserLink.tsx @@ -8,7 +8,7 @@ import './UserLink.scss'; const block = cn('user-link'); -interface Props { +export interface UserCardProps { className?: string; noLink?: boolean; internal?: boolean; // use YT link @@ -18,7 +18,8 @@ interface Props { children?: React.ReactElement; } -export function UserCard({userName, className, noLink, internal, children}: Props) { +export function DefaultUserCard(props: UserCardProps) { + const {userName, className, noLink, internal, children} = props; const url = internal ? `/${YT.cluster}/users?filter=${userName}` : UIFactory.makeUrlForUserName({login: userName, cluster: YT.cluster}); @@ -26,6 +27,10 @@ export function UserCard({userName, className, noLink, internal, children}: Prop return ; } +export function UserCard(props: UserCardProps) { + return UIFactory.renderUserCard(props); +} + export function UserName({ userName, url,