Skip to content

refactor: Add group badge to diff groups from users #4478

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

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions site/src/components/GroupAvatar/GroupAvatar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Story } from "@storybook/react"
import { GroupAvatar, GroupAvatarProps } from "./GroupAvatar"

export default {
title: "components/GroupAvatar",
component: GroupAvatar,
}

const Template: Story<GroupAvatarProps> = (args) => <GroupAvatar {...args} />

export const Example = Template.bind({})
Example.args = {
name: "My Group",
}
43 changes: 43 additions & 0 deletions site/src/components/GroupAvatar/GroupAvatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Avatar from "@material-ui/core/Avatar"
import Badge from "@material-ui/core/Badge"
import { withStyles } from "@material-ui/core/styles"
import Group from "@material-ui/icons/Group"
import { FC } from "react"
import { firstLetter } from "util/firstLetter"

const StyledBadge = withStyles((theme) => ({
badge: {
backgroundColor: theme.palette.background.paper,
border: `1px solid ${theme.palette.divider}`,
borderRadius: "100%",
width: 24,
height: 24,
display: "flex",
alignItems: "center",
justifyContent: "center",

"& svg": {
width: 14,
height: 14,
},
},
}))(Badge)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does (Badge) do here? Is that applying the styles for Badge as well?

Copy link
Collaborator Author

@BrunoQuaresma BrunoQuaresma Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is a better way, IMO, to modify component styles. So what it does is extend the Badge component with the new styles.


export type GroupAvatarProps = {
name: string
}

export const GroupAvatar: FC<GroupAvatarProps> = ({ name }) => {
return (
<StyledBadge
overlap="circular"
anchorOrigin={{
vertical: "bottom",
horizontal: "right",
}}
badgeContent={<Group />}
>
<Avatar>{firstLetter(name)}</Avatar>
</StyledBadge>
)
}
2 changes: 2 additions & 0 deletions site/src/pages/GroupsPage/GroupsPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import React from "react"
import { Link as RouterLink, useNavigate } from "react-router-dom"
import { Paywall } from "components/Paywall/Paywall"
import { Group } from "api/typesGenerated"
import { GroupAvatar } from "components/GroupAvatar/GroupAvatar"

export type GroupsPageViewProps = {
groups: Group[] | undefined
Expand Down Expand Up @@ -135,6 +136,7 @@ export const GroupsPageView: React.FC<GroupsPageViewProps> = ({
>
<TableCell>
<AvatarData
avatar={<GroupAvatar name={group.name} />}
title={group.name}
subtitle={`${group.members.length} members`}
highlightTitle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from "components/UserOrGroupAutocomplete/UserOrGroupAutocomplete"
import { FC, useState } from "react"
import { Maybe } from "components/Conditionals/Maybe"
import { GroupAvatar } from "components/GroupAvatar/GroupAvatar"

type AddTemplateUserOrGroupProps = {
organizationId: string
Expand Down Expand Up @@ -208,6 +209,7 @@ export const TemplatePermissionsPageView: FC<
<TableRow key={group.id}>
<TableCell>
<AvatarData
avatar={<GroupAvatar name={group.name} />}
title={group.name}
subtitle={`${group.members.length} members`}
highlightTitle
Expand Down
2 changes: 1 addition & 1 deletion site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const MockUser: TypesGen.User = {
status: "active",
organization_ids: ["fc0774ce-cc9e-48d4-80ae-88f7a4d4a8b0"],
roles: [MockOwnerRole],
avatar_url: "https://github.com/coder.png",
avatar_url: "https://avatars.githubusercontent.com/u/95932066?s=200&v=4",
last_seen_at: "",
}

Expand Down