1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-24 01:18:01 +02:00

feat: show user's roles and project owners ()

This change shows the user's roles and project owners in the personal
dashboard.
This commit is contained in:
Thomas Heartman 2024-09-26 12:47:29 +02:00 committed by GitHub
parent 4397af0df7
commit d6f5280a98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 72 additions and 9 deletions
frontend/src/component/personalDashboard

View File

@ -25,6 +25,7 @@ import { usePersonalDashboard } from 'hooks/api/getters/usePersonalDashboard/use
import { getFeatureTypeIcons } from 'utils/getFeatureTypeIcons';
import type { PersonalDashboardSchema } from '../../openapi';
import { FlagExposure } from 'component/feature/FeatureView/FeatureOverview/FeatureLifecycle/FlagExposure';
import { RoleAndOwnerInfo } from './RoleAndOwnerInfo';
const ScreenExplanation = styled(Typography)(({ theme }) => ({
marginTop: theme.spacing(1),
@ -285,15 +286,13 @@ export const PersonalDashboard = () => {
) : null}
</SpacedGridItem>
<SpacedGridItem item lg={4} md={1} />
<SpacedGridItem
item
lg={8}
md={1}
sx={{ display: 'flex', gap: 1, alignItems: 'center' }}
>
<span>Your roles in this project:</span>{' '}
<Badge color='secondary'>Member</Badge>{' '}
<Badge color='secondary'>Another</Badge>
<SpacedGridItem item lg={8} md={1}>
{activeProject ? (
<RoleAndOwnerInfo
roles={['owner', 'custom']}
owners={[{ ownerType: 'system' }]}
/>
) : null}
</SpacedGridItem>
</ContentGrid>
<ContentGrid container columns={{ lg: 12, md: 1 }} sx={{ mt: 2 }}>

View File

@ -0,0 +1,64 @@
import { styled } from '@mui/material';
import { AvatarGroup } from 'component/common/AvatarGroup/AvatarGroup';
import { Badge } from 'component/common/Badge/Badge';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import type { ProjectSchemaOwners } from 'openapi';
type Props = {
roles: string[];
owners: ProjectSchemaOwners;
};
const Wrapper = styled('div')(({ theme }) => ({
width: '100%',
display: 'flex',
flexDirection: 'row',
gap: theme.spacing(1),
justifyContent: 'space-between',
}));
const InfoSection = styled('div')(({ theme }) => ({
display: 'flex',
gap: theme.spacing(1),
}));
const mapOwners =
(unleashUrl?: string) => (owner: ProjectSchemaOwners[number]) => {
if (owner.ownerType === 'user') {
return {
name: owner.name,
imageUrl: owner.imageUrl || undefined,
email: owner.email || undefined,
};
}
if (owner.ownerType === 'group') {
return {
name: owner.name,
};
}
return {
name: 'System',
imageUrl: `${unleashUrl}/logo-unleash.png`,
};
};
export const RoleAndOwnerInfo = ({ roles, owners }: Props) => {
const { uiConfig } = useUiConfig();
const mappedOwners = owners.map(mapOwners(uiConfig.unleashUrl));
return (
<Wrapper>
<InfoSection>
<span>Your roles in this project:</span>
{roles.map((role) => (
<Badge key={role} color='secondary'>
{role}
</Badge>
))}
</InfoSection>
<InfoSection>
<span>Project owner{owners.length > 1 ? 's' : ''}</span>
<AvatarGroup users={mappedOwners} avatarLimit={3} />
</InfoSection>
</Wrapper>
);
};