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

feat: hook up admin / owner data to UI #8300

Merged
merged 8 commits into from
Sep 30, 2024
71 changes: 49 additions & 22 deletions frontend/src/component/personalDashboard/ContentGridNoProjects.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Grid, Typography, styled } from '@mui/material';
import { AvatarGroupFromOwners } from 'component/common/AvatarGroupFromOwners/AvatarGroupFromOwners';
import { UserAvatar } from 'component/common/UserAvatar/UserAvatar';
import type { ProjectSchemaOwners } from 'openapi';
import type { PersonalDashboardSchemaAdminsItem } from 'openapi/models/personalDashboardSchemaAdminsItem';
import type { PersonalDashboardSchemaProjectOwnersItem } from 'openapi/models/personalDashboardSchemaProjectOwnersItem';
import { Link } from 'react-router-dom';

const ContentGrid = styled(Grid)(({ theme }) => ({
Expand Down Expand Up @@ -61,8 +62,8 @@ const AdminListItem = styled('li')(({ theme }) => ({
}));

type Props = {
owners: ProjectSchemaOwners;
admins: { name: string; imageUrl?: string }[];
owners: PersonalDashboardSchemaProjectOwnersItem[];
admins: PersonalDashboardSchemaAdminsItem[];
};

export const ContentGridNoProjects: React.FC<Props> = ({ owners, admins }) => {
Expand Down Expand Up @@ -97,23 +98,37 @@ export const ContentGridNoProjects: React.FC<Props> = ({ owners, admins }) => {
Contact Unleash admin
</TitleContainer>
<BoxMainContent>
<p>
Your Unleash administrator
{admins.length > 1 ? 's are' : ' is'}:
</p>
<AdminList>
{admins.map((admin) => (
<AdminListItem key={admin.name}>
<UserAvatar
sx={{
margin: 0,
}}
user={admin}
/>
<Typography>{admin.name}</Typography>
</AdminListItem>
))}
</AdminList>
{admins.length ? (
<>
<p>
Your Unleash administrator
{admins.length > 1 ? 's are' : ' is'}:
</p>
<AdminList>
{admins.map((admin) => {
return (
<AdminListItem key={admin.id}>
<UserAvatar
sx={{
margin: 0,
}}
user={admin}
/>
<Typography>
{admin.name ||
admin.username ||
admin.email}
</Typography>
</AdminListItem>
);
})}
</AdminList>
</>
) : (
<p>
You have no Unleash administrators to contact.
</p>
)}
</BoxMainContent>
</GridContent>
</SpacedGridItem>
Expand All @@ -124,8 +139,20 @@ export const ContentGridNoProjects: React.FC<Props> = ({ owners, admins }) => {
Ask a project owner to add you to their project
</TitleContainer>
<BoxMainContent>
<p>Project owners in Unleash:</p>
<AvatarGroupFromOwners users={owners} avatarLimit={9} />
{owners.length ? (
<>
<p>Project owners in Unleash:</p>
<AvatarGroupFromOwners
users={owners}
avatarLimit={9}
/>
</>
) : (
<p>
There are no project owners in Unleash to ask
for access.
</p>
)}
</BoxMainContent>
</GridContent>
</SpacedGridItem>
Expand Down
13 changes: 3 additions & 10 deletions frontend/src/component/personalDashboard/PersonalDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,10 @@ export const PersonalDashboard = () => {
) : null}
</ScreenExplanation>

{noProjects ? (
{noProjects && personalDashboard ? (
<ContentGridNoProjects
owners={[{ ownerType: 'system' }]}
admins={[
{ name: 'admin' },
{
name: 'Christopher Tompkins',
imageUrl:
'https://avatars.githubusercontent.com/u/1010371?v=4',
},
]}
owners={personalDashboard.projectOwners}
admins={personalDashboard.admins}
/>
) : (
<ContentGrid container columns={{ lg: 12, md: 1 }}>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/openapi/models/personalDashboardSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import type { PersonalDashboardSchemaProjectsItem } from './personalDashboardSch
*/
export interface PersonalDashboardSchema {
/** Users with the admin role in Unleash. */
admins?: PersonalDashboardSchemaAdminsItem[];
admins: PersonalDashboardSchemaAdminsItem[];
/** A list of flags a user created or favorited */
flags: PersonalDashboardSchemaFlagsItem[];
/** Users with the project owner role in Unleash. Only contains owners of projects that are visible to the user. */
projectOwners?: PersonalDashboardSchemaProjectOwnersItem[];
projectOwners: PersonalDashboardSchemaProjectOwnersItem[];
/** A list of projects that a user participates in with any role e.g. member or owner or any custom role */
projects: PersonalDashboardSchemaProjectsItem[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

export type PersonalDashboardSchemaAdminsItem = {
/** @nullable */
email?: string | null;
email?: string;
/** The user ID. */
id: number;
/** @nullable */
imageUrl?: string | null;
imageUrl?: string;
/** The user's name. */
name?: string;
/** The user's username. */
Expand Down
4 changes: 1 addition & 3 deletions src/lib/openapi/spec/personal-dashboard-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const personalDashboardSchema = {
type: 'object',
description: 'Project and flags relevant to the user',
additionalProperties: false,
required: ['projects', 'flags'],
required: ['projects', 'flags', 'admins', 'projectOwners'],
properties: {
admins: {
type: 'array',
Expand All @@ -31,12 +31,10 @@ export const personalDashboardSchema = {
},
imageUrl: {
type: 'string',
nullable: true,
example: 'https://example.com/peek-at-you.jpg',
},
email: {
type: 'string',
nullable: true,
example: '[email protected]',
},
},
Expand Down