Skip to content

refactor: Update users page to looks like others #1850

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 4 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 23 additions & 0 deletions site/src/components/AvatarData/AvatarData.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Story } from "@storybook/react"
import React from "react"
import { AvatarData, AvatarDataProps } from "./AvatarData"

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

const Template: Story<AvatarDataProps> = (args: AvatarDataProps) => <AvatarData {...args} />

export const Example = Template.bind({})
Example.args = {
title: "coder",
subtitle: "coder@coder.com",
}

export const WithLink = Template.bind({})
WithLink.args = {
title: "coder",
subtitle: "coder@coder.com",
link: "/users/coder",
}
67 changes: 67 additions & 0 deletions site/src/components/AvatarData/AvatarData.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import Avatar from "@material-ui/core/Avatar"
import Link from "@material-ui/core/Link"
import { makeStyles } from "@material-ui/core/styles"
import React from "react"
import { Link as RouterLink } from "react-router-dom"
import { combineClasses } from "../../util/combineClasses"
import { firstLetter } from "../../util/firstLetter"

export interface AvatarDataProps {
title: string
subtitle: string
link?: string
}

export const AvatarData: React.FC<AvatarDataProps> = ({ title, subtitle, link }) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't find a better name for it 😓

Copy link
Member

Choose a reason for hiding this comment

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

Seems fine!

const styles = useStyles()

return (
<div className={styles.root}>
<Avatar variant="square" className={styles.avatar}>
{firstLetter(title)}
</Avatar>

{link ? (
<Link component={RouterLink} to={link} className={combineClasses([styles.info, styles.link])}>
<b>{title}</b>
<span>{subtitle}</span>
</Link>
) : (
<div className={styles.info}>
<b>{title}</b>
<span>{subtitle}</span>
</div>
)}
</div>
)
}

const useStyles = makeStyles((theme) => ({
root: {
display: "flex",
alignItems: "center",
},
avatar: {
borderRadius: 2,
marginRight: theme.spacing(1),
width: 24,
height: 24,
fontSize: 16,
},
info: {
display: "flex",
flexDirection: "column",
color: theme.palette.text.primary,

"& span": {
fontSize: 12,
color: theme.palette.text.secondary,
},
},
link: {
textDecoration: "none",
"&:hover": {
textDecoration: "underline",
},
},
}))
28 changes: 0 additions & 28 deletions site/src/components/Header/Header.test.tsx

This file was deleted.

118 changes: 0 additions & 118 deletions site/src/components/Header/Header.tsx

This file was deleted.

35 changes: 0 additions & 35 deletions site/src/components/HeaderButton/HeaderButton.tsx

This file was deleted.

5 changes: 5 additions & 0 deletions site/src/components/RoleSelect/RoleSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,10 @@ const useStyles = makeStyles((theme: Theme) => ({
// Set a fixed width for the select. It avoids selects having different sizes
// depending on how many roles they have selected.
width: theme.spacing(25),
"& .MuiSelect-root": {
// Adjusting padding because it does not have label
paddingTop: theme.spacing(1.5),
paddingBottom: theme.spacing(1.5),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added these because the select when there is no label is very BIG.

},
},
}))
4 changes: 2 additions & 2 deletions site/src/components/UsersTable/UsersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import TableHead from "@material-ui/core/TableHead"
import TableRow from "@material-ui/core/TableRow"
import React from "react"
import * as TypesGen from "../../api/typesGenerated"
import { AvatarData } from "../AvatarData/AvatarData"
import { EmptyState } from "../EmptyState/EmptyState"
import { RoleSelect } from "../RoleSelect/RoleSelect"
import { TableLoader } from "../TableLoader/TableLoader"
import { TableRowMenu } from "../TableRowMenu/TableRowMenu"
import { UserCell } from "../UserCell/UserCell"

export const Language = {
pageTitle: "Users",
Expand Down Expand Up @@ -60,7 +60,7 @@ export const UsersTable: React.FC<UsersTableProps> = ({
users.map((u) => (
<TableRow key={u.id}>
<TableCell>
<UserCell Avatar={{ username: u.username }} primaryText={u.username} caption={u.email} />{" "}
<AvatarData title={u.username} subtitle={u.email} />
</TableCell>
<TableCell>
{canEditUsers ? (
Expand Down
18 changes: 6 additions & 12 deletions site/src/pages/TemplatesPage/TemplatesPageView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Avatar from "@material-ui/core/Avatar"
import Box from "@material-ui/core/Box"
import Link from "@material-ui/core/Link"
import { makeStyles } from "@material-ui/core/styles"
import Table from "@material-ui/core/Table"
Expand All @@ -12,10 +10,10 @@ import relativeTime from "dayjs/plugin/relativeTime"
import React from "react"
import { Link as RouterLink } from "react-router-dom"
import * as TypesGen from "../../api/typesGenerated"
import { AvatarData } from "../../components/AvatarData/AvatarData"
import { Margins } from "../../components/Margins/Margins"
import { Stack } from "../../components/Stack/Stack"
import { TableLoader } from "../../components/TableLoader/TableLoader"
import { firstLetter } from "../../util/firstLetter"

dayjs.extend(relativeTime)

Expand Down Expand Up @@ -73,15 +71,11 @@ export const TemplatesPageView: React.FC<TemplatesPageViewProps> = (props) => {
{props.templates?.map((template) => (
<TableRow key={template.id}>
<TableCell>
<Box alignItems="center" display="flex">
<Avatar variant="square" className={styles.templateAvatar}>
{firstLetter(template.name)}
</Avatar>
<Link component={RouterLink} to={`/templates/${template.name}`} className={styles.templateLink}>
<b>{template.name}</b>
<span>{template.description}</span>
</Link>
</Box>
<AvatarData
title={template.name}
subtitle={template.description}
link={`/templates/${template.name}`}
/>
</TableCell>

<TableCell>{Language.developerCount(template.workspace_owner_count)}</TableCell>
Expand Down
Loading