-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(shell-ui): distinguish network from auth failures and surface both in a recovery banner #1553
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
Open
kgarg2468
wants to merge
3
commits into
develop
Choose a base branch
from
fix/305-network-vs-auth-errors
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
102 changes: 102 additions & 0 deletions
102
apps/shell-ui/src/components/layout/ConnectionErrorBanner.tsx
This file contains hidden or 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,102 @@ | ||
| import React, { CSSProperties, useEffect, useState } from 'react'; | ||
| import { ConnectionState } from 'shared'; | ||
| import { ConnectionManager } from '../../connection/connection'; | ||
| import { useConnectionStatus } from '../../hooks/useConnectionStatus'; | ||
|
|
||
| const styles = { | ||
| banner: { | ||
| position: 'fixed', | ||
| top: 0, | ||
| left: 0, | ||
| right: 0, | ||
| zIndex: 1000, | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| gap: 12, | ||
| minHeight: 36, | ||
| padding: '6px 12px', | ||
| backgroundColor: 'var(--rr-bg-paper)', | ||
| borderBottom: '1px solid var(--rr-border)', | ||
| color: 'var(--rr-text-primary)', | ||
| fontFamily: 'var(--rr-font-family)', | ||
| fontSize: 'var(--rr-font-size-widget)', | ||
| } as CSSProperties, | ||
| message: { flex: '0 1 auto' } as CSSProperties, | ||
| action: { | ||
| border: 0, | ||
| background: 'none', | ||
| padding: 0, | ||
| color: 'var(--rr-brand)', | ||
| font: 'inherit', | ||
| fontWeight: 600, | ||
| cursor: 'pointer', | ||
| } as CSSProperties, | ||
| dismiss: { | ||
| position: 'absolute', | ||
| right: 12, | ||
| border: 0, | ||
| background: 'none', | ||
| padding: '0 4px', | ||
| color: 'var(--rr-text-secondary)', | ||
| fontSize: 20, | ||
| lineHeight: 1, | ||
| cursor: 'pointer', | ||
| } as CSSProperties, | ||
| }; | ||
|
|
||
| export interface ConnectionErrorBannerProps { | ||
| /** Override the status-derived failure message for other connection errors. */ | ||
| message?: string; | ||
| /** Override retry handling; defaults to ConnectionManager.reconnect(). */ | ||
| onRetry?: () => void | Promise<void>; | ||
| /** Override sign-in handling; defaults to ConnectionManager.startOAuth(false). */ | ||
| onSignIn?: () => void | Promise<void>; | ||
| } | ||
|
|
||
| /** A dismissible recovery banner for authentication and transport failures. */ | ||
| export const ConnectionErrorBanner: React.FC<ConnectionErrorBannerProps> = ({ message, onRetry, onSignIn }) => { | ||
| const status = useConnectionStatus(); | ||
| const [dismissed, setDismissed] = useState(false); | ||
| // The failure is latched manager-side (status.lastFailure) so reconnect | ||
| // attempts and anonymous connects can't erase it before it renders. | ||
| const failure = status.lastFailure; | ||
|
|
||
| useEffect(() => { | ||
| setDismissed(false); | ||
| }, [failure?.state, failure?.lastError]); | ||
|
|
||
| if (dismissed || !failure) return null; | ||
|
|
||
| const isNetworkFailure = failure.state === ConnectionState.NETWORK_ERROR; | ||
| const defaultMessage = isNetworkFailure | ||
| ? 'Can\'t reach the server — check your connection and retry.' | ||
| : 'Your session has expired — please sign in again.'; | ||
| const action = isNetworkFailure ? 'Retry' : 'Sign in'; | ||
| const onAction = isNetworkFailure | ||
| ? onRetry ?? (() => { | ||
| const connection = ConnectionManager.getInstance(); | ||
| if (!connection.hasAttached()) { | ||
| window.location.reload(); | ||
| return; | ||
| } | ||
| return connection.reconnect(); | ||
| }) | ||
| : onSignIn ?? (() => ConnectionManager.getInstance().startOAuth(false)); | ||
|
|
||
| return ( | ||
| <div style={styles.banner} role="alert"> | ||
| <span style={styles.message} title={failure.lastError}>{message ?? defaultMessage}</span> | ||
| <button type="button" style={styles.action} onClick={() => { | ||
| void Promise.resolve().then(onAction).catch((error) => { | ||
| console.error('[ConnectionErrorBanner] Recovery action failed:', error); | ||
| }); | ||
| }}> | ||
| {action} | ||
| </button> | ||
| <button type="button" style={styles.dismiss} aria-label="Dismiss connection error" onClick={() => setDismissed(true)}> | ||
| × | ||
| </button> | ||
| </div> | ||
| ); | ||
| }; | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.