@delmaredigital/payload-experiments 0.4.0-rc.10 → 0.4.0-rc.11

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 (140) hide show
  1. package/dist/admin/MetricSourceSelect.js +10 -3
  2. package/dist/admin/copy/blocks.js +3 -3
  3. package/dist/admin/copy/goals.d.ts +15 -8
  4. package/dist/admin/copy/goals.js +18 -8
  5. package/dist/admin/copy/newTest.d.ts +3 -2
  6. package/dist/admin/copy/newTest.js +3 -2
  7. package/dist/admin/surface/SurfaceShell.d.ts +4 -2
  8. package/dist/admin/surface/SurfaceShell.js +25 -3
  9. package/dist/admin/surface/TestRowMenu.d.ts +7 -0
  10. package/dist/admin/surface/TestRowMenu.js +9 -2
  11. package/dist/admin/surface/TestsHome.js +8 -1
  12. package/dist/admin/surface/goals/DeleteGoalDialog.d.ts +7 -0
  13. package/dist/admin/surface/goals/DeleteGoalDialog.js +42 -0
  14. package/dist/admin/surface/goals/GoalForm.d.ts +1 -0
  15. package/dist/admin/surface/goals/GoalForm.js +280 -191
  16. package/dist/admin/surface/goals/GoalsList.js +102 -33
  17. package/dist/admin/surface/goals/data.d.ts +2 -0
  18. package/dist/admin/surface/goals/data.js +9 -0
  19. package/dist/admin/surface/goals/goals.css +3 -2
  20. package/dist/admin/surface/goals/goals.model.d.ts +2 -2
  21. package/dist/admin/surface/goals/goals.model.js +7 -12
  22. package/dist/admin/surface/home.model.d.ts +1 -0
  23. package/dist/admin/surface/home.model.js +5 -1
  24. package/dist/admin/surface/newTest/NewTest.js +56 -29
  25. package/dist/admin/surface/newTest/PageWizard.d.ts +3 -1
  26. package/dist/admin/surface/newTest/PageWizard.js +14 -14
  27. package/dist/admin/surface/newTest/newTest.css +3 -3
  28. package/dist/admin/surface/results/ResultsHeader.d.ts +1 -1
  29. package/dist/admin/surface/results/ResultsHeader.js +69 -41
  30. package/dist/admin/surface/surface.css +20 -1
  31. package/dist/admin/surface/test/TestPage.js +46 -34
  32. package/dist/admin/surface/useXpStepNav.d.ts +11 -0
  33. package/dist/admin/surface/useXpStepNav.js +14 -0
  34. package/dist/admin/views/TestsSurfaceClient.js +27 -3
  35. package/dist/blocks/createExperimentBlock.js +1 -1
  36. package/dist/blocks/formState.js +1 -1
  37. package/dist/collections/metrics.js +12 -5
  38. package/dist/collections/serialize.js +3 -2
  39. package/dist/db/snapshots.d.ts +1 -0
  40. package/dist/goals/sourceLabel.d.ts +2 -0
  41. package/dist/goals/sourceLabel.js +4 -0
  42. package/dist/plugin.js +51 -1
  43. package/dist/puck/editor/ExperimentSlotEditor.d.ts +2 -1
  44. package/dist/puck/editor/ExperimentSlotEditor.js +96 -43
  45. package/dist/puck/editor/QuickTestActions.d.ts +2 -2
  46. package/dist/puck/editor/QuickTestActions.js +42 -27
  47. package/dist/puck/editor/ResultsReadout.d.ts +3 -1
  48. package/dist/puck/editor/ResultsReadout.js +28 -16
  49. package/dist/puck/editor/VersionBuilder.d.ts +2 -1
  50. package/dist/puck/editor/VersionBuilder.js +14 -8
  51. package/dist/puck/editor/copy.d.ts +3 -3
  52. package/dist/puck/editor/copy.js +4 -4
  53. package/dist/puck/editor/editor.chrome.css +9 -1
  54. package/dist/puck/editor/editor.css +10 -1
  55. package/dist/puck/nestedTestCopy.js +1 -1
  56. package/dist/puck/slotConfig.d.ts +1 -1
  57. package/dist/puck/slotConfig.js +1 -1
  58. package/dist/results/analyse.d.ts +2 -0
  59. package/dist/results/analyse.js +2 -2
  60. package/dist/results/verdict.d.ts +1 -1
  61. package/dist/results/verdict.js +7 -6
  62. package/dist/server/runResults.js +2 -1
  63. package/dist/testSurface/PreviewLinks.d.ts +2 -1
  64. package/dist/testSurface/PreviewLinks.js +3 -3
  65. package/dist/testSurface/actions/DecideDialog.d.ts +3 -2
  66. package/dist/testSurface/actions/DecideDialog.js +21 -12
  67. package/dist/testSurface/actions/LifecycleAction.d.ts +2 -1
  68. package/dist/testSurface/actions/LifecycleAction.js +3 -1
  69. package/dist/testSurface/actions/actions.model.js +6 -5
  70. package/dist/testSurface/actions/decide.model.d.ts +1 -0
  71. package/dist/testSurface/actions/decide.model.js +1 -0
  72. package/dist/testSurface/allocation.model.js +6 -3
  73. package/dist/testSurface/copy/actions.d.ts +12 -9
  74. package/dist/testSurface/copy/actions.js +12 -9
  75. package/dist/testSurface/copy/advanced.d.ts +10 -0
  76. package/dist/testSurface/copy/advanced.js +10 -0
  77. package/dist/testSurface/copy/arms.d.ts +1 -1
  78. package/dist/testSurface/copy/arms.js +1 -1
  79. package/dist/testSurface/copy/audience.d.ts +4 -3
  80. package/dist/testSurface/copy/audience.js +5 -4
  81. package/dist/testSurface/copy/common.d.ts +2 -2
  82. package/dist/testSurface/copy/common.js +2 -2
  83. package/dist/testSurface/copy/metrics.d.ts +6 -0
  84. package/dist/testSurface/copy/metrics.js +8 -0
  85. package/dist/testSurface/copy/readiness.d.ts +3 -3
  86. package/dist/testSurface/copy/readiness.js +5 -5
  87. package/dist/testSurface/copy/recommendation.d.ts +4 -4
  88. package/dist/testSurface/copy/recommendation.js +4 -4
  89. package/dist/testSurface/copy/results.d.ts +13 -9
  90. package/dist/testSurface/copy/results.js +15 -9
  91. package/dist/testSurface/copy/review.d.ts +12 -9
  92. package/dist/testSurface/copy/review.js +13 -9
  93. package/dist/testSurface/copy/setting.d.ts +1 -2
  94. package/dist/testSurface/copy/setting.js +1 -2
  95. package/dist/testSurface/copy/surface.js +1 -1
  96. package/dist/testSurface/copy/testPage.d.ts +13 -9
  97. package/dist/testSurface/copy/testPage.js +16 -13
  98. package/dist/testSurface/format/date.d.ts +1 -0
  99. package/dist/testSurface/format/date.js +11 -0
  100. package/dist/testSurface/labels.d.ts +1 -2
  101. package/dist/testSurface/labels.js +2 -3
  102. package/dist/testSurface/lockedNotice.model.d.ts +2 -0
  103. package/dist/testSurface/lockedNotice.model.js +31 -0
  104. package/dist/testSurface/results/results.model.d.ts +3 -2
  105. package/dist/testSurface/results/results.model.js +10 -9
  106. package/dist/testSurface/surface/pageBlock/pageBlock.model.js +1 -1
  107. package/dist/testSurface/surface/pageBlock/parts.js +17 -7
  108. package/dist/testSurface/surface/pagePicker/PageCombobox.js +0 -5
  109. package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +1 -1
  110. package/dist/testSurface/surface/readiness/ActionDialogs.js +54 -33
  111. package/dist/testSurface/surface/readiness/Banner.d.ts +3 -1
  112. package/dist/testSurface/surface/readiness/Banner.js +86 -75
  113. package/dist/testSurface/surface/readiness/SaveStatus.d.ts +5 -2
  114. package/dist/testSurface/surface/readiness/SaveStatus.js +8 -7
  115. package/dist/testSurface/surface/readiness/readiness.model.js +1 -1
  116. package/dist/testSurface/surface/results/ResultsBody.d.ts +4 -1
  117. package/dist/testSurface/surface/results/ResultsBody.js +119 -80
  118. package/dist/testSurface/surface/results/recommendation.model.js +3 -3
  119. package/dist/testSurface/surface/setting/parts.js +31 -28
  120. package/dist/testSurface/surface/setting/setting.css +2 -1
  121. package/dist/testSurface/surface/test/AdvancedSection.js +10 -4
  122. package/dist/testSurface/surface/test/GoalSection.js +11 -11
  123. package/dist/testSurface/surface/test/LengthSection.js +20 -13
  124. package/dist/testSurface/surface/test/PageHoldout.d.ts +1 -1
  125. package/dist/testSurface/surface/test/PageHoldout.js +7 -7
  126. package/dist/testSurface/surface/test/ReadinessBar.d.ts +1 -1
  127. package/dist/testSurface/surface/test/ReadinessBar.js +4 -10
  128. package/dist/testSurface/surface/test/Section.js +8 -0
  129. package/dist/testSurface/surface/test/TargetingSection.js +7 -2
  130. package/dist/testSurface/surface/test/VersionsSection.js +88 -68
  131. package/dist/testSurface/surface/test/fields.d.ts +4 -3
  132. package/dist/testSurface/surface/test/fields.js +10 -16
  133. package/dist/testSurface/surface/test/pageParts.js +3 -1
  134. package/dist/testSurface/surface/test/testPage.css +9 -1
  135. package/dist/testSurface/surfaceUrls.d.ts +1 -0
  136. package/dist/testSurface/surfaceUrls.js +4 -0
  137. package/dist/ui/Dialog.js +25 -0
  138. package/dist/ui/Inputs.js +0 -1
  139. package/dist/ui/ui.css +1 -0
  140. package/package.json +1 -1
