@delmaredigital/payload-experiments 0.4.0-rc.9 → 0.4.0

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 (254) hide show
  1. package/README.md +2 -8
  2. package/dist/admin/MetricSourceSelect.js +10 -3
  3. package/dist/admin/armSelect/armSelect.model.d.ts +1 -1
  4. package/dist/admin/blocks/BlockPanel.d.ts +1 -0
  5. package/dist/admin/blocks/BlockPanel.js +75 -29
  6. package/dist/admin/blocks/model.js +5 -4
  7. package/dist/admin/copy/blocks.d.ts +14 -11
  8. package/dist/admin/copy/blocks.js +33 -22
  9. package/dist/admin/copy/goals.d.ts +15 -8
  10. package/dist/admin/copy/goals.js +18 -8
  11. package/dist/admin/copy/newTest.d.ts +10 -7
  12. package/dist/admin/copy/newTest.js +14 -7
  13. package/dist/admin/copy/status.d.ts +1 -1
  14. package/dist/admin/copy/status.js +2 -1
  15. package/dist/admin/pageCollections.d.ts +1 -0
  16. package/dist/admin/pageCollections.js +3 -0
  17. package/dist/admin/placementStatus.model.js +5 -3
  18. package/dist/admin/status.model.d.ts +1 -0
  19. package/dist/admin/status.model.js +2 -1
  20. package/dist/admin/surface/ResultsRoute.js +4 -8
  21. package/dist/admin/surface/SurfaceShell.d.ts +4 -2
  22. package/dist/admin/surface/SurfaceShell.js +28 -3
  23. package/dist/admin/surface/TestRowMenu.d.ts +13 -0
  24. package/dist/admin/surface/TestRowMenu.js +163 -0
  25. package/dist/admin/surface/TestsHome.d.ts +4 -3
  26. package/dist/admin/surface/TestsHome.js +186 -47
  27. package/dist/admin/surface/TestsSurface.js +2 -1
  28. package/dist/admin/surface/goals/DeleteGoalDialog.d.ts +7 -0
  29. package/dist/admin/surface/goals/DeleteGoalDialog.js +42 -0
  30. package/dist/admin/surface/goals/GoalForm.d.ts +1 -0
  31. package/dist/admin/surface/goals/GoalForm.js +280 -198
  32. package/dist/admin/surface/goals/GoalsList.js +102 -33
  33. package/dist/admin/surface/goals/data.d.ts +2 -0
  34. package/dist/admin/surface/goals/data.js +9 -0
  35. package/dist/admin/surface/goals/goals.css +3 -2
  36. package/dist/admin/surface/goals/goals.model.d.ts +2 -2
  37. package/dist/admin/surface/goals/goals.model.js +7 -12
  38. package/dist/admin/surface/home.model.d.ts +15 -8
  39. package/dist/admin/surface/home.model.js +22 -18
  40. package/dist/admin/surface/newTest/NewTest.d.ts +3 -3
  41. package/dist/admin/surface/newTest/NewTest.js +156 -96
  42. package/dist/admin/surface/newTest/PageWizard.d.ts +4 -1
  43. package/dist/admin/surface/newTest/PageWizard.js +93 -68
  44. package/dist/admin/surface/newTest/newTest.css +28 -11
  45. package/dist/admin/surface/results/ResultsHeader.d.ts +1 -1
  46. package/dist/admin/surface/results/ResultsHeader.js +90 -63
  47. package/dist/admin/surface/surface.css +29 -0
  48. package/dist/admin/surface/test/TestPage.js +46 -38
  49. package/dist/admin/surface/useXpStepNav.d.ts +11 -0
  50. package/dist/admin/surface/useXpStepNav.js +14 -0
  51. package/dist/admin/views/TestsSurfaceClient.js +27 -3
  52. package/dist/admin/views/buildSurfaceProps.js +18 -66
  53. package/dist/arms/copy.d.ts +13 -3
  54. package/dist/arms/copy.js +5 -4
  55. package/dist/blocks/createExperimentBlock.js +1 -1
  56. package/dist/blocks/formState.js +1 -1
  57. package/dist/collections/experiments/armInvariants.js +8 -5
  58. package/dist/collections/metrics.js +12 -5
  59. package/dist/collections/serialize.js +3 -2
  60. package/dist/db/pageCopies.d.ts +5 -0
  61. package/dist/db/pageCopies.js +31 -0
  62. package/dist/db/snapshots.d.ts +1 -0
  63. package/dist/endpoints/duplicateOriginal.d.ts +38 -0
  64. package/dist/endpoints/duplicateOriginal.js +414 -0
  65. package/dist/endpoints/editorSurface.js +1 -1
  66. package/dist/endpoints/index.js +20 -0
  67. package/dist/endpoints/pages.js +245 -66
  68. package/dist/endpoints/placementStatus.js +1 -0
  69. package/dist/endpoints/results.js +3 -0
  70. package/dist/endpoints/testVersion.d.ts +2 -0
  71. package/dist/endpoints/testVersion.js +38 -0
  72. package/dist/endpoints/transitions.js +4 -5
  73. package/dist/exports/index.d.ts +1 -1
  74. package/dist/goals/picker/copy.js +1 -1
  75. package/dist/goals/sourceLabel.d.ts +2 -0
  76. package/dist/goals/sourceLabel.js +4 -0
  77. package/dist/hooks/trackPageCopies.d.ts +11 -0
  78. package/dist/hooks/trackPageCopies.js +7 -0
  79. package/dist/labels/arms.d.ts +3 -0
  80. package/dist/labels/arms.js +8 -0
  81. package/dist/options.d.ts +2 -0
  82. package/dist/options.js +18 -2
  83. package/dist/plugin.js +56 -2
  84. package/dist/puck/editor/ConfigureTestDrawer.d.ts +7 -7
  85. package/dist/puck/editor/ConfigureTestDrawer.js +36 -26
  86. package/dist/puck/editor/ExperimentSlotEditor.d.ts +2 -1
  87. package/dist/puck/editor/ExperimentSlotEditor.js +219 -106
  88. package/dist/puck/editor/LeftoverVersions.js +17 -32
  89. package/dist/puck/editor/QuickTestActions.d.ts +2 -2
  90. package/dist/puck/editor/QuickTestActions.js +44 -34
  91. package/dist/puck/editor/ResultsReadout.d.ts +3 -1
  92. package/dist/puck/editor/ResultsReadout.js +28 -16
  93. package/dist/puck/editor/VersionBuilder.d.ts +4 -2
  94. package/dist/puck/editor/VersionBuilder.js +42 -63
  95. package/dist/puck/editor/armWrites.js +1 -1
  96. package/dist/puck/editor/copy.d.ts +10 -6
  97. package/dist/puck/editor/copy.js +22 -12
  98. package/dist/puck/editor/editor.chrome.css +9 -8
  99. package/dist/puck/editor/editor.css +14 -9
  100. package/dist/puck/editor/placementsCache.d.ts +1 -1
  101. package/dist/puck/editor/placementsCache.js +9 -17
  102. package/dist/puck/editor/usePageSaveReadiness.d.ts +1 -4
  103. package/dist/puck/editor/usePageSaveReadiness.js +18 -21
  104. package/dist/puck/editor/usePlacementNotice.d.ts +2 -2
  105. package/dist/puck/editor/usePlacementNotice.js +4 -5
  106. package/dist/puck/nestedTestCopy.js +2 -2
  107. package/dist/puck/slotConfig.d.ts +1 -1
  108. package/dist/puck/slotConfig.js +1 -1
  109. package/dist/results/analyse.d.ts +2 -0
  110. package/dist/results/analyse.js +2 -2
  111. package/dist/results/verdict.d.ts +4 -4
  112. package/dist/results/verdict.js +13 -10
  113. package/dist/server/runResults.js +2 -1
  114. package/dist/testSurface/PreviewLinks.d.ts +2 -1
  115. package/dist/testSurface/PreviewLinks.js +3 -3
  116. package/dist/testSurface/actions/DecideDialog.d.ts +7 -4
  117. package/dist/testSurface/actions/DecideDialog.js +71 -59
  118. package/dist/testSurface/actions/LifecycleAction.d.ts +17 -0
  119. package/dist/testSurface/actions/LifecycleAction.js +107 -0
  120. package/dist/testSurface/actions/MakeContentResult.js +1 -1
  121. package/dist/testSurface/actions/actions.model.d.ts +13 -5
  122. package/dist/testSurface/actions/actions.model.js +75 -22
  123. package/dist/testSurface/actions/decide.model.d.ts +1 -0
  124. package/dist/testSurface/actions/decide.model.js +1 -0
  125. package/dist/testSurface/allocation.model.js +6 -3
  126. package/dist/testSurface/api.d.ts +4 -1
  127. package/dist/testSurface/api.js +22 -14
  128. package/dist/testSurface/copy/actions.d.ts +36 -14
  129. package/dist/testSurface/copy/actions.js +39 -17
  130. package/dist/testSurface/copy/advanced.d.ts +10 -0
  131. package/dist/testSurface/copy/advanced.js +10 -0
  132. package/dist/testSurface/copy/arms.d.ts +1 -1
  133. package/dist/testSurface/copy/arms.js +1 -1
  134. package/dist/testSurface/copy/audience.d.ts +4 -3
  135. package/dist/testSurface/copy/audience.js +5 -4
  136. package/dist/testSurface/copy/common.d.ts +6 -6
  137. package/dist/testSurface/copy/common.js +6 -6
  138. package/dist/testSurface/copy/metrics.d.ts +6 -0
  139. package/dist/testSurface/copy/metrics.js +8 -0
  140. package/dist/testSurface/copy/pages.d.ts +67 -7
  141. package/dist/testSurface/copy/pages.js +74 -7
  142. package/dist/testSurface/copy/readiness.d.ts +8 -6
  143. package/dist/testSurface/copy/readiness.js +19 -10
  144. package/dist/testSurface/copy/recommendation.d.ts +1 -22
  145. package/dist/testSurface/copy/recommendation.js +2 -22
  146. package/dist/testSurface/copy/results.d.ts +16 -10
  147. package/dist/testSurface/copy/results.js +19 -11
  148. package/dist/testSurface/copy/review.d.ts +13 -10
  149. package/dist/testSurface/copy/review.js +14 -10
  150. package/dist/testSurface/copy/setting.d.ts +1 -2
  151. package/dist/testSurface/copy/setting.js +1 -2
  152. package/dist/testSurface/copy/surface.d.ts +11 -2
  153. package/dist/testSurface/copy/surface.js +14 -11
  154. package/dist/testSurface/copy/testPage.d.ts +16 -10
  155. package/dist/testSurface/copy/testPage.js +24 -18
  156. package/dist/testSurface/format/date.d.ts +5 -2
  157. package/dist/testSurface/format/date.js +24 -8
  158. package/dist/testSurface/format/roundProgress.d.ts +6 -0
  159. package/dist/testSurface/format/roundProgress.js +15 -0
  160. package/dist/testSurface/format/useDateFormatter.d.ts +3 -0
  161. package/dist/testSurface/format/useDateFormatter.js +8 -0
  162. package/dist/testSurface/labels.d.ts +1 -2
  163. package/dist/testSurface/labels.js +2 -3
  164. package/dist/testSurface/lockedNotice.model.d.ts +2 -0
  165. package/dist/testSurface/lockedNotice.model.js +31 -0
  166. package/dist/testSurface/readPreflight.d.ts +0 -1
  167. package/dist/testSurface/readPreflight.js +0 -1
  168. package/dist/testSurface/results/CiChart.js +2 -1
  169. package/dist/testSurface/results/DataTable.d.ts +1 -1
  170. package/dist/testSurface/results/DataTable.js +4 -3
  171. package/dist/testSurface/results/VerdictHero.d.ts +1 -1
  172. package/dist/testSurface/results/legacy.d.ts +0 -5
  173. package/dist/testSurface/results/legacy.js +0 -14
  174. package/dist/testSurface/results/results.css +2 -2
  175. package/dist/testSurface/results/results.model.d.ts +8 -3
  176. package/dist/testSurface/results/results.model.js +25 -21
  177. package/dist/testSurface/results/snapshot.d.ts +2 -0
  178. package/dist/testSurface/results/snapshot.js +3 -0
  179. package/dist/testSurface/surface/contracts.d.ts +6 -1
  180. package/dist/testSurface/surface/editorPlacement.d.ts +1 -1
  181. package/dist/testSurface/surface/editorPlacement.js +1 -1
  182. package/dist/testSurface/surface/pageBlock/pageBlock.model.js +1 -1
  183. package/dist/testSurface/surface/pageBlock/parts.js +25 -12
  184. package/dist/testSurface/surface/pagePicker/CopyRoute.d.ts +8 -1
  185. package/dist/testSurface/surface/pagePicker/CopyRoute.js +243 -22
  186. package/dist/testSurface/surface/pagePicker/PageCombobox.d.ts +15 -4
  187. package/dist/testSurface/surface/pagePicker/PageCombobox.js +298 -209
  188. package/dist/testSurface/surface/pagePicker/pagePicker.css +73 -10
  189. package/dist/testSurface/surface/pagePicker/pagePicker.model.d.ts +5 -3
  190. package/dist/testSurface/surface/pagePicker/pagePicker.model.js +17 -2
  191. package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +5 -3
  192. package/dist/testSurface/surface/readiness/ActionDialogs.js +213 -207
  193. package/dist/testSurface/surface/readiness/Banner.d.ts +5 -1
  194. package/dist/testSurface/surface/readiness/Banner.js +109 -148
  195. package/dist/testSurface/surface/readiness/SaveStatus.d.ts +5 -2
  196. package/dist/testSurface/surface/readiness/SaveStatus.js +8 -7
  197. package/dist/testSurface/surface/readiness/readiness.model.d.ts +14 -5
  198. package/dist/testSurface/surface/readiness/readiness.model.js +62 -12
  199. package/dist/testSurface/surface/readiness/useTransition.d.ts +3 -1
  200. package/dist/testSurface/surface/readiness/useTransition.js +49 -8
  201. package/dist/testSurface/surface/results/ReleasePages.d.ts +4 -3
  202. package/dist/testSurface/surface/results/ReleasePages.js +41 -41
  203. package/dist/testSurface/surface/results/ResultsBody.d.ts +7 -2
  204. package/dist/testSurface/surface/results/ResultsBody.js +170 -110
  205. package/dist/testSurface/surface/results/recommendation.model.d.ts +6 -9
  206. package/dist/testSurface/surface/results/recommendation.model.js +15 -59
  207. package/dist/testSurface/surface/results/useResults.d.ts +6 -2
  208. package/dist/testSurface/surface/setting/parts.js +31 -28
  209. package/dist/testSurface/surface/setting/setting.css +2 -1
  210. package/dist/testSurface/surface/test/AdvancedSection.js +10 -4
  211. package/dist/testSurface/surface/test/DeleteTest.d.ts +5 -1
  212. package/dist/testSurface/surface/test/DeleteTest.js +63 -55
  213. package/dist/testSurface/surface/test/GoalSection.js +11 -11
  214. package/dist/testSurface/surface/test/LengthSection.js +21 -13
  215. package/dist/testSurface/surface/test/PageHoldout.d.ts +1 -1
  216. package/dist/testSurface/surface/test/PageHoldout.js +7 -7
  217. package/dist/testSurface/surface/test/ReadinessBar.d.ts +2 -1
  218. package/dist/testSurface/surface/test/ReadinessBar.js +4 -10
  219. package/dist/testSurface/surface/test/Section.js +8 -0
  220. package/dist/testSurface/surface/test/TargetingSection.js +7 -2
  221. package/dist/testSurface/surface/test/TestSurface.js +17 -43
  222. package/dist/testSurface/surface/test/VersionsSection.js +93 -70
  223. package/dist/testSurface/surface/test/fields.d.ts +4 -3
  224. package/dist/testSurface/surface/test/fields.js +10 -16
  225. package/dist/testSurface/surface/test/pageParts.js +13 -7
  226. package/dist/testSurface/surface/test/testPage.css +9 -2
  227. package/dist/testSurface/surface/useTestDocument.d.ts +1 -3
  228. package/dist/testSurface/surface/useTestDocument.js +110 -52
  229. package/dist/testSurface/surface/watchTestDocument.d.ts +15 -0
  230. package/dist/testSurface/surface/watchTestDocument.js +181 -0
  231. package/dist/testSurface/surfaceUrls.d.ts +1 -0
  232. package/dist/testSurface/surfaceUrls.js +4 -0
  233. package/dist/testSurface/useApi.d.ts +3 -0
  234. package/dist/transitions/addMetric.d.ts +1 -1
  235. package/dist/transitions/addMetric.js +5 -1
  236. package/dist/transitions/kernel.d.ts +2 -0
  237. package/dist/transitions/kernel.js +1 -1
  238. package/dist/transitions/pageAddress.d.ts +6 -0
  239. package/dist/transitions/pageAddress.js +71 -0
  240. package/dist/transitions/pageVersions.d.ts +1 -1
  241. package/dist/transitions/preflightData.js +10 -2
  242. package/dist/transitions/start.d.ts +1 -1
  243. package/dist/transitions/start.js +8 -5
  244. package/dist/types/armKey.d.ts +2 -0
  245. package/dist/types/armKey.js +1 -0
  246. package/dist/types/contracts.d.ts +11 -1
  247. package/dist/types/endpoints.d.ts +38 -9
  248. package/dist/types/endpoints.js +1 -1
  249. package/dist/types/surface.d.ts +7 -9
  250. package/dist/ui/Dialog.d.ts +21 -2
  251. package/dist/ui/Dialog.js +101 -4
  252. package/dist/ui/Inputs.js +0 -1
  253. package/dist/ui/ui.css +5 -1
  254. package/package.json +2 -2
