Skip to content

Commit 86caa80

Browse files
committed
Handle errors
1 parent bdb0614 commit 86caa80

File tree

5 files changed

+247
-211
lines changed

5 files changed

+247
-211
lines changed

site/src/api/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export const getWorkspaces = async (
288288

289289
// TODO change types
290290
export const getWorkspacesCount = async (
291-
options: TypesGen.AuditLogCountRequest = {}
291+
options: TypesGen.AuditLogCountRequest = {},
292292
): Promise<TypesGen.AuditLogCountResponse> => {
293293
const searchParams = new URLSearchParams()
294294
if (options.q) {

site/src/components/AlertBanner/AlertBanner.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import { severityConstants } from "./severityConstants"
1111
import { AlertBannerCtas } from "./AlertBannerCtas"
1212

1313
/**
14-
* severity: the level of alert severity (see ./severityTypes.ts)
15-
* text: default text to be displayed to the user; useful for warnings or as a fallback error message
16-
* error: should be passed in if the severity is 'Error'; warnings can use 'text' instead
17-
* actions: an array of CTAs passed in by the consumer
18-
* dismissible: determines whether or not the banner should have a `Dismiss` CTA
19-
* retry: a handler to retry the action that spawned the error
14+
* @param severity: the level of alert severity (see ./severityTypes.ts)
15+
* @param text: default text to be displayed to the user; useful for warnings or as a fallback error message
16+
* @param error: should be passed in if the severity is 'Error'; warnings can use 'text' instead
17+
* @param actions: an array of CTAs passed in by the consumer
18+
* @param dismissible: determines whether or not the banner should have a `Dismiss` CTA
19+
* @param retry: a handler to retry the action that spawned the error
2020
*/
2121
export const AlertBanner: FC<AlertBannerProps> = ({
2222
severity,

site/src/pages/WorkspacesPage/WorkspacesPage.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { useMachine } from "@xstate/react"
22
import { FC } from "react"
33
import { Helmet } from "react-helmet-async"
4-
import { useSearchParams } from "react-router-dom"
4+
import { useNavigate, useSearchParams } from "react-router-dom"
55
import { workspaceFilterQuery } from "util/filters"
66
import { pageTitle } from "util/page"
77
import { workspacesMachine } from "xServices/workspaces/workspacesXService"
88
import { WorkspacesPageView } from "./WorkspacesPageView"
99

1010
const WorkspacesPage: FC = () => {
11+
const navigate = useNavigate()
1112
const [searchParams, setSearchParams] = useSearchParams()
1213
const filter = searchParams.get("filter") ?? workspaceFilterQuery.me
1314
const currentPage = searchParams.get("page")
@@ -16,7 +17,7 @@ const WorkspacesPage: FC = () => {
1617
const [workspacesState, send] = useMachine(workspacesMachine, {
1718
context: {
1819
page: currentPage,
19-
limit: 25,
20+
limit: 2, //TODO
2021
filter,
2122
},
2223
actions: {
@@ -28,7 +29,14 @@ const WorkspacesPage: FC = () => {
2829
},
2930
})
3031

31-
const { workspaceRefs, count, page, limit } = workspacesState.context
32+
const {
33+
workspaceRefs,
34+
count,
35+
page,
36+
limit,
37+
getWorkspacesError,
38+
getCountError,
39+
} = workspacesState.context
3240

3341
return (
3442
<>
@@ -41,6 +49,8 @@ const WorkspacesPage: FC = () => {
4149
isLoading={!workspaceRefs}
4250
workspaceRefs={workspaceRefs}
4351
count={count}
52+
getWorkspacesError={getWorkspacesError}
53+
getCountError={getCountError}
4454
page={page}
4555
limit={limit}
4656
onNext={() => {

site/src/pages/WorkspacesPage/WorkspacesPageView.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Link from "@material-ui/core/Link"
2+
import { AlertBanner } from "components/AlertBanner/AlertBanner"
23
import { Maybe } from "components/Conditionals/Maybe"
34
import { PaginationWidget } from "components/PaginationWidget/PaginationWidget"
45
import { FC } from "react"
@@ -29,6 +30,8 @@ export interface WorkspacesPageViewProps {
2930
isLoading?: boolean
3031
workspaceRefs?: WorkspaceItemMachineRef[]
3132
count?: number
33+
getWorkspacesError: Error | unknown
34+
getCountError: Error | unknown
3235
page: number
3336
limit: number
3437
filter?: string
@@ -44,6 +47,8 @@ export const WorkspacesPageView: FC<
4447
isLoading,
4548
workspaceRefs,
4649
count,
50+
getWorkspacesError,
51+
getCountError,
4752
page,
4853
limit,
4954
filter,
@@ -80,6 +85,21 @@ export const WorkspacesPageView: FC<
8085
</PageHeaderSubtitle>
8186
</PageHeader>
8287

88+
<Maybe condition={getWorkspacesError !== undefined}>
89+
<AlertBanner
90+
error={getWorkspacesError}
91+
severity={
92+
workspaceRefs !== undefined && workspaceRefs.length > 0
93+
? "warning"
94+
: "error"
95+
}
96+
/>
97+
</Maybe>
98+
99+
<Maybe condition={getCountError !== undefined}>
100+
<AlertBanner error={getCountError} severity="warning" />
101+
</Maybe>
102+
83103
<SearchBarWithFilter
84104
filter={filter}
85105
onFilter={onFilter}

0 commit comments

Comments
 (0)