forked from opendatahub-io/odh-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor external routing and error handling components
- Updated ExternalRoutes to use ExternalRedirectNotFound instead of Navigate for unmatched routes. - Introduced RedirectErrorState component to handle redirect errors with customizable actions and fallback options. - Enhanced PipelinesSdkRedirects to display RedirectErrorState on error, providing navigation options to users. - Added ExternalRedirectNotFound component to show a user-friendly message for non-existent external redirects. This improves user experience by providing clearer error states and navigation options during redirects.
- Loading branch information
1 parent
bc1050e
commit 89c8d87
Showing
5 changed files
with
204 additions
and
25 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,106 @@ | ||
import { | ||
PageSection, | ||
EmptyState, | ||
EmptyStateVariant, | ||
EmptyStateBody, | ||
EmptyStateFooter, | ||
EmptyStateActions, | ||
Button, | ||
} from '@patternfly/react-core'; | ||
import { ExclamationCircleIcon } from '@patternfly/react-icons'; | ||
import React from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { EitherOrNone } from '~/typeHelpers'; | ||
|
||
type RedirectErrorStateProps = { | ||
title?: string; | ||
errorMessage?: string; | ||
} & EitherOrNone< | ||
{ | ||
fallbackUrl: string; | ||
fallbackText: string; | ||
}, | ||
{ | ||
actions: React.ReactNode | React.ReactNode[]; | ||
} | ||
>; | ||
|
||
/** | ||
* A component that displays an error state with optional title, message and actions | ||
* Used for showing redirect/navigation errors with fallback options | ||
* | ||
* Props for the RedirectErrorState component | ||
* @property {string} [title] - Optional title text to display in the error state | ||
* @property {string} [errorMessage] - Optional error message to display | ||
* @property {string} [fallbackUrl] - URL to navigate to when fallback button is clicked | ||
* @property {React.ReactNode | React.ReactNode[]} [actions] - Custom action buttons/elements to display | ||
* | ||
* Note: The component accepts either fallbackUrl OR actions prop, but not both. | ||
* This is enforced by the EitherOrNone type helper. | ||
* | ||
* @example | ||
* ```tsx | ||
* // With fallback URL | ||
* <RedirectErrorState | ||
* title="Error redirecting to pipelines" | ||
* errorMessage={error.message} | ||
* fallbackUrl="/pipelines" | ||
* /> | ||
* | ||
* // With custom actions | ||
* <RedirectErrorState | ||
* title="Error redirecting to pipelines" | ||
* errorMessage={error.message} | ||
* actions={ | ||
* <> | ||
* <Button variant="link" onClick={() => navigate('/pipelines')}> | ||
* Go to pipelines | ||
* </Button> | ||
* <Button variant="link" onClick={() => navigate('/experiments')}> | ||
* Go to experiments | ||
* </Button> | ||
* </> | ||
* } | ||
* /> | ||
* ``` | ||
*/ | ||
|
||
const RedirectErrorState: React.FC<RedirectErrorStateProps> = ({ | ||
title, | ||
errorMessage, | ||
fallbackUrl, | ||
fallbackText, | ||
actions, | ||
}) => { | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<PageSection hasBodyWrapper={false} isFilled> | ||
<EmptyState | ||
headingLevel="h1" | ||
icon={ExclamationCircleIcon} | ||
titleText={title ?? 'Error redirecting'} | ||
variant={EmptyStateVariant.lg} | ||
data-id="redirect-error" | ||
> | ||
{errorMessage && <EmptyStateBody>{errorMessage}</EmptyStateBody>} | ||
{fallbackUrl && ( | ||
<EmptyStateFooter> | ||
<EmptyStateActions> | ||
<Button variant="link" onClick={() => navigate(fallbackUrl)}> | ||
{fallbackText} | ||
</Button> | ||
</EmptyStateActions> | ||
</EmptyStateFooter> | ||
)} | ||
{actions && ( | ||
<EmptyStateFooter> | ||
<EmptyStateActions>{actions}</EmptyStateActions> | ||
</EmptyStateFooter> | ||
)} | ||
</EmptyState> | ||
</PageSection> | ||
); | ||
}; | ||
|
||
export default RedirectErrorState; |
20 changes: 20 additions & 0 deletions
20
frontend/src/pages/external/redirectComponents/ExternalRedirectNotFound.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,20 @@ | ||
import React from 'react'; | ||
import ApplicationsPage from '~/pages/ApplicationsPage'; | ||
import RedirectErrorState from '~/pages/external/RedirectErrorState'; | ||
|
||
const ExternalRedirectNotFound: React.FC = () => ( | ||
<ApplicationsPage | ||
loaded | ||
empty | ||
emptyStatePage={ | ||
<RedirectErrorState | ||
title="Not Found" | ||
errorMessage="There is no external redirect for this URL" | ||
fallbackText="Go to home" | ||
fallbackUrl="/" | ||
/> | ||
} | ||
/> | ||
); | ||
|
||
export default ExternalRedirectNotFound; |
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