Skip to content

refactor(site): improve the overall user table design #9342

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 6 commits into from
Aug 25, 2023
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 last seen table value
  • Loading branch information
BrunoQuaresma committed Aug 25, 2023
commit 55dd4b07fe8868b8d394634537c8a50e8cae26e0
6 changes: 2 additions & 4 deletions site/src/components/UsersTable/UsersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ export const UsersTable: FC<React.PropsWithChildren<UsersTableProps>> = ({
<UserRoleHelpTooltip />
</Stack>
</TableCell>
<TableCell width="10%">{Language.loginTypeLabel}</TableCell>
<TableCell width="10%">{Language.statusLabel}</TableCell>
<TableCell width="10%">{Language.lastSeenLabel}</TableCell>

<TableCell width="15%">{Language.loginTypeLabel}</TableCell>
<TableCell width="15%">{Language.statusLabel}</TableCell>
{/* 1% is a trick to make the table cell width fit the content */}
{canEditUsers && <TableCell width="1%" />}
</TableRow>
Expand Down
52 changes: 45 additions & 7 deletions site/src/components/UsersTable/UsersTableBody.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Box from "@mui/material/Box"
import { makeStyles } from "@mui/styles"
import Box, { BoxProps } from "@mui/material/Box"
import { makeStyles, useTheme } from "@mui/styles"
import TableCell from "@mui/material/TableCell"
import TableRow from "@mui/material/TableRow"
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne"
import { LastUsed } from "components/LastUsed/LastUsed"
import { Pill } from "components/Pill/Pill"
import { FC } from "react"
import { useTranslation } from "react-i18next"
Expand All @@ -16,6 +15,8 @@ import { TableRowMenu } from "../TableRowMenu/TableRowMenu"
import { EditRolesButton } from "components/EditRolesButton/EditRolesButton"
import { Stack } from "components/Stack/Stack"
import { EnterpriseBadge } from "components/DeploySettingsLayout/Badges"
import dayjs from "dayjs"
import { Theme } from "@mui/material/styles"

const isOwnerRole = (role: TypesGen.Role): boolean => {
return role.name === "owner"
Expand Down Expand Up @@ -166,11 +167,10 @@ export const UsersTableBody: FC<
: undefined,
])}
>
{user.status}
</TableCell>
<TableCell>
<LastUsed lastUsedAt={user.last_seen_at} />
<Box>{user.status}</Box>
<LastSeen value={user.last_seen_at} sx={{ fontSize: 12 }} />
</TableCell>

{canEditUsers && (
<TableCell>
<TableRowMenu
Expand Down Expand Up @@ -236,6 +236,44 @@ export const UsersTableBody: FC<
)
}

export const LastSeen = ({
value,
...boxProps
}: { value: string } & BoxProps) => {
const theme: Theme = useTheme()
const t = dayjs(value)
const now = dayjs()

let message = t.fromNow()
let color = theme.palette.text.secondary

if (t.isAfter(now.subtract(1, "hour"))) {
color = theme.palette.success.light
// 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
} else if (t.isAfter(now.subtract(1, "month"))) {
color = theme.palette.warning.light
} else if (t.isAfter(now.subtract(100, "year"))) {
color = theme.palette.error.light
} else {
message = "Never"
}

return (
<Box
component="span"
data-chromatic="ignore"
{...boxProps}
sx={{ color, ...boxProps.sx }}
>
{message}
</Box>
)
}

const useStyles = makeStyles((theme) => ({
status: {
textTransform: "capitalize",
Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/WorkspacesPage/WorkspacesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Box from "@mui/material/Box"
import { AvatarData } from "components/AvatarData/AvatarData"
import { Avatar } from "components/Avatar/Avatar"
import { Stack } from "components/Stack/Stack"
import { LastUsed } from "components/LastUsed/LastUsed"
import { LastUsed } from "pages/WorkspacesPage/LastUsed"
import { WorkspaceOutdatedTooltip } from "components/Tooltips"
import { WorkspaceStatusBadge } from "components/WorkspaceStatusBadge/WorkspaceStatusBadge"
import { getDisplayWorkspaceTemplateName } from "utils/workspace"
Expand Down