Skip to content

Conversation

@kurtdoherty
Copy link
Contributor

@kurtdoherty kurtdoherty commented Mar 14, 2025

fixes: #26

Scope

  • Refactor example pages to use RR6's nested routing;
  • Restructure pages to encourage better domain boundaries.

note: I've also smuggled in an upgrade to React 19

Out-of-scope

The following changes have been explicitly de-scoped for now:

  • Refactoring of data loading architecture to reduce request waterfalls;
  • Use of route loaders to initiative retrieval of page data early.

Changes

The main changes to the folder structure are as follows:

Before After
components/contacts/list components/contacts/ContactListPage
components/contacts/edit components/contacts/ContactDetailPage
components/contacts/form components/contacts/common/ContactForm
components/contacts/new components/contacts/CreateContactPage
components/contacts/page components/contacts/ViewContactDesktopRedirect
components/contacts/view components/contacts/ContactDetailPage/FullContactDetails
components/contacts/routes.ts
components/login components/LoginPage
components/login/routes.ts
components/new/page components/new/NewPage
components/new/routes.ts
constants/routes.ts
core/router.tsx
routes.tsx

@kurtdoherty kurtdoherty force-pushed the refactor-react-router-usage branch 5 times, most recently from fb6fb50 to aa7fa9b Compare March 14, 2025 03:53
@kurtdoherty kurtdoherty force-pushed the refactor-react-router-usage branch from aa7fa9b to 50bfdaa Compare March 14, 2025 03:59
"dayjs": "^1.11.13",
"just-debounce-it": "^3.2.0",
"qs": "^6.14.0",
"query-string": "9.1.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: small scout to bump React and TypeScript to the their most recent minor versions. A React 19 upgrade for this template is not in scope for this work.

@@ -1,9 +1,9 @@
import { LoginModule } from '..'
import { LoginPage } from '..'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: You'll see many changes like this where I've updated the name of the exported component to align with that component's updated folder name.

}

export const LoginModule: FC = () => {
export const LoginPage = () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: FC is generally not needed, so I've removed it where I've made other changes.

note: As noted in the test file, you'll see lots of renaming of the components I've moved so they're component name matches their folder name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: This was originally components/contacts/edit. The design of this page is weird as it combines both a "detail" page AND a series of edit/update forms 🤷 This is not aligned in anyway with the design system, but it's beyond the scope of this work to change it here.

The only changes I've made to this file, like most of the other page components, is replacing the use of the old "routes" constants with the new URL builders.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: This used to be components/contacts/page. It's now solely responsible for handling the redirect to the detail page from (I assume) the Agency Cloud desktop application.

}

describe('PrivateRouteWrapper', () => {
it('should match a snapshot', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: PrivateRouteWrapper no longer accepts children as it renders an Outlet instead.

<MemoryRouter>
<Routes>
<Route path="/" element={children} />
<Route path="/foo" element="Foo" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Extra route for one of the tests so we don't need to assert on a function being called, but can instead assert on DOM content


if (connectInternalRedirect && location?.pathname !== connectInternalRedirect) {
redirect(connectInternalRedirect)
return <Navigate to={connectInternalRedirect} replace />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: redirect is not intended for use in components; that's what Navigate is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: new top-level route config. Maintains lazy loading of all routes except the login page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: This file enables all the contact pages to be lazy loaded by RR6's router. When we upgrade to RR7, these "route prop" objects will move to individual files. For now though, this is a simple way of enabling lazy loading without having to jump through too many hoops in our route config (routes.tsx)

There's one of these for the "new page" as well.

@kurtdoherty kurtdoherty requested a review from ksolanki7 March 14, 2025 04:13
@kurtdoherty
Copy link
Contributor Author

@ksolanki7 Apologies for the size of this PR 😬 It was going to take too long to stage it all nicely. For the most part, I don't think there's a whole lot here that needs your review, but I've added comments throughout.

Copy link
Contributor

@ksolanki7 ksolanki7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kurtdoherty Changes look good to me,

  • I have run this locally, there are no issues found so far.
  • I'll approve the PR now and then play with this new architecture for building routes over ABX project.

Note: I'll approach you if have any concerns or suggestion while working on the project.

@kurtdoherty kurtdoherty merged commit 702da11 into master Mar 18, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants