Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle lots of project roles better #8383

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 81 additions & 9 deletions frontend/src/component/personalDashboard/RoleAndOwnerInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { styled } from '@mui/material';
import { Typography, styled } from '@mui/material';
import { Badge } from 'component/common/Badge/Badge';
import { AvatarGroupFromOwners } from 'component/common/AvatarGroupFromOwners/AvatarGroupFromOwners';
import type { ProjectSchemaOwners } from 'openapi';
import { HtmlTooltip } from 'component/common/HtmlTooltip/HtmlTooltip';

type Props = {
roles: string[];
Expand All @@ -22,26 +23,97 @@ const InfoSection = styled('div')(({ theme }) => ({
alignItems: 'center',
}));

const Roles = styled('ul')(({ theme }) => ({
display: 'flex',
gap: theme.spacing(1),
flexFlow: 'row wrap',
listStyle: 'none',
padding: 0,
}));

const TooltipRoles = styled('ul')(({ theme }) => ({
gap: theme.spacing(1),
flexFlow: 'column',
display: 'flex',
listStyle: 'none',
padding: 0,
}));

const RoleBadge = styled(Badge)({
whitespace: 'nowrap',
});

const StyledAvatarGroup = styled(AvatarGroupFromOwners)({
width: 'max-content',
});

export const RoleAndOwnerInfo = ({ roles, owners }: Props) => {
const firstRoles = roles.slice(0, 3);
const extraRoles = roles.slice(3);
return (
<Wrapper>
<InfoSection>
{roles.length > 0 ? (
<>
<span>Your roles in this project:</span>
{roles.map((role) => (
<Badge key={role} color='secondary'>
{role}
</Badge>
))}
<Typography
sx={{
whiteSpace: 'nowrap',
}}
variant='body1'
component='h4'
>
Your roles in this project:
</Typography>
<Roles>
{firstRoles.map((role) => (
<li>
<RoleBadge key={role} color='secondary'>
{role}
</RoleBadge>
</li>
))}
{extraRoles.length ? (
<li>
<HtmlTooltip
arrow
title={
<TooltipRoles>
{extraRoles.map((role) => (
<li>
<RoleBadge>
{role}
</RoleBadge>
</li>
))}
</TooltipRoles>
}
>
<RoleBadge
key={'extra-roles'}
color='secondary'
>
{`+ ${extraRoles.length} more`}
</RoleBadge>
</HtmlTooltip>
</li>
) : null}
</Roles>
</>
) : (
<span>You have no project roles in this project.</span>
)}
</InfoSection>
<InfoSection>
<span>Project owner{owners.length > 1 ? 's' : ''}</span>
<AvatarGroupFromOwners users={owners} avatarLimit={3} />
<Typography
variant='body1'
component='h4'
sx={{
whiteSpace: 'nowrap',
}}
>
Project owner{owners.length > 1 ? 's' : ''}
</Typography>
<StyledAvatarGroup users={owners} avatarLimit={3} />
</InfoSection>
</Wrapper>
);
Expand Down
Loading