-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display a generic fallback component when initial config load fails (#…
…8588) Fixes: #8487 #5027 1. Summary The purpose of these changes is to elevate the dev/user experience when the initial config load call fails for whatever reason by displaying a fallback component. 2. Solution I ended up making more changes than I initially planned. I had to update the order of the contexts a bit because `GenericErrorFallback` is dependent on `AppThemeProvider` for styling and `AppThemeProvider` is dependent on `ObjectMetadataItemsProvider` for [`useObjectMetadataItem`](https://github.com/khuddite/twenty/blob/ae2f193d68c6168e4c8323297d58f6dbc1de9fdf/packages/twenty-front/src/modules/object-metadata/hooks/useObjectMetadataItem.ts#L22) hook (`AppThemeProvider` -> `useColorScheme` -> `useUpdateOneRecord` -> `useObjectMetadataItem`). I had to create a wrapper component for `AppThemeProvider` and stylize it in a way that it looks responsive on both mobile and desktop devices. Finally, I had to introduce the `isErrored` flag to differentiate the loading and error states. There are some improvements we can make later - - Display a loading state for the initial config load - Implement a refetch logic for the initial config loading failure 3. Recording https://github.com/user-attachments/assets/c2f43573-8006-4118-8e18-8576099d78fd https://github.com/user-attachments/assets/9c5853d3-539b-4880-aa38-c416c3e13594 --------- Co-authored-by: Félix Malfait <felix@twenty.com>
- Loading branch information
1 parent
04c359a
commit 62df0f0
Showing
12 changed files
with
229 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 13 additions & 3 deletions
16
packages/twenty-front/src/modules/client-config/components/ClientConfigProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
import { isClientConfigLoadedState } from '@/client-config/states/isClientConfigLoadedState'; | ||
import { clientConfigApiStatusState } from '@/client-config/states/clientConfigApiStatusState'; | ||
import { ClientConfigError } from '@/error-handler/components/ClientConfigError'; | ||
|
||
export const ClientConfigProvider: React.FC<React.PropsWithChildren> = ({ | ||
children, | ||
}) => { | ||
const isClientConfigLoaded = useRecoilValue(isClientConfigLoadedState); | ||
const { isLoaded, isErrored, error } = useRecoilValue( | ||
clientConfigApiStatusState, | ||
); | ||
|
||
return isClientConfigLoaded ? <>{children}</> : <></>; | ||
// TODO: Implement a better loading strategy | ||
if (!isLoaded) return null; | ||
|
||
return isErrored && error instanceof Error ? ( | ||
<ClientConfigError error={error} /> | ||
) : ( | ||
children | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/twenty-front/src/modules/client-config/states/clientConfigApiStatusState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { createState } from 'twenty-ui'; | ||
|
||
type ClientConfigApiStatus = { | ||
isLoaded: boolean; | ||
isErrored: boolean; | ||
error?: Error; | ||
}; | ||
|
||
export const clientConfigApiStatusState = createState<ClientConfigApiStatus>({ | ||
key: 'clientConfigApiStatus', | ||
defaultValue: { isLoaded: false, isErrored: false, error: undefined }, | ||
}); |
6 changes: 0 additions & 6 deletions
6
packages/twenty-front/src/modules/client-config/states/isClientConfigLoadedState.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/twenty-front/src/modules/error-handler/components/ClientConfigError.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import styled from '@emotion/styled'; | ||
import { MOBILE_VIEWPORT } from 'twenty-ui'; | ||
import { GenericErrorFallback } from './GenericErrorFallback'; | ||
|
||
const StyledContainer = styled.div` | ||
background: ${({ theme }) => theme.background.noisy}; | ||
box-sizing: border-box; | ||
display: flex; | ||
height: 100dvh; | ||
width: 100%; | ||
padding-top: ${({ theme }) => theme.spacing(3)}; | ||
padding-left: ${({ theme }) => theme.spacing(3)}; | ||
padding-bottom: 0; | ||
@media (max-width: ${MOBILE_VIEWPORT}px) { | ||
padding-left: 0; | ||
padding-bottom: ${({ theme }) => theme.spacing(3)}; | ||
} | ||
`; | ||
|
||
type ClientConfigErrorProps = { | ||
error: Error; | ||
}; | ||
|
||
export const ClientConfigError = ({ error }: ClientConfigErrorProps) => { | ||
// TODO: Implement a better loading strategy | ||
const handleReset = () => { | ||
window.location.reload(); | ||
}; | ||
|
||
return ( | ||
<StyledContainer> | ||
<GenericErrorFallback | ||
error={error} | ||
resetErrorBoundary={handleReset} | ||
title="Unable to Reach Back-end" | ||
hidePageHeader | ||
/> | ||
</StyledContainer> | ||
); | ||
}; |
Oops, something went wrong.