@@ -6,51 +6,59 @@ import { formatAdminURL } from '../../../testSurface/format/adminURL.js';
6
6
  import { surfaceUrls } from '../../../testSurface/surfaceUrls.js';
7
7
  import { Button } from '../../../ui/Button.js';
8
8
  import { StatusChip } from '../../../ui/StatusChip.js';
9
+ import { useXpStepNav } from '../useXpStepNav.js';
9
10
  import { SurfaceShell } from '../SurfaceShell.js';
10
11
  export function TestPage({ id, surface, onTitleChange }) {
11
12
  return /*#__PURE__*/ _jsx(TestSurface, {
12
13
  id: id,
13
14
  surface: surface,
14
15
  onTitleChange: onTitleChange,
15
- renderFrame: ({ test, children })=>{
16
- const doc = test.doc;
17
- return /*#__PURE__*/ _jsx(SurfaceShell, {
18
- adminRoute: surface.adminRoute,
19
- title: doc?.name ?? C.test,
20
- crumbs: [
21
- {
22
- label: C.tests,
23
- href: surfaceUrls.home(surface.adminRoute)
24
- },
25
- {
26
- label: doc?.name ?? C.test
27
- }
28
- ],
29
- status: doc ? /*#__PURE__*/ _jsxs(_Fragment, {
30
- children: [
31
- /*#__PURE__*/ _jsx("span", {
32
- className: "xp-tests-kind",
33
- children: C.kinds[doc.kind]
34
- }),
35
- !test.statusReadPending ? /*#__PURE__*/ _jsx(StatusChip, {
36
- status: doc.status
37
- }) : null
38
- ]
39
- }) : undefined,
40
- actions: doc && !test.statusReadPending && surface.canReadResults && [
41
- 'running',
42
- 'stopped',
43
- 'decided'
44
- ].includes(doc.status) ? /*#__PURE__*/ _jsx(Button, {
45
- variant: "secondary",
46
- href: formatAdminURL({
47
- adminRoute: surface.adminRoute,
48
- path: `/experiments/${encodeURIComponent(String(doc.id))}/results`
49
- }),
50
- children: C.results
51
- }) : undefined,
16
+ renderFrame: ({ test, children })=>/*#__PURE__*/ _jsx(TestPageFrame, {
17
+ test: test,
18
+ surface: surface,
52
19
  children: children
53
- });
20
+ })
21
+ });
22
+ }
23
+ function TestPageFrame({ test, surface, children }) {
24
+ const doc = test.doc;
25
+ const crumbs = [
26
+ {
27
+ label: C.tests,
28
+ url: surfaceUrls.home(surface.adminRoute)
29
+ },
30
+ {
31
+ label: doc?.name ?? C.test
54
32
  }
33
+ ];
34
+ useXpStepNav(crumbs);
35
+ return /*#__PURE__*/ _jsx(SurfaceShell, {
36
+ adminRoute: surface.adminRoute,
37
+ title: doc?.name ?? C.test,
38
+ dynamicTitle: Boolean(doc?.name),
39
+ crumbs: crumbs.map(({ label, url })=>({
40
+ label,
41
+ href: url
42
+ })),
43
+ status: doc ? /*#__PURE__*/ _jsxs(_Fragment, {
44
+ children: [
45
+ /*#__PURE__*/ _jsx("span", {
46
+ className: "xp-tests-kind",
47
+ children: C.kinds[doc.kind]
48
+ }),
49
+ !test.statusReadPending ? /*#__PURE__*/ _jsx(StatusChip, {
50
+ status: doc.status
51
+ }) : null
52
+ ]
53
+ }) : undefined,
54
+ actions: doc && !test.statusReadPending && surface.canReadResults && doc.status !== 'draft' ? /*#__PURE__*/ _jsx(Button, {
55
+ variant: "secondary",
56
+ href: formatAdminURL({
57
+ adminRoute: surface.adminRoute,
58
+ path: `/experiments/${encodeURIComponent(String(doc.id))}/results`
59
+ }),
60
+ children: C.results
61
+ }) : undefined,
62
+ children: children
55
63
  });
56
64
  }
@@ -0,0 +1,11 @@
1
+ import type { TestsRoute } from '../../types/surface.js';
2
+ export type StepNavItem = {
3
+ label: string;
4
+ url?: string;
5
+ };
6
+ export declare const XpStepNavContext: import("react").Context<{
7
+ route: TestsRoute;
8
+ items: StepNavItem[];
9
+ setStepNav: (items: StepNavItem[]) => void;
10
+ } | undefined>;
11
+ export declare function useXpStepNav(items: StepNavItem[]): void;
@@ -0,0 +1,14 @@
1
+ 'use client';
2
+ import { createContext, useContext, useEffect } from 'react';
3
+ export const XpStepNavContext = createContext(undefined);
4
+ export function useXpStepNav(items) {
5
+ const setStepNav = useContext(XpStepNavContext)?.setStepNav;
6
+ // Callers can pass inline crumbs without resetting Payload's provider on every render.
7
+ const crumbs = JSON.stringify(items);
8
+ useEffect(()=>{
9
+ setStepNav?.(JSON.parse(crumbs));
10
+ }, [
11
+ crumbs,
12
+ setStepNav
13
+ ]);
14
+ }
@@ -1,11 +1,35 @@
1
1
  'use client';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useLocale } from '@payloadcms/ui';
