Skip to content

Commit dd481f5

Browse files
committed
Add errors to all search bar pages
1 parent 9d992b0 commit dd481f5

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

site/src/components/WorkspacesTable/WorkspacesTable.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ export interface WorkspacesTableProps {
2020
workspaces?: Workspace[]
2121
isUsingFilter: boolean
2222
onUpdateWorkspace: (workspace: Workspace) => void
23+
error?: Error | unknown
2324
}
2425

2526
export const WorkspacesTable: FC<WorkspacesTableProps> = ({
2627
workspaces,
2728
isUsingFilter,
2829
onUpdateWorkspace,
30+
error,
2931
}) => {
3032
return (
3133
<TableContainer>
@@ -44,6 +46,7 @@ export const WorkspacesTable: FC<WorkspacesTableProps> = ({
4446
workspaces={workspaces}
4547
isUsingFilter={isUsingFilter}
4648
onUpdateWorkspace={onUpdateWorkspace}
49+
error={error}
4750
/>
4851
</TableBody>
4952
</Table>

site/src/components/WorkspacesTable/WorkspacesTableBody.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ interface TableBodyProps {
1515
workspaces?: Workspace[]
1616
isUsingFilter: boolean
1717
onUpdateWorkspace: (workspace: Workspace) => void
18+
error?: Error | unknown
1819
}
1920

2021
export const WorkspacesTableBody: FC<
2122
React.PropsWithChildren<TableBodyProps>
22-
> = ({ workspaces, isUsingFilter, onUpdateWorkspace }) => {
23+
> = ({ workspaces, isUsingFilter, onUpdateWorkspace, error }) => {
2324
const { t } = useTranslation("workspacesPage")
2425
const styles = useStyles()
2526

27+
if (error) {
28+
return <TableEmpty message={t("emptyResultsMessage")} />
29+
}
30+
2631
if (!workspaces) {
2732
return <TableLoader />
2833
}

site/src/pages/AuditPage/AuditPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const AuditPage: FC = () => {
2626
},
2727
})
2828

29-
const { auditLogs, count } = auditState.context
29+
const { auditLogs, count, apiError } = auditState.context
3030
const paginationRef = auditState.context.paginationRef as PaginationMachineRef
3131
const { audit_log: isAuditLogVisible } = useFeatureVisibility()
3232

@@ -45,6 +45,7 @@ const AuditPage: FC = () => {
4545
paginationRef={paginationRef}
4646
isNonInitialPage={nonInitialPage(searchParams)}
4747
isAuditLogVisible={isAuditLogVisible}
48+
error={apiError}
4849
/>
4950
</>
5051
)

site/src/pages/AuditPage/AuditPageView.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface AuditPageViewProps {
5454
paginationRef: PaginationMachineRef
5555
isNonInitialPage: boolean
5656
isAuditLogVisible: boolean
57+
error?: Error | unknown
5758
}
5859

5960
export const AuditPageView: FC<AuditPageViewProps> = ({
@@ -64,8 +65,10 @@ export const AuditPageView: FC<AuditPageViewProps> = ({
6465
paginationRef,
6566
isNonInitialPage,
6667
isAuditLogVisible,
68+
error,
6769
}) => {
6870
const { t } = useTranslation("auditLog")
71+
6972
const isLoading = auditLogs === undefined || count === undefined
7073
const isEmpty = !isLoading && auditLogs.length === 0
7174

@@ -88,12 +91,21 @@ export const AuditPageView: FC<AuditPageViewProps> = ({
8891
filter={filter}
8992
onFilter={onFilter}
9093
presetFilters={presetFilters}
94+
error={error}
9195
/>
9296

9397
<TableContainer>
9498
<Table>
9599
<TableBody>
96100
<ChooseOne>
101+
{/* Error condition should just show an empty table. */}
102+
<Cond condition={Boolean(error)}>
103+
<TableRow>
104+
<TableCell colSpan={999}>
105+
<EmptyState message={t("table.noLogs")} />
106+
</TableCell>
107+
</TableRow>
108+
</Cond>
97109
<Cond condition={isLoading}>
98110
<TableLoader />
99111
</Cond>

site/src/pages/WorkspacesPage/WorkspacesPageView.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export const WorkspacesPageView: FC<
102102
workspaces={workspaces}
103103
isUsingFilter={filter !== workspaceFilterQuery.me}
104104
onUpdateWorkspace={onUpdateWorkspace}
105+
error={error}
105106
/>
106107
{count !== undefined && (
107108
<PaginationWidgetBase

site/src/xServices/audit/auditXService.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getAuditLogs } from "api/api"
2-
import { getErrorMessage } from "api/errors"
2+
import { getErrorMessage, isApiError } from "api/errors"
33
import { AuditLog, AuditLogResponse } from "api/typesGenerated"
44
import { displayError } from "components/GlobalSnackbar/utils"
55
import { getPaginationData } from "components/PaginationWidget/utils"
@@ -18,6 +18,7 @@ interface AuditContext {
1818
filter: string
1919
paginationContext: PaginationContext
2020
paginationRef?: PaginationMachineRef
21+
apiError?: Error | unknown
2122
}
2223

2324
export const auditMachine = createMachine(
@@ -52,7 +53,7 @@ export const auditMachine = createMachine(
5253
// Right now, XState doesn't a good job with state + context typing so
5354
// this forces the AuditPageView to showing the loading state when the
5455
// loading state is called again by cleaning up the audit logs data
55-
entry: "clearPreviousAuditLogs",
56+
entry: ["clearPreviousAuditLogs", "clearError"],
5657
invoke: {
5758
src: "loadAuditLogsAndCount",
5859
onDone: {
@@ -61,7 +62,7 @@ export const auditMachine = createMachine(
6162
},
6263
onError: {
6364
target: "idle",
64-
actions: ["displayApiError"],
65+
actions: ["displayApiError", "assignError"],
6566
},
6667
},
6768
onDone: "idle",
@@ -98,6 +99,12 @@ export const auditMachine = createMachine(
9899
assignFilter: assign({
99100
filter: (_, { filter }) => filter,
100101
}),
102+
assignError: assign({
103+
apiError: (_, event) => event.data,
104+
}),
105+
clearError: assign({
106+
apiError: (_) => undefined,
107+
}),
101108
displayApiError: (_, event) => {
102109
const message = getErrorMessage(
103110
event.data,

0 commit comments

Comments
 (0)