[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)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 82/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript
- 領域
- backend
調査の方向性
packages/payload-plugin-ab/src/utils/injectAdminFields.tsから始め、patchFieldがinjectAdminFieldsに渡されたフィールドをどのように処理するかを追ってください。issueに記載されたレイアウトコンテナに対応するよう、走査処理を更新してください。次に、packages/payload-plugin-ab/tests/utils/injectAdminFields.test.tsを読み、記載されたネストされたケース、名前付きグループのケース、既存のadminフィールドがあるケースを網羅してください。対応するレイアウトコンテナ内でvariantフィールドが非表示になり、名前付きグループのケースが変更されない状態になれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- TypeScript
- スター
- 34
- フォーク
- 5
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 41
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
focusreactive/payload-plugins のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
focusreactive/payload-plugins#263 ·
メンテナーはふだん 1 日以内に返信
-
comments, seo, analytics, and presets publish ESM that fails to load in Node.js (follow-up to #149)オープン
難易度 3/5 1〜2日 初心者へのやさしさ 62/100
focusreactive/payload-plugins#240 ·
メンテナーはふだん 1 日以内に返信
-
released released on @next
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
focusreactive/payload-plugins#210 · コメント 10 件 ·
メンテナーはふだん 1 日以内に返信
-
[translator] Re-extract the traversal engine into its own package再び着手できるかも @SearheiParkhamchuk が 41 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンchore low priority translator
focusreactive/payload-plugins#203 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
[translator] Open the seam to hosts: export the module type and provenance()再び着手できるかも @SearheiParkhamchuk が 41 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンenhancement low priority translator
focusreactive/payload-plugins#202 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
focusreactive/payload-plugins の issue をすべて見る
似ている issue
-
verified whatsapp
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
メンテナーはふだん 6 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 2 日以内に返信
-
openidconnect: option to use client_secret_post (client_id with "-" rejected by LemonLDAP::NG 2.21)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
MTES-MCT/monitorenv#3257 ·
メンテナーはふだん 1 日以内に返信