8000 refactor: Show template version in the workspace page by BrunoQuaresma · Pull Request #5194 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

refactor: Show template version in the workspace page #5194

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 5 commits into from
Nov 30, 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
Prev Previous commit
Next Next commit
Display version on workspaces table
  • Loading branch information
BrunoQuaresma committed Nov 29, 2022
commit fffcecbc3d10799c610be80ff72272d59cfaef86
107 changes: 41 additions & 66 deletions site/src/components/WorkspacesTable/WorkspacesRow.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,41 @@
import { makeStyles, Theme } from "@material-ui/core/styles"
import TableCell from "@material-ui/core/TableCell"
import { makeStyles } from "@material-ui/core/styles"
import TableRow from "@material-ui/core/TableRow"
import KeyboardArrowRight from "@material-ui/icons/KeyboardArrowRight"
import useTheme from "@material-ui/styles/useTheme"
import { useActor } from "@xstate/react"
import { AvatarData } from "components/AvatarData/AvatarData"
import { WorkspaceStatusBadge } from "components/WorkspaceStatusBadge/WorkspaceStatusBadge"
import { useClickable } from "hooks/useClickable"
import { FC } from "react"
import { useNavigate } from "react-router-dom"
import { getDisplayWorkspaceTemplateName } from "util/workspace"
import { WorkspaceItemMachineRef } from "../../xServices/workspaces/workspacesXService"
import { LastUsed } from "../LastUsed/LastUsed"
import {
TableCellData,
TableCellDataPrimary,
} from "../TableCellData/TableCellData"
import { TableCellLink } from "../TableCellLink/TableCellLink"
import { OutdatedHelpTooltip } from "../Tooltip 8000 s"

const Language = {
upToDateLabel: "Up to date",
outdatedLabel: "Outdated",
}

export const WorkspacesRow: FC<
React.PropsWithChildren<{ workspaceRef: WorkspaceItemMachineRef }>
> = ({ workspaceRef }) => {
export const WorkspacesRow: FC<{ workspaceRef: WorkspaceItemMachineRef }> = ({
workspaceRef,
}) => {
const styles = useStyles()
const navigate = useNavigate()
const theme: Theme = useTheme()
const [workspaceState, send] = useActor(workspaceRef)
const { data: workspace } = workspaceState.context
const workspacePageLink = `/@${workspace.owner_name}/${workspace.name}`
const hasTemplateIcon =
workspace.template_icon && workspace.template_icon !== ""
const displayTemplateName = getDisplayWorkspaceTemplateName(workspace)
const clickable = useClickable(() => {
navigate(workspacePageLink)
})

return (
<TableRow
className={styles.row}
hover
data-testid={`workspace-${workspace.id}`}
tabIndex={0}
onKeyDown={(event) => {
if (event.key === "Enter") {
navigate(workspacePageLink)
}
}}
className={styles.clickableTableRow}
{...clickable}
>
<TableCellLink to={workspacePageLink}>
<TableCell>
<AvatarData
highlightTitle
title={workspace.name}
Expand All @@ -60,78 +48,61 @@ export const WorkspacesRow: FC<
) : undefined
}
/>
</TableCellLink>
</TableCell>

<TableCellLink to={workspacePageLink}>
<TableCellDataPrimary>{displayTemplateName}</TableCellDataPrimary>
</TableCellLink>
<TableCellLink to={workspacePageLink}>
<TableCellData>
<LastUsed lastUsedAt={workspace.last_used_at} />
</TableCellData>
</TableCellLink>
<TableCell>{displayTemplateName}</TableCell>

<TableCellLink to={workspacePageLink}>
{workspace.outdated ? (
<span className={styles.outdatedLabel}>
{Language.outdatedLabel}
<TableCell>
<div className={styles.version}>
{workspace.latest_build.template_version_name}
{workspace.outdated && (
<OutdatedHelpTooltip
onUpdateVersion={() => {
send("UPDATE_VERSION")
}}
/>
</span>
) : (
<span style={{ color: theme.palette.text.secondary }}>
{Language.upToDateLabel}
</span>
)}
</TableCellLink>
)}
</div>
</TableCell>

<TableCellLink to={workspacePageLink}>
<TableCell>
<LastUsed lastUsedAt={workspace.last_used_at} />
</TableCell>

<TableCell>
<WorkspaceStatusBadge build={workspace.latest_build} />
</TableCellLink>
<TableCellLink to={workspacePageLink}>
</TableCell>

<TableCell>
<div className={styles.arrowCell}>
<KeyboardArrowRight className={styles.arrowRight} />
</div>
</TableCellLink>
</TableCell>
</TableRow>
)
}

const useStyles = makeStyles((theme) => ({
clickableTableRow: {
"&:hover td": {
backgroundColor: theme.palette.action.hover,
},
row: {
cursor: "pointer",

"&:focus": {
outline: `1px solid ${theme.palette.secondary.dark}`,
},

"& .MuiTableCell-root:last-child": {
paddingRight: theme.spacing(2),
outlineOffset: -1,
},
},

arrowRight: {
color: theme.palette.text.secondary,
width: 20,
height: 20,
},

arrowCell: {
display: "flex",
paddingLeft: theme.spacing(2),
},
outdatedLabel: {
color: theme.palette.error.main,
display: "flex",
alignItems: "center",
gap: theme.spacing(0.5),
},
buildTime: {
color: theme.palette.text.secondary,
fontSize: 12,
},

templateIconWrapper: {
// Same size then the avatar component
width: 36,
Expand All @@ -142,4 +113,8 @@ const useStyles = makeStyles((theme) => ({
width: "100%",
},
},

version: {
display: "flex",
},
}))
6 changes: 3 additions & 3 deletions site/src/components/WorkspacesTable/WorkspacesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export const WorkspacesTable: FC<
<Table>
<TableHead>
<TableRow>
<TableCell width="25%">{Language.name}</TableCell>
<TableCell width="35%">{Language.template}</TableCell>
<TableCell width="30%">{Language.name}</TableCell>
<TableCell width="25%">{Language.template}</TableCell>
<TableCell width="25%">{Language.version}</TableCell>
<TableCell width="20%">{Language.lastUsed}</TableCell>
<TableCell width="20%">{Language.version}</TableCell>
<TableCell width="20%">{Language.status}</TableCell>
<TableCell width="1%"></TableCell>
</TableRow>
Expand Down
0