Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,12 @@ export const Error: Story = {
error: mockApiError({ message: "Something went wrong" }),
},
};

export const InvalidPageNumber: Story = {
args: {
workspaces: [],
count: 5,
limit: 25,
page: 1000,
},
};
51 changes: 39 additions & 12 deletions site/src/pages/WorkspacesPage/WorkspacesPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import KeyboardArrowDownOutlined from "@mui/icons-material/KeyboardArrowDownOutl
import PlayArrowOutlined from "@mui/icons-material/PlayArrowOutlined";
import StopOutlined from "@mui/icons-material/StopOutlined";
import LoadingButton from "@mui/lab/LoadingButton";
import Button from "@mui/material/Button";
import Divider from "@mui/material/Divider";
import type { ComponentProps } from "react";
import type { UseQueryResult } from "react-query";
import { hasError, isApiValidationError } from "api/errors";
import type { Template, Workspace } from "api/typesGenerated";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { EmptyState } from "components/EmptyState/EmptyState";
import { Margins } from "components/Margins/Margins";
import {
MoreMenu,
Expand Down Expand Up @@ -85,6 +87,11 @@ export const WorkspacesPageView = ({
canCreateTemplate,
canChangeVersions,
}: WorkspacesPageViewProps) => {
// Let's say the user has 5 workspaces, but tried to hit page 100, which does
// not exist. In this case, the page is not valid and we want to show a better
// error message.
const invalidPageNumber = page > 1 && workspaces?.length === 0;

return (
<Margins>
<PageHeader
Expand Down Expand Up @@ -167,7 +174,7 @@ export const WorkspacesPageView = ({
</MoreMenuContent>
</MoreMenu>
</>
) : (
) : invalidPageNumber ? null : (
<PaginationHeader
paginationUnitLabel="workspaces"
limit={limit}
Expand All @@ -178,18 +185,38 @@ export const WorkspacesPageView = ({
)}
</TableToolbar>

<WorkspacesTable
canCreateTemplate={canCreateTemplate}
workspaces={workspaces}
isUsingFilter={filterProps.filter.used}
onUpdateWorkspace={onUpdateWorkspace}
checkedWorkspaces={checkedWorkspaces}
onCheckChange={onCheckChange}
canCheckWorkspaces={canCheckWorkspaces}
templates={templates}
/>
{invalidPageNumber ? (
<EmptyState
css={(theme) => ({
border: `1px solid ${theme.palette.divider}`,
borderRadius: theme.shape.borderRadius,
})}
message="Page not found"
description="The page you are trying to access does not exist."
cta={
<Button
onClick={() => {
onPageChange(1);
}}
>
Back to the first page
</Button>
}
/>
) : (
<WorkspacesTable
canCreateTemplate={canCreateTemplate}
workspaces={workspaces}
isUsingFilter={filterProps.filter.used}
onUpdateWorkspace={onUpdateWorkspace}
checkedWorkspaces={checkedWorkspaces}
onCheckChange={onCheckChange}
canCheckWorkspaces={canCheckWorkspaces}
templates={templates}
/>
)}

{count !== undefined && (
{count !== undefined && !invalidPageNumber && (
// Temporary styling stopgap before component is migrated to using
// PaginationContainer (which renders PaginationWidgetBase using CSS
// flexbox gaps)
Expand Down