Repository navigation
feat: display specific errors if templates page fails - #4023
Conversation
| defaultMessage={t("errors.getTemplatesError")} | ||
| /> | ||
| ) : ( | ||
| <TableContainer> |
There was a problem hiding this comment.
I find this triple, JSX ternary a little confusing and personally think this is a good candidate for early return.
There was a problem hiding this comment.
How would you do the early return? I'm not seeing a good way of doing it since the margins and page header need to be there in each case. I could put those in a const but at that point I'd rather put the content (error or data) in a const and still use the conditional so you can easily see what's definitely there vs what's conditional.
There was a problem hiding this comment.
I might move the margins and page header into TemplatesPage.tsx - they seem like page scaffolding to me. Then, one could decompose the TemplatesPageView file:
export const TemplatesPageView = () => {
if (props.getOrganizationsError) {
return <ErrorSummary />
}
if (props.getTemplatesError) {
return <ErrorSummary />
}
if (empty) {
return (
<TableContainer>
<LoadingTableBody />
</TableContainer>
)
}
return (
<TableContainer>
<TemplateTableBody templates={templates} />
</TableContainer>
)
}
I think the benefit here is we are writing state in a declarative way - it is apparent at a glance what states the developer should be aware of. Let me know what you think!
There was a problem hiding this comment.
Yeah, this looks nice and readable, but the scaffolding is in the view for storybook reasons. I'm open to a refactor but I think I'll leave it for future work so I can get the error handling in.
| </TableHead> | ||
| <TableBody> | ||
| {props.loading && <TableLoader />} | ||
| {empty && ( |
There was a problem hiding this comment.
What do you think about making a parent table component that accepts a child table body component? That child component could be a loading component, or a data-filled component. I was wondering if breaking apart state into components here might make this a little easier to read and reason about.
There was a problem hiding this comment.
Sounds like a good idea, can you make a ticket for it? We could apply it in multiple places.
| import { TemplatesPageView } from "./TemplatesPageView" | ||
|
|
||
| const TemplatesPage: React.FC = () => { | ||
| export const TemplatesPage: React.FC = () => { |
There was a problem hiding this comment.
I think we need to update the import of TemplatesPage in AppRouter.tsx and in TemplatesPage.test.tsx.
| <div className={styles.templateIconWrapper}> | ||
| <img alt="" src={template.icon} /> | ||
| </div> | ||
| ) : undefined |
There was a problem hiding this comment.
I don't think we need a ternary here.
Kira-Pilot
left a comment
There was a problem hiding this comment.
This looks good after we fix the import issue!
I didn't have a ticket for this one, but I noticed while working on this page that it was swallowing errors.