Skip to content

refactor: Remove avatar from workspace name #3006

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
Jul 15, 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
Next Next commit
refactor: Remove avatar from workspace name
  • Loading branch information
BrunoQuaresma committed Jul 15, 2022
commit 54d643c61dc4bfe32ccfb35c2064c30bb310ef68
45 changes: 16 additions & 29 deletions site/src/components/AvatarData/AvatarData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,39 @@ import Link from "@material-ui/core/Link"
import { makeStyles } from "@material-ui/core/styles"
import { FC } from "react"
import { Link as RouterLink } from "react-router-dom"
import { combineClasses } from "../../util/combineClasses"
import { firstLetter } from "../../util/firstLetter"
import {
TableCellData,
TableCellDataPrimary,
TableCellDataSecondary,
} from "../TableCellData/TableCellData"

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

export const AvatarData: FC<AvatarDataProps> = ({ title, subtitle, link }) => {
export const AvatarData: FC<AvatarDataProps> = ({ title, subtitle, link, highlightTitle }) => {
const styles = useStyles()

return (
<div className={styles.root}>
<Avatar 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 to={link} underline="none" component={RouterLink}>
<TableCellData>
<TableCellDataPrimary highlight={highlightTitle}>{title}</TableCellDataPrimary>
<TableCellDataSecondary>{subtitle}</TableCellDataSecondary>
</TableCellData>
</Link>
) : (
<div className={styles.info}>
<b>{title}</b>
<span>{subtitle}</span>
</div>
<TableCellData>
<TableCellDataPrimary highlight={highlightTitle}>{title}</TableCellDataPrimary>
<TableCellDataSecondary>{subtitle}</TableCellDataSecondary>
</TableCellData>
)}
</div>
)
Expand All @@ -46,20 +49,4 @@ const useStyles = makeStyles((theme) => ({
avatar: {
marginRight: theme.spacing(1.5),
},
info: {
display: "flex",
flexDirection: "column",
color: theme.palette.text.primary,

"& span": {
fontSize: 12,
color: theme.palette.text.secondary,
},
},
link: {
textDecoration: "none",
"&:hover": {
textDecoration: "underline",
},
},
}))
35 changes: 35 additions & 0 deletions site/src/components/TableCellData/TableCellData.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { makeStyles } from "@material-ui/core/styles"
import React from "react"
import { Stack } from "../Stack/Stack"

export const TableCellData: React.FC = ({ children }) => {
return <Stack spacing={0}>{children}</Stack>
}

export const TableCellDataPrimary: React.FC<{ highlight?: boolean }> = ({
children,
highlight,
}) => {
const styles = useStyles({ highlight })

return <span className={styles.primary}>{children}</span>
}

export const TableCellDataSecondary: React.FC = ({ children }) => {
const styles = useStyles()

return <span className={styles.secondary}>{children}</span>
}

const useStyles = makeStyles((theme) => ({
Copy link
Member

@Kira-Pilot Kira-Pilot Jul 15, 2022

Choose a reason for hiding this comment

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

If you want, you can type this whole style hook so that you don't have to redeclare the type every time you use the highlight prop below:

import { Theme } from "@material-ui/core/styles/createMuiTheme"

interface StyleProps {
  highlight?: boolean
}

const useStyles = makeStyles<Theme, StyleProps>((theme) => ({
....

primary: {
color: ({ highlight }: { highlight?: boolean }) =>
highlight ? theme.palette.text.primary : theme.palette.text.secondary,
fontWeight: ({ highlight }: { highlight?: boolean }) => (highlight ? 600 : undefined),
},

secondary: {
fontSize: 12,
color: theme.palette.text.secondary,
},
}))
2 changes: 1 addition & 1 deletion site/src/components/UsersTable/UsersTableBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const UsersTableBody: FC<UsersTableBodyProps> = ({
return (
<TableRow key={user.id}>
<TableCell>
<AvatarData title={user.username} subtitle={user.email} />
<AvatarData title={user.username} subtitle={user.email} highlightTitle />
</TableCell>
<TableCell
className={combineClasses([
Expand Down
13 changes: 11 additions & 2 deletions site/src/components/WorkspacesTable/WorkspacesRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import { useNavigate } from "react-router-dom"
import { getDisplayStatus, getDisplayWorkspaceBuildInitiatedBy } from "../../util/workspace"
import { WorkspaceItemMachineRef } from "../../xServices/workspaces/workspacesXService"
import { AvatarData } from "../AvatarData/AvatarData"
import {
TableCellData,
TableCellDataPrimary,
TableCellDataSecondary,
} from "../TableCellData/TableCellData"
import { TableCellLink } from "../TableCellLink/TableCellLink"
import { OutdatedHelpTooltip } from "../Tooltips"

Expand Down Expand Up @@ -43,15 +48,19 @@ export const WorkspacesRow: FC<{ workspaceRef: WorkspaceItemMachineRef }> = ({ w
className={styles.clickableTableRow}
>
<TableCellLink to={workspacePageLink}>
<AvatarData title={workspace.name} subtitle={workspace.owner_name} />
<TableCellData>
<TableCellDataPrimary highlight>{workspace.name}</TableCellDataPrimary>
<TableCellDataSecondary>{workspace.owner_name}</TableCellDataSecondary>
</TableCellData>
</TableCellLink>

<TableCellLink to={workspacePageLink}>{workspace.template_name}</TableCellLink>
<TableCellLink to={workspacePageLink}>
<AvatarData
title={initiatedBy}
subtitle={dayjs().to(dayjs(workspace.latest_build.created_at))}
/>
</TableCellLink>
<TableCellLink to={workspacePageLink}>{workspace.template_name}</TableCellLink>
<TableCellLink to={workspacePageLink}>
{workspace.outdated ? (
<span className={styles.outdatedLabel}>
Expand Down
4 changes: 2 additions & 2 deletions site/src/components/WorkspacesTable/WorkspacesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export const WorkspacesTable: FC<WorkspacesTableProps> = ({ isLoading, workspace
<TableHead>
<TableRow>
<TableCell width="25%">{Language.name}</TableCell>
<TableCell width="20%">{Language.lastBuiltBy}</TableCell>
<TableCell width="20%">{Language.template}</TableCell>
<TableCell width="20%">{Language.version}</TableCell>
<TableCell width="25%">{Language.lastBuiltBy}</TableCell>
<TableCell width="15%">{Language.version}</TableCell>
<TableCell width="15%">{Language.status}</TableCell>
<TableCell width="1%"></TableCell>
</TableRow>
Expand Down
6 changes: 5 additions & 1 deletion site/src/pages/TemplatesPage/TemplatesPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ export const TemplatesPageView: FC<TemplatesPageViewProps> = (props) => {
className={styles.clickableTableRow}
>
<TableCellLink to={templatePageLink}>
<AvatarData title={template.name} subtitle={template.description} />
<AvatarData
title={template.name}
subtitle={template.description}
highlightTitle
/>
</TableCellLink>

<TableCellLink to={templatePageLink}>
Expand Down