@@ -4,8 +4,9 @@ import { canStartTest, hasBrowserWritablePrimary, readyToStart } from '../../../
4
4
  import { BlockerList } from '../../../testSurface/surface/readiness/BlockerList.js';
5
5
  import { ReadinessReadStatus } from '../../../testSurface/surface/readiness/SaveStatus.js';
6
6
  import { surfaceUrls } from '../../../testSurface/surfaceUrls.js';
7
- import { useEffect, useState } from 'react';
7
+ import { Fragment, useEffect, useState } from 'react';
8
8
  import { formatAdminURL } from 'payload/shared';
9
+ import { useXpStepNav } from '../useXpStepNav.js';
9
10
  import { SurfaceShell } from '../SurfaceShell.js';
10
11
  import { Button } from '../../../ui/Button.js';
11
12
  import { Banner, StatusChip } from '../../../ui/Feedback.js';
@@ -18,7 +19,7 @@ import { READINESS_COPY as R, runningCopy, stoppedCopy, decidedCopy } from '../.
18
19
  import { RESULTS_COPY as C } from '../../../testSurface/copy/results.js';
19
20
  import { METRICS_COPY } from '../../../testSurface/copy/metrics.js';
20
21
  import { TEST_PAGE } from '../../../testSurface/copy/testPage.js';
21
- export function ResultsHeader({ test, surface, resultsVersion, children, actions, released }) {
22
+ export function ResultsHeader({ test, surface, resultsVersion, children, roundActions, editOnPage, refresh, released }) {
22
23
  const doc = test.doc;
23
24
  const [selected, setSelected] = useState(null);
24
25
  const [audience, setAudience] = useState();
@@ -52,12 +53,9 @@ export function ResultsHeader({ test, surface, resultsVersion, children, actions
52
53
  const available = availableActions({
53
54
  ...doc,
54
55
  decision,
55
- canManage: surface.canManage
56
- }).filter((action)=>![
57
- 'decide',
58
- 'release-pages',
59
- 'delete'
60
- ].includes(action.id));
56
+ canManage: surface.canManage,
57
+ canReadResults: surface.canReadResults
58
+ });
61
59
  const setup = doc.status === 'draft' || doc.status === 'stopped';
62
60
  const blockers = blockingSteps(test.preflight, pageReadinessContext(doc, test.preflight, surface));
63
61
  const ready = readyToStart(test);
@@ -67,22 +65,39 @@ export function ResultsHeader({ test, surface, resultsVersion, children, actions
67
65
  adminRoute: surface.adminRoute,
68
66
  path: `/experiments/${encodeURIComponent(String(doc.id))}`
69
67
  });
68
+ const pageEditors = [
69
+ ...new Set(test.preflight?.pagePlacements?.flatMap((page)=>page.editorUrl ? [
70
+ page.editorUrl
71
+ ] : []) ?? [])
72
+ ];
73
+ const pageEditor = pageEditors.length ? /*#__PURE__*/ _jsx(Button, {
74
+ size: "sm",
75
+ href: pageEditors.length === 1 ? pageEditors[0] : `${testURL}#section-versions`,
76
+ children: TEST_PAGE.editOnPage
77
+ }) : null;
78
+ const crumbs = [
79
+ {
80
+ label: C.tests,
81
+ url: surfaceUrls.home(surface.adminRoute)
82
+ },
83
+ {
84
+ label: doc.name,
85
+ url: testURL
86
+ },
87
+ {
88
+ label: C.results
89
+ }
90
+ ];
91
+ useXpStepNav(crumbs);
70
92
  return /*#__PURE__*/ _jsxs(SurfaceShell, {
71
93
  adminRoute: surface.adminRoute,
72
94
  title: doc.name,
73
- crumbs: [
74
- {
75
- label: C.tests,
76
- href: surface.canManage ? surfaceUrls.home(surface.adminRoute) : undefined
77
- },
78
- {
79
- label: doc.name,
80
- href: testURL
81
- },
82
- {
83
- label: C.results
84
- }
85
- ],
95
+ dynamicTitle: true,
96
+ className: "xp-results-shell",
97
+ crumbs: crumbs.map(({ label, url })=>({
98
+ label,
99
+ href: url
100
+ })),
86
101
  status: /*#__PURE__*/ _jsxs(_Fragment, {
87
102
  children: [
88
103
  /*#__PURE__*/ _jsx("span", {
@@ -108,24 +123,30 @@ export function ResultsHeader({ test, surface, resultsVersion, children, actions
108
123
  ]
109
124
  }),
110
125
  actions: /*#__PURE__*/ _jsxs("div", {
111
- className: "xp-ui-button-group",
126
+ className: "xp-results-header-actions xp-ui-button-group",
112
127
  children: [
113
128
  /*#__PURE__*/ _jsx(Button, {
114
- variant: "quiet",
129
+ size: "sm",
115
130
  href: testURL,
116
131
  children: C.backToSetup
117
132
  }),
118
- !test.statusReadPending && available.map((item)=>/*#__PURE__*/ _jsx(LifecycleButton, {
133
+ editOnPage ?? pageEditor,
134
+ refresh,
135
+ !test.statusReadPending && available.map((item)=>{
136
+ if (item.id === 'decide' || item.id === 'release-pages') return /*#__PURE__*/ _jsx(Fragment, {
137
+ children: roundActions[item.id]
138
+ }, item.id);
139
+ if (item.id === 'delete') return /*#__PURE__*/ _jsx(DeleteTestAction, {
140
+ test: test,
141
+ surface: surface
142
+ }, item.id);
143
+ return /*#__PURE__*/ _jsx(LifecycleButton, {
119
144
  action: item,
120
145
  disabled: item.id === 'start' && !canStartTest(test),
121
146
  reason: item.id === 'start' ? startReason : item.unavailable,
122
147
  showReason: item.id !== 'start',
123
148
  onClick: ()=>setSelected(item)
124
- }, item.id)),
125
- actions,
126
- /*#__PURE__*/ _jsx(DeleteTestAction, {
127
- test: test,
128
- surface: surface
149
+ }, item.id);
129
150
  })
130
151
  ]
131
152
  }),
@@ -158,21 +179,28 @@ export function ResultsHeader({ test, surface, resultsVersion, children, actions
158
179
  export function ReaderResultsShell({ surface, children, data }) {
159
180
  // CORE-48 sends a missing name as an empty string.
160
181
  const title = data?.experiment?.name?.trim() || C.test;
182
+ const crumbs = [
183
+ {
184
+ label: C.tests,
185
+ url: surface.canManage ? surfaceUrls.home(surface.adminRoute) : undefined
186
+ },
187
+ {
188
+ label: title
189
+ },
190
+ {
191
+ label: C.results
192
+ }
193
+ ];
194
+ useXpStepNav(crumbs);
161
195
  return /*#__PURE__*/ _jsx(SurfaceShell, {
162
196
  adminRoute: surface.adminRoute,
163
197
  title: title,
164
- crumbs: [
165
- {
166
- label: C.tests,
167
- href: surface.canManage ? surfaceUrls.home(surface.adminRoute) : undefined
168
- },
169
- {
170
- label: title
171
- },
172
- {
173
- label: C.results
174
- }
175
- ],
198
+ dynamicTitle: Boolean(data?.experiment?.name?.trim()),
199
+ className: "xp-results-shell",
200
+ crumbs: crumbs.map(({ label, url })=>({
201
+ label,
202
+ href: url
203
+ })),
176
204
  children: children
177
205
  });
178
206
  }
@@ -36,9 +36,11 @@
36
36
  .xp-tests-row-menu-trigger { width: 36px; padding-inline: 0; }
37
37
  .xp-tests-row-menu-items { position: absolute; inset-inline-end: 0; top: calc(100% + var(--xp-space-1)); z-index: 2; display: grid; width: min(16rem, calc(100vw - 2rem)); padding: var(--xp-space-1); border: 1px solid var(--xp-border-strong); border-radius: var(--xp-radius-control); background: var(--xp-surface); }
38
38
  .xp-tests-menu-item { display: grid; min-height: 36px; padding: var(--xp-space-2); text-align: start; font: var(--xp-text-body); color: var(--xp-text); background: transparent; border: 0; border-radius: var(--xp-radius-control); cursor: pointer; }
39
+ .xp-tests-menu-item--primary { color: var(--xp-accent-fg); background: var(--xp-accent); }
40
+ .xp-tests-menu-item--primary:hover, .xp-tests-menu-item--primary:focus-visible { background: var(--xp-accent-hover); }
39
41
  .xp-tests-menu-item--danger { color: var(--xp-error); }
40
42
  .xp-tests-menu-item[aria-disabled='true'] { cursor: not-allowed; }
41
- .xp-tests-menu-item:hover, .xp-tests-menu-item:focus-visible { background: var(--xp-surface-2); }
43
+ .xp-tests-menu-item:not(.xp-tests-menu-item--primary):is(:hover, :focus-visible) { background: var(--xp-surface-2); }
42
44
  .xp-tests-menu-item:focus-visible { outline: 2px solid var(--xp-focus); outline-offset: -2px; }
43
45
  .xp-tests-menu-item > .xp-ui-help { margin: 0; }
44
46
  .xp-tests-health { display: inline-flex; align-items: center; gap: 7px; font: 500 13px/18px var(--xp-font); }
@@ -72,3 +74,20 @@
72
74
  .xp-tests-shell-heading { min-width: 0; }
73
75
  .xp-tests-shell-subtitle { margin-top: var(--xp-space-2); color: var(--xp-text-2); font: var(--xp-text-small); }
74
76
  .xp-tests-shell-subtitle p { margin: 0; }
77
+
78
+ .xp-results-header-actions { align-items: flex-start; }
79
+ .xp-results-refresh { display: flex; align-items: center; gap: var(--xp-space-2); }
80
+ .xp-results-refresh > .xp-ui-help { margin: 0; white-space: nowrap; }
81
+ @media (min-width: 900px) {
82
+ .xp-results-shell .xp-tests-shell-main { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: var(--xp-space-2) var(--xp-space-4); }
83
+ .xp-results-shell .xp-tests-shell-heading { display: contents; }
84
+ .xp-results-shell .xp-tests-shell-title { grid-row: 1; grid-column: 1; }
85
+ .xp-results-shell .xp-tests-shell-actions { grid-row: 1; grid-column: 2; }
86
+ .xp-results-shell .xp-tests-shell-subtitle { grid-row: 2; grid-column: 1 / -1; margin: 0; }
87
+ .xp-results-header-actions { flex-wrap: nowrap; }
88
+ .xp-results-header-actions .xp-ui-button { white-space: nowrap; }
89
+ }
90
+ @media (max-width: 899px) {
91
+ .xp-results-shell .xp-tests-shell-main { flex-direction: column; gap: var(--xp-space-3); }
92
+ .xp-results-shell .xp-tests-shell-actions { justify-content: flex-start; }
93
+ }
@@ -6,47 +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 && doc.status !== 'draft' ? /*#__PURE__*/ _jsx(Button, {
41
- variant: "secondary",
42
- href: formatAdminURL({
43
- adminRoute: surface.adminRoute,
44
- path: `/experiments/${encodeURIComponent(String(doc.id))}/results`
45
- }),
46
- children: C.results
47
- }) : undefined,
16
+ renderFrame: ({ test, children })=>/*#__PURE__*/ _jsx(TestPageFrame, {
17
+ test: test,
18
+ surface: surface,
48
19
  children: children
49
- });
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
50
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
51
63
  });
52
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
  }
@@ -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,
@@ -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)
@@ -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,2 @@
1
+ /** Present unlabelled source keys in sentence case. */
2
+ export declare function goalSourceLabel(key: string): string;
@@ -0,0 +1,4 @@
1
+ /** Present unlabelled source keys in sentence case. */ export function goalSourceLabel(key) {
2
+ const words = key.replace(/^(?:events|click):/, '').replace(/[-_]+/g, ' ').trim().toLowerCase();
3
+ return words.charAt(0).toUpperCase() + words.slice(1);
4
+ }
package/dist/plugin.js CHANGED
@@ -40,9 +40,59 @@ export function createExperimentsPlugin(input) {
40
40
  ...config.admin?.components,
41
41
  views: {
42
42
  ...config.admin?.components?.views,
43
+ xpNewTest: {
44
+ Component: paths.XP_TESTS_VIEW,
45
+ path: '/experiments/new',
46
+ exact: true,
47
+ meta: {
48
+ title: {
49
+ absolute: 'New test · Tests'
50
+ },
51
+ titleSuffix: ''
52
+ }
53
+ },
54
+ xpNewGoal: {
55
+ Component: paths.XP_TESTS_VIEW,
56
+ path: '/experiments/goals/new',
57
+ exact: true,
58
+ meta: {
59
+ title: {
60
+ absolute: 'New goal · Tests'
61
+ },
62
+ titleSuffix: ''
63
+ }
64
+ },
65
+ xpGoal: {
66
+ Component: paths.XP_TESTS_VIEW,
67
+ path: '/experiments/goals/:id',
68
+ exact: true,
69
+ meta: {
70
+ title: {
71
+ absolute: 'Goal · Tests'
72
+ },
73
+ titleSuffix: ''
74
+ }
75
+ },
76
+ xpResults: {
77
+ Component: paths.XP_TESTS_VIEW,
78
+ path: '/experiments/:id/results',
79
+ exact: true,
80
+ meta: {
81
+ title: {
82
+ absolute: 'Results · Tests'
83
+ },
84
+ titleSuffix: ''
85
+ }
86
+ },
43
87
  xpTests: {
44
88
  Component: paths.XP_TESTS_VIEW,
45
- path: '/experiments/:segments*'
89
+ path: '/experiments/:segments*',
90
+ meta: {
91
+ title: {
92
+ absolute: 'Test · Tests'
93
+ },
94
+ titleSuffix: ''
95
+ }
46
96
  }
47
97
  }
48
98
  }
@@ -1,4 +1,5 @@
1
1
  import { type ComponentConfig } from '@puckeditor/core';
2
+ import { type ReactNode } from 'react';
2
3
  import type { ExperimentSlotProps } from '../../types/puck.js';
3
4
  import { type PuckRoutes } from '../routes.js';
4
5
  import './editor.css';
@@ -12,7 +13,7 @@ export declare const ExperimentSlotEditor: {
12
13
  defaultProps?: ExperimentSlotProps | undefined;
13
14
  fields?: import("@puckeditor/core").Fields<ExperimentSlotProps, {}> | undefined;
14
15
  renderFields?: ((props: {
15
- fields: Partial<Record<keyof ExperimentSlotProps, import("react").ReactNode>>;
16
+ fields: Partial<Record<keyof ExperimentSlotProps, ReactNode>>;
16
17
  }) => import("react").ReactElement) | undefined;
17
18
  permissions?: Partial<import("@puckeditor/core").Permissions>;
18
19
  inline?: boolean;