Skip to content

Commit

Permalink
[206] Switch to nested routes to simplify the routing
Browse files Browse the repository at this point in the history
Bug: #206
Signed-off-by: Stéphane Bégaudeau <[email protected]>
  • Loading branch information
sbegaudeau committed Jul 16, 2023
1 parent 7517902 commit 40a13e4
Show file tree
Hide file tree
Showing 21 changed files with 521 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import TimelineSeparator from '@mui/lab/TimelineSeparator';
import Avatar from '@mui/material/Avatar';
import Box from '@mui/material/Box';
import Link from '@mui/material/Link';
import { useTheme } from '@mui/material/styles';
import Tooltip from '@mui/material/Tooltip';
import Typography from '@mui/material/Typography';
import { useTheme } from '@mui/material/styles';
import { Link as RouterLink } from 'react-router-dom';
import { formatTime } from '../utils/formatTime';
import { ActivityTimelineItemProps } from './ActivityTimelineItem.types';
Expand Down Expand Up @@ -123,15 +123,15 @@ export const ActivityTimelineItem = ({ date, kind, createdBy, title, description
<Tooltip title={createdBy.name}>
<Avatar
component={RouterLink}
to={`/profile/${createdBy.username}`}
to={`/profiles/${createdBy.username}`}
alt={createdBy.name}
src={createdBy.imageUrl}
sx={{ width: 24, height: 24 }}
/>
</Tooltip>
<Link
component={RouterLink}
to={`/profile/${createdBy.username}`}
to={`/profiles/${createdBy.username}`}
color="inherit"
underline="hover"
sx={{ fontWeight: 'bold' }}
Expand Down
73 changes: 28 additions & 45 deletions frontend/svalyn-studio-app/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,22 @@ import CssBaseline from '@mui/material/CssBaseline';
import { ThemeProvider } from '@mui/material/styles';
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import { PaletteProvider } from '../palette/PaletteProvider';
import { ChangeProposalView } from '../views/changeproposal/ChangeProposalView';
import { DomainView } from '../views/domain/DomainView';
import { DomainsView } from '../views/domains/DomainsView';
import { ErrorView } from '../views/error/ErrorView';
import { HelpView } from '../views/help/HelpView';
import { ChangeProposalRouter } from '../views/changeproposal/ChangeProposalRouter';
import { DomainRouter } from '../views/domains/DomainRouter';
import { ErrorRouter } from '../views/error/ErrorRouter';
import { HelpRouter } from '../views/help/HelpRouter';
import { HomeView } from '../views/home/HomeView';
import { InvitationsView } from '../views/invitations/InvitationsView';
import { LoginView } from '../views/login/LoginView';
import { NewChangeProposalView } from '../views/new-changeproposal/NewChangeProposalView';
import { NewOrganizationView } from '../views/new-organization/NewOrganizationView';
import { InvitationRouter } from '../views/invitations/InvitationRouter';
import { LoginRouter } from '../views/login/LoginRouter';
import { NewRouter } from '../views/new-organization/NewRouter';
import { NotFoundView } from '../views/notfound/NotFoundView';
import { NotificationsView } from '../views/notifications/NotificationsView';
import { OAuth2RedirectView } from '../views/oauth2redirect/OAuth2RedirectView';
import { OrganizationView } from '../views/organization/OrganizationView';
import { ProfileView } from '../views/profile/ProfileView';
import { ProjectView } from '../views/project/ProjectView';
import { ResourceView } from '../views/resource/ResourceView';
import { SearchView } from '../views/search/SearchView';
import { SettingsView } from '../views/settings/SettingsView';
import { WorkspaceView } from '../views/workspace/WorkspaceView';
import { NotificationRouter } from '../views/notifications/NotificationRouter';
import { OAuth2Router } from '../views/oauth2redirect/OAuth2Router';
import { OrganizationRouter } from '../views/organization/OrganizationRouter';
import { ProfileRouter } from '../views/profile/ProfileRouter';
import { ProjectRouter } from '../views/project/ProjectRouter';
import { SearchRouter } from '../views/search/SearchRouter';
import { SettingsRouter } from '../views/settings/SettingsRouter';
import { AuthenticationRedirectionBoundary } from './AuthenticationRedirectionBoundary';
import { theme } from './theme';

Expand All @@ -53,33 +49,20 @@ export const App = () => {
<PaletteProvider>
<Routes>
<Route path="/" element={<HomeView />} />
<Route path="/new/organization" element={<NewOrganizationView />} />
<Route path="/orgs/:organizationIdentifier" element={<OrganizationView />} />
<Route path="/orgs/:organizationIdentifier/tags" element={<OrganizationView />} />
<Route path="/orgs/:organizationIdentifier/members" element={<OrganizationView />} />
<Route path="/orgs/:organizationIdentifier/settings" element={<OrganizationView />} />
<Route path="/projects/:projectIdentifier" element={<ProjectView />} />
<Route path="/projects/:projectIdentifier/activity" element={<ProjectView />} />
<Route path="/projects/:projectIdentifier/changeproposals" element={<ProjectView />} />
<Route path="/projects/:projectIdentifier/tags" element={<ProjectView />} />
<Route path="/projects/:projectIdentifier/settings" element={<ProjectView />} />
<Route path="/projects/:projectIdentifier/new/changeproposal" element={<NewChangeProposalView />} />
<Route path="/projects/:projectIdentifier/changes/:changeId/resources/*" element={<ResourceView />} />
<Route path="/projects/:projectIdentifier/changes/:changeId" element={<WorkspaceView />} />
<Route path="/changeproposals/:changeProposalId" element={<ChangeProposalView />} />
<Route path="/changeproposals/:changeProposalId/files" element={<ChangeProposalView />} />
<Route path="/domains" element={<DomainsView />} />
<Route path="/domains/:domainIdentifier" element={<DomainView />} />
<Route path="/search" element={<SearchView />} />
<Route path="/settings" element={<SettingsView />} />
<Route path="/settings/authentication-tokens" element={<SettingsView />} />
<Route path="/login" element={<LoginView />} />
<Route path="/oauth2/redirect" element={<OAuth2RedirectView />} />
<Route path="/profile/:username" element={<ProfileView />} />
<Route path="/invitations" element={<InvitationsView />} />
<Route path="/notifications" element={<NotificationsView />} />
<Route path="/error" element={<ErrorView />} />
<Route path="help" element={<HelpView />} />
<Route path="/new/*" element={<NewRouter />} />
<Route path="/orgs/*" element={<OrganizationRouter />} />
<Route path="/projects/*" element={<ProjectRouter />} />
<Route path="/changeproposals/*" element={<ChangeProposalRouter />} />
<Route path="/domains/*" element={<DomainRouter />} />
<Route path="/search/*" element={<SearchRouter />} />
<Route path="/profiles/*" element={<ProfileRouter />} />
<Route path="/notifications/*" element={<NotificationRouter />} />
<Route path="/invitations/*" element={<InvitationRouter />} />
<Route path="/settings/*" element={<SettingsRouter />} />
<Route path="/help/*" element={<HelpRouter />} />
<Route path="/error/*" element={<ErrorRouter />} />
<Route path="/login/*" element={<LoginRouter />} />
<Route path="/oauth2/*" element={<OAuth2Router />} />
<Route path="*" element={<NotFoundView />} />
</Routes>
</PaletteProvider>
Expand Down
2 changes: 1 addition & 1 deletion frontend/svalyn-studio-app/src/navbars/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const Navbar = ({ children }: NavbarProps) => {
</MenuItem>
<MenuItem
component={RouterLink}
to={`/profile/${state.viewer.username}`}
to={`/profiles/${state.viewer.username}`}
onClick={handleCloseUserMenu}
>
<ListItemIcon>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2023 Stéphane Bégaudeau.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { Outlet, Route, Routes } from 'react-router-dom';
import { ChangeProposalView } from './ChangeProposalView';

export const ChangeProposalRouter = () => {
return (
<>
<Routes>
<Route path=":changeProposalId" element={<ChangeProposalView />} />
<Route path=":changeProposalId/files" element={<ChangeProposalView />} />
</Routes>

<Outlet />
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,13 @@ const ChangeProposalReviews = ({ changeProposal }: ChangeProposalReviewsProps) =
<Tooltip title={review.createdBy.name}>
<Avatar
component={RouterLink}
to={`/profile/${review.createdBy.username}`}
to={`/profiles/${review.createdBy.username}`}
alt={review.createdBy.name}
src={review.createdBy.imageUrl}
sx={{ width: 24, height: 24 }}
/>
</Tooltip>
<Link variant="body1" component={RouterLink} to={`/profile/${review.createdBy.username}`}>
<Link variant="body1" component={RouterLink} to={`/profiles/${review.createdBy.username}`}>
{review.createdBy.username}
</Link>
<Typography> approved these changes</Typography>
Expand Down Expand Up @@ -360,13 +360,13 @@ const ChangeProposalReviews = ({ changeProposal }: ChangeProposalReviewsProps) =
<Tooltip title={review.createdBy.name}>
<Avatar
component={RouterLink}
to={`/profile/${review.createdBy.username}`}
to={`/profiles/${review.createdBy.username}`}
alt={review.createdBy.name}
src={review.createdBy.imageUrl}
sx={{ width: 24, height: 24 }}
/>
</Tooltip>
<Link variant="body1" component={RouterLink} to={`/profile/${review.createdBy.username}`}>
<Link variant="body1" component={RouterLink} to={`/profiles/${review.createdBy.username}`}>
{review.createdBy.username}
</Link>
<Typography> requested updates</Typography>
Expand Down
35 changes: 35 additions & 0 deletions frontend/svalyn-studio-app/src/views/domains/DomainRouter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2023 Stéphane Bégaudeau.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { Outlet, Route, Routes } from 'react-router-dom';
import { DomainView } from '../domain/DomainView';
import { DomainsView } from './DomainsView';

export const DomainRouter = () => {
return (
<>
<Routes>
<Route index element={<DomainsView />} />
<Route path=":domainIdentifier" element={<DomainView />} />
</Routes>

<Outlet />
</>
);
};
33 changes: 33 additions & 0 deletions frontend/svalyn-studio-app/src/views/error/ErrorRouter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 Stéphane Bégaudeau.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { Outlet, Route, Routes } from 'react-router-dom';
import { ErrorView } from './ErrorView';

export const ErrorRouter = () => {
return (
<>
<Routes>
<Route index element={<ErrorView />} />
</Routes>

<Outlet />
</>
);
};
33 changes: 33 additions & 0 deletions frontend/svalyn-studio-app/src/views/help/HelpRouter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 Stéphane Bégaudeau.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { Outlet, Route, Routes } from 'react-router-dom';
import { HelpView } from './HelpView';

export const HelpRouter = () => {
return (
<>
<Routes>
<Route index element={<HelpView />} />
</Routes>

<Outlet />
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 Stéphane Bégaudeau.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { Outlet, Route, Routes } from 'react-router-dom';
import { InvitationsView } from './InvitationsView';

export const InvitationRouter = () => {
return (
<>
<Routes>
<Route index element={<InvitationsView />} />
</Routes>

<Outlet />
</>
);
};
33 changes: 33 additions & 0 deletions frontend/svalyn-studio-app/src/views/login/LoginRouter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 Stéphane Bégaudeau.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { Outlet, Route, Routes } from 'react-router-dom';
import { LoginView } from './LoginView';

export const LoginRouter = () => {
return (
<>
<Routes>
<Route index element={<LoginView />} />
</Routes>

<Outlet />
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 Stéphane Bégaudeau.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { Outlet, Route, Routes } from 'react-router-dom';
import { NewOrganizationView } from './NewOrganizationView';

export const NewRouter = () => {
return (
<>
<Routes>
<Route path="organization" element={<NewOrganizationView />} />
</Routes>

<Outlet />
</>
);
};
Loading

0 comments on commit 40a13e4

Please sign in to comment.