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

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 (221) hide show
  1. package/README.md +12 -12
  2. package/dist/admin/blocks/model.js +2 -2
  3. package/dist/admin/copy/blocks.js +1 -1
  4. package/dist/admin/surface/ResultsRoute.js +17 -11
  5. package/dist/admin/surface/TestsHome.js +53 -20
  6. package/dist/admin/surface/newTest/PageWizard.js +8 -2
  7. package/dist/admin/surface/results/ResultsHeader.js +11 -6
  8. package/dist/admin/surface/test/TestPage.js +3 -3
  9. package/dist/blocks/formState.js +1 -1
  10. package/dist/collections/experiments/config.js +8 -3
  11. package/dist/collections/experiments/deleteGuard.js +2 -2
  12. package/dist/collections/experiments/lockHook.js +21 -2
  13. package/dist/collections/experiments/pickSlug.js +2 -0
  14. package/dist/collections/metricsGuards.js +2 -0
  15. package/dist/collections/serialize.js +5 -4
  16. package/dist/constants.d.ts +1 -0
  17. package/dist/constants.js +1 -0
  18. package/dist/db/adapter.d.ts +9 -1
  19. package/dist/db/adapter.js +77 -1
  20. package/dist/db/delete.d.ts +1 -1
  21. package/dist/db/delete.js +2 -4
  22. package/dist/db/events.d.ts +9 -0
  23. package/dist/db/events.js +42 -8
  24. package/dist/db/executor.d.ts +7 -1
  25. package/dist/db/executor.js +7 -3
  26. package/dist/db/results.d.ts +5 -1
  27. package/dist/db/results.js +21 -5
  28. package/dist/db/snapshots.d.ts +1 -0
  29. package/dist/endpoints/deleteImpact.js +2 -1
  30. package/dist/endpoints/events.js +103 -39
  31. package/dist/endpoints/index.js +2 -8
  32. package/dist/endpoints/placementStatus.js +7 -4
  33. package/dist/endpoints/results.d.ts +1 -1
  34. package/dist/endpoints/results.js +6 -2
  35. package/dist/endpoints/routeId.d.ts +2 -2
  36. package/dist/endpoints/routeId.js +11 -5
  37. package/dist/endpoints/summary.js +46 -12
  38. package/dist/endpoints/transitions.js +37 -24
  39. package/dist/errors.d.ts +4 -0
  40. package/dist/errors.js +6 -0
  41. package/dist/events/request.d.ts +6 -2
  42. package/dist/events/request.js +35 -8
  43. package/dist/events/rows.d.ts +1 -1
  44. package/dist/events/rows.js +24 -8
  45. package/dist/events/writable.d.ts +9 -0
  46. package/dist/events/writable.js +13 -0
  47. package/dist/exports/index.d.ts +1 -1
  48. package/dist/exports/rsc.d.ts +1 -0
  49. package/dist/exports/rsc.js +1 -0
  50. package/dist/goals/fairness.js +2 -2
  51. package/dist/hooks/hostHook.js +6 -2
  52. package/dist/hooks/pageGuard.js +4 -0
  53. package/dist/lib/fetchAllDocs.d.ts +1 -1
  54. package/dist/manifest/compile.js +8 -5
  55. package/dist/onInit.js +14 -0
  56. package/dist/options.js +5 -0
  57. package/dist/proxy/pageNavigation.d.ts +4 -0
  58. package/dist/proxy/pageNavigation.js +28 -0
  59. package/dist/proxy/resolve.js +52 -25
  60. package/dist/puck/editor/ConfigureTestDrawer.js +5 -4
  61. package/dist/puck/editor/ExperimentSlotEditor.js +182 -58
  62. package/dist/puck/editor/QuickTestActions.d.ts +5 -2
  63. package/dist/puck/editor/QuickTestActions.js +16 -4
  64. package/dist/puck/editor/ResultsReadout.d.ts +2 -1
  65. package/dist/puck/editor/ResultsReadout.js +2 -1
  66. package/dist/puck/editor/VersionBuilder.d.ts +13 -2
  67. package/dist/puck/editor/VersionBuilder.js +133 -49
  68. package/dist/puck/editor/armWrites.js +1 -1
  69. package/dist/puck/editor/armsCache.js +1 -3
  70. package/dist/puck/editor/copy.d.ts +4 -1
  71. package/dist/puck/editor/copy.js +4 -1
  72. package/dist/puck/editor/editor.chrome.css +1 -0
  73. package/dist/puck/editor/editor.css +1 -0
  74. package/dist/puck/editor/editor.model.d.ts +1 -0
  75. package/dist/puck/editor/placementsCache.d.ts +5 -1
  76. package/dist/puck/editor/placementsCache.js +17 -9
  77. package/dist/puck/editor/usePageSaveReadiness.d.ts +9 -0
  78. package/dist/puck/editor/usePageSaveReadiness.js +34 -0
  79. package/dist/puck/editor/usePlacementNotice.d.ts +2 -2
  80. package/dist/puck/editor/usePlacementNotice.js +5 -4
  81. package/dist/results/aggregate.d.ts +6 -3
  82. package/dist/results/aggregate.js +9 -9
  83. package/dist/results/health.d.ts +8 -0
  84. package/dist/results/health.js +28 -0
  85. package/dist/results/identityCredit.d.ts +1 -0
  86. package/dist/results/identityCredit.js +4 -1
  87. package/dist/results/verdict.js +2 -1
  88. package/dist/runtime/cookie.d.ts +10 -2
  89. package/dist/runtime/cookie.js +38 -6
  90. package/dist/runtime/cookieOptions.d.ts +6 -0
  91. package/dist/runtime/cookieOptions.js +14 -0
  92. package/dist/runtime/proxyRuntime.d.ts +1 -0
  93. package/dist/runtime/proxyRuntime.js +18 -8
  94. package/dist/runtime/signing.d.ts +1 -0
  95. package/dist/runtime/signing.js +5 -0
  96. package/dist/sanitizeReadinessDetail.d.ts +2 -2
  97. package/dist/sanitizeReadinessDetail.js +20 -2
  98. package/dist/server/getAssignments.js +11 -10
  99. package/dist/server/recordContentChange.d.ts +1 -1
  100. package/dist/server/recordContentChange.js +11 -2
  101. package/dist/server/resolveExperimentBlocks.js +2 -4
  102. package/dist/server/resolveExperimentData.js +2 -5
  103. package/dist/server/runResults.js +52 -14
  104. package/dist/server/startExperiment.d.ts +20 -0
  105. package/dist/server/startExperiment.js +70 -0
  106. package/dist/server/trackConversion.js +10 -13
  107. package/dist/testSurface/actions/DecideDialog.d.ts +4 -1
  108. package/dist/testSurface/actions/DecideDialog.js +32 -14
  109. package/dist/testSurface/actions/MakeContentResult.d.ts +4 -3
  110. package/dist/testSurface/actions/MakeContentResult.js +9 -1
  111. package/dist/testSurface/api.d.ts +5 -5
  112. package/dist/testSurface/api.js +21 -9
  113. package/dist/testSurface/copy/actions.d.ts +1 -0
  114. package/dist/testSurface/copy/actions.js +1 -0
  115. package/dist/testSurface/copy/common.d.ts +3 -1
  116. package/dist/testSurface/copy/common.js +4 -2
  117. package/dist/testSurface/copy/languages.d.ts +1 -0
  118. package/dist/testSurface/copy/languages.js +1 -0
  119. package/dist/testSurface/copy/metrics.d.ts +1 -0
  120. package/dist/testSurface/copy/metrics.js +1 -0
  121. package/dist/testSurface/copy/readiness.d.ts +12 -1
  122. package/dist/testSurface/copy/readiness.js +18 -1
  123. package/dist/testSurface/copy/results.d.ts +5 -2
  124. package/dist/testSurface/copy/results.js +5 -2
  125. package/dist/testSurface/copy/testPage.d.ts +20 -2
  126. package/dist/testSurface/copy/testPage.js +34 -3
  127. package/dist/testSurface/readPreflight.d.ts +5 -0
  128. package/dist/testSurface/readPreflight.js +7 -0
  129. package/dist/testSurface/readinessRead.d.ts +3 -0
  130. package/dist/testSurface/readinessRead.js +4 -0
  131. package/dist/testSurface/results/VerdictHero.d.ts +2 -1
  132. package/dist/testSurface/results/VerdictHero.js +5 -1
  133. package/dist/testSurface/results/results.model.d.ts +1 -1
  134. package/dist/testSurface/results/results.model.js +6 -2
  135. package/dist/testSurface/surface/contracts.d.ts +8 -1
  136. package/dist/testSurface/surface/editorPlacement.d.ts +2 -2
  137. package/dist/testSurface/surface/editorPlacement.js +1 -1
  138. package/dist/testSurface/surface/pageBlock/pageBlock.model.js +2 -2
  139. package/dist/testSurface/surface/pagePicker/PageCombobox.js +20 -6
  140. package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +4 -2
  141. package/dist/testSurface/surface/readiness/ActionDialogs.js +39 -34
  142. package/dist/testSurface/surface/readiness/Banner.js +23 -12
  143. package/dist/testSurface/surface/readiness/SaveStatus.d.ts +4 -3
  144. package/dist/testSurface/surface/readiness/SaveStatus.js +15 -15
  145. package/dist/testSurface/surface/readiness/readiness.model.d.ts +6 -1
  146. package/dist/testSurface/surface/readiness/readiness.model.js +108 -11
  147. package/dist/testSurface/surface/readiness/useTransition.d.ts +4 -4
  148. package/dist/testSurface/surface/readiness/useTransition.js +12 -10
  149. package/dist/testSurface/surface/results/ReleasePages.d.ts +4 -2
  150. package/dist/testSurface/surface/results/ReleasePages.js +5 -4
  151. package/dist/testSurface/surface/results/ResultsBody.d.ts +4 -2
  152. package/dist/testSurface/surface/results/ResultsBody.js +86 -43
  153. package/dist/testSurface/surface/results/useResults.d.ts +7 -6
  154. package/dist/testSurface/surface/results/useResults.js +3 -2
  155. package/dist/testSurface/surface/setting/parts.js +58 -18
  156. package/dist/testSurface/surface/test/AdvancedSection.js +1 -0
  157. package/dist/testSurface/surface/test/DeleteTest.d.ts +6 -2
  158. package/dist/testSurface/surface/test/DeleteTest.js +145 -54
  159. package/dist/testSurface/surface/test/GoalSection.js +7 -3
  160. package/dist/testSurface/surface/test/LengthSection.js +3 -0
  161. package/dist/testSurface/surface/test/PageHoldout.js +4 -1
  162. package/dist/testSurface/surface/test/ReadinessBar.js +1 -1
  163. package/dist/testSurface/surface/test/TargetingSection.js +77 -12
  164. package/dist/testSurface/surface/test/TestSurface.js +81 -19
  165. package/dist/testSurface/surface/test/VersionsSection.js +56 -29
  166. package/dist/testSurface/surface/test/fields.d.ts +29 -4
  167. package/dist/testSurface/surface/test/fields.js +159 -39
  168. package/dist/testSurface/surface/test/pageParts.js +14 -5
  169. package/dist/testSurface/surface/test/testPage.model.d.ts +1 -0
  170. package/dist/testSurface/surface/test/testPage.model.js +6 -0
  171. package/dist/testSurface/surface/testDocument.model.d.ts +3 -0
  172. package/dist/testSurface/surface/testDocument.model.js +4 -1
  173. package/dist/testSurface/surface/useTestDocument.d.ts +22 -4
  174. package/dist/testSurface/surface/useTestDocument.js +407 -160
  175. package/dist/testSurface/useApi.d.ts +5 -5
  176. package/dist/testSurface/useOnTestReturn.d.ts +2 -0
  177. package/dist/testSurface/useOnTestReturn.js +27 -0
  178. package/dist/testSurface/useReadinessPolling.js +3 -1
  179. package/dist/transitions/addMetric.d.ts +1 -4
  180. package/dist/transitions/allocate.d.ts +2 -2
  181. package/dist/transitions/allocate.js +3 -1
  182. package/dist/transitions/archive.d.ts +1 -1
  183. package/dist/transitions/archive.js +3 -2
  184. package/dist/transitions/checkStart.d.ts +1 -0
  185. package/dist/transitions/checkStart.js +17 -6
  186. package/dist/transitions/decide.d.ts +1 -1
  187. package/dist/transitions/decide.js +5 -3
  188. package/dist/transitions/deleteExperiment.d.ts +2 -2
  189. package/dist/transitions/deleteExperiment.js +17 -7
  190. package/dist/transitions/kernel.d.ts +2 -0
  191. package/dist/transitions/kernel.js +9 -4
  192. package/dist/transitions/makeContent.d.ts +2 -1
  193. package/dist/transitions/makeContent.js +12 -8
  194. package/dist/transitions/nestedPlacementNames.d.ts +2 -2
  195. package/dist/transitions/nestedPlacementNames.js +4 -5
  196. package/dist/transitions/phaseRecord.d.ts +2 -0
  197. package/dist/transitions/phaseRecord.js +5 -0
  198. package/dist/transitions/placementInteractions.d.ts +3 -3
  199. package/dist/transitions/placementInteractions.js +8 -7
  200. package/dist/transitions/placements.d.ts +2 -0
  201. package/dist/transitions/placements.js +5 -5
  202. package/dist/transitions/preflightData.d.ts +3 -2
  203. package/dist/transitions/preflightData.js +67 -41
  204. package/dist/transitions/releaseHoldout.d.ts +2 -1
  205. package/dist/transitions/releaseHoldout.js +3 -1
  206. package/dist/transitions/releasePages.d.ts +2 -1
  207. package/dist/transitions/releasePages.js +3 -1
  208. package/dist/transitions/resolveCaps.d.ts +2 -4
  209. package/dist/transitions/start.d.ts +6 -8
  210. package/dist/transitions/start.js +67 -34
  211. package/dist/transitions/startReads.d.ts +7 -0
  212. package/dist/transitions/startReads.js +28 -0
  213. package/dist/transitions/stop.d.ts +2 -1
  214. package/dist/transitions/stop.js +3 -2
  215. package/dist/types/contracts.d.ts +6 -3
  216. package/dist/types/endpoints.d.ts +52 -9
  217. package/dist/types/runtime.d.ts +15 -9
  218. package/dist/types/snapshot.d.ts +2 -0
  219. package/dist/ui/ChipsInput.d.ts +8 -1
  220. package/dist/ui/ChipsInput.js +17 -4
  221. package/package.json +2 -2
