Skip to content

Commit

Permalink
feat(UserCard): add UserCard support in UIFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
Flunt1k authored and ma-efremoff committed Apr 16, 2024
1 parent 65abfc5 commit c99fae5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions packages/ui/src/ui/UIFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
| {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -555,6 +558,10 @@ const uiFactory: UIFactory = {
return undefined;
},

renderUserCard(props: UserCardProps): React.ReactNode {
return <DefaultUserCard {...props} />;
},

makeSupportContent(_x, makeContent) {
const {reportBugUrl} = uiSettings;
if (!reportBugUrl) {
Expand Down
9 changes: 7 additions & 2 deletions packages/ui/src/ui/components/UserLink/UserLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,14 +18,19 @@ 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});

return <UserName {...{className, userName, url: noLink ? undefined : url, children}} />;
}

export function UserCard(props: UserCardProps) {
return UIFactory.renderUserCard(props);
}

export function UserName({
userName,
url,
Expand Down

0 comments on commit c99fae5

Please # to comment.