Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(table): update table to support error messages #230

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 3.0.26

- Updated table component to support error messages

## 3.0.25

- Updated images for markdown files
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@catena-x/portal-shared-components",
"version": "3.0.25",
"version": "3.0.26",
"description": "Catena-X Portal Shared Components",
"author": "Catena-X Contributors",
"license": "Apache-2.0",
Expand Down
21 changes: 15 additions & 6 deletions src/components/basic/Table/components/Error/Error400Overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ const flexColumn = {
alignItems: 'center',
}

export const Error400Overlay = () => (
export const Error400Overlay = ({
errorMessage4xx,
}: {
errorMessage4xx?: string
}) => (
<Box
sx={{
...flexRow,
Expand All @@ -49,13 +53,18 @@ export const Error400Overlay = () => (
<Box
sx={{
...flexColumn,
paddingTop: '20px',
}}
>
<Typography variant="body2">
Something went wrong. Please contact
</Typography>
<Typography variant="body2">your administrator</Typography>
{errorMessage4xx ? (
<Typography variant="body2">{errorMessage4xx}</Typography>
) : (
<>
<Typography variant="body2">
Something went wrong. Please contact
</Typography>
<Typography variant="body2">your administrator</Typography>
</>
)}
</Box>
</Box>
)
10 changes: 8 additions & 2 deletions src/components/basic/Table/components/Error/Error500Overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ const flexColumn = {
alignItems: 'center',
}

export const Error500Overlay = ({ reload }: { reload: () => void }) => (
export const Error500Overlay = ({
reload,
errorMessage5xx,
}: {
reload: () => void
errorMessage5xx?: string
}) => (
<Box
sx={{
...flexColumn,
Expand All @@ -42,7 +48,7 @@ export const Error500Overlay = ({ reload }: { reload: () => void }) => (
}}
variant="body2"
>
Load Failed. Reload
{errorMessage5xx ?? 'Load Failed. Reload'}
</Typography>
<div
onClick={reload}
Expand Down
33 changes: 19 additions & 14 deletions src/components/basic/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface TableProps extends DataGridProps {
fontSizeCell?: string
error?: {
status: number
message?: string
}
reload?: () => void
autoFocus?: boolean
Expand Down Expand Up @@ -175,6 +176,23 @@ export const Table = ({
}
}

const renderErrorMessage = () => {
if (error == null) {
return <Typography variant="body2">{noRowsMsg ?? 'No rows'}</Typography>
}
if (error.status >= 400 && error.status < 500) {
return <Error400Overlay errorMessage4xx={error.message} />
}
return (
<Error500Overlay
reload={() => {
reload?.()
}}
errorMessage5xx={error.message}
/>
)
}

const NoRowsOverlay = () => {
return (
<Stack
Expand All @@ -183,20 +201,7 @@ export const Table = ({
justifyContent="center"
sx={{ backgroundColor: '#fff', pointerEvents: 'auto' }}
>
{error != null && error.status === 500 && (
<Error500Overlay
reload={() => {
reload?.()
}}
/>
)}
{error != null &&
(error.status === 400 ||
error.status === 404 ||
error.status === 401) && <Error400Overlay />}
{error == null && (
<Typography variant="body2">{noRowsMsg ?? 'No rows'}</Typography>
)}
{renderErrorMessage()}
</Stack>
)
}
Expand Down
Loading