-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #483 from IQSS/feat/435-private-routes-guard
Private Routes Guard
- Loading branch information
Showing
26 changed files
with
422 additions
and
129 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
35 changes: 35 additions & 0 deletions
35
packages/design-system/src/lib/components/spinner/Spinner.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,35 @@ | ||
import { ElementType } from 'react' | ||
import { Spinner as SpinnerBS } from 'react-bootstrap' | ||
|
||
type SpinnerVariant = | ||
| 'primary' | ||
| 'secondary' | ||
| 'success' | ||
| 'danger' | ||
| 'warning' | ||
| 'info' | ||
| 'light' | ||
| 'dark' | ||
type SpinnerAnimations = 'border' | 'grow' | ||
|
||
interface SpinnerProps { | ||
variant?: SpinnerVariant | ||
animation?: SpinnerAnimations | ||
size?: 'sm' | ||
role?: string | ||
as?: ElementType | ||
} | ||
|
||
export const Spinner = ({ | ||
variant = 'primary', | ||
animation, | ||
size, | ||
role = 'status', | ||
as | ||
}: SpinnerProps) => { | ||
return ( | ||
<SpinnerBS variant={variant} animation={animation} size={size} role={role} as={as}> | ||
<span className="visually-hidden">Loading...</span> | ||
</SpinnerBS> | ||
) | ||
} |
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
64 changes: 64 additions & 0 deletions
64
packages/design-system/src/lib/stories/spinner/Spinner.stories.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,64 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
|
||
import { Spinner } from '../../components/spinner/Spinner' | ||
|
||
/** | ||
* ## Description | ||
* The Spinner component is used to indicate a loading state. | ||
*/ | ||
const meta: Meta<typeof Spinner> = { | ||
title: 'Spinner', | ||
component: Spinner, | ||
tags: ['autodocs'], | ||
parameters: { | ||
layout: 'centered' | ||
} | ||
} | ||
|
||
export default meta | ||
type Story = StoryObj<typeof Spinner> | ||
|
||
export const Default: Story = { | ||
render: () => <Spinner variant="primary" /> | ||
} | ||
|
||
export const AllBorderVariantsAtAGlance: Story = { | ||
render: () => ( | ||
<div style={{ display: 'flex', gap: '1rem', alignItems: 'center' }}> | ||
<Spinner animation="border" variant="primary" /> | ||
<Spinner animation="border" variant="secondary" /> | ||
<Spinner animation="border" variant="success" /> | ||
<Spinner animation="border" variant="danger" /> | ||
<Spinner animation="border" variant="warning" /> | ||
<Spinner animation="border" variant="info" /> | ||
<Spinner animation="border" variant="light" /> | ||
<Spinner animation="border" variant="dark" /> | ||
</div> | ||
) | ||
} | ||
|
||
export const AllGrowVariantsAtAGlance: Story = { | ||
render: () => ( | ||
<div style={{ display: 'flex', gap: '1rem', alignItems: 'center' }}> | ||
<Spinner animation="grow" variant="primary" /> | ||
<Spinner animation="grow" variant="secondary" /> | ||
<Spinner animation="grow" variant="success" /> | ||
<Spinner animation="grow" variant="danger" /> | ||
<Spinner animation="grow" variant="warning" /> | ||
<Spinner animation="grow" variant="info" /> | ||
<Spinner animation="grow" variant="light" /> | ||
<Spinner animation="grow" variant="dark" /> | ||
</div> | ||
) | ||
} | ||
|
||
export const AllSizesAtAGlance: Story = { | ||
render: () => ( | ||
<div style={{ display: 'flex', gap: '1rem', alignItems: 'center' }}> | ||
<Spinner animation="border" variant="primary" size="sm" /> | ||
<Spinner animation="border" variant="primary" /> | ||
<Spinner animation="grow" variant="primary" size="sm" /> | ||
<Spinner animation="grow" variant="primary" /> | ||
</div> | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/design-system/tests/component/spinner/Spinner.spec.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,9 @@ | ||
import { Spinner } from '../../../src/lib/components/spinner/Spinner' | ||
|
||
describe('Spinner', () => { | ||
it('renders correctly', () => { | ||
cy.mount(<Spinner />) | ||
|
||
cy.findAllByRole('status').should('exist') | ||
}) | ||
}) |
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.
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,23 @@ | ||
import { Outlet } from 'react-router-dom' | ||
import { Route } from '../sections/Route.enum' | ||
import { useSession } from '../sections/session/SessionContext' | ||
import { AppLoader } from '../sections/shared/layout/app-loader/AppLoader' | ||
import { BASE_URL } from '../config' | ||
|
||
export const ProtectedRoute = () => { | ||
const { user, isLoadingUser } = useSession() | ||
|
||
if (isLoadingUser) { | ||
return <AppLoader /> | ||
} | ||
|
||
if (!user) { | ||
window.location.href = `${BASE_URL}${Route.LOG_IN}` | ||
return null | ||
} | ||
|
||
// When we have the login page inside the SPA, we can use the following code: | ||
// return !user ? <Navigate to="/login" replace /> : <Outlet /> | ||
|
||
return <Outlet /> | ||
} |
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,17 @@ | ||
import { createBrowserRouter, RouterProvider } from 'react-router-dom' | ||
import { DatasetNonNumericVersion } from '../dataset/domain/models/Dataset' | ||
import { routes } from './routes' | ||
|
||
const browserRouter = createBrowserRouter(routes, { basename: import.meta.env.BASE_URL }) | ||
|
||
export function Router() { | ||
return <RouterProvider router={browserRouter} /> | ||
} | ||
|
||
export function searchParamVersionToDomainVersion(version?: string): string | undefined { | ||
if (version === 'DRAFT') { | ||
return DatasetNonNumericVersion.DRAFT.toString() | ||
} | ||
|
||
return version | ||
} |
Oops, something went wrong.