-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
resolves #3056 (FR-408) > [!NOTE] >This PR implements the Global soft timeout section from the Network Timeout UX guide written in Loop document. Implements network status monitoring improvements and request timeout handling: 1. Added a soft timeout notification that appears after 15 seconds of waiting for network requests 2. Moved the NetworkStatusBanner below the WebUIHeader for better visual hierarchy 3. Standardized request timeout handling: - Default timeout: 30 seconds - Soft timeout: 15 seconds - Removed hardcoded timeout values across the codebase - only [`recalculate_usage`](https://github.com/lablup/backend.ai-webui/blob/4fceaeaafcf23c3ab9acb45999c5aaae813eff7d/src/lib/backend.ai-client-esm.ts#L4520-L4530) request remain specific hardcoded timeout. ## Soft-timeout Alert view <img width="1067" alt="image" src="https://github.com/user-attachments/assets/75e010c3-bb60-4a3d-8d4a-9fa69e81fece" /> The soft timeout alert view will appear after 15 seconds of waiting, while still allowing the request to complete. If the request fails after 30 seconds, the error notification will be shown instead. This provides better feedback to users during slow network conditions. The soft timeout alert view appears with a debounced setting. It's displayed for at least 5 seconds after the soft timeout is triggered. Additionally, if there is a successful network request without hitting the soft timeout, the soft timeout alert view will disappear automatically. ## Offline Alert view <img width="1066" alt="image" src="https://github.com/user-attachments/assets/860c7977-ac7e-4e59-925c-33f4f46db900" /> Offline alert view works same as before this PR. ## How to Test - Reduce `requestSoftTimeout` to 1000 in `backend.ai-client-esm.ts` for testing. - Open WebUI, and open the browser developer tools. Set the throttling 3G and navigate to another page or wait for an automatic update request. - You should see the soft timeout alert view.- After removing the throttling setting, the soft timeout alert view will disappear automatically. - If you click the close button, the soft timeout view will not reappear until you refresh the browser hard.
- Loading branch information
Showing
9 changed files
with
104 additions
and
49 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
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,55 +1,83 @@ | ||
import { useNetwork } from 'ahooks'; | ||
import { useDebounce, useNetwork } from 'ahooks'; | ||
import { Alert } from 'antd'; | ||
import { createStyles } from 'antd-style'; | ||
import { atom, useAtom } from 'jotai'; | ||
import { atom, useSetAtom } from 'jotai'; | ||
import { useEffect, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
const networkSoftTimeoutAtom = atom(false); | ||
const isDisplayedNetworkStatusState = atom(false); | ||
|
||
const useStyles = createStyles(({ token, css }) => ({ | ||
borderError: css` | ||
border-bottom: 1px solid ${token.colorErrorBorder} !important; | ||
padding-left: ${token.marginLG}px; | ||
padding-right: ${token.marginLG}px; | ||
`, | ||
borderWarning: css` | ||
border-bottom: 1px solid ${token.colorWarningBorder} !important; | ||
padding-left: ${token.marginLG}px; | ||
padding-right: ${token.marginLG}px; | ||
`, | ||
})); | ||
const NetworkStatusBanner = () => { | ||
const { t } = useTranslation(); | ||
const network = useNetwork(); | ||
|
||
const setDisplayedStatus = useSetAtom(isDisplayedNetworkStatusState); | ||
const { styles } = useStyles(); | ||
const [showSoftTimeoutAlert, setShowSoftTimeoutAlert] = useState(false); | ||
const [dismissSoftTimeoutAlert, setDismissSoftTimeoutAlert] = useState(false); | ||
|
||
useEffect(() => { | ||
const softHandler = () => { | ||
setShowSoftTimeoutAlert(true); | ||
}; | ||
const successHandler = () => { | ||
setShowSoftTimeoutAlert(false); | ||
}; | ||
document.addEventListener('backend-ai-network-soft-time-out', softHandler); | ||
document.addEventListener( | ||
'backend-ai-network-success-without-soft-time-out', | ||
successHandler, | ||
); | ||
}, []); | ||
|
||
const debouncedShowAlert = useDebounce(showSoftTimeoutAlert, { | ||
leading: true, | ||
trailing: true, | ||
wait: 5_000, | ||
}); | ||
|
||
const shouldOpenOfflineAlert = !network.online; | ||
const shouldOpenSoftAlert = | ||
!shouldOpenOfflineAlert && debouncedShowAlert && !dismissSoftTimeoutAlert; | ||
|
||
useEffect(() => { | ||
setDisplayedStatus(shouldOpenOfflineAlert || shouldOpenSoftAlert); | ||
}, [setDisplayedStatus, shouldOpenOfflineAlert, shouldOpenSoftAlert]); | ||
|
||
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; | ||
return ( | ||
<> | ||
{shouldOpenOfflineAlert && ( | ||
<Alert | ||
message={t('webui.YouAreOffline')} | ||
className={styles.borderError} | ||
type="error" | ||
banner | ||
/> | ||
)} | ||
{shouldOpenSoftAlert && ( | ||
<Alert | ||
message={t('webui.NetworkSoftTimeout')} | ||
className={styles.borderWarning} | ||
banner | ||
closable | ||
onClose={() => { | ||
setDismissSoftTimeoutAlert(true); | ||
}} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
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