Skip to content

Commit 0ef8514

Browse files
authored
chore: match templates search error with workspace search error (coder#14479)
* chore: make templates search error the same as workspaces
1 parent 0f8251b commit 0ef8514

File tree

3 files changed

+62
-37
lines changed

3 files changed

+62
-37
lines changed

site/src/pages/TemplatesPage/TemplatesFilter.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ import type { FC } from "react";
1616

1717
interface TemplatesFilterProps {
1818
filter: ReturnType<typeof useFilter>;
19+
error?: unknown;
1920
}
2021

21-
export const TemplatesFilter: FC<TemplatesFilterProps> = ({ filter }) => {
22+
export const TemplatesFilter: FC<TemplatesFilterProps> = ({
23+
filter,
24+
error,
25+
}) => {
2226
const organizationMenu = useFilterMenu({
2327
onChange: (option) =>
2428
filter.update({ ...filter.values, organization: option?.value }),
@@ -48,6 +52,7 @@ export const TemplatesFilter: FC<TemplatesFilterProps> = ({ filter }) => {
4852
// learnMoreLink={docs("/templates#template-filtering")}
4953
isLoading={false}
5054
filter={filter}
55+
error={error}
5156
options={
5257
<>
5358
<SelectFilter

site/src/pages/TemplatesPage/TemplatesPageView.stories.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,22 @@ export const WithError: Story = {
112112
canCreateTemplates: false,
113113
},
114114
};
115+
116+
export const WithValidationError: Story = {
117+
args: {
118+
error: mockApiError({
119+
message: "Something went wrong fetching templates.",
120+
detail:
121+
"This is a more detailed error message that should help you understand what went wrong.",
122+
validations: [
123+
{
124+
field: "search",
125+
detail: "That search query was invalid, why did you do that?",
126+
},
127+
],
128+
}),
129+
templates: undefined,
130+
examples: undefined,
131+
canCreateTemplates: false,
132+
},
133+
};

site/src/pages/TemplatesPage/TemplatesPageView.tsx

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import TableCell from "@mui/material/TableCell";
99
import TableContainer from "@mui/material/TableContainer";
1010
import TableHead from "@mui/material/TableHead";
1111
import TableRow from "@mui/material/TableRow";
12+
import { hasError, isApiValidationError } from "api/errors";
1213
import type { Template, TemplateExample } from "api/typesGenerated";
1314
import { ErrorAlert } from "components/Alert/ErrorAlert";
1415
import { ExternalAvatar } from "components/Avatar/Avatar";
@@ -228,45 +229,45 @@ export const TemplatesPageView: FC<TemplatesPageViewProps> = ({
228229
</PageHeaderSubtitle>
229230
</PageHeader>
230231

231-
<TemplatesFilter filter={filter} />
232-
233-
{error ? (
232+
<TemplatesFilter filter={filter} error={error} />
233+
{/* Validation errors are shown on the filter, other errors are an alert box. */}
234+
{hasError(error) && !isApiValidationError(error) && (
234235
<ErrorAlert error={error} />
235-
) : (
236-
<TableContainer>
237-
<Table>
238-
<TableHead>
239-
<TableRow>
240-
<TableCell width="35%">{Language.nameLabel}</TableCell>
241-
<TableCell width="15%">
242-
{showOrganizations ? "Organization" : Language.usedByLabel}
243-
</TableCell>
244-
<TableCell width="10%">{Language.buildTimeLabel}</TableCell>
245-
<TableCell width="15%">{Language.lastUpdatedLabel}</TableCell>
246-
<TableCell width="1%" />
247-
</TableRow>
248-
</TableHead>
249-
<TableBody>
250-
{isLoading && <TableLoader />}
236+
)}
251237

252-
{isEmpty ? (
253-
<EmptyTemplates
254-
canCreateTemplates={canCreateTemplates}
255-
examples={examples ?? []}
238+
<TableContainer>
239+
<Table>
240+
<TableHead>
241+
<TableRow>
242+
<TableCell width="35%">{Language.nameLabel}</TableCell>
243+
<TableCell width="15%">
244+
{showOrganizations ? "Organization" : Language.usedByLabel}
245+
</TableCell>
246+
<TableCell width="10%">{Language.buildTimeLabel}</TableCell>
247+
<TableCell width="15%">{Language.lastUpdatedLabel}</TableCell>
248+
<TableCell width="1%" />
249+
</TableRow>
250+
</TableHead>
251+
<TableBody>
252+
{isLoading && <TableLoader />}
253+
254+
{isEmpty ? (
255+
<EmptyTemplates
256+
canCreateTemplates={canCreateTemplates}
257+
examples={examples ?? []}
258+
/>
259+
) : (
260+
templates?.map((template) => (
261+
<TemplateRow
262+
key={template.id}
263+
showOrganizations={showOrganizations}
264+
template={template}
256265
/>
257-
) : (
258-
templates?.map((template) => (
259-
<TemplateRow
260-
key={template.id}
261-
showOrganizations={showOrganizations}
262-
template={template}
263-
/>
264-
))
265-
)}
266-
</TableBody>
267-
</Table>
268-
</TableContainer>
269-
)}
266+
))
267+
)}
268+
</TableBody>
269+
</Table>
270+
</TableContainer>
270271
</Margins>
271272
);
272273
};

0 commit comments

Comments
 (0)