@@ -1,49 +1,100 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { placementLanguageSuffix } from '../../copy/languages.js';
4
- import { useEffect, useRef, useState } from 'react';
4
+ import { useCallback, useEffect, useRef, useState } from 'react';
5
5
  import { createApi } from '../../api.js';
6
- import { DELETE_TEST as C } from '../../copy/testPage.js';
6
+ import { API_MESSAGES } from '../../copy/common.js';
7
+ import { DELETE_TEST as C, deleteStatusCopy } from '../../copy/testPage.js';
8
+ import { useOnTestReturn } from '../../useOnTestReturn.js';
7
9
  import { Button } from '../../../ui/Button.js';
8
10
  import { Dialog } from '../../../ui/Dialog.js';
9
11
  const VISIBLE_PAGES = 5;
10
12
  export const DELETE_IMPACT_TIMEOUT_MS = 15_000;
11
- /** Matches deleteExperiment's status guard; the server rechecks under its lock. */ export function DeleteTest({ test, canManage, apiRoute, contentLocale, onDeleted }) {
13
+ /** Matches deleteExperiment's status guard; the server rechecks under its lock. */ export function DeleteTest({ test, canManage, apiRoute, contentLocale, onDeleted, onStatusChanged, onDialogChange }) {
12
14
  const [open, setOpen] = useState(false);
13
15
  const [busy, setBusy] = useState(false);
14
16
  const pending = useRef(false);
17
+ const actions = useRef(null);
15
18
  const [error, setError] = useState();
16
- const [impact, setImpact] = useState({
19
+ const [checked, setChecked] = useState();
20
+ const [refusal, setRefusal] = useState();
21
+ const [checkAttempt, setCheckAttempt] = useState(0);
22
+ const checkKey = JSON.stringify([
23
+ test.id,
24
+ apiRoute,
25
+ contentLocale,
26
+ test.status,
27
+ typeof test.updatedAt === 'string' ? test.updatedAt : null,
28
+ checkAttempt
29
+ ]);
30
+ const impact = refusal ?? (checked?.key === checkKey ? checked.impact : {
17
31
  state: 'loading'
18
32
  });
33
+ const deletable = test.status === 'draft' || test.status === 'archived';
34
+ const statusMessage = deletable ? undefined : deleteStatusCopy(test.status, test.kind);
35
+ const blocked = !canManage ? API_MESSAGES.forbidden : impact.state === 'blocked' ? impact.reason === 'invalid-status' ? statusMessage ?? impact.message : impact.message : statusMessage;
36
+ useOnTestReturn(useCallback(()=>{
37
+ if (!pending.current) setCheckAttempt((value)=>value + 1);
38
+ }, []), open && !blocked);
39
+ useEffect(()=>{
40
+ if (open && blocked && !busy) actions.current?.querySelector('[data-dialog-cancel]')?.focus();
41
+ }, [
42
+ open,
43
+ blocked,
44
+ busy
45
+ ]);
19
46
  useEffect(()=>{
20
- if (!open) return;
47
+ if (!open || !deletable || !canManage || refusal) return;
21
48
  let current = true;
22
49
  const controller = new AbortController();
50
+ const record = (impact)=>setChecked({
51
+ key: checkKey,
52
+ impact
53
+ });
23
54
  const timer = setTimeout(()=>{
24
55
  if (!current) return;
25
56
  current = false;
26
57
  controller.abort();
27
- setImpact({
58
+ record({
28
59
  state: 'failed'
29
60
  });
30
61
  }, DELETE_IMPACT_TIMEOUT_MS);
31
- setImpact({
32
- state: 'loading'
33
- });
34
62
  void createApi(apiRoute, contentLocale).deleteImpact(test.id, controller.signal).then((result)=>{
35
63
  if (!current) return;
36
64
  clearTimeout(timer);
37
- setImpact(result.ok && result.data && [
38
- 'none',
39
- 'block',
40
- 'page'
41
- ].includes(result.data.effect) ? {
42
- state: 'ready',
43
- data: result.data
44
- } : {
65
+ if (result.ok) {
66
+ record(readableImpact(result.data) ? {
67
+ state: 'ready',
68
+ data: result.data
69
+ } : {
70
+ state: 'blocked',
71
+ message: API_MESSAGES.unreadable
72
+ });
73
+ } else if (result.status === 0 || result.status >= 500) record({
45
74
  state: 'failed'
46
75
  });
76
+ else if (result.status === 404) setRefusal({
77
+ state: 'blocked',
78
+ message: C.alreadyDeleted,
79
+ reason: 'already-deleted'
80
+ });
81
+ else if (result.status === 409 && result.code === 'invalid-status') {
82
+ setRefusal({
83
+ state: 'blocked',
84
+ message: result.message,
85
+ reason: 'invalid-status',
86
+ refusedStatus: test.status
87
+ });
88
+ } else setRefusal({
89
+ state: 'blocked',
90
+ message: result.message
91
+ });
92
+ if (!result.ok && !onDialogChange && [
93
+ 401,
94
+ 403,
95
+ 404,
96
+ 409
97
+ ].includes(result.status)) onStatusChanged();
47
98
  });
48
99
  return ()=>{
49
100
  current = false;
@@ -52,84 +103,119 @@ export const DELETE_IMPACT_TIMEOUT_MS = 15_000;
52
103
  };
53
104
  }, [
54
105
  open,
106
+ deletable,
107
+ canManage,
108
+ refusal,
109
+ checkKey,
55
110
  test.id,
56
111
  apiRoute,
57
112
  contentLocale
58
113
  ]);
59
- if (!canManage || ![
60
- 'draft',
61
- 'archived'
62
- ].includes(test.status)) return null;
114
+ if (!open && (!canManage || !deletable)) return null;
63
115
  const checking = impact.state === 'loading';
116
+ function showDialog() {
117
+ setError(undefined);
118
+ setChecked(undefined);
119
+ setRefusal(undefined);
120
+ setOpen(true);
121
+ onDialogChange?.(true);
122
+ }
123
+ function close() {
124
+ setOpen(false);
125
+ onDialogChange?.(false);
126
+ // Keep the refusal visible until dismissed. Reloading can move the row to another group.
127
+ if (impact.state === 'blocked' && impact.reason === 'already-deleted') onDeleted('already');
128
+ if (onDialogChange && impact.state === 'blocked' && impact.reason === 'invalid-status') onStatusChanged();
129
+ }
64
130
  async function remove() {
65
- if (checking || pending.current) return;
131
+ if (blocked || checking || pending.current) return;
66
132
  pending.current = true;
67
133
  setBusy(true);
68
134
  setError(undefined);
69
135
  const result = await createApi(apiRoute).deleteTest(test.id);
70
136
  if (result.ok || result.status === 404) {
71
137
  setOpen(false);
138
+ onDialogChange?.(false);
72
139
  onDeleted(result.ok ? 'done' : 'already');
73
- } else setError(result.message);
140
+ } else if (result.status === 409 && result.code === 'invalid-status') {
141
+ setRefusal({
142
+ state: 'blocked',
143
+ message: result.message,
144
+ reason: 'invalid-status',
145
+ refusedStatus: test.status
146
+ });
147
+ if (!onDialogChange) onStatusChanged();
148
+ } else if (result.status === 401 || result.status === 403) {
149
+ setRefusal({
150
+ state: 'blocked',
151
+ message: result.message
152
+ });
153
+ onStatusChanged();
154
+ } else {
155
+ setError(result.message);
156
+ if (result.status === 409) onStatusChanged();
157
+ }
74
158
  pending.current = false;
75
159
  setBusy(false);
76
160
  }
77
161
  return /*#__PURE__*/ _jsxs(_Fragment, {
78
162
  children: [
79
- /*#__PURE__*/ _jsx(Button, {
163
+ canManage && deletable && (refusal?.reason !== 'invalid-status' || refusal.refusedStatus !== test.status) ? /*#__PURE__*/ _jsx(Button, {
80
164
  variant: "quiet",
81
165
  size: "sm",
82
- onClick: ()=>{
83
- setError(undefined);
84
- setImpact({
85
- state: 'loading'
86
- });
87
- setOpen(true);
88
- },
166
+ onClick: showDialog,
89
167
  children: C.action
90
- }),
168
+ }) : null,
91
169
  /*#__PURE__*/ _jsxs(Dialog, {
92
170
  open: open,
93
171
  title: C.title(test.name),
94
172
  initialFocus: "cancel",
95
173
  dismissible: !busy,
96
- onClose: ()=>setOpen(false),
174
+ onClose: close,
97
175
  children: [
98
- /*#__PURE__*/ _jsx("p", {
99
- children: C.consequences
100
- }),
101
- /*#__PURE__*/ _jsx("p", {
102
- children: C.content
103
- }),
104
- /*#__PURE__*/ _jsx("p", {
105
- role: "status",
106
- "aria-atomic": "true",
107
- children: checking ? C.checking : impact.state === 'failed' ? C.checkFailed : impact.state === 'ready' ? impactSummary(impact.data) : ''
108
- }),
109
- impact.state === 'ready' ? /*#__PURE__*/ _jsx(ImpactDetails, {
110
- impact: impact.data
111
- }) : null,
112
- error ? /*#__PURE__*/ _jsx("p", {
176
+ blocked ? /*#__PURE__*/ _jsx("p", {
113
177
  role: "alert",
114
- children: error
115
- }) : null,
178
+ children: blocked
179
+ }) : /*#__PURE__*/ _jsxs(_Fragment, {
180
+ children: [
181
+ /*#__PURE__*/ _jsx("p", {
182
+ children: C.consequences
183
+ }),
184
+ /*#__PURE__*/ _jsx("p", {
185
+ children: C.content
186
+ }),
187
+ /*#__PURE__*/ _jsx("p", {
188
+ role: "status",
189
+ "aria-atomic": "true",
190
+ children: checking ? C.checking : impact.state === 'failed' ? C.checkFailed : impact.state === 'ready' ? impactSummary(impact.data) : ''
191
+ }),
192
+ impact.state === 'ready' ? /*#__PURE__*/ _jsx(ImpactDetails, {
193
+ impact: impact.data
194
+ }) : null,
195
+ error ? /*#__PURE__*/ _jsx("p", {
196
+ role: "alert",
197
+ children: error
198
+ }) : null
199
+ ]
200
+ }),
116
201
  /*#__PURE__*/ _jsxs("div", {
202
+ ref: actions,
117
203
  className: "xp-ui-button-group",
118
204
  children: [
119
205
  /*#__PURE__*/ _jsx(Button, {
120
206
  "data-dialog-cancel": true,
121
207
  disabled: busy,
122
- onClick: ()=>setOpen(false),
123
- children: C.cancel
208
+ onClick: close,
209
+ children: blocked ? C.close : C.cancel
124
210
  }),
125
- /*#__PURE__*/ _jsx(Button, {
211
+ !blocked ? /*#__PURE__*/ _jsx(Button, {
126
212
  variant: "danger",
127
213
  disabled: checking,
128
214
  "aria-disabled": busy || checking || undefined,
129
215
  "aria-busy": busy || undefined,
130
216
  onClick: ()=>void remove(),
131
217
  children: C.action
132
- })
218
+ }) : null
133
219
  ]
134
220
  })
135
221
  ]
@@ -137,6 +223,11 @@ export const DELETE_IMPACT_TIMEOUT_MS = 15_000;
137
223
  ]
138
224
  });
139
225
  }
226
+ function readableImpact(impact) {
227
+ if (impact?.effect === 'none') return true;
228
+ if (impact?.effect === 'page') return typeof impact.winnerPath === 'string' && Array.isArray(impact.addresses) && impact.addresses.every((path)=>typeof path === 'string') && (impact.afterPaths === undefined || impact.afterPaths !== null && typeof impact.afterPaths === 'object' && Object.values(impact.afterPaths).every((path)=>typeof path === 'string'));
229
+ return impact?.effect === 'block' && typeof impact.controlLabel === 'string' && Number.isInteger(impact.pageCount) && Number.isInteger(impact.unreadablePages) && Array.isArray(impact.placements) && impact.placements.every((place)=>typeof place?.title === 'string' && typeof place.before?.label === 'string' && typeof place.after?.label === 'string' && (place.path === null || typeof place.path === 'string') && (place.locales === undefined || Array.isArray(place.locales) && place.locales.every((locale)=>typeof locale === 'string')));
230
+ }
140
231
  function impactSummary(impact) {
141
232
  return impact.effect === 'none' ? C.noEffect : C.changedPages(impact.effect === 'block' ? impact.pageCount : impact.addresses.length);
142
233
  }
@@ -7,8 +7,8 @@ import { Button } from '../../../ui/Button.js';
7
7
  import { useEffect, useMemo, useState } from 'react';
8
8
  import { surfaceUrls } from '../../surfaceUrls.js';
9
9
  import { TEST_PAGE as C } from '../../copy/testPage.js';
10
- import { METRIC_KIND_LABELS } from '../../copy/metrics.js';
11
- import { isClickSource } from '../../../goals/key.js';
10
+ import { METRICS_COPY, METRIC_KIND_LABELS } from '../../copy/metrics.js';
11
+ import { isClickSource, validClickSource } from '../../../goals/key.js';
12
12
  import { createApi } from '../../api.js';
13
13
  import { sourceFor } from '../../metricSource.model.js';
14
14
  import { reviewView } from '../../review/review.model.js';
@@ -209,7 +209,8 @@ export function GoalSection({ test, surface, embedded = false }) {
209
209
  });
210
210
  const display = (ids)=>ids.length ? ids.map((id)=>options.find((option)=>option.value === String(id))?.label ?? unknownGoal).join(', ') : C.noGoal;
211
211
  const primary = metrics.find((metric)=>String(metric.id) === String(doc.metrics?.primary));
212
- const kind = sourceFor(primary?.source, surface.metricSources)?.kind;
212
+ const primarySource = sourceFor(primary?.source, surface.metricSources);
213
+ const kind = primarySource?.kind;
213
214
  const baseline = test.preflight?.baseline && String(test.preflight.baseline.metricId) === String(doc.metrics?.primary) ? reviewView(test.preflight, {
214
215
  primaryMetricKind: kind
215
216
  }).baseline : null;
@@ -266,6 +267,9 @@ export function GoalSection({ test, surface, embedded = false }) {
266
267
  primary && isClickSource(primary.source) ? /*#__PURE__*/ _jsx("p", {
267
268
  children: C.clickGoalHelp
268
269
  }) : null,
270
+ validClickSource(primary?.source) || primarySource?.clientWritable && primarySource.kind !== 'revenue' ? /*#__PURE__*/ _jsx("p", {
271
+ children: METRICS_COPY.browserWritablePrimary
272
+ }) : null,
269
273
  baseline ? /*#__PURE__*/ _jsxs("p", {
270
274
  children: [
271
275
  primary?.name ? `${primary.name}: ` : '',
@@ -30,6 +30,8 @@ export function LengthSection({ test, surface }) {
30
30
  /*#__PURE__*/ _jsxs("div", {
31
31
  children: [
32
32
  /*#__PURE__*/ _jsx(TextEdit, {
33
+ test: test,
34
+ draftKey: "analysis.reachPerDay",
33
35
  label: required ? `${C.reach} ${C.required}` : C.reach,
34
36
  value: doc.analysis?.reachPerDay ?? '',
35
37
  type: "number",
@@ -51,6 +53,7 @@ export function LengthSection({ test, surface }) {
51
53
  /*#__PURE__*/ _jsxs("div", {
52
54
  children: [
53
55
  /*#__PURE__*/ _jsx(TextEdit, {
56
+ test: test,
54
57
  label: C.duration,
55
58
  value: doc.analysis?.plannedDurationDays ?? 28,
56
59
  type: "number",
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
3
3
  import { TEST_PAGE as C } from '../../copy/testPage.js';
4
4
  import { ARMS_COPY } from '../../copy/arms.js';
5
5
  import { addHoldoutArm, removeArm, splitEvenly } from '../../arms/arms.model.js';
6
- import { balanceWeight } from './testPage.model.js';
6
+ import { balanceWeight, trafficSplit } from './testPage.model.js';
7
7
  import { FieldErrors, reasonFor, save, TextEdit } from './fields.js';
8
8
  import { Button } from '../../../ui/Button.js';
9
9
  /** Whole-page holdouts have no page of their own; their controls live under Advanced. */ export function PageHoldout({ test }) {
@@ -16,6 +16,7 @@ import { Button } from '../../../ui/Button.js';
16
16
  arm ? /*#__PURE__*/ _jsxs(_Fragment, {
17
17
  children: [
18
18
  /*#__PURE__*/ _jsx(TextEdit, {
19
+ test: test,
19
20
  label: `${C.holdoutPrefix}${C.label}`,
20
21
  value: arm.label,
21
22
  reason: reason,
@@ -27,8 +28,10 @@ import { Button } from '../../../ui/Button.js';
27
28
  }))
28
29
  }),
29
30
  /*#__PURE__*/ _jsx(TextEdit, {
31
+ test: test,
30
32
  label: `${C.holdoutPrefix}${C.weight}`,
31
33
  type: "number",
34
+ scope: trafficSplit(doc.arms),
32
35
  min: 0,
33
36
  max: 100,
34
37
  value: arm.weight,
@@ -27,6 +27,6 @@ import { ReadinessContent } from '../readiness/Banner.js';
27
27
  "aria-label": C.label,
28
28
  children: props.test.doc ? /*#__PURE__*/ _jsx(ReadinessContent, {
29
29
  ...props
30
- }, `${props.test.doc.id}/${props.test.doc.status}`) : null
30
+ }, `${props.test.doc.id}/${props.test.doc.status}/${props.test.doc.phase}`) : null
31
31
  });
32
32
  }
@@ -1,12 +1,12 @@
1
1
  'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { Button } from '../../../ui/Button.js';
4
4
  import { useId, useState } from 'react';
5
5
  import { ChipsInput } from '../../../ui/ChipsInput.js';
6
6
  import { AUDIENCE_COPY } from '../../copy/audience.js';
7
7
  import { coerceValue, emptyListHint, humaniseAttribute, opLabel, opsFor, readListValue, readTargetingRules, valueInput } from '../../targeting/targeting.model.js';
8
8
  import { TEST_PAGE as C, NUMBER_COMPARISONS } from '../../copy/testPage.js';
9
- import { CheckboxList, FieldErrors, reasonFor, save, SelectEdit, TextEdit } from './fields.js';
9
+ import { CheckboxList, FieldErrors, reasonFor, save, SavedValueChanged, SelectEdit, TextEdit, useDraftAnnouncement, useFieldDraft } from './fields.js';
10
10
  import { Section } from './Section.js';
11
11
  export function TargetingSection({ test, surface }) {
12
12
  const id = useId();
@@ -59,12 +59,20 @@ export function TargetingSection({ test, surface }) {
59
59
  ...partial
60
60
  } : row));
61
61
  const hint = emptyListHint(rule.op, rule.value);
62
+ const draftKey = JSON.stringify([
63
+ 'targeting',
64
+ rowsRevision,
65
+ index,
66
+ rule.attribute,
67
+ rule.op,
68
+ rules.length
69
+ ]);
62
70
  const changeValue = (raw)=>{
63
71
  const current = test.doc.targeting?.[index];
64
72
  const schema = current && surface.attributeKeys[current.attribute];
65
- if (!current || !schema) return;
73
+ if (!current || !schema) return false;
66
74
  const value = coerceValue(schema.type, current.op, raw);
67
- if (value !== null) setRule({
75
+ return value !== null && setRule({
68
76
  value
69
77
  });
70
78
  };
@@ -125,15 +133,15 @@ export function TargetingSection({ test, surface }) {
125
133
  ])
126
134
  ] : values.filter((saved)=>saved !== value));
127
135
  }
128
- }) : input.kind === 'chips' ? /*#__PURE__*/ _jsx(ChipsInput, {
136
+ }) : input.kind === 'chips' ? /*#__PURE__*/ _jsx(TargetingChips, {
137
+ draftKey: draftKey,
138
+ test: test,
129
139
  id: `${id}-${index}-value`,
130
- label: C.value,
131
- value: readListValue(rule.value),
132
- disabled: Boolean(reason),
133
- description: reason ?? AUDIENCE_COPY.listDescription,
134
- placeholder: AUDIENCE_COPY.listPlaceholder,
135
- onChange: changeValue
136
- }, `${rule.attribute}-${rule.op}`) : input.kind === 'select' ? /*#__PURE__*/ _jsx(SelectEdit, {
140
+ label: C.targetingValue(humaniseAttribute(rule.attribute)),
141
+ values: readListValue(rule.value),
142
+ reason: reason,
143
+ onCommit: changeValue
144
+ }, draftKey) : input.kind === 'select' ? /*#__PURE__*/ _jsx(SelectEdit, {
137
145
  label: C.value,
138
146
  reason: reason,
139
147
  value: String(rule.value),
@@ -155,6 +163,8 @@ export function TargetingSection({ test, surface }) {
155
163
  ],
156
164
  onCommit: changeValue
157
165
  }) : /*#__PURE__*/ _jsx(TextEdit, {
166
+ test: test,
167
+ draftKey: draftKey,
158
168
  label: C.value,
159
169
  reason: reason,
160
170
  value: Array.isArray(rule.value) ? rule.value.join(', ') : String(rule.value),
@@ -210,3 +220,58 @@ export function TargetingSection({ test, surface }) {
210
220
  ]
211
221
  });
212
222
  }
223
+ function TargetingChips({ test, draftKey, id, label, values, reason, onCommit }) {
224
+ const saved = values.join(', ');
225
+ const draft = useFieldDraft(test, draftKey, label, '', saved);
226
+ const [announcement, announce] = useDraftAnnouncement();
227
+ const choice = draft.dirty && !draft.saving && (draft.conflict || draft.retry || reason);
228
+ const locked = Boolean(reason || test.stale || draft.saving);
229
+ const commit = (text, confirmed = false)=>{
230
+ if (locked || choice && !confirmed) {
231
+ announce();
232
+ return;
233
+ }
234
+ const next = [
235
+ ...new Set([
236
+ ...values,
237
+ ...text.split(',').map((value)=>value.trim()).filter(Boolean)
238
+ ])
239
+ ];
240
+ if (next.length === values.length) {
241
+ draft.discard();
242
+ return;
243
+ }
244
+ if (text !== draft.value || !draft.dirty) draft.change(text);
245
+ draft.submit(()=>onCommit(next));
246
+ };
247
+ const choiceId = choice ? `${id}-new-value` : undefined;
248
+ return /*#__PURE__*/ _jsxs(_Fragment, {
249
+ children: [
250
+ /*#__PURE__*/ _jsx(ChipsInput, {
251
+ id: id,
252
+ label: C.value,
253
+ value: values,
254
+ disabled: locked,
255
+ description: reason ?? AUDIENCE_COPY.listDescription,
256
+ placeholder: AUDIENCE_COPY.listPlaceholder,
257
+ onChange: onCommit,
258
+ draft: {
259
+ value: draft.dirty ? draft.value : '',
260
+ change: draft.change,
261
+ submit: commit,
262
+ discard: draft.discard,
263
+ describedBy: choiceId
264
+ }
265
+ }),
266
+ choiceId ? /*#__PURE__*/ _jsx(SavedValueChanged, {
267
+ id: choiceId,
268
+ value: saved,
269
+ reason: reason,
270
+ conflict: draft.conflict,
271
+ announce: announcement,
272
+ onKeep: !locked ? ()=>commit(draft.value, true) : undefined,
273
+ onDiscard: draft.discard
274
+ }) : null
275
+ ]
276
+ });
277
+ }