-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Not connected alert banner in React (#2492)
### TL;DR Added a network status banner to the main layout component. | before | after | | -- | -- | | ![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/XqC2uNFuj0wg8I60sMUh/2bef7928-f35c-45b9-b050-4bbadba4721e.png) | ![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/XqC2uNFuj0wg8I60sMUh/ebb01c92-29d8-46db-aed6-da473d39b63f.png) | ### What changed? - Introduced `NetworkStatusBanner` component. - Displays when the user is offline - Updated translations for the offline message in multiple languages. - Removed old snackbar-based offline indicator. ### How to test? 1. Go offline and verify that the new banner appears with the appropriate message. ### Why make this change? Enhances user experience by providing clearer visual feedback on network status directly within the main layout. --- <!-- Please precisely, concisely, and concretely describe what this PR changes, the rationale behind codes, and how it affects the users and other developers. --> **Checklist:** (if applicable) - [ ] Mention to the original issue - [ ] Documentation - [ ] Minium required manager version - [ ] Specific setting for review (eg., KB link, endpoint or how to setup) - [ ] Minimum requirements to check during review - [ ] Test case(s) to demonstrate the difference of before/after
- Loading branch information
Showing
27 changed files
with
79 additions
and
134 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useNetwork } from 'ahooks'; | ||
import { Alert } from 'antd'; | ||
import { createStyles } from 'antd-style'; | ||
import { atom, useAtom } from 'jotai'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
const networkSoftTimeoutAtom = atom(false); | ||
|
||
const useStyles = createStyles(({ token, css }) => ({ | ||
borderError: css` | ||
border-bottom: 1px solid ${token.colorErrorBorder} !important; | ||
`, | ||
borderWarning: css` | ||
border-bottom: 1px solid ${token.colorWarningBorder} !important; | ||
`, | ||
})); | ||
const NetworkStatusBanner = () => { | ||
const { t } = useTranslation(); | ||
const network = useNetwork(); | ||
|
||
const { styles } = useStyles(); | ||
|
||
const [softTimeout, setSoftTimeout] = useAtom(networkSoftTimeoutAtom); | ||
|
||
// const handler = (()=>{ | ||
// }); | ||
|
||
// useEffect(()=>{ | ||
// document.addEventListener('backendai.client.softtimeout', handler); | ||
// return ()=>{ | ||
// document.removeEventListener('backendai.client.softtimeout', handler); | ||
// } | ||
// },[]) | ||
|
||
return !network.online ? ( | ||
<Alert | ||
message={t('webui.YouAreOffline')} | ||
className={styles.borderError} | ||
type="error" | ||
banner | ||
/> | ||
) : softTimeout ? ( | ||
<Alert | ||
message={t('webui.NetworkSoftTimeout')} | ||
className={styles.borderWarning} | ||
banner | ||
closable | ||
onClose={() => { | ||
setSoftTimeout(false); | ||
}} | ||
/> | ||
) : null; | ||
}; | ||
|
||
export default NetworkStatusBanner; |
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
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
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.