[payload-plugin-ab]: the slug and tenant fields stay editable on variants when they sit inside a layout field (row, collapsible, unnamed group or tab)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- backend
Research direction
Start with packages/payload-plugin-ab/src/utils/injectAdminFields.ts and trace how patchField handles fields passed to injectAdminFields. Update the traversal for the layout containers listed in the issue, then read packages/payload-plugin-ab/tests/utils/injectAdminFields.test.ts and cover the listed nested, named-group, and existing-admin cases. Done when variant fields in supported layout containers are hidden and the named-group case remains unchanged.
Written by the indexing model from the issue text.
Description
TL;DR
The plugin hides the bucket field (slugField) and the tenant field on variant documents, but it looks for them only among a collection's top-level fields. When a collection puts the field inside a layout-only container (a row, a collapsible, an unnamed group or an unnamed tab), nothing is hidden and no warning is logged. Editors then see the variant's <slug>--<id> value and can change it, which breaks the variant's bucket. The data path is unchanged, because those containers add no data level, so the plugin's reads and writes still work. Only the admin condition is lost. The fix is a recursive patchField that walks layout containers, plus a unit test.
For the implementing agent
Scope
- Package:
packages/payload-plugin-ab(@focus-reactive/payload-plugin-ab), seen in 2.10.1, still present in 2.11.1. - File:
packages/payload-plugin-ab/src/utils/injectAdminFields.ts. New test:packages/payload-plugin-ab/tests/utils/injectAdminFields.test.ts. - Line numbers refer to commit 2065eea8.
Root cause
injectAdminFields.ts:29-34:
/** Find a top-level field by name and patch it. Returns the new fields array. */
function patchField(fields: Field[], name: string, patcher: (f: Field) => Field): Field[] {
return fields.map((f) => {
if ("name" in f && f.name === name) return patcher(f);
return f;
});
}
- It is called for the bucket field at line 94 and for the tenant field at line 99.
- A field nested in
{ type: "group", label: "URL", admin: { position: "sidebar" }, fields: [slug, ...] }is never matched, sohideOnVariant(lines 17-26) is never applied. - The plugin reads and writes the value at the document's top level (
variantDoc[slugField]ingenerateVariantData,parentDoc[slugField]and[slugField]: `${originalSlug}--${nanoid()}`in the duplicate-variant endpoint). Layout containers keep that path, so only the hiding fails.
Change
Make patchField recurse into containers that do not add a data level, and stop at the first match:
row,collapsible: recurse intofieldsgroupwithoutname: recurse intofieldstabs: recurse into each tab withoutname
Do not recurse into named groups, named tabs, arrays or blocks. A field there has a different data path, and hiding it would hide an unrelated field with the same name.
Optional: log a warning (once per collection) when slugField matches no field. Today a typo or a moved field fails silently.
Test
tests/utils/injectAdminFields.test.ts. For each case, call injectAdminFields and assert that the matched field's admin.condition returns false for { _abVariantOf: 1 } and true for {}:
slugat the top level (current behaviour, must keep passing).sluginside an unnamed sidebar group.sluginside a collapsible inside an unnamed tab.sluginside a named groupmeta: no condition is added, and the top-level fields are unchanged.- An existing
adminon the field (e.g.description,position) is kept.
Reproduction
-
Add a collection to the plugin's
collectionswith the slug field in a sidebar group:fields: [ { type: "group", label: "URL", admin: { position: "sidebar" }, fields: [{ name: "slug", type: "text", required: true }], }, { name: "title", type: "text" }, ] -
Create a document, then create an A/B variant from the admin.
-
Open the variant: the URL group shows
slugwith<slug>--<id>, editable. Expected: the field is hidden, as it is whenslugis a top-level field.
Workaround
Keep slugField (and the tenant field) as a top-level field with admin.position: "sidebar", outside any group.
- Dominant language
- TypeScript
- Stars
- 34
- Forks
- 5
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 41
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from focusreactive/payload-plugins
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
focusreactive/payload-plugins#263 ·
Maintainers usually reply within 1 day
-
comments, seo, analytics, and presets publish ESM that fails to load in Node.js (follow-up to #149)Open
Difficulty 3/5 1-2 days Newbie friendliness 62/100
focusreactive/payload-plugins#240 ·
Maintainers usually reply within 1 day
-
released released on @next
Difficulty 5/5 Over a week Newbie friendliness 35/100
focusreactive/payload-plugins#210 · 10 comments ·
Maintainers usually reply within 1 day
-
[translator] Re-extract the traversal engine into its own packageMay be free again @SearheiParkhamchuk claimed this 41 days ago, and no pull request is open. Openchore low priority translator
focusreactive/payload-plugins#203 · 1 assignee ·
Maintainers usually reply within 1 day
-
[translator] Open the seam to hosts: export the module type and provenance()May be free again @SearheiParkhamchuk claimed this 41 days ago, and no pull request is open. Openenhancement low priority translator
focusreactive/payload-plugins#202 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in focusreactive/payload-plugins
Similar issues
-
verified whatsapp
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 6 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 2 days
-
openidconnect: option to use client_secret_post (client_id with "-" rejected by LemonLDAP::NG 2.21)Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
MTES-MCT/monitorenv#3257 ·
Maintainers usually reply within 1 day