@delmaredigital/payload-experiments 0.4.0-rc.5 → 0.4.0-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/dist/admin/blocks/BlockPanel.js +6 -4
  2. package/dist/admin/blocks/inject.js +1 -0
  3. package/dist/admin/blocks/model.d.ts +3 -2
  4. package/dist/admin/blocks/model.js +8 -4
  5. package/dist/admin/copy/blocks.d.ts +3 -2
  6. package/dist/admin/copy/blocks.js +7 -6
  7. package/dist/admin/copy/newTest.d.ts +1 -1
  8. package/dist/admin/copy/newTest.js +1 -1
  9. package/dist/admin/surface/ResultsRoute.js +2 -1
  10. package/dist/admin/surface/TestsHome.d.ts +2 -1
  11. package/dist/admin/surface/TestsHome.js +91 -37
  12. package/dist/admin/surface/TestsSurface.js +3 -0
  13. package/dist/admin/surface/home.model.d.ts +2 -0
  14. package/dist/admin/surface/newTest/NewTest.js +16 -18
  15. package/dist/admin/surface/newTest/PageWizard.js +1 -0
  16. package/dist/admin/surface/newTest/newTest.css +3 -1
  17. package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
  18. package/dist/admin/views/TestsSurfaceClient.js +11 -0
  19. package/dist/admin/views/buildSurfaceProps.js +10 -3
  20. package/dist/blocks/bindings.js +8 -14
  21. package/dist/blocks/placementLanguages.d.ts +7 -0
  22. package/dist/blocks/placementLanguages.js +27 -0
  23. package/dist/blocks/placementLocale.d.ts +23 -7
  24. package/dist/blocks/placementLocale.js +221 -66
  25. package/dist/db/appends.d.ts +13 -0
  26. package/dist/db/appends.js +49 -0
  27. package/dist/db/bulkPlacementRemoval.js +8 -4
  28. package/dist/endpoints/contentLocale.d.ts +6 -0
  29. package/dist/endpoints/contentLocale.js +15 -0
  30. package/dist/endpoints/deleteImpact.d.ts +6 -0
  31. package/dist/endpoints/deleteImpact.js +206 -0
  32. package/dist/endpoints/index.js +7 -0
  33. package/dist/endpoints/pages.js +7 -3
  34. package/dist/endpoints/placementStatus.js +6 -1
  35. package/dist/endpoints/preflight.d.ts +1 -1
  36. package/dist/endpoints/preflight.js +17 -2
  37. package/dist/exports/adminClient.d.ts +1 -1
  38. package/dist/exports/adminClient.js +1 -1
  39. package/dist/exports/index.d.ts +1 -1
  40. package/dist/goals/fairness.js +43 -34
  41. package/dist/hooks/blockRemovalRule.d.ts +4 -3
  42. package/dist/hooks/blockRemovalRule.js +33 -9
  43. package/dist/hooks/pageGuard.d.ts +3 -0
  44. package/dist/hooks/pageGuard.js +34 -24
  45. package/dist/hooks/puckNestedTests.d.ts +8 -0
  46. package/dist/hooks/puckNestedTests.js +36 -0
  47. package/dist/lib/placementPages.d.ts +2 -1
  48. package/dist/lib/placementPages.js +10 -2
  49. package/dist/manifest/compile.d.ts +2 -1
  50. package/dist/manifest/compile.js +5 -1
  51. package/dist/puck/ExperimentPicker.d.ts +2 -1
  52. package/dist/puck/ExperimentPicker.js +37 -30
  53. package/dist/puck/ExperimentSlot.js +3 -1
  54. package/dist/puck/copy.d.ts +1 -0
  55. package/dist/puck/copy.js +1 -0
  56. package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
  57. package/dist/puck/editor/ConfigureTestDrawer.js +4 -2
  58. package/dist/puck/editor/CreateExperimentDrawer.d.ts +2 -1
  59. package/dist/puck/editor/CreateExperimentDrawer.js +24 -20
  60. package/dist/puck/editor/EditorControls.d.ts +1 -1
  61. package/dist/puck/editor/EditorControls.js +1 -1
  62. package/dist/puck/editor/ExperimentSlotEditor.js +405 -394
  63. package/dist/puck/editor/LeftoverVersions.d.ts +4 -2
  64. package/dist/puck/editor/LeftoverVersions.js +23 -44
  65. package/dist/puck/editor/QuickTestActions.js +2 -2
  66. package/dist/puck/editor/VersionBuilder.d.ts +41 -13
  67. package/dist/puck/editor/VersionBuilder.js +461 -224
  68. package/dist/puck/editor/armWrites.d.ts +9 -2
  69. package/dist/puck/editor/armWrites.js +40 -2
  70. package/dist/puck/editor/armsCache.d.ts +1 -1
  71. package/dist/puck/editor/armsCache.js +2 -1
  72. package/dist/puck/editor/blockClipboard.d.ts +16 -0
  73. package/dist/puck/editor/blockClipboard.js +20 -0
  74. package/dist/puck/editor/copy.d.ts +27 -26
  75. package/dist/puck/editor/copy.js +28 -26
  76. package/dist/puck/editor/createTest.d.ts +3 -0
  77. package/dist/puck/editor/createTest.js +33 -0
  78. package/dist/puck/editor/editor.chrome.css +138 -17
  79. package/dist/puck/editor/editor.css +156 -22
  80. package/dist/puck/editor/editor.model.d.ts +2 -1
  81. package/dist/puck/editor/editor.model.js +3 -3
  82. package/dist/puck/editor/experimentOutlinePlugin.js +1 -1
  83. package/dist/puck/editor/localPlacements.d.ts +5 -2
  84. package/dist/puck/editor/localPlacements.js +32 -18
  85. package/dist/puck/editor/placementsCache.d.ts +18 -12
  86. package/dist/puck/editor/placementsCache.js +52 -47
  87. package/dist/puck/editor/sidebar.d.ts +2 -6
  88. package/dist/puck/editor/sidebar.js +3 -6
  89. package/dist/puck/editor/usePlacementNotice.d.ts +1 -1
  90. package/dist/puck/editor/usePlacementNotice.js +4 -3
  91. package/dist/puck/experimentSlug.d.ts +2 -0
  92. package/dist/puck/experimentSlug.js +3 -0
  93. package/dist/puck/nestedTestCopy.d.ts +8 -0
  94. package/dist/puck/nestedTestCopy.js +22 -0
  95. package/dist/puck/nestedTests.d.ts +17 -0
  96. package/dist/puck/nestedTests.js +30 -0
  97. package/dist/puck/slotConfig.d.ts +1 -1
  98. package/dist/puck/slotConfig.js +17 -4
  99. package/dist/puck/visibility.d.ts +20 -0
  100. package/dist/puck/visibility.js +81 -0
  101. package/dist/server/recordContentChange.js +37 -20
  102. package/dist/server/resolveExperimentData.js +6 -3
  103. package/dist/testSurface/PreviewLinks.js +6 -2
  104. package/dist/testSurface/api.d.ts +6 -3
  105. package/dist/testSurface/api.js +10 -6
  106. package/dist/testSurface/contentLocaleURL.d.ts +2 -0
  107. package/dist/testSurface/contentLocaleURL.js +3 -0
  108. package/dist/testSurface/copy/common.d.ts +4 -0
  109. package/dist/testSurface/copy/common.js +8 -4
  110. package/dist/testSurface/copy/languages.d.ts +11 -0
  111. package/dist/testSurface/copy/languages.js +7 -0
  112. package/dist/testSurface/copy/readiness.d.ts +2 -1
  113. package/dist/testSurface/copy/readiness.js +2 -1
  114. package/dist/testSurface/copy/testPage.d.ts +28 -6
  115. package/dist/testSurface/copy/testPage.js +28 -6
  116. package/dist/testSurface/placementLabel.d.ts +8 -0
  117. package/dist/testSurface/placementLabel.js +24 -0
  118. package/dist/testSurface/placements/placementLabels.d.ts +2 -0
  119. package/dist/testSurface/placements/placementLabels.js +2 -1
  120. package/dist/testSurface/results/results.css +1 -1
  121. package/dist/testSurface/results/results.model.d.ts +1 -1
  122. package/dist/testSurface/surface/contracts.d.ts +2 -0
  123. package/dist/testSurface/surface/editorPlacement.d.ts +5 -0
  124. package/dist/testSurface/surface/editorPlacement.js +18 -0
  125. package/dist/testSurface/surface/pageBlock/pageBlock.model.js +2 -1
  126. package/dist/testSurface/surface/pageBlock/parts.js +24 -6
  127. package/dist/testSurface/surface/readiness/ActionDialogs.js +28 -34
  128. package/dist/testSurface/surface/readiness/readiness.model.js +9 -2
  129. package/dist/testSurface/surface/results/useResults.d.ts +4 -1
  130. package/dist/testSurface/surface/test/DeleteTest.d.ts +15 -0
  131. package/dist/testSurface/surface/test/DeleteTest.js +171 -0
  132. package/dist/testSurface/surface/test/GoalSection.js +101 -74
  133. package/dist/testSurface/surface/test/TestSurface.js +29 -9
  134. package/dist/testSurface/surface/test/fields.d.ts +1 -3
  135. package/dist/testSurface/surface/test/fields.js +5 -35
  136. package/dist/testSurface/surface/useTestDocument.d.ts +2 -1
  137. package/dist/testSurface/surface/useTestDocument.js +20 -4
  138. package/dist/testSurface/useApi.d.ts +4 -1
  139. package/dist/transitions/checkStart.d.ts +4 -1
  140. package/dist/transitions/checkStart.js +117 -14
  141. package/dist/transitions/contentFields.js +9 -5
  142. package/dist/transitions/makeContent.js +29 -9
  143. package/dist/transitions/nestedPlacementNames.d.ts +5 -0
  144. package/dist/transitions/nestedPlacementNames.js +33 -0
  145. package/dist/transitions/pageVersions.js +3 -1
  146. package/dist/transitions/placementInteractions.js +7 -4
  147. package/dist/transitions/placements.d.ts +26 -1
  148. package/dist/transitions/placements.js +239 -87
  149. package/dist/transitions/preflightData.d.ts +2 -1
  150. package/dist/transitions/preflightData.js +66 -3
  151. package/dist/transitions/start.js +4 -1
  152. package/dist/types/endpoints.d.ts +35 -1
  153. package/dist/types/endpoints.js +1 -1
  154. package/dist/types/puck.d.ts +1 -0
  155. package/dist/types/surface.d.ts +2 -0
  156. package/dist/ui/Button.js +2 -2
  157. package/dist/ui/Inputs.d.ts +4 -3
  158. package/dist/ui/Inputs.js +7 -4
  159. package/dist/ui/SelectControl.d.ts +33 -0
  160. package/dist/ui/SelectControl.js +504 -0
  161. package/dist/ui/Tabs.d.ts +0 -1
  162. package/dist/ui/Tabs.js +28 -40
  163. package/dist/ui/ui.css +18 -5
  164. package/package.json +3 -2
