[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)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 82/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- backend
Línea de trabajo
Empieza con packages/payload-plugin-ab/src/utils/injectAdminFields.ts y sigue cómo patchField procesa los campos que se pasan a injectAdminFields. Actualiza el recorrido para los contenedores de diseño indicados en el issue. Luego, lee packages/payload-plugin-ab/tests/utils/injectAdminFields.test.ts y cubre los casos anidados, los grupos con nombre y los casos con campos de admin existentes que se indican. El trabajo está terminado cuando los campos variant se ocultan en los contenedores de diseño compatibles y el caso del grupo con nombre permanece sin cambios.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 34
- Forks
- 5
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 41
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de focusreactive/payload-plugins
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
focusreactive/payload-plugins#263 ·
Los mantenedores suelen responder en 1 día
-
comments, seo, analytics, and presets publish ESM that fails to load in Node.js (follow-up to #149)Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 62/100
focusreactive/payload-plugins#240 ·
Los mantenedores suelen responder en 1 día
-
released released on @next
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
focusreactive/payload-plugins#210 · 10 comentarios ·
Los mantenedores suelen responder en 1 día
-
[translator] Re-extract the traversal engine into its own packageQuizá libre de nuevo @SearheiParkhamchuk la tomó hace 41 días y no hay ningún pull request abierto. Abiertochore low priority translator
focusreactive/payload-plugins#203 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[translator] Open the seam to hosts: export the module type and provenance()Quizá libre de nuevo @SearheiParkhamchuk la tomó hace 41 días y no hay ningún pull request abierto. Abiertoenhancement low priority translator
focusreactive/payload-plugins#202 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de focusreactive/payload-plugins
Issues similares
-
verified whatsapp
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 6 días
-
Feature: use a darkmode logoAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 2 días
-
openidconnect: option to use client_secret_post (client_id with "-" rejected by LemonLDAP::NG 2.21)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Amélioration du résumé regAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
MTES-MCT/monitorenv#3257 ·
Los mantenedores suelen responder en 1 día