Skip to content

refactor(site): Remove version and add template link in workspaces page #5990

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
Feb 2, 2023
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
2 changes: 1 addition & 1 deletion site/src/components/AvatarData/AvatarData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Stack } from "components/Stack/Stack"
import { makeStyles } from "@material-ui/core/styles"

export interface AvatarDataProps {
title: string
title: string | JSX.Element
subtitle?: string
src?: string
avatar?: React.ReactNode
Expand Down
63 changes: 35 additions & 28 deletions site/src/components/LastUsed/LastUsed.tsx
Original file line number Diff line number Diff line change
@@ -1,69 +1,76 @@
import { makeStyles, Theme, useTheme } from "@material-ui/core/styles"
import { FC } from "react"

import Icon from "@material-ui/icons/Brightness1"
import dayjs from "dayjs"
import relativeTime from "dayjs/plugin/relativeTime"
import { colors } from "theme/colors"
import { Stack } from "components/Stack/Stack"

dayjs.extend(relativeTime)

type CircleProps = { color: string; variant?: "solid" | "outlined" }

const Circle: FC<CircleProps> = ({ color, variant = "solid" }) => {
const styles = useCircleStyles({ color, variant })
return <div className={styles.root} />
}

const useCircleStyles = makeStyles((theme) => ({
root: {
width: theme.spacing(1),
height: theme.spacing(1),
backgroundColor: (props: CircleProps) =>
props.variant === "solid" ? props.color : undefined,
border: (props: CircleProps) =>
props.variant === "outlined" ? `1px solid ${props.color}` : undefined,
borderRadius: 9999,
},
}))

interface LastUsedProps {
lastUsedAt: string
}

export const LastUsed: FC<LastUsedProps> = ({ lastUsedAt }) => {
const theme: Theme = useTheme()
const styles = useStyles()

const t = dayjs(lastUsedAt)
const now = dayjs()

let color = theme.palette.text.secondary
let message = t.fromNow()
let displayCircle = true
let circle: JSX.Element = (
<Circle color={theme.palette.text.secondary} variant="outlined" />
)

if (t.isAfter(now.subtract(1, "hour"))) {
color = colors.green[9]
circle = <Circle color={colors.green[9]} />
// Since the agent reports on a 10m interval,
// the last_used_at can be inaccurate when recent.
message = "Now"
} else if (t.isAfter(now.subtract(3, "day"))) {
color = theme.palette.text.secondary
circle = <Circle color={theme.palette.text.secondary} />
} else if (t.isAfter(now.subtract(1, "month"))) {
color = theme.palette.warning.light
circle = <Circle color={theme.palette.warning.light} />
} else if (t.isAfter(now.subtract(100, "year"))) {
color = colors.red[10]
circle = <Circle color={colors.red[10]} />
} else {
// color = theme.palette.error.light
message = "Never"
displayCircle = false
}

return (
<span className={styles.root}>
<span
style={{
color: color,
display: displayCircle ? undefined : "none",
}}
>
<Icon className={styles.icon} />
</span>
<Stack
className={styles.root}
direction="row"
spacing={1}
alignItems="center"
>
{circle}
<span data-chromatic="ignore">{message}</span>
</span>
</Stack>
)
}

const useStyles = makeStyles((theme) => ({
root: {
display: "flex",
alignItems: "center",
color: theme.palette.text.secondary,
},
icon: {
marginRight: 8,
width: 10,
height: 10,
},
}))
4 changes: 2 additions & 2 deletions site/src/components/Tooltips/HelpTooltip/HelpTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export const HelpTooltipLinksGroup: FC<PropsWithChildren<unknown>> = ({
const getButtonSpacingFromSize = (size?: Size): number => {
switch (size) {
case "small":
return 2.75
return 2.5
case "medium":
default:
return 3
Expand All @@ -208,7 +208,7 @@ const getButtonSpacingFromSize = (size?: Size): number => {
const getIconSpacingFromSize = (size?: Size): number => {
switch (size) {
case "small":
return 1.75
return 1.5
case "medium":
default:
return 2
Expand Down
61 changes: 38 additions & 23 deletions site/src/components/WorkspacesTable/WorkspacesRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ 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 { useNavigate, Link as RouterLink } from "react-router-dom"
import { getDisplayWorkspaceTemplateName } from "util/workspace"
import { LastUsed } from "../LastUsed/LastUsed"
import { Workspace } from "api/typesGenerated"
import { OutdatedHelpTooltip } from "components/Tooltips/OutdatedHelpTooltip"
import { Avatar } from "components/Avatar/Avatar"
import { Stack } from "components/Stack/Stack"
import TemplateLinkIcon from "@material-ui/icons/OpenInNewOutlined"
import Link from "@material-ui/core/Link"

export const WorkspacesRow: FC<{
workspace: Workspace
Expand All @@ -36,7 +39,18 @@ export const WorkspacesRow: FC<{
>
<TableCell>
<AvatarData
title={workspace.name}
title={
<Stack direction="row" spacing={0} alignItems="center">
{workspace.name}
{workspace.outdated && (
<OutdatedHelpTooltip
onUpdateVersion={() => {
onUpdateWorkspace(workspace)
}}
/>
)}
</Stack>
}
subtitle={workspace.owner_name}
avatar={
hasTemplateIcon && (
Expand All @@ -46,19 +60,21 @@ export const WorkspacesRow: FC<{
/>
</TableCell>

<TableCell>{displayTemplateName}</TableCell>

<TableCell>
<div className={styles.version}>
{workspace.latest_build.template_version_name}
{workspace.outdated && (
<OutdatedHelpTooltip
onUpdateVersion={() => {
onUpdateWorkspace(workspace)
}}
/>
)}
</div>
<Link
component={RouterLink}
to={`/templates/${workspace.template_name}`}
className={styles.templateLink}
title={`Go to ${displayTemplateName} page`}
onClick={(e) => {
e.stopPropagation()
}}
>
<Stack direction="row" alignItems="center" spacing={1}>
<TemplateLinkIcon className={styles.templateLinkIcon} />
<span>{displayTemplateName}</span>
</Stack>
</Link>
</TableCell>

<TableCell>
Expand Down Expand Up @@ -99,18 +115,17 @@ const useStyles = makeStyles((theme) => ({
paddingLeft: theme.spacing(2),
},

templateIconWrapper: {
// Same size then the avatar component
width: 36,
height: 36,
padding: 2,
templateLink: {
color: theme.palette.text.secondary,

"& img": {
width: "100%",
"&:hover": {
color: theme.palette.text.primary,
textDecoration: "none",
},
},

version: {
display: "flex",
templateLinkIcon: {
width: theme.spacing(1.5),
height: theme.spacing(1.5),
},
}))
8 changes: 3 additions & 5 deletions site/src/components/WorkspacesTable/WorkspacesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const Language = {
name: "Name",
template: "Template",
lastUsed: "Last Used",
version: "Version",
status: "Status",
lastBuiltBy: "Last Built By",
}
Expand All @@ -33,12 +32,11 @@ export const WorkspacesTable: FC<WorkspacesTableProps> = ({
<Table>
<TableHead>
<TableRow>
<TableCell width="30%">{Language.name}</TableCell>
<TableCell width="40%">{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.status}</TableCell>
<TableCell width="1%"></TableCell>
<TableCell width="15%">{Language.status}</TableCell>
<TableCell width="1%" />
</TableRow>
</TableHead>
<TableBody>
Expand Down