@@ -6,7 +6,7 @@ import { useEffect, useId, useRef, useState } from 'react';
6
6
  import { copyOriginalIntoVersion, syncExperimentSlots, unwrapExperimentBlock } from '../../blocks/formState.js';
7
7
  import { BLOCK_COPY, blockSyncNotice, blockUnwrapNotice, blockDeleteConfirmation, blockUnwrapConfirmation, blockRunningUnwrap, blockDecidedUnwrap, blockFinishedCopy } from '../../admin/copy/blocks.js';
8
8
  import { API_MESSAGES } from '../../testSurface/copy/common.js';
9
- import { isOrphan, liveStatus, slotLabel, statusSentence } from './model.js';
9
+ import { canUnwrapOriginal, liveStatus, slotLabel, statusSentence } from './model.js';
10
10
  import { createApi } from '../../testSurface/api.js';
11
11
  import { useBlockStatus, setBlockStatus } from './statusCache.js';
12
12
  import { useBlockForm } from './useBlockForm.js';
@@ -65,7 +65,9 @@ export function BlockStatusField({ path }) {
65
65
  const api = createApi(config.routes.api);
66
66
  const found = await api.findTestIdBySlug(block.experiment);
67
67
  if (!found.ok) throw new RefusalError(found.message);
68
- const removed = await api.deleteTest(found.data);
68
+ const removed = await api.deleteTest(found.data, {
69
+ draft: true
70
+ });
69
71
  if (!removed.ok) throw new RefusalError(removed.message);
70
72
  deleted = true;
71
73
  setBlockStatus(config.routes.api, block.experiment, {
@@ -81,7 +83,7 @@ export function BlockStatusField({ path }) {
81
83
  }
82
84
  }
83
85
  const sentence = statusSentence(status);
84
- const linkedCopy = liveStatus(status) ? status.status === 'running' ? blockRunningUnwrap : status.status === 'decided' ? blockDecidedUnwrap : status.status === 'archived' && status.winnerArm ? blockFinishedCopy(slotLabel(status.winnerArm, status)) : undefined : undefined;
86
+ const linkedCopy = liveStatus(status) ? status.status === 'running' ? blockRunningUnwrap : status.status === 'decided' ? blockDecidedUnwrap : status.status === 'archived' && status.winnerArm && !status.discarded ? blockFinishedCopy(slotLabel(status.winnerArm, status), status.winnerArm === 'control', status.winnerArm !== 'control' && canUnwrapOriginal(status, block)) : undefined : undefined;
85
87
  const href = formatAdminURL({
86
88
  adminRoute: config.routes.admin,
87
89
  path: `/experiments/by-slug/${encodeURIComponent(block?.experiment ?? '')}`
@@ -107,7 +109,7 @@ export function BlockStatusField({ path }) {
107
109
  role: "status",
108
110
  children: blockSyncNotice(Boolean(collection?.versions?.drafts))
109
111
  }) : null,
110
- isOrphan(status) || draft || stopped ? /*#__PURE__*/ _jsx(Button, {
112
+ canUnwrapOriginal(status, block) || draft || stopped ? /*#__PURE__*/ _jsx(Button, {
111
113
  disabled: busy,
112
114
  onClick: ()=>draft || stopped ? openModal(modalSlug) : void unwrap(),
113
115
  children: draft ? BLOCK_COPY.removeAndUnwrap : BLOCK_COPY.unwrap
@@ -7,6 +7,7 @@ import { XP_TEST_BLOCK } from '../paths.js';
7
7
  name: 'xpTestBlock',
8
8
  type: 'ui',
9
9
  admin: {
10
+ // Payload supplies the active locale's form data here; there is no raw adapter row.
10
11
  condition: (data)=>{
11
12
  try {
12
13
  return registration.appliesTo ? registration.appliesTo(data) === true : true;
@@ -1,4 +1,5 @@
1
1
  import type { PlacementStatusResult } from '../../types/endpoints.js';
2
+ import { type HostBlock } from '../../blocks/model.js';
2
3
  import type { RowsField } from './formApi.js';
3
4
  export type BlockStatus = PlacementStatusResult['slugs'][string];
4
5
  export type LiveBlockStatus = Extract<BlockStatus, {
@@ -7,10 +8,10 @@ export type LiveBlockStatus = Extract<BlockStatus, {
7
8
  export declare function liveStatus(status: BlockStatus | null): status is LiveBlockStatus;
8
9
  export declare function slotLabel(slot: string, status: BlockStatus | null): string;
9
10
  export declare function statusSentence(status: BlockStatus): string;
10
- export declare function isOrphan(status: BlockStatus): boolean;
11
+ export declare function canUnwrapOriginal(status: BlockStatus, block?: HostBlock): boolean;
11
12
  export declare function labelText(value: unknown): string | undefined;
12
13
  export declare function blockChoices(value: unknown, field: RowsField, blockSlug: string): {
13
- block: import("../../blocks/model.js").HostBlock;
14
+ block: HostBlock;
14
15
  index: number;
15
16
  label: string;
16
17
  option: string;
@@ -1,4 +1,4 @@
1
- import { hostBlocks } from '../../blocks/model.js';
1
+ import { hostBlocks, slotBlocks } from '../../blocks/model.js';
2
2
  import { BLOCK_COPY, blockDecidedStatus, blockDraftStatus, blockFinishedStatus, blockPosition } from '../../admin/copy/blocks.js';
3
3
  export function liveStatus(status) {
4
4
  return !!status && 'status' in status;
@@ -20,11 +20,15 @@ export function statusSentence(status) {
20
20
  case 'decided':
21
21
  return blockDecidedStatus(winnerLabel, status.rollout);
22
22
  case 'archived':
23
- return status.winnerArm ? blockFinishedStatus(winnerLabel) : BLOCK_COPY.discarded;
23
+ return status.discarded ? BLOCK_COPY.discarded : status.winnerArm ? blockFinishedStatus(winnerLabel, status.winnerArm === 'control') : BLOCK_COPY.neverDecided;
24
24
  }
25
25
  }
26
- export function isOrphan(status) {
27
- return !liveStatus(status) || status.status === 'archived' && !status.winnerArm;
26
+ export function canUnwrapOriginal(status, block) {
27
+ if (!liveStatus(status)) return true;
28
+ if (status.status !== 'archived') return false;
29
+ if (status.discarded || !status.winnerArm || status.winnerArm === 'control') return true;
30
+ const slot = status.arms.find((arm)=>arm.key === status.winnerArm)?.slot ?? status.winnerArm;
31
+ return !!block && slotBlocks(block, slot).length === 0;
28
32
  }
29
33
  export function labelText(value) {
30
34
  return typeof value === 'string' ? value : value && typeof value === 'object' ? Object.values(value).find((item)=>typeof item === 'string') : undefined;
@@ -18,6 +18,7 @@ export declare const BLOCK_COPY: {
18
18
  finishUnwrap: string;
19
19
  deleted: string;
20
20
  discarded: string;
21
+ neverDecided: string;
21
22
  running: string;
22
23
  stopped: string;
23
24
  slotLabels: Record<string, string>;
@@ -34,8 +35,8 @@ export type BlockLinkedCopy = {
34
35
  };
35
36
  export declare const blockRunningUnwrap: BlockLinkedCopy;
36
37
  export declare const blockDecidedUnwrap: BlockLinkedCopy;
37
- export declare const blockFinishedCopy: (winner: string) => BlockLinkedCopy;
38
- export declare const blockFinishedStatus: (winner: string) => string;
38
+ export declare const blockFinishedCopy: (winner: string, originalWon?: boolean, emptyWinner?: boolean) => BlockLinkedCopy;
39
+ export declare const blockFinishedStatus: (winner: string, originalWon?: boolean) => string;
39
40
  export declare const blockDeleteConfirmation: (name: string) => string;
40
41
  export declare const blockUnwrapConfirmation: (name: string) => string;
41
42
  export declare const blockUnwrapNotice: (drafts: boolean, deleted: boolean) => string;
@@ -18,7 +18,8 @@ export const BLOCK_COPY = {
18
18
  noLongerDraft: API_MESSAGES.testNoLongerDraft,
19
19
  finishUnwrap: 'The test was removed; use Unwrap to finish.',
20
20
  deleted: "This block's test was deleted; the page shows the Original.",
21
- discarded: 'This test has ended; the page shows the Original.',
21
+ discarded: 'Winner discarded: this block shows the Original. Use Unwrap to replace it with the Original content.',
22
+ neverDecided: 'Archived without a winner: this block shows the Original. Use Unwrap to replace it with the Original content.',
22
23
  running: "Running: visitors see different versions. Edit a version's tab to change it; the change is noted on the results.",
23
24
  stopped: 'Stopped: visitors see the Original.',
24
25
  slotLabels: {
@@ -49,13 +50,13 @@ export const blockDecidedUnwrap = {
49
50
  link: 'the test',
50
51
  after: '.'
51
52
  };
52
- export const blockFinishedCopy = (winner)=>({
53
- before: `Finished: visitors see ${winner}. Use "Make it the content" on `,
53
+ export const blockFinishedCopy = (winner, originalWon = false, emptyWinner = false)=>({
54
+ before: emptyWinner ? 'Archived: the winner has no content here, so visitors see the Original. Unwrap leaves the page as visitors see it now. View the results on ' : originalWon ? `Archived: the Original won. This block shows ${winner}. Use Unwrap to keep its content without the Experiment block. View the results on ` : `Archived: this block keeps serving ${winner}, with the Original as a fallback if it is empty. To replace it, copy the content into ordinary page blocks, then remove this Experiment block. View the results on `,
54
55
  link: 'the test',
55
- after: ' to replace this block.'
56
+ after: '.'
56
57
  });
57
- export const blockFinishedStatus = (winner)=>{
58
- const copy = blockFinishedCopy(winner);
58
+ export const blockFinishedStatus = (winner, originalWon = false)=>{
59
+ const copy = blockFinishedCopy(winner, originalWon);
59
60
  return copy.before + copy.link + copy.after;
60
61
  };
61
62
  export const blockDeleteConfirmation = (name)=>`Delete the draft test ${name} and put the Original back in its place? Deleting the test can't be undone.`;
@@ -15,7 +15,7 @@ export declare const NEW_TEST_COPY: {
15
15
  readonly blockMeaning: "Compare different versions of content on a page.";
16
16
  readonly settingMeaning: "Compare different choices for a setting on your site.";
17
17
  readonly unavailable: "A developer needs to set up pages or settings before you can create a test.";
18
- readonly handoff: "Open the page, add an Experiment block where you want the test, and choose Test this block.";
18
+ readonly handoff: "Open the page, add an Experiment block where you want it, and choose Set up test.";
19
19
  readonly noPages: "There are no pages yet.";
20
20
  readonly recentPages: "Showing the 50 most recently edited.";
21
21
  readonly open: "Open";
@@ -15,7 +15,7 @@ export const NEW_TEST_COPY = {
15
15
  blockMeaning: 'Compare different versions of content on a page.',
16
16
  settingMeaning: 'Compare different choices for a setting on your site.',
17
17
  unavailable: 'A developer needs to set up pages or settings before you can create a test.',
18
- handoff: 'Open the page, add an Experiment block where you want the test, and choose Test this block.',
18
+ handoff: 'Open the page, add an Experiment block where you want it, and choose Set up test.',
19
19
  noPages: 'There are no pages yet.',
20
20
  recentPages: 'Showing the 50 most recently edited.',
21
21
  open: 'Open',
@@ -22,7 +22,8 @@ export function ResultsRoute(props) {
22
22
  }
23
23
  function ManagedResults({ id, surface, onTitleChange }) {
24
24
  const test = useTestDocument(id, {
25
- apiRoute: surface.apiRoute
25
+ apiRoute: surface.apiRoute,
26
+ contentLocale: surface.contentLocale
26
27
  });
27
28
  useEffect(()=>{
28
29
  if (test.doc?.name) onTitleChange?.(test.doc.name);
@@ -1,8 +1,9 @@
1
1
  import type { SurfaceShellProps } from './SurfaceShell.js';
2
2
  import type { ReadinessContext } from '../../testSurface/surface/readiness/readiness.model.js';
3
- export declare function TestsHome({ adminRoute, apiRoute, canManage, crumbs, flagPoints }: {
3
+ export declare function TestsHome({ adminRoute, apiRoute, contentLocale, canManage, crumbs, flagPoints }: {
4
4
  adminRoute: string;
5
5
  apiRoute: string;
6
+ contentLocale?: string;
6
7
  canManage?: boolean;
7
8
  crumbs?: SurfaceShellProps['crumbs'];
8
9
  flagPoints?: ReadinessContext['flagPoints'];
@@ -1,7 +1,9 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { DeleteTest } from '../../testSurface/surface/test/DeleteTest.js';
4
+ import { DELETE_TEST } from '../../testSurface/copy/testPage.js';
3
5
  import { surfaceUrls } from '../../testSurface/surfaceUrls.js';
4
- import { useEffect, useMemo, useState } from 'react';
6
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
5
7
  import { formatAdminURL } from 'payload/shared';
6
8
  import { fetchAllDocs } from '../../lib/fetchAllDocs.js';
7
9
  import { createApi } from '../../testSurface/api.js';
@@ -28,7 +30,7 @@ const HOME_FIELDS = [
28
30
  const homeFieldsComplete = true;
29
31
  void homeFieldsComplete;
30
32
  const HOME_SELECT = HOME_FIELDS.map((field)=>`select[${field}]=true`).join('&');
31
- export function TestsHome({ adminRoute, apiRoute, canManage = false, crumbs, flagPoints }) {
33
+ export function TestsHome({ adminRoute, apiRoute, contentLocale, canManage = false, crumbs, flagPoints }) {
32
34
  const api = useMemo(()=>createApi(apiRoute), [
33
35
  apiRoute
34
36
  ]);
@@ -37,6 +39,24 @@ export function TestsHome({ adminRoute, apiRoute, canManage = false, crumbs, fla
37
39
  });
38
40
  const [search, setSearch] = useState('');
39
41
  const [attempt, setAttempt] = useState(0);
42
+ const [notice, setNotice] = useState();
43
+ const noticeRef = useRef(null);
44
+ useLayoutEffect(()=>{
45
+ if (notice) noticeRef.current?.focus();
46
+ }, [
47
+ notice
48
+ ]);
49
+ useEffect(()=>{
50
+ const url = new URL(window.location.href);
51
+ const deleted = url.searchParams.get('deleted');
52
+ if (deleted === 'done' || deleted === 'already') setNotice({
53
+ outcome: deleted
54
+ });
55
+ if (url.searchParams.has('deleted')) {
56
+ url.searchParams.delete('deleted');
57
+ window.history.replaceState(window.history.state, '', `${url.pathname}${url.search}${url.hash}`);
58
+ }
59
+ }, []);
40
60
  useEffect(()=>{
41
61
  let active = true;
42
62
  const controller = new AbortController();
@@ -120,7 +140,7 @@ export function TestsHome({ adminRoute, apiRoute, canManage = false, crumbs, fla
120
140
  }),
121
141
  children: SURFACE_COPY.newTest
122
142
  });
123
- return /*#__PURE__*/ _jsx(SurfaceShell, {
143
+ return /*#__PURE__*/ _jsxs(SurfaceShell, {
124
144
  adminRoute: adminRoute,
125
145
  crumbs: crumbs,
126
146
  actions: /*#__PURE__*/ _jsxs(_Fragment, {
@@ -161,37 +181,59 @@ export function TestsHome({ adminRoute, apiRoute, canManage = false, crumbs, fla
161
181
  newTest
162
182
  ]
163
183
  }),
164
- children: state.loading ? /*#__PURE__*/ _jsx("p", {
165
- role: "status",
166
- children: SURFACE_COPY.loading
167
- }) : state.error ? /*#__PURE__*/ _jsx(Banner, {
168
- tone: "error",
169
- action: retry,
170
- children: SURFACE_COPY.loadError
171
- }) : /*#__PURE__*/ _jsxs(_Fragment, {
172
- children: [
173
- state.summaryError ? /*#__PURE__*/ _jsx(Banner, {
174
- tone: "error",
175
- action: retry,
176
- children: SURFACE_COPY.summaryError
177
- }) : null,
178
- state.tests.length === 0 ? /*#__PURE__*/ _jsx(EmptyState, {
179
- action: newTest,
180
- children: SURFACE_COPY.empty
181
- }) : /*#__PURE__*/ _jsx(TestGroups, {
182
- tests: state.tests,
183
- summaries: state.summaries,
184
- goalNames: state.goalNames,
185
- adminRoute: adminRoute,
186
- flagPoints: flagPoints,
187
- search: search,
188
- clear: ()=>setSearch('')
189
- })
190
- ]
191
- })
184
+ children: [
185
+ /*#__PURE__*/ _jsx("p", {
186
+ ref: noticeRef,
187
+ role: "status",
188
+ "aria-atomic": "true",
189
+ tabIndex: -1,
190
+ "data-testid": "delete-notice",
191
+ children: notice ? notice.outcome === 'done' ? DELETE_TEST.deleted : DELETE_TEST.alreadyDeleted : ''
192
+ }),
193
+ state.loading ? /*#__PURE__*/ _jsx("p", {
194
+ role: "status",
195
+ children: SURFACE_COPY.loading
196
+ }) : state.error ? /*#__PURE__*/ _jsx(Banner, {
197
+ tone: "error",
198
+ action: retry,
199
+ children: SURFACE_COPY.loadError
200
+ }) : /*#__PURE__*/ _jsxs(_Fragment, {
201
+ children: [
202
+ state.summaryError ? /*#__PURE__*/ _jsx(Banner, {
203
+ tone: "error",
204
+ action: retry,
205
+ children: SURFACE_COPY.summaryError
206
+ }) : null,
207
+ state.tests.length === 0 ? /*#__PURE__*/ _jsx(EmptyState, {
208
+ action: newTest,
209
+ children: SURFACE_COPY.empty
210
+ }) : /*#__PURE__*/ _jsx(TestGroups, {
211
+ tests: state.tests,
212
+ summaries: state.summaries,
213
+ goalNames: state.goalNames,
214
+ adminRoute: adminRoute,
215
+ apiRoute: apiRoute,
216
+ contentLocale: contentLocale,
217
+ canManage: canManage,
218
+ onDeleted: (id, outcome)=>{
219
+ setNotice({
220
+ outcome
221
+ });
222
+ setState((current)=>!current.loading && !current.error ? {
223
+ ...current,
224
+ tests: current.tests.filter((test)=>String(test.id) !== String(id))
225
+ } : current);
226
+ },
227
+ flagPoints: flagPoints,
228
+ search: search,
229
+ clear: ()=>setSearch('')
230
+ })
231
+ ]
232
+ })
233
+ ]
192
234
  });
193
235
  }
194
- function TestGroups({ tests, summaries, goalNames, adminRoute, flagPoints, search, clear }) {
236
+ function TestGroups({ tests, summaries, goalNames, adminRoute, apiRoute, contentLocale, canManage, onDeleted, flagPoints, search, clear }) {
195
237
  const groups = groupTests(tests, summaries, search);
196
238
  if (!groups.some((group)=>group.tests.length)) return /*#__PURE__*/ _jsxs("div", {
197
239
  className: "xp-tests-no-matches",
@@ -253,11 +295,23 @@ function TestGroups({ tests, summaries, goalNames, adminRoute, flagPoints, searc
253
295
  })
254
296
  ]
255
297
  }),
256
- /*#__PURE__*/ _jsx(Button, {
257
- className: "xp-tests-row-action",
258
- size: "sm",
259
- href: card.href,
260
- children: card.action
298
+ /*#__PURE__*/ _jsxs("div", {
299
+ className: "xp-ui-button-group",
300
+ children: [
301
+ /*#__PURE__*/ _jsx(DeleteTest, {
302
+ test: test,
303
+ canManage: canManage,
304
+ apiRoute: apiRoute,
305
+ contentLocale: contentLocale,
306
+ onDeleted: (outcome)=>onDeleted(test.id, outcome)
307
+ }),
308
+ /*#__PURE__*/ _jsx(Button, {
309
+ className: "xp-tests-row-action",
310
+ size: "sm",
311
+ href: card.href,
312
+ children: card.action
313
+ })
314
+ ]
261
315
  })
262
316
  ]
263
317
  }, test.id);
@@ -22,6 +22,8 @@ function SurfacePage(props) {
22
22
  const surface = {
23
23
  adminRoute: props.adminRoute,
24
24
  apiRoute: props.apiRoute,
25
+ contentLocale: props.contentLocale,
26
+ contentLanguageLabels: props.contentLanguageLabels,
25
27
  canManage: props.canManage,
26
28
  canReadResults: props.canReadResults,
27
29
  isAdmin: props.isAdmin,
@@ -48,6 +50,7 @@ function SurfacePage(props) {
48
50
  if (props.route === 'home') return /*#__PURE__*/ _jsx(TestsHome, {
49
51
  adminRoute: props.adminRoute,
50
52
  apiRoute: props.apiRoute,
53
+ contentLocale: props.contentLocale,
51
54
  canManage: props.canManage,
52
55
  flagPoints: props.flagPoints,
53
56
  crumbs: crumbs
@@ -17,6 +17,8 @@ export interface HomeTest {
17
17
  decision?: {
18
18
  winnerArm?: string | null;
19
19
  holdoutReleasedAt?: string | null;
20
+ discardedAt?: string | null;
21
+ pagesReleasedAt?: string | null;
20
22
  } | null;
21
23
  }
22
24
  type Summary = SummaryResponse[DocId] | undefined;
@@ -8,6 +8,7 @@ import { formatAdminURL } from 'payload/shared';
8
8
  import { NEW_TEST_COPY as C } from '../../copy/newTest.js';
9
9
  import { CreateRefused, createTest } from '../../../puck/editor/createTest.js';
10
10
  import { PageWizard } from './PageWizard.js';
11
+ import { Select } from '../../../ui/Select.js';
11
12
  import './newTest.css';
12
13
  export function NewTest({ surface, pages }) {
13
14
  const router = useRouter();
@@ -282,25 +283,22 @@ export function NewTest({ surface, pages }) {
282
283
  /*#__PURE__*/ _jsx("summary", {
283
284
  children: C.advanced
284
285
  }),
285
- /*#__PURE__*/ _jsxs("label", {
286
+ /*#__PURE__*/ _jsxs(Select, {
287
+ id: "xp-new-group",
288
+ label: C.group,
289
+ "aria-describedby": "xp-new-group-help",
290
+ disabled: layerState !== 'ready',
291
+ value: layer === undefined ? '' : layers.findIndex((item)=>item.id === layer),
292
+ onChange: (event)=>setLayer(event.currentTarget.value === '' ? undefined : layers[Number(event.currentTarget.value)]?.id),
286
293
  children: [
287
- C.group,
288
- /*#__PURE__*/ _jsxs("select", {
289
- "aria-describedby": "xp-new-group-help",
290
- disabled: layerState !== 'ready',
291
- value: layer === undefined ? '' : layers.findIndex((item)=>item.id === layer),
292
- onChange: (event)=>setLayer(event.currentTarget.value === '' ? undefined : layers[Number(event.currentTarget.value)]?.id),
293
- children: [
294
- /*#__PURE__*/ _jsx("option", {
295
- value: "",
296
- children: C.noGroup
297
- }),
298
- layers.map((item, index)=>/*#__PURE__*/ _jsx("option", {
299
- value: index,
300
- children: item.name
301
- }, index))
302
- ]
303
- })
294
+ /*#__PURE__*/ _jsx("option", {
295
+ value: "",
296
+ children: C.noGroup
297
+ }),
298
+ layers.map((item, index)=>/*#__PURE__*/ _jsx("option", {
299
+ value: index,
300
+ children: item.name
301
+ }, index))
304
302
  ]
305
303
  }),
306
304
  /*#__PURE__*/ _jsx("p", {
@@ -24,6 +24,7 @@ import { useTransition } from '../../../testSurface/surface/readiness/useTransit
24
24
  const [step, setStep] = useState(collections.length > 1 ? 'collection' : 'control');
25
25
  const test = useTestDocument(id, {
26
26
  apiRoute: surface.apiRoute,
27
+ contentLocale: surface.contentLocale,
27
28
  refetchPreflightOnFocus: step === 'review'
28
29
  });
29
30
  const testUrl = formatAdminURL({
@@ -4,6 +4,8 @@
4
4
  .xp-new-test-card strong { font-size: 1.25rem; }
5
5
  .xp-new-test-card:hover { background: var(--xp-surface-raised); }
6
6
  .xp-new-test label { display: block; margin-block: .75rem; }
7
- .xp-new-test input:not([type=radio]), .xp-new-test textarea, .xp-new-test select { display: block; width: 100%; max-width: 36rem; padding: .5rem; color: var(--xp-text); background: var(--xp-input-bg); border: 1px solid var(--xp-input-border); font: inherit; }
7
+ .xp-new-test input:not([type=radio]), .xp-new-test textarea { display: block; width: 100%; max-width: 36rem; padding: .5rem; color: var(--xp-text); background: var(--xp-input-bg); border: 1px solid var(--xp-input-border); font: inherit; }
8
8
  .xp-new-test-choice span { display: block; margin-left: 1.5rem; }
9
9
  .xp-new-test-actions { display: flex; gap: 1rem; margin-top: var(--xp-space-4); }
10
+
11
+ .xp-new-test .xp-ui-combobox-wrap { max-width: 36rem; }
@@ -0,0 +1,3 @@
1
+ import type { TestsSurfaceProps } from '../../types/surface.js';
2
+ /** Payload context stays at the admin entry; the mountable surface stays neutral. */
3
+ export declare function TestsSurface(props: TestsSurfaceProps): import("react").JSX.Element;
@@ -0,0 +1,11 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useLocale } from '@payloadcms/ui';
4
+ import { TestsSurface as Surface } from '../surface/TestsSurface.js';
5
+ /** Payload context stays at the admin entry; the mountable surface stays neutral. */ export function TestsSurface(props) {
6
+ const locale = useLocale();
7
+ return /*#__PURE__*/ _jsx(Surface, {
8
+ ...props,
9
+ contentLocale: locale?.code
10
+ });
11
+ }
@@ -1,8 +1,10 @@
1
+ import { placementLanguageNames } from '../../blocks/placementLanguages.js';
2
+ import { placementReader } from '../../blocks/placementLocale.js';
1
3
  import { flattenTopLevelFields, formatAdminURL } from 'payload/shared';
2
4
  import { serializeAttributeKeys, serializeFlagPoints, serializeMetricSources } from '../../collections/serialize.js';
3
5
  import { serializePageCollections } from '../pageCollections.js';
4
6
  import { collectionLabel as resolveLabel } from '../../collections/labels.js';
5
- import { documentEditor, puckCollections } from '../../options.js';
7
+ import { puckCollections } from '../../options.js';
6
8
  import { xpOptionsFromReq } from '../../options/fromReq.js';
7
9
  import { routeAccess } from './access.model.js';
8
10
  export async function buildSurfaceProps({ req, route, id, searchParams }) {
@@ -71,8 +73,10 @@ export async function buildSurfaceProps({ req, route, id, searchParams }) {
71
73
  }
72
74
  });
73
75
  // The new-test list uses the latest draft's editing intent, as the "Test a block" field condition does (§4.1).
74
- return result.docs.map((doc)=>{
75
- const editor = documentEditor(options, collection, doc);
76
+ return result.docs.map((row)=>{
77
+ const placement = placementReader(req, collection, options).read(row, req.locale === 'all' ? 'all-locales' : 'localized');
78
+ const doc = placement.doc;
79
+ const editor = placement.editor;
76
80
  if (editor !== 'puck' && editor !== 'blocks') return null;
77
81
  const id = doc.id;
78
82
  const customUrl = options.admin?.editorUrl?.({
@@ -111,6 +115,9 @@ export async function buildSurfaceProps({ req, route, id, searchParams }) {
111
115
  },
112
116
  adminRoute,
113
117
  apiRoute: req.payload.config.routes.api,
118
+ ...req.payload.config.localization ? {
119
+ contentLanguageLabels: placementLanguageNames(req, req.payload.config.localization.localeCodes)
120
+ } : {},
114
121
  canManage,
115
122
  canReadResults,
116
123
  isAdmin,
@@ -1,5 +1,7 @@
1
+ import { puckExperimentSlug } from '../puck/experimentSlug.js';
2
+ import { walkVisiblePuck } from '../puck/visibility.js';
1
3
  import { documentEditor, puckCollections } from '../options.js';
2
- import { EXPERIMENT_BLOCK_SLUG, hostBlocks, isObject } from './model.js';
4
+ import { EXPERIMENT_BLOCK_SLUG, hostBlocks } from './model.js';
3
5
  /** Same document-kind rule as the scan; Payload blocks are top level, Puck is recursive. */ export function placementSlugs(options, collection, doc) {
4
6
  if (!doc) return [];
5
7
  const editor = documentEditor(options, collection, doc);
@@ -15,19 +17,11 @@ import { EXPERIMENT_BLOCK_SLUG, hostBlocks, isObject } from './model.js';
15
17
  if (editor !== 'puck') return [];
16
18
  const registration = puckCollections(options).find((r)=>r.slug === collection);
17
19
  const found = new Set();
18
- function walk(v) {
19
- if (Array.isArray(v)) {
20
- v.forEach(walk);
21
- return;
22
- }
23
- if (!isObject(v)) return;
24
- if (v.type === 'ExperimentSlot' && isObject(v.props)) {
25
- const ref = v.props.experiment, slug = typeof ref === 'string' ? ref : isObject(ref) ? ref.slug : undefined;
26
- if (typeof slug === 'string') found.add(slug);
27
- }
28
- Object.values(v).forEach(walk);
29
- }
30
- if (registration) walk(doc[registration.field]);
20
+ if (registration) walkVisiblePuck(doc[registration.field], (node, visibility)=>{
21
+ if (visibility.hidden || node.type !== 'ExperimentSlot') return;
22
+ const slug = puckExperimentSlug(node.props.experiment);
23
+ if (typeof slug === 'string') found.add(slug);
24
+ });
31
25
  return [
32
26
  ...found
33
27
  ];
@@ -0,0 +1,7 @@
1
+ import type { PayloadRequest } from 'payload';
2
+ /** One language naming rule for placement lists and visitor-impact details. */
3
+ export declare function placementLanguages(req: PayloadRequest, codes: readonly string[]): {
4
+ locales?: string[];
5
+ allLocales?: true;
6
+ };
7
+ export declare function placementLanguageNames(req: PayloadRequest, codes: readonly string[]): string[];
@@ -0,0 +1,27 @@
1
+ import { getTranslation } from '@payloadcms/translations';
2
+ /** One language naming rule for placement lists and visitor-impact details. */ export function placementLanguages(req, codes) {
3
+ const localization = req.payload.config.localization;
4
+ const unique = [
5
+ ...new Set(codes.filter(Boolean))
6
+ ];
7
+ if (localization && unique.length === localization.localeCodes.length) return {
8
+ allLocales: true
9
+ };
10
+ const locales = placementLanguageNames(req, unique);
11
+ return locales.length ? {
12
+ locales
13
+ } : {};
14
+ }
15
+ export function placementLanguageNames(req, codes) {
16
+ const localization = req.payload.config.localization;
17
+ const unique = [
18
+ ...new Set(codes.filter(Boolean))
19
+ ];
20
+ return unique.map((code)=>{
21
+ const label = localization && localization.locales.find((entry)=>entry.code === code)?.label;
22
+ return label ? getTranslation(label, req.i18n ?? {
23
+ language: 'en',
24
+ fallbackLanguage: 'en'
25
+ }) || code : code;
26
+ });
27
+ }
@@ -1,10 +1,21 @@
1
1
  import { type PayloadRequest } from 'payload';
2
- import type { DocId } from '../types/contracts.js';
3
- /** Adapter rows retain locale maps; Start's Local API scan flattens these fields
4
- * to req.locale (and req.fallbackLocale). Registrations name top-level fields.
5
- * Match Payload afterRead/promise.js:50-89: [] is present, not a fallback.
2
+ import type { DocId, ResolvedOptions } from '../types/contracts.js';
3
+ export type PlacementInput = 'all-locales' | 'localized';
4
+ export declare function placementLocaleContent(req: PayloadRequest, collection: string, doc: Record<string, unknown> | undefined, input: PlacementInput): Record<string, unknown> | undefined;
5
+ /** The single document → locale view → editor/placements boundary. Compiled schemas are shared per sanitized config.
6
+ * Local API and form documents explicitly bypass all-locale projection.
6
7
  */
7
- export declare function placementLocaleContent(req: PayloadRequest, collection: string, doc: Record<string, unknown> | undefined): Record<string, unknown> | undefined;
8
+ export declare function placementReader(req: PayloadRequest, collection: string, options?: Pick<ResolvedOptions, "puck" | "blocks">): {
9
+ views: PlacementLocaleView[];
10
+ documentViews: PlacementLocaleView[];
11
+ read(doc: Record<string, unknown> | null | undefined, input: PlacementInput, view?: PlacementLocaleView): {
12
+ view: PlacementLocaleView;
13
+ readonly doc: Record<string, unknown> | undefined;
14
+ readonly editor: "page" | "puck" | "blocks";
15
+ readonly slugs: string[];
16
+ };
17
+ };
18
+ export declare function allPlacementSlugs(req: PayloadRequest, collection: string, doc: Record<string, unknown> | undefined, input: PlacementInput): string[];
8
19
  export interface PlacementLocaleView {
9
20
  locale: string;
10
21
  fallbackLocale: import('payload').TypedFallbackLocale;
@@ -13,9 +24,14 @@ export declare const placementDocumentKey: (collection: string, id: DocId, view:
13
24
  export type RemovedPlacementViews = Map<string, PlacementLocaleView[]>;
14
25
  export declare function localeRequest(req: PayloadRequest, view: PlacementLocaleView): PayloadRequest;
15
26
  /** Canonical views of registered content, without multiplying nonlocalized rows. */
16
- export declare function placementLocaleViews(req: PayloadRequest, collection: string): PlacementLocaleView[];
27
+ export declare function placementLocaleViews(req: PayloadRequest, collection: string, options?: Pick<ResolvedOptions, "puck" | "blocks">): PlacementLocaleView[];
17
28
  /** Compare every locale view: a localized edit can also change fallback
18
29
  * content in another locale. Whole-row removals replace every view with absence.
19
30
  * The incoming hook document is already flattened to the writing locale.
20
31
  */
21
- export declare function removedPlacementViews(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>, removingPage: boolean): RemovedPlacementViews;
32
+ export declare function removedPlacementViews(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>, removingPage: boolean, input?: PlacementInput): RemovedPlacementViews;
33
+ /** Rebuild unchanged locale maps around a flattened hook write before reading each view. */
34
+ export declare function mergedPlacementLocales(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>): Record<string, unknown>;
35
+ /** Project host document adapters before they run. Callers own path normalization
36
+ * and use sortLockKeys for the existing experiment → page-path lock ordering. */
37
+ export declare function placementDocumentPaths(req: PayloadRequest, collection: string, docs: Array<Record<string, unknown> | undefined>, input: PlacementInput, pathOf: (doc: Record<string, unknown>) => string | null): string[];