@@ -4,12 +4,14 @@ import KeyboardArrowDownOutlined from "@mui/icons-material/KeyboardArrowDownOutl
4
4
import PlayArrowOutlined from "@mui/icons-material/PlayArrowOutlined" ;
5
5
import StopOutlined from "@mui/icons-material/StopOutlined" ;
6
6
import LoadingButton from "@mui/lab/LoadingButton" ;
7
+ import Button from "@mui/material/Button" ;
7
8
import Divider from "@mui/material/Divider" ;
8
9
import type { ComponentProps } from "react" ;
9
10
import type { UseQueryResult } from "react-query" ;
10
11
import { hasError , isApiValidationError } from "api/errors" ;
11
12
import type { Template , Workspace } from "api/typesGenerated" ;
12
13
import { ErrorAlert } from "components/Alert/ErrorAlert" ;
14
+ import { EmptyState } from "components/EmptyState/EmptyState" ;
13
15
import { Margins } from "components/Margins/Margins" ;
14
16
import {
15
17
MoreMenu ,
@@ -85,6 +87,11 @@ export const WorkspacesPageView = ({
85
87
canCreateTemplate,
86
88
canChangeVersions,
87
89
} : WorkspacesPageViewProps ) => {
90
+ // Let's say the user has 5 workspaces, but tried to hit page 100, which does
91
+ // not exist. In this case, the page is not valid and we want to show a better
92
+ // error message.
93
+ const invalidPageNumber = page !== 1 && workspaces ?. length === 0 ;
94
+
88
95
return (
89
96
< Margins >
90
97
< PageHeader
@@ -168,26 +175,48 @@ export const WorkspacesPageView = ({
168
175
</ MoreMenu >
169
176
</ >
170
177
) : (
171
- < PaginationHeader
172
- paginationUnitLabel = "workspaces"
173
- limit = { limit }
174
- totalRecords = { count }
175
- currentOffsetStart = { ( page - 1 ) * limit + 1 }
176
- css = { { paddingBottom : "0" } }
177
- />
178
+ ! invalidPageNumber && (
179
+ < PaginationHeader
180
+ paginationUnitLabel = "workspaces"
181
+ limit = { limit }
182
+ totalRecords = { count }
183
+ currentOffsetStart = { ( page - 1 ) * limit + 1 }
184
+ css = { { paddingBottom : "0" } }
185
+ />
186
+ )
178
187
) }
179
188
</ TableToolbar >
180
189
181
- < WorkspacesTable
182
- canCreateTemplate = { canCreateTemplate }
183
- workspaces = { workspaces }
184
- isUsingFilter = { filterProps . filter . used }
185
- onUpdateWorkspace = { onUpdateWorkspace }
186
- checkedWorkspaces = { checkedWorkspaces }
187
- onCheckChange = { onCheckChange }
188
- canCheckWorkspaces = { canCheckWorkspaces }
189
- templates = { templates }
190
- />
190
+ { invalidPageNumber ? (
191
+ < EmptyState
192
+ css = { ( theme ) => ( {
193
+ border : `1px solid ${ theme . palette . divider } ` ,
194
+ borderRadius : theme . shape . borderRadius ,
195
+ } ) }
196
+ message = "Page not found"
197
+ description = "The page you are trying to access does not exist."
198
+ cta = {
199
+ < Button
200
+ onClick = { ( ) => {
201
+ onPageChange ( 1 ) ;
202
+ } }
203
+ >
204
+ Back to the first page
205
+ </ Button >
206
+ }
207
+ />
208
+ ) : (
209
+ < WorkspacesTable
210
+ canCreateTemplate = { canCreateTemplate }
211
+ workspaces = { workspaces }
212
+ isUsingFilter = { filterProps . filter . used }
213
+ onUpdateWorkspace = { onUpdateWorkspace }
214
+ checkedWorkspaces = { checkedWorkspaces }
215
+ onCheckChange = { onCheckChange }
216
+ canCheckWorkspaces = { canCheckWorkspaces }
217
+ templates = { templates }
218
+ />
219
+ ) }
191
220
192
221
{ count !== undefined && (
193
222
// Temporary styling stopgap before component is migrated to using
0 commit comments