3
+ import { useLocale, useStepNav } from '@payloadcms/ui';
4
+ import { useCallback, useState } from 'react';
4
5
  import { TestsSurface as Surface } from '../surface/TestsSurface.js';
6
+ import { XpStepNavContext } from '../surface/useXpStepNav.js';
5
7
  /** Payload context stays at the admin entry; the mountable surface stays neutral. */ export function TestsSurface(props) {
6
8
  const locale = useLocale();
7
- return /*#__PURE__*/ _jsx(Surface, {
9
+ const { setStepNav } = useStepNav();
10
+ // Each screen starts with its own shell crumbs until it publishes step nav.
11
+ return /*#__PURE__*/ _jsx(ScreenStepNav, {
8
12
  ...props,
9
- contentLocale: locale?.code
13
+ contentLocale: locale?.code,
14
+ publishToPayload: setStepNav
15
+ }, `${props.route}/${props.id ?? ''}`);
16
+ }
17
+ function ScreenStepNav({ publishToPayload, ...props }) {
18
+ const [items, setItems] = useState([]);
19
+ const setStepNav = useCallback((next)=>{
20
+ setItems(next);
21
+ publishToPayload(next);
22
+ }, [
23
+ publishToPayload
24
+ ]);
25
+ return /*#__PURE__*/ _jsx(XpStepNavContext, {
26
+ value: {
27
+ route: props.route,
28
+ items,
29
+ setStepNav
30
+ },
31
+ children: /*#__PURE__*/ _jsx(Surface, {
32
+ ...props
33
+ })
10
34
  });
11
35
  }
@@ -1,10 +1,8 @@
1
1
  import { placementLanguageNames } from '../../blocks/placementLanguages.js';
2
- import { placementReader } from '../../blocks/placementLocale.js';
3
- import { flattenTopLevelFields, formatAdminURL } from 'payload/shared';
4
2
  import { serializeAttributeKeys, serializeFlagPoints, serializeMetricSources } from '../../collections/serialize.js';
5
3
  import { serializePageCollections } from '../pageCollections.js';
6
4
  import { collectionLabel as resolveLabel } from '../../collections/labels.js';
7
- import { puckCollections } from '../../options.js';
5
+ import { blockPageSlugs, puckCollections } from '../../options.js';
8
6
  import { xpOptionsFromReq } from '../../options/fromReq.js';
9
7
  import { routeAccess } from './access.model.js';
10
8
  export async function buildSurfaceProps({ req, route, id, searchParams }) {
@@ -43,66 +41,20 @@ export async function buildSurfaceProps({ req, route, id, searchParams }) {
43
41
  const defaults = state.flagDefaults;
44
42
  for (const point of flagPoints)point.effectiveDefaults = defaults?.[point.id]?.params ?? point.defaultParams;
45
43
  }
46
- const registrations = [
47
- ...new Set([
48
- ...options.puck?.enabled ? puckCollections(options) : [],
49
- ...options.blocks?.collections ?? []
50
- ].map((entry)=>entry.slug))
51
- ];
52
- const pages = route === 'new' && canManage && registrations.length ? (await Promise.all(registrations.map(async (collection)=>{
53
- try {
54
- const config = req.payload.config.collections.find((item)=>item.slug === collection);
55
- const useAsTitle = config?.admin.useAsTitle ?? 'id';
56
- const collectionLabel = resolveLabel(config?.labels.plural, collection, req);
57
- // appliesTo may inspect any stored field; ordinary Puck lists keep their title-only projection.
58
- const predicateFields = options.blocks?.collections.some((entry)=>entry.slug === collection) ? Object.fromEntries(flattenTopLevelFields(config?.fields ?? []).map((field)=>[
59
- field.name,
60
- true
61
- ])) : {};
62
- const result = await req.payload.find({
63
- collection,
64
- req,
65
- overrideAccess: false,
66
- depth: 0,
67
- limit: 50,
68
- sort: '-updatedAt',
69
- draft: true,
70
- select: {
71
- [useAsTitle]: true,
72
- ...predicateFields
73
- }
74
- });
75
- // The new-test list uses the latest draft's editing intent, as the "Test a block" field condition does (§4.1).
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;
80
- if (editor !== 'puck' && editor !== 'blocks') return null;
81
- const id = doc.id;
82
- const customUrl = options.admin?.editorUrl?.({
83
- collection,
84
- id,
85
- draft: true,
86
- editor,
87
- doc
88
- });
89
- const title = doc[useAsTitle];
90
- return {
91
- collection,
92
- collectionLabel,
93
- id,
94
- editor,
95
- title: typeof title === 'string' || typeof title === 'number' ? String(title) : String(id),
96
- editorUrl: typeof customUrl === 'string' ? customUrl : formatAdminURL({
97
- adminRoute,
98
- path: `/collections/${collection}/${encodeURIComponent(String(id))}`
99
- })
100
- };
101
- }).filter((page)=>page !== null);
102
- } catch {
103
- return [];
104
- }
105
- }))).flat() : undefined;
44
+ const blockPageCollections = route === 'new' && canManage ? blockPageSlugs(options).map((slug)=>{
45
+ const config = req.payload.config.collections.find((item)=>item.slug === slug);
46
+ const block = options.blocks?.collections.find((entry)=>entry.slug === slug);
47
+ const puck = options.puck?.enabled && puckCollections(options).some((entry)=>entry.slug === slug);
48
+ const editors = block ? [
49
+ 'blocks'
50
+ ] : [];
51
+ if (puck && (!block || block.appliesTo)) editors.push('puck');
52
+ return {
53
+ slug,
54
+ label: resolveLabel(config?.labels.plural, slug, req),
55
+ editors
56
+ };
57
+ }) : [];
106
58
  const descriptions = options.admin?.descriptions;
107
59
  const returnToTest = (await searchParams)?.return;
108
60
  return {
@@ -122,9 +74,9 @@ export async function buildSurfaceProps({ req, route, id, searchParams }) {
122
74
  canReadResults,
123
75
  isAdmin,
124
76
  flagPoints,
125
- ...pages === undefined ? {} : {
126
- pages
127
- },
77
+ ...blockPageCollections.length ? {
78
+ blockPageCollections
79
+ } : {},
128
80
  pageCollections: serializePageCollections(options.pages?.collections ?? [], req),
129
81
  collectionTitles: Object.fromEntries(req.payload.config.collections.flatMap((collection)=>{
130
82
  const title = collection.admin.useAsTitle;
@@ -1,6 +1,16 @@
1
- import type { ArmIssueCode } from '../types/endpoints.js';
2
- export declare const ISSUE_COPY: Record<ArmIssueCode, string>;
1
+ export declare const ISSUE_COPY: {
2
+ 'weights-total': string;
3
+ 'control-count': string;
4
+ 'control-first': (label?: string) => string;
5
+ 'holdout-last': string;
6
+ 'holdout-count': string;
7
+ 'variant-count': string;
8
+ 'duplicate-key': string;
9
+ 'duplicate-slot': string;
10
+ 'slot-required': string;
11
+ 'invalid-key': string;
12
+ };
3
13
  export declare function issueMessage(issue: {
4
14
  code: string;
5
15
  message: string;
6
- }, total: number): string;
16
+ }, total: number, controlLabel?: string): string;
package/dist/arms/copy.js CHANGED
@@ -1,7 +1,8 @@
1
+ import { controlVersionName } from '../labels/arms.js';
1
2
  export const ISSUE_COPY = {
2
3
  'weights-total': 'Weights must add up to 100%. They add up to {total}% now.',
3
- 'control-count': 'Include exactly one Original.',
4
- 'control-first': 'Put the Original first.',
4
+ 'control-count': 'Include exactly one version that visitors see today.',
5
+ 'control-first': (label)=>`Put ${controlVersionName(label)} first.`,
5
6
  'holdout-last': 'Put the holdout last.',
6
7
  'holdout-count': 'Include only one holdout.',
7
8
  'variant-count': 'Include up to three variants.',
@@ -10,7 +11,7 @@ export const ISSUE_COPY = {
10
11
  'slot-required': 'Choose the matching content slot for this group.',
11
12
  'invalid-key': 'Use the standard group names: Original, Variant A–C, Holdout.'
12
13
  };
13
- export function issueMessage(issue, total) {
14
+ export function issueMessage(issue, total, controlLabel) {
14
15
  const copy = Object.hasOwn(ISSUE_COPY, issue.code) ? ISSUE_COPY[issue.code] : issue.message;
15
- return copy.replace('{total}', String(total));
16
+ return typeof copy === 'function' ? copy(controlLabel) : copy.replace('{total}', String(total));
16
17
  }
@@ -6,7 +6,7 @@ export function validateExperimentSlots(value) {
6
6
  return new Set(slots).size === slots.length ? true : 'Each version appears once';
7
7
  }
8
8
  export function createExperimentBlock({ blocks, slug = EXPERIMENT_BLOCK_SLUG }) {
9
- if (blocks.some((block)=>block.slug === slug)) throw new Error('Experiment blocks cannot be nested.');
9
+ if (blocks.some((block)=>block.slug === slug)) throw new Error("Test blocks can't be placed inside another Test block.");
10
10
  return {
11
11
  slug,
12
12
  labels: {
@@ -55,7 +55,7 @@ import { BLOCK_SLOTS, EXPERIMENT_BLOCK_SLUG, isObject, slotBlocks } from './mode
55
55
  return copyRows(value, field);
56
56
  }
57
57
  export function wrapExperimentBlock(block, experiment, field, config = {}, blockSlug = EXPERIMENT_BLOCK_SLUG) {
58
- if (block.blockType === blockSlug) throw new Error('Experiment blocks cannot be nested.');
58
+ if (block.blockType === blockSlug) throw new Error("Test blocks can't be placed inside another Test block.");
59
59
  return {
60
60
  id: globalThis.crypto.randomUUID(),
61
61
  blockType: blockSlug,
@@ -1,3 +1,4 @@
1
+ import { ARM_LABELS, controlVersionName } from '../../labels/arms.js';
1
2
  /** The groups a new experiment starts with: Original 50 / Variant A 50, no holdout (spec §5.1, O4). Block slots equal the key. */ export function defaultArms(kind) {
2
3
  const slot = (key)=>kind === 'block' ? {
3
4
  slot: key
@@ -6,7 +7,7 @@
6
7
  {
7
8
  key: 'control',
8
9
  kind: 'control',
9
- label: 'Original',
10
+ label: ARM_LABELS.control,
10
11
  weight: 50,
11
12
  ...slot('control')
12
13
  },
@@ -34,8 +35,10 @@ export function checkArms(arms, kind) {
34
35
  if (arms.some((arm)=>!Number.isInteger(arm.weight) || arm.weight < 0) || arms.reduce((total, arm)=>total + arm.weight, 0) !== 100) {
35
36
  issue('weights-total', 'Group shares must be whole numbers that add up to exactly 100.');
36
37
  }
37
- if (arms.filter((arm)=>arm.kind === 'control').length !== 1) issue('control-count', 'Exactly one Original is required.');
38
- if (arms.some((arm, index)=>arm.kind === 'control' && index !== 0)) issue('control-first', 'The Original must be first.');
38
+ const controls = arms.filter((arm)=>arm.kind === 'control');
39
+ const controlLabel = controls[0]?.label;
40
+ if (controls.length !== 1) issue('control-count', 'Exactly one version must be the one visitors see today.');
41
+ if (arms.some((arm, index)=>arm.kind === 'control' && index !== 0)) issue('control-first', `${controlVersionName(controlLabel, true)} must be first.`);
39
42
  if (arms.filter((arm)=>arm.kind === 'holdout').length > 1) issue('holdout-count', 'Only one Holdout is allowed.');
40
43
  if (arms.some((arm, index)=>arm.kind === 'holdout' && index !== arms.length - 1)) issue('holdout-last', 'The Holdout must be the last group.');
41
44
  if (arms.filter((arm)=>arm.kind === 'variant').length > 3) issue('variant-count', 'At most three variants are allowed.');
@@ -53,9 +56,9 @@ export function checkArms(arms, kind) {
53
56
  keys.add(arm.key);
54
57
  if (kind === 'block') {
55
58
  if (arm.kind === 'holdout') {
56
- if (arm.slot != null) issue('invalid-key', 'The Holdout has no content of its own; it sees the Original.', index);
59
+ if (arm.slot != null) issue('invalid-key', `The Holdout has no content of its own; it sees ${controlVersionName(controlLabel)}.`, index);
57
60
  } else {
58
- if (!arm.slot || arm.slot !== arm.key) issue('slot-required', 'Each Original and Variant needs its own content area.', index);
61
+ if (!arm.slot || arm.slot !== arm.key) issue('slot-required', 'Each version needs its own content area.', index);
59
62
  if (arm.slot && slots.has(arm.slot)) issue('duplicate-slot', 'Two groups cannot share the same content area.', index);
60
63
  if (arm.slot) slots.add(arm.slot);
61
64
  }
@@ -19,6 +19,12 @@ export function metricsCollection(options) {
19
19
  admin: {
20
20
  group: SURFACE_COPY.title,
21
21
  useAsTitle: 'name',
22
+ meta: {
23
+ title: {
24
+ absolute: 'Goals · Tests'
25
+ },
26
+ titleSuffix: ''
27
+ },
22
28
  components: {
23
29
  views: {
24
30
  list: {
@@ -54,11 +60,12 @@ export function metricsCollection(options) {
54
60
  const source = sources.find((source)=>source.id === (data.source ?? originalDoc?.source));
55
61
  const capping = data.capping === undefined ? originalDoc?.capping : data.capping;
56
62
  // Payload may submit an empty optional group as { type: null, value: null }.
57
- const hasCapping = capping != null && (capping.type != null || capping.value != null);
58
- if (source?.kind === 'revenue' && !hasCapping) data.capping = {
59
- type: 'percentile',
60
- value: 0.99
61
- };
63
+ if (source?.kind === 'revenue' && capping?.type == null && capping?.value == null) {
64
+ data.capping = {
65
+ type: 'percentile',
66
+ value: 0.99
67
+ };
68
+ }
62
69
  return data;
63
70
  }
64
71
  ]
@@ -1,4 +1,5 @@
1
1
  import { browserWritableMetric } from '../events/writable.js';
2
+ import { goalSourceLabel } from '../goals/sourceLabel.js';
2
3
  export function serializeFlagPoints(options) {
3
4
  return (options.flagPoints ?? []).map(({ id, label, description, params, defaultParams })=>({
4
5
  id,
@@ -22,14 +23,14 @@ export function serializeMetricSources(options) {
22
23
  },
23
24
  ...(options.metricSources ?? []).map(({ id, label, kind, keyedBy })=>({
24
25
  id,
25
- label,
26
+ label: label?.trim() || goalSourceLabel(id),
26
27
  kind,
27
28
  keyedBy,
28
29
  clientWritable: browserWritableMetric(id, options)
29
30
  })),
30
31
  ...(options.eventSources ?? []).map(({ name })=>({
31
32
  id: `events:${name}`,
32
- label: name,
33
+ label: goalSourceLabel(name),
33
34
  kind: 'binomial',
34
35
  keyedBy: 'visitor',
35
36
  clientWritable: browserWritableMetric(`events:${name}`, options)
@@ -0,0 +1,5 @@
1
+ import type { Payload } from 'payload';
2
+ import type { DocId } from '../types/contracts.js';
3
+ /** Read only the tracked IDs. Omitting req puts this adapter read on the pool,
4
+ * so a row visible here survived the copy transaction. */
5
+ export declare function committedPageCopyIds(payload: Payload, collection: string, created: DocId[]): Promise<DocId[]>;
@@ -0,0 +1,31 @@
1
+ /** Read only the tracked IDs. Omitting req puts this adapter read on the pool,
2
+ * so a row visible here survived the copy transaction. */ export async function committedPageCopyIds(payload, collection, created) {
3
+ const ids = [
4
+ ...new Set(created)
5
+ ];
6
+ if (!ids.length) return [];
7
+ const adapter = payload.db;
8
+ // The original transaction may have died before the adapter marked its write.
9
+ // Always check the primary so replica lag can't hide a committed draft.
10
+ const primary = adapter.primaryDrizzle ? {
11
+ ...adapter,
12
+ drizzle: adapter.primaryDrizzle
13
+ } : adapter;
14
+ const { docs } = await primary.find({
15
+ collection,
16
+ where: {
17
+ id: {
18
+ in: ids
19
+ }
20
+ },
21
+ select: {
22
+ id: true
23
+ },
24
+ sort: 'id',
25
+ limit: ids.length,
26
+ pagination: false,
27
+ // The adapter has no access layer. Only IDs from this write are checked here.
28
+ overrideAccess: false
29
+ });
30
+ return docs.map((doc)=>doc.id);
31
+ }
@@ -33,6 +33,7 @@ export interface ResultsCandidate {
33
33
  key: string;
34
34
  weight: number;
35
35
  kind?: string;
36
+ label?: string;
36
37
  pageTarget?: string;
37
38
  }>;
38
39
  layerSlug: string | null;
@@ -0,0 +1,38 @@
1
+ import { type PayloadRequest } from 'payload';
2
+ import type { Arm, DocId, ExperimentsPageCollection, ResolvedOptions } from '../types/contracts.js';
3
+ import type { CopyPagePlan, EndpointContext } from '../types/endpoints.js';
4
+ declare function readTest(req: PayloadRequest, id: DocId): Promise<import("payload").JsonObject & import("payload").TypeWithID>;
5
+ export declare function preparePageCopy<TUser extends {
6
+ id: DocId;
7
+ }>(req: PayloadRequest, options: ResolvedOptions<TUser>, test: Awaited<ReturnType<typeof readTest>>, key: string, confirmed?: CopyPagePlan): Promise<{
8
+ plan: {
9
+ title: string;
10
+ path: string;
11
+ phase: number;
12
+ updatedAt: string;
13
+ originalId: string | number;
14
+ originalUpdatedAt: string;
15
+ };
16
+ data: Record<string, unknown>;
17
+ entry: ExperimentsPageCollection;
18
+ titleField: string;
19
+ homeFlags: string[];
20
+ hasSlugHistory: boolean;
21
+ requiredUniqueFields: string[];
22
+ original: import("payload").JsonObject & import("payload").TypeWithID;
23
+ arms: Arm[];
24
+ reader: {
25
+ views: import("../blocks/placementLocale.js").PlacementLocaleView[];
26
+ documentViews: import("../blocks/placementLocale.js").PlacementLocaleView[];
27
+ read(doc: Record<string, unknown> | null | undefined, input: import("../blocks/placementLocale.js").PlacementInput, view?: import("../blocks/placementLocale.js").PlacementLocaleView): {
28
+ view: import("../blocks/placementLocale.js").PlacementLocaleView;
29
+ readonly doc: Record<string, unknown> | undefined;
30
+ readonly editor: "page" | "puck" | "blocks";
31
+ readonly slugs: string[];
32
+ };
33
+ };
34
+ }>;
35
+ export declare function handleDuplicateOriginal<TUser extends {
36
+ id: DocId;
37
+ }>(req: PayloadRequest, { options }: EndpointContext<TUser>): Promise<Response>;
38
+ export {};