Registry: let an add-on add routes under another add-on's layout

Open
#225 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
react, typescript

Research direction

Start by reading the route registration and generation code that produces .plone/registry.routes.json, then compare it with the layout route in packages/publicui/index.ts. Work out how parent ids, load order, and missing-parent behavior should fit the registry; done means add-ons can register child routes by parent id without depending on configuration order, with the missing-parent behavior documented or reported clearly.

Written by the indexing model from the issue text.

Description

Summary

An add-on can register a route at the top of the tree, but it cannot add one under a layout another add-on registered. A page registered with registerRoute renders without the site's frame: no header, no navigation, no user tools, so no way back. To get the frame, a page has to be a child of @plone/publicui's layout route (packages/publicui/index.ts), and the registry has no way to add one.

The use case

pas.plugins.identity, ported to Aurora in collective/pas-plugins-identity#132, adds signed-in pages: /identities (sign-in methods), /applications (authorized OAuth applications), /confirm-email, /complete-profile and /oauth-consent.

They belong inside the site's frame, beside publicui's own search page. They are reached from links in the header's authenticatedTools slot, and the header is how the user gets back.

The add-on finds publicui's layout entry by its file and pushes its routes into its children:

// pas.plugins.identity, frontend/packages/aurora-identity/lib/routes.ts
export function addRouteUnder(routes, layoutFile, route): boolean {
  for (const entry of routes) {
    if (entry.type === 'layout' && entry.file === layoutFile) {
      entry.children.push(route);
      return true;
    }
    if ('children' in entry && entry.children) {
      if (addRouteUnder(entry.children, layoutFile, route)) return true;
    }
  }
  return false;
}

addRouteUnder(config.routes, '@plone/publicui/routes/index.tsx', IDENTITIES_ROUTE);

(source)

It falls back to registerRoute at the top when publicui is not there.

The same problems as replacing a route:

  • It depends on another package's file path.
  • It depends on that package being configured first.
  • It is a mutation of the registry's own array that nothing records.

What it depends on in React Router. The page's path (identities) is static, so React Router ranks it above publicui's * catch-all. Without that, the order of children would matter, and the add-on would have to insert before the catch-all.

Proposal

Let registerRoute name a parent:

config.registerRoute({
  parent: 'publicui-layout', // the layout route's options.id
  type: 'route',
  path: 'identities',
  file: '@plone-collective/aurora-identity/routes/identities.tsx',
  options: { id: 'identity-identities' },
});

The pieces it needs:

  • Stable, documented ids for the layouts add-ons are expected to extend: publicui's site layout and cmsui's layout at least.
  • Load order handled by the registry. Children are attached when .plone/registry.routes.json is generated, after every add-on has been configured, so registration order does not matter.
  • A clear error when the named parent does not exist. Or a documented fallback to the top level, which is what an add-on that should work with or without publicui wants.

An alternative is a well-known slot of routes in the site layout, but routes registered by id compose better with route replacement (plone/aurora#224).

Related

Dominant language
JavaScript
Stars
10
Forks
9
Avg merge
4d 7h
Merged PRs (30d)
54

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from plone/aurora

All issues in plone/aurora

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.