Skip to content

Commit ab90651

Browse files
refactor(site): Add skeletons for table loading state (#6626)
1 parent 811a69f commit ab90651

File tree

8 files changed

+72
-9
lines changed

8 files changed

+72
-9
lines changed

site/src/components/AvatarData/AvatarData.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ export const AvatarData: FC<PropsWithChildren<AvatarDataProps>> = ({
2323
}
2424

2525
return (
26-
<Stack spacing={1.5} direction="row" alignItems="center">
26+
<Stack
27+
spacing={1.5}
28+
direction="row"
29+
alignItems="center"
30+
className={styles.root}
31+
>
2732
{avatar}
2833

2934
<Stack spacing={0}>
@@ -35,6 +40,10 @@ export const AvatarData: FC<PropsWithChildren<AvatarDataProps>> = ({
3540
}
3641

3742
const useStyles = makeStyles((theme) => ({
43+
root: {
44+
minHeight: theme.spacing(5), // Make it predictable for the skeleton
45+
},
46+
3847
title: {
3948
color: theme.palette.text.primary,
4049
fontWeight: 600,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { FC } from "react"
2+
import { Stack } from "components/Stack/Stack"
3+
import { Skeleton } from "@material-ui/lab"
4+
5+
export const AvatarDataSkeleton: FC = () => {
6+
return (
7+
<Stack spacing={1.5} direction="row" alignItems="center">
8+
<Skeleton variant="circle" width={36} height={36} />
9+
10+
<Stack spacing={0}>
11+
<Skeleton variant="text" width={100} />
12+
<Skeleton variant="text" width={60} />
13+
</Stack>
14+
</Stack>
15+
)
16+
}

site/src/components/TableLoader/TableLoader.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { makeStyles } from "@material-ui/core/styles"
22
import TableCell from "@material-ui/core/TableCell"
33
import TableRow from "@material-ui/core/TableRow"
4+
import Skeleton from "@material-ui/lab/Skeleton"
5+
import { AvatarDataSkeleton } from "components/AvatarData/AvatarDataSkeleton"
46
import { FC } from "react"
57
import { Loader } from "../Loader/Loader"
68

@@ -22,3 +24,36 @@ const useStyles = makeStyles((theme) => ({
2224
height: theme.spacing(20),
2325
},
2426
}))
27+
28+
export const TableLoaderSkeleton: FC<{
29+
columns: number
30+
rows?: number
31+
useAvatarData?: boolean
32+
}> = ({ columns, rows = 4, useAvatarData = false }) => {
33+
const placeholderColumns = Array(columns).fill(undefined)
34+
const placeholderRows = Array(rows).fill(undefined)
35+
36+
return (
37+
<>
38+
{placeholderRows.map((_, rowIndex) => (
39+
<TableRow key={rowIndex} role="progressbar" data-testid="loader">
40+
{placeholderColumns.map((_, columnIndex) => {
41+
if (useAvatarData && columnIndex === 0) {
42+
return (
43+
<TableCell key={columnIndex}>
44+
<AvatarDataSkeleton />
45+
</TableCell>
46+
)
47+
}
48+
49+
return (
50+
<TableCell key={columnIndex}>
51+
<Skeleton variant="text" width="25%" />
52+
</TableCell>
53+
)
54+
})}
55+
</TableRow>
56+
))}
57+
</>
58+
)
59+
}

site/src/components/UsersTable/UsersTableBody.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as TypesGen from "../../api/typesGenerated"
1111
import { combineClasses } from "../../util/combineClasses"
1212
import { AvatarData } from "../AvatarData/AvatarData"
1313
import { EmptyState } from "../EmptyState/EmptyState"
14-
import { TableLoader } from "../TableLoader/TableLoader"
14+
import { TableLoaderSkeleton } from "../TableLoader/TableLoader"
1515
import { TableRowMenu } from "../TableRowMenu/TableRowMenu"
1616
import { EditRolesButton } from "components/EditRolesButton/EditRolesButton"
1717
import { Stack } from "components/Stack/Stack"
@@ -70,7 +70,7 @@ export const UsersTableBody: FC<
7070
return (
7171
<ChooseOne>
7272
<Cond condition={Boolean(isLoading)}>
73-
<TableLoader />
73+
<TableLoaderSkeleton columns={4} useAvatarData />
7474
</Cond>
7575
<Cond condition={!users || users.length === 0}>
7676
<ChooseOne>

site/src/components/WorkspacesTable/WorkspacesTableBody.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { TableEmpty } from "components/TableEmpty/TableEmpty"
88
import { FC } from "react"
99
import { useTranslation } from "react-i18next"
1010
import { Link as RouterLink } from "react-router-dom"
11-
import { TableLoader } from "../TableLoader/TableLoader"
11+
import { TableLoaderSkeleton } from "../TableLoader/TableLoader"
1212
import { WorkspacesRow } from "./WorkspacesRow"
1313

1414
interface TableBodyProps {
@@ -29,7 +29,7 @@ export const WorkspacesTableBody: FC<
2929
}
3030

3131
if (!workspaces) {
32-
return <TableLoader />
32+
return <TableLoaderSkeleton columns={4} useAvatarData />
3333
}
3434

3535
if (workspaces.length === 0) {

site/src/pages/GroupsPage/GroupsPageView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { AvatarData } from "components/AvatarData/AvatarData"
1515
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne"
1616
import { EmptyState } from "components/EmptyState/EmptyState"
1717
import { Stack } from "components/Stack/Stack"
18-
import { TableLoader } from "components/TableLoader/TableLoader"
18+
import { TableLoaderSkeleton } from "components/TableLoader/TableLoader"
1919
import { UserAvatar } from "components/UserAvatar/UserAvatar"
2020
import { FC } from "react"
2121
import { Link as RouterLink, useNavigate } from "react-router-dom"
@@ -83,7 +83,7 @@ export const GroupsPageView: FC<GroupsPageViewProps> = ({
8383
<TableBody>
8484
<ChooseOne>
8585
<Cond condition={isLoading}>
86-
<TableLoader />
86+
<TableLoaderSkeleton columns={2} useAvatarData />
8787
</Cond>
8888

8989
<Cond condition={isEmpty}>

site/src/pages/TemplatesPage/TemplatesPageView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
PageHeaderTitle,
2727
} from "../../components/PageHeader/PageHeader"
2828
import { Stack } from "../../components/Stack/Stack"
29-
import { TableLoader } from "../../components/TableLoader/TableLoader"
29+
import { TableLoaderSkeleton } from "../../components/TableLoader/TableLoader"
3030
import {
3131
HelpTooltip,
3232
HelpTooltipLink,
@@ -210,7 +210,7 @@ export const TemplatesPageView: FC<
210210
</TableHead>
211211
<TableBody>
212212
<Maybe condition={isLoading}>
213-
<TableLoader />
213+
<TableLoaderSkeleton columns={4} useAvatarData />
214214
</Maybe>
215215

216216
<ChooseOne>

site/src/theme/props.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,7 @@ export const props = {
4141
MuiPaper: {
4242
elevation: 0,
4343
},
44+
MuiSkeleton: {
45+
animation: "wave",
46+
},
4447
} as ComponentsProps

0 commit comments

Comments
 (0)