-
Notifications
You must be signed in to change notification settings - Fork 2
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: Styled team viewer table #3146
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ad23f55
feat: Styled team viewer table
ianjon3s a7d2589
feat: Single table markup, rename editor roles
ianjon3s d2df356
fix: Remove redundant fragment
ianjon3s 46c2b3d
feat: Filter out admins without email set
ianjon3s 0311d7e
feat: Refinements based on feedback
ianjon3s 4f8b336
feat: Refinements based on feedback
ianjon3s 56ec6d7
feat: Members table as component
ianjon3s 4be516c
feat: Members table outside scope of TeamMembers
ianjon3s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
152 changes: 148 additions & 4 deletions
152
editor.planx.uk/src/pages/FlowEditor/components/Team/TeamMembers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,163 @@ | ||
import Avatar from "@mui/material/Avatar"; | ||
import Box from "@mui/material/Box"; | ||
import Chip from "@mui/material/Chip"; | ||
import Container from "@mui/material/Container"; | ||
import { styled } from "@mui/material/styles"; | ||
import Table from "@mui/material/Table"; | ||
import TableBody from "@mui/material/TableBody"; | ||
import TableCell from "@mui/material/TableCell"; | ||
import TableContainer from "@mui/material/TableContainer"; | ||
import TableHead from "@mui/material/TableHead"; | ||
import TableRow from "@mui/material/TableRow"; | ||
import Typography from "@mui/material/Typography"; | ||
import { Role, User } from "@opensystemslab/planx-core/types"; | ||
import React from "react"; | ||
import { FONT_WEIGHT_SEMI_BOLD } from "theme"; | ||
import EditorRow from "ui/editor/EditorRow"; | ||
|
||
const StyledAvatar = styled(Avatar)(({ theme }) => ({ | ||
background: theme.palette.background.dark, | ||
color: theme.palette.common.white, | ||
fontSize: "1em", | ||
fontWeight: FONT_WEIGHT_SEMI_BOLD, | ||
marginRight: theme.spacing(1), | ||
})); | ||
|
||
const StyledTableRow = styled(TableRow)(({ theme }) => ({ | ||
"&:nth-of-type(even)": { | ||
background: theme.palette.background.paper, | ||
}, | ||
})); | ||
|
||
export type TeamMember = Omit<User, "teams" | "isPlatformAdmin"> & { | ||
role: Role; | ||
}; | ||
|
||
const roleLabels: Record<string, string> = { | ||
platformAdmin: "Admin", | ||
teamEditor: "Editor", | ||
teamViewer: "Viewer", | ||
}; | ||
ianjon3s marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
interface Props { | ||
teamMembersByRole: Record<Role, TeamMember[]>; | ||
teamMembersByRole: Record<string, TeamMember[]>; | ||
} | ||
|
||
const MembersTable: React.FC<{ members: TeamMember[] }> = ({ members }) => { | ||
const getRoleLabel = (role: string) => { | ||
return roleLabels[role] || role; | ||
}; | ||
|
||
if (members.length === 0) { | ||
return ( | ||
<Table> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell> | ||
<strong>No members found</strong> | ||
</TableCell> | ||
</TableRow> | ||
</TableHead> | ||
</Table> | ||
); | ||
} | ||
|
||
return ( | ||
<TableContainer> | ||
<Table> | ||
<TableHead> | ||
<StyledTableRow> | ||
<TableCell sx={{ width: 300 }}> | ||
<strong>User</strong> | ||
</TableCell> | ||
<TableCell sx={{ width: 200 }}> | ||
<strong>Role</strong> | ||
</TableCell> | ||
<TableCell> | ||
<strong>Email</strong> | ||
</TableCell> | ||
</StyledTableRow> | ||
</TableHead> | ||
<TableBody> | ||
{members.map((member) => ( | ||
<StyledTableRow key={member.id}> | ||
<TableCell | ||
sx={{ | ||
display: "flex", | ||
flexDirection: "row", | ||
alignItems: "center", | ||
}} | ||
> | ||
<StyledAvatar> | ||
{member.firstName[0]} | ||
{member.lastName[0]} | ||
</StyledAvatar> | ||
{member.firstName} {member.lastName} | ||
</TableCell> | ||
<TableCell> | ||
<Chip | ||
label={getRoleLabel(member.role)} | ||
size="small" | ||
sx={{ background: "#ddd" }} | ||
/> | ||
</TableCell> | ||
<TableCell>{member.email}</TableCell> | ||
</StyledTableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
); | ||
}; | ||
|
||
export const TeamMembers: React.FC<Props> = ({ teamMembersByRole }) => { | ||
const platformAdmins = (teamMembersByRole.platformAdmin || []).filter( | ||
(member) => member.email, | ||
); | ||
const otherRoles = Object.keys(teamMembersByRole) | ||
.filter((role) => role !== "platformAdmin") | ||
.reduce((acc: TeamMember[], role) => { | ||
return acc.concat(teamMembersByRole[role]); | ||
}, []); | ||
|
||
const archivedMembers = otherRoles.filter( | ||
(member) => member.role !== "platformAdmin" && !member.email, | ||
); | ||
|
||
return ( | ||
<Box component="pre" sx={{ fontSize: 12 }}> | ||
{JSON.stringify(teamMembersByRole, null, 4)} | ||
</Box> | ||
<Container maxWidth="contentWrap"> | ||
<Box py={7}> | ||
<EditorRow> | ||
<Typography variant="h2" component="h3" gutterBottom> | ||
Team editors | ||
</Typography> | ||
<Typography variant="body1"> | ||
Editors have access to edit your services. | ||
</Typography> | ||
<MembersTable members={otherRoles} /> | ||
</EditorRow> | ||
<EditorRow> | ||
<Typography variant="h2" component="h3" gutterBottom> | ||
Admins | ||
</Typography> | ||
<Typography variant="body1"> | ||
Admins have editor access across all teams. | ||
</Typography> | ||
<MembersTable members={platformAdmins} /> | ||
</EditorRow> | ||
{archivedMembers.length > 0 && ( | ||
<EditorRow> | ||
<Typography variant="h2" component="h3" gutterBottom> | ||
Archived team editors | ||
</Typography> | ||
<Typography variant="body1"> | ||
Past team members who no longer have access to the Editor, but may | ||
be part of the edit history of your services. | ||
</Typography> | ||
<MembersTable members={archivedMembers} /> | ||
</EditorRow> | ||
)} | ||
</Box> | ||
</Container> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect! This diff really nicely illustrates the idea that a React functional component (
React.FC
) is just a function, and arguments become React props.You could also "unnest" this component and take it outside of the scope of
TeamMembers
- it's maybe worth doing as there's no need for it to be nested withinTeamMembers
. I think a few of the helper functions would also need to move with this. This shows a nice compositional model where we can make many small independent components and compose them together 👍Not a totally necessary step here, happy to approve as-is.