Skip to content

Convert the Templates route tree to react-router v6 (the last Switch)#484

Open
blaipr wants to merge 2 commits into
ctrliq:mainfrom
blaipr:feature/templates-router-v6
Open

Convert the Templates route tree to react-router v6 (the last Switch)#484
blaipr wants to merge 2 commits into
ctrliq:mainfrom
blaipr:feature/templates-router-v6

Conversation

@blaipr

@blaipr blaipr commented Jun 17, 2026

Copy link
Copy Markdown
Contributor
SUMMARY

Converts the Templates route tree to react-router v6, which removes the last <Switch> left on main.

Now that App.js is v6 (#425), it mounts Templates as a descendant at /templates/*. Templates.js was still a v5-compat <Switch> with absolute paths, kept that way deliberately while the rest of the migration landed. It kept working because <Switch> prefix-matches the full path, but it has to become v6 <Routes> before the react-router-dom-v5-compat bridge can be removed.

What changed:

  • Templates.js: <Switch> becomes <Routes> with relative children (job_template/add, workflow_job_template/add, job_template/:id/*, workflow_job_template/:id/*, and an index route for the list).
  • Template.js and WorkflowJobTemplate.js: their internal <Routes> move to relative paths (dropping the :templateType/:id/ prefix that assumed a /templates base), and useParams now comes from react-router-dom-v5-compat. A v5 useParams returns {} for a v6 descendant, which would have made the template id come through as undefined.
  • The three test files remount these components under the real v6 parent route so useParams resolves the id, matching how Templates.js mounts them.
ISSUE TYPE
  • Bug, Docs Fix or other nominal change
COMPONENT NAME
  • UI
ASCENDER VERSION
awx: 25.4.1.dev61+gb47febf4d1
ADDITIONAL INFORMATION

Verified locally:

  • npm --prefix awx/ui run test for the four Template suites: 23 of 23 tests pass. ESLint clean on the three production files.
  • Browser smoke test on a dev instance (port 3002) against a running backend, since unit tests mock the router and miss real route resolution. Logged in and walked all 18 Template routes: the list, both add forms, and every detail tab for a job template and a workflow job template (details, access, notifications, schedules, jobs, survey, edit, visualizer). No route landed on a not-found page and there were no /api/v2/.../undefined/... requests. The one 4xx seen was /api/v2/projects/null/ on a job template whose project field is genuinely null, which is a property of that template's edit form and not related to routing. Re-running edit on a job template that has a project was clean.

blaipr added 2 commits June 17, 2026 11:59
App.js is now v6 (ctrliq#425) and mounts Templates as a descendant at /templates/*, so Templates.js becomes v6 <Routes> with relative children (job_template/add, workflow_job_template/add, job_template/:id/*, workflow_job_template/:id/*, index list). Template.js and WorkflowJobTemplate.js move their internal <Routes> to relative paths and read useParams from react-router-dom-v5-compat (v5 useParams returns {} as a v6 descendant). Tests remount these under the real v6 parent route. This removes the last <Switch> from main, unblocking the eventual react-router-dom-v5-compat bridge removal.
These three files were the only overlap between this PR and the screens/Template RTL conversion (ctrliq#483). Make this PR own them outright: convert them from enzyme to React Testing Library, mounted under the real v6 parent route so useParams resolves :id. ctrliq#483 drops these three so the two PRs become independently mergeable in either order, with all three landing as RTL.
blaipr added a commit to blaipr/ascender that referenced this pull request Jun 17, 2026
Templates.test.js, Template.test.js and WorkflowJobTemplate.test.js are the only files this PR shared with ctrliq#484 (Templates route tree -> v6). ctrliq#484 now owns and RTL-converts those three (mounted for v6). Revert them here so the two PRs touch disjoint files and are independently mergeable in either order; this PR still converts the rest of screens/Template to RTL.
@cigamit cigamit requested a review from Copilot June 17, 2026 22:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR completes the react-router v6 migration for the Templates route subtree by replacing the remaining v5 <Switch>/absolute-path routing with v6 <Routes> and relative child routes, aligning behavior with the v6 App.js parent mount at /templates/*.

Changes:

  • Convert Templates.js to v6-style <Routes> with relative paths and an index route for the list view.
  • Update Template.js and WorkflowJobTemplate.js to use relative nested routes and useParams from react-router-dom-v5-compat so :id resolves correctly as v6 descendants.
  • Rework affected test suites to mount components under the real v6 parent route using RTL helpers so params and nested routing resolve as in the app.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
awx/ui/src/screens/Template/Templates.js Switches Templates subtree routing from v5 <Switch> to v6 <Routes> with relative child routes.
awx/ui/src/screens/Template/Template.js Makes Template detail tab routes relative and updates param sourcing for v6-descendant correctness.
awx/ui/src/screens/Template/WorkflowJobTemplate.js Makes WorkflowJobTemplate tab routes relative and updates param sourcing for v6-descendant correctness.
awx/ui/src/screens/Template/Templates.test.js Updates the Templates smoke test to mount under /templates/* using RTL contexts.
awx/ui/src/screens/Template/Template.test.js Updates Template tests to mount under the v6 parent route and use RTL assertions.
awx/ui/src/screens/Template/WorkflowJobTemplate.test.js Updates WorkflowJobTemplate tests to mount under the v6 parent route and use RTL assertions.

Comment on lines +82 to +92
<Route
index
element={
<PageSection>
<PersistentFilters pageKey="templates">
<TemplateList />
</PersistentFilters>
</PageSection>
}
/>
</Routes>
Comment on lines +23 to +34
function renderTemplate(entry = '/templates/job_template/1/foobar') {
const history = createMemoryHistory({ initialEntries: [entry] });
return renderWithContexts(
<Routes>
<Route
path="/templates/job_template/:id/*"
element={<Template setBreadcrumb={() => {}} me={mockMe} />}
/>
</Routes>,
{ context: { router: { history } } }
);
}
Comment on lines +25 to +36
function renderWFJT(entry = '/templates/workflow_job_template/1/foobar', me = mockMe) {
const history = createMemoryHistory({ initialEntries: [entry] });
return renderWithContexts(
<Routes>
<Route
path="/templates/workflow_job_template/:id/*"
element={<WorkflowJobTemplate setBreadcrumb={() => {}} me={me} />}
/>
</Routes>,
{ context: { router: { history } } }
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants