feat(ui): add admin.groups for ordering nav groups in the sidebar#17098
Open
devinoldenburg wants to merge 1 commit into
Open
feat(ui): add admin.groups for ordering nav groups in the sidebar#17098devinoldenburg wants to merge 1 commit into
devinoldenburg wants to merge 1 commit into
Conversation
The admin sidebar renders nav groups in first-encounter order, which forces the implicit Collections/Globals groups to the top and pushes globals-only custom groups to the bottom. There has been no config option to control the order of the groups themselves (Discussion payloadcms#1277, open since Oct 2022). Add an optional `admin.groups` array to the sanitized config. When present, `groupNavItems` sorts the resulting groups to match it; groups not listed keep their existing first-encounter order and are appended after the listed ones, so the default behavior is preserved when the option is omitted or empty. Labels are compared against the translated group label, so the same value used in `admin.group` (or `general:collections` / `general:globals` for the default groups) should be used. Refs payloadcms#17097
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Adds an optional
admin.groupsarray that controls the order nav groups render in the admin sidebar. Example:groups?: (Record<string, string> | string)[]to the top-leveladminconfig type (packages/payload/src/config/types.ts).groupOrder?parameter togroupNavItems(packages/ui/src/utilities/groupNavItems.ts) and a new exportedsortGroupsByOrderhelper. WhengroupOrderis provided and non-empty, the resulting groups are sorted to match it; groups not listed keep their existing first-encounter order and are appended after the listed ones.config.admin?.groupsthrough both call sites:getNavGroups(dashboard cards / dashboard view) andNav/index.tsx(sidebar).Why?
Today the sidebar renders nav groups in first-encounter order. Because
groupNavItemsseeds its reducer with[Collections, Globals], the implicit Collections group is always forced to the top and globals-only custom groups are always forced to the bottom, regardless of how the user declares their config. There is no config option to control group order (Discussion #1277, open since Oct 2022, 26+ upvotes; Discussion #14528). The only workarounds today are prefix hacks likegroup: '1. System'(which leak the digit into the rendered label) or swapping in a fully customNavcomponent.This has come up repeatedly for ~3.5 years without a core fix. Tracking issue: #17097.
How?
The change is intentionally minimal and backward compatible:
groupNavItemskeeps its existing reduce + seed-array behavior unchanged, so whengroupOrderis omitted the output is byte-identical to before.filter(group => group.entities.length > 0)step, ifgroupOrderis a non-empty array, the filtered groups are passed throughsortGroupsByOrder, which:groupOrderand pushes the first unmatched group whose translated label equals the wanted label,getTranslation(..., i18n), so the same value used inadmin.groupworks. For the default groups, users should use the translation key ('Collections'/'Globals') — shown in the JSDoc example.The two callers pass
config.admin?.groups(sanitized config, always present) orpayload.config.admin.groups(already destructured onpayload.config).Before / After
Config:
Before (
admin.groupsignored — first-encounter order):After (
admin.groupsrespected):Tests
Added
packages/ui/src/utilities/groupNavItems.spec.ts(vitest, same style as the neighboring.spec.tsfiles inpackages/ui/src/utilities/). Covers:groupOrderis omitted,admin.groups,admin.groupsarray keeps default behavior.All 5 pass locally:
This PR only changes group-level ordering. Item-level ordering within a group is intentionally left as-is (definition order) to keep the change minimal and backward compatible; that can be a follow-up.
Fixes #17097