@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
@@ -16,50 +16,58 @@ import { READINESS_COPY as C } from '../../copy/readiness.js';
16
16
  import { API_MESSAGES, refusalMessage } from '../../copy/common.js';
17
17
  import { createApi } from '../../api.js';
18
18
  import { blockingSteps, pageReadinessContext } from './readiness.model.js';
19
+ import { actionWaitMessage } from './SaveStatus.js';
19
20
  import { useTransition } from './useTransition.js';
20
21
  /** Prop-driven ConfirmDialog adapter: same model/copy, section reload instead of a page reload. */ export function ConfirmAction({ test, surface, action, winnerLabel, onClose }) {
21
22
  const api = createApi(surface.apiRoute);
23
+ const [openedPhase] = useState(test.doc?.phase);
22
24
  const [typed, setTyped] = useState('');
23
25
  const [content, setContent] = useState(null);
24
26
  const [reportBusy, setReportBusy] = useState(false);
25
27
  const transition = useTransition(test, onClose, surface);
28
+ const wait = action.id === 'start' ? actionWaitMessage(test) : undefined;
26
29
  const phrase = action.confirm.phrase ? expectedConfirm(action.confirm.phrase.action, winnerLabel) : null;
27
30
  const ready = action.id !== 'start' || !transition.checking && canStartTest(test, surface.editorPlacementMessage);
28
- const enabled = ready && !transition.busy && !test.hasUnsaved && test.saving !== 'saving' && (!phrase || matchesConfirm(phrase, typed));
31
+ const enabled = ready && !test.statusReadPending && !transition.busy && !wait && (!phrase || matchesConfirm(phrase, typed));
29
32
  async function submit(finish = false) {
30
33
  if (!enabled || !test.doc) return;
31
- const id = test.doc.id;
34
+ const { id, phase } = test.doc;
32
35
  await transition.run(finish ? 'archive' : action.id === 'start' && test.doc.status === 'stopped' ? 'restart' : action.id, async ()=>{
33
36
  if (finish) return api.archive(id, {
34
- mode: 'after-content'
37
+ mode: 'after-content',
38
+ phase
35
39
  });
36
40
  if (action.archive) return api.archive(id, {
37
41
  ...action.archive,
42
+ phase,
38
43
  ...phrase ? {
39
44
  confirmation: typed.trim()
40
45
  } : {}
41
46
  });
42
- if (action.id === 'start') return api.start(id);
43
- if (action.id === 'stop') return api.stop(id);
44
- if (action.id === 'release-holdout') return api.releaseHoldout(id);
45
- const result = await api.makeContent(id);
47
+ if (action.id === 'start') return api.start(id, openedPhase);
48
+ if (action.id === 'stop') return api.stop(id, openedPhase);
49
+ if (action.id === 'release-holdout') return api.releaseHoldout(id, phase);
50
+ const result = await api.makeContent(id, phase);
46
51
  if (result.ok && result.data) {
47
52
  setContent(result.data);
48
53
  return result;
49
54
  }
50
- return result.ok ? {
51
- ok: false,
52
- status: 0,
53
- retryable: true,
54
- message: API_MESSAGES.unreadable
55
- } : result;
55
+ if (result.ok) {
56
+ await test.reload();
57
+ return {
58
+ ok: false,
59
+ status: 0,
60
+ retryable: true,
61
+ message: API_MESSAGES.unreadable
62
+ };
63
+ }
64
+ return result;
56
65
  }, {
57
- reloadOnSuccess: finish || action.id !== 'make-content'
66
+ closeOnSuccess: finish || action.id !== 'make-content'
58
67
  });
59
68
  }
60
69
  function close() {
61
70
  if (transition.busy || reportBusy) return;
62
- if (content) void test.reload();
63
71
  onClose();
64
72
  }
65
73
  return /*#__PURE__*/ _jsxs(Dialog, {
@@ -77,9 +85,13 @@ import { useTransition } from './useTransition.js';
77
85
  isDecided: (content.doc?.status ?? test.doc?.status) === 'decided',
78
86
  onRetry: ()=>submit(),
79
87
  onFinish: ()=>submit(true),
80
- busy: transition.busy,
88
+ busy: transition.busy || test.statusReadPending,
81
89
  onBusyChange: setReportBusy,
82
- onActionStart: transition.clearError
90
+ onActionStart: transition.clearError,
91
+ onDocumentChange: async (result)=>{
92
+ if (result.ok) test.acceptTransition?.(result.data);
93
+ await test.reload();
94
+ }
83
95
  }) : /*#__PURE__*/ _jsxs(_Fragment, {
84
96
  children: [
85
97
  /*#__PURE__*/ _jsx("p", {
@@ -115,8 +127,8 @@ import { useTransition } from './useTransition.js';
115
127
  role: "alert",
116
128
  children: transition.error
117
129
  }) : null,
118
- !content && (test.hasUnsaved || test.saving === 'saving') ? /*#__PURE__*/ _jsx("p", {
119
- children: test.stale ? C.reloadFirst : C.saveFirst
130
+ !content && wait ? /*#__PURE__*/ _jsx("p", {
131
+ children: wait
120
132
  }) : !content && action.id === 'start' && !readyToStart(test, surface.editorPlacementMessage) ? /*#__PURE__*/ _jsx("p", {
121
133
  children: test.preflightError ? test.preflightError : test.doc ? blockingSteps(test.preflight, pageReadinessContext(test.doc, test.preflight, surface))[0]?.sentence ?? C.checking : C.checking
122
134
  }) : null,
@@ -139,11 +151,12 @@ import { useTransition } from './useTransition.js';
139
151
  }
140
152
  /** AllocateDialog's validation and copy, with data supplied by the test document. */ export function AllocateAction({ test, surface, onClose }) {
141
153
  const current = test.doc?.allocation ?? 100;
154
+ const [openedPhase] = useState(test.doc?.phase);
142
155
  const [value, setValue] = useState(String(Math.min(100, current + 1)));
143
156
  const transition = useTransition(test, onClose, surface);
144
157
  const allocation = Number(value);
145
158
  const valid = value.trim() !== '' && Number.isInteger(allocation) && allocation > current && allocation <= 100;
146
- const disabled = transition.busy || test.hasUnsaved || test.saving === 'saving';
159
+ const disabled = transition.busy || test.statusReadPending;
147
160
  return /*#__PURE__*/ _jsxs(Dialog, {
148
161
  open: true,
149
162
  dismissible: !transition.busy,
@@ -169,9 +182,6 @@ import { useTransition } from './useTransition.js';
169
182
  })
170
183
  ]
171
184
  }),
172
- test.hasUnsaved || test.saving === 'saving' ? /*#__PURE__*/ _jsx("p", {
173
- children: test.stale ? C.reloadFirst : C.saveFirst
174
- }) : null,
175
185
  !valid ? /*#__PURE__*/ _jsx("p", {
176
186
  children: R.allocationInvalid
177
187
  }) : null,
@@ -189,7 +199,8 @@ import { useTransition } from './useTransition.js';
189
199
  onClick: ()=>{
190
200
  // Not-found can also mean the experiment is missing; use round copy for the missing phase record.
191
201
  if (valid && test.doc) void transition.run('allocate', ()=>createApi(surface.apiRoute).allocate(test.doc.id, {
192
- allocation
202
+ allocation,
203
+ phase: openedPhase
193
204
  }, {
194
205
  notFound: API_MESSAGES.roundChanged
195
206
  }));
@@ -244,10 +255,9 @@ import { useTransition } from './useTransition.js';
244
255
  ].filter((id)=>id != null).map(String));
245
256
  const available = metrics.filter((item)=>!attached.has(String(item.id)));
246
257
  const selected = available.find((item)=>String(item.id) === metric);
247
- const disabled = transition.busy || test.hasUnsaved || test.saving === 'saving';
258
+ const disabled = transition.busy || test.statusReadPending;
248
259
  function close() {
249
260
  if (transition.busy) return;
250
- if (warnings) void test.reload();
251
261
  onClose();
252
262
  }
253
263
  return /*#__PURE__*/ _jsxs(Dialog, {
@@ -318,9 +328,7 @@ import { useTransition } from './useTransition.js';
318
328
  role: "alert",
319
329
  children: loadError ?? transition.error
320
330
  }) : null,
321
- test.hasUnsaved || test.saving === 'saving' ? /*#__PURE__*/ _jsx("p", {
322
- children: test.stale ? C.reloadFirst : C.saveFirst
323
- }) : !loading && !loadError && available.length > 0 && !selected ? /*#__PURE__*/ _jsx("p", {
331
+ !loading && !loadError && available.length > 0 && !selected ? /*#__PURE__*/ _jsx("p", {
324
332
  children: C.chooseGoalToAdd
325
333
  }) : null,
326
334
  /*#__PURE__*/ _jsx(Button, {
@@ -337,14 +345,11 @@ import { useTransition } from './useTransition.js';
337
345
  });
338
346
  if (result.ok) {
339
347
  if (result.data?.warnings?.length) setWarnings(result.data.warnings);
340
- else {
341
- await test.reload();
342
- onClose();
343
- }
348
+ else onClose();
344
349
  }
345
350
  return result;
346
351
  }, {
347
- reloadOnSuccess: false
352
+ closeOnSuccess: false
348
353
  });
349
354
  },
350
355
  children: C.addGoal
@@ -1,14 +1,15 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { canStartTest, readyToStart } from '../../readinessRead.js';
3
+ import { canStartTest, hasBrowserWritablePrimary, readyToStart } from '../../readinessRead.js';
4
4
  import { useEffect, useState } from 'react';
5
5
  import { Button } from '../../../ui/Button.js';
6
- import { SaveStatus, saveStatusMessage } from './SaveStatus.js';
6
+ import { actionWaitMessage, SaveStatus, saveStatusMessage } from './SaveStatus.js';
7
7
  import { jumpToSection } from '../test/jumpToSection.js';
8
8
  import { actionGroupLabel, availableActions } from '../../actions/actions.model.js';
9
9
  import { createApi } from '../../api.js';
10
10
  import { TEST_PAGE } from '../../copy/testPage.js';
11
11
  import { READINESS_COPY as C, decidedCopy, fixFieldsNext, runningCopy, stoppedCopy } from '../../copy/readiness.js';
12
+ import { METRICS_COPY } from '../../copy/metrics.js';
12
13
  import { READINESS, daysRemaining, displayDate, blockingSteps, pageReadinessContext, errorSection } from './readiness.model.js';
13
14
  import { AddMetricAction, AllocateAction, ConfirmAction } from './ActionDialogs.js';
14
15
  import { preflightPlacementLabel } from '../../placements/placementLabels.js';
@@ -63,13 +64,13 @@ export function ReadinessContent({ test, surface, resultsVersion }) {
63
64
  const setup = doc.status === 'draft' || doc.status === 'stopped';
64
65
  const ready = readyToStart(test, surface.editorPlacementMessage);
65
66
  const startEnabled = !transition.checking && canStartTest(test, surface.editorPlacementMessage);
66
- const unsaved = test.hasUnsaved || test.saving === 'saving';
67
+ const wait = setup ? actionWaitMessage(test) : undefined;
67
68
  const blockers = [
68
69
  ...readinessBlockers
69
70
  ];
70
- if (unsaved && !test.stale) blockers.unshift({
71
+ if (wait && !test.stale) blockers.unshift({
71
72
  section: 'header',
72
- sentence: C.saveFirst,
73
+ sentence: wait,
73
74
  code: 'unsaved'
74
75
  });
75
76
  else if (!test.preflight && !test.preflightError) blockers.unshift({
@@ -90,7 +91,7 @@ export function ReadinessContent({ test, surface, resultsVersion }) {
90
91
  sentence: test.stale ? C.reloadFirst : C.reloadAfterError,
91
92
  code: 'save-error'
92
93
  });
93
- const startReason = blockers[0]?.sentence ?? test.preflightError ?? (!ready ? C.checking : undefined);
94
+ const startReason = wait ?? blockers[0]?.sentence ?? test.preflightError ?? (!ready ? C.checking : undefined);
94
95
  const actions = availableActions({
95
96
  status: doc.status,
96
97
  kind: doc.kind,
@@ -105,13 +106,23 @@ export function ReadinessContent({ test, surface, resultsVersion }) {
105
106
  label: C.allocate
106
107
  } : action);
107
108
  const action = actions.find((item)=>item.id === selected);
108
- const sentence = transition.busy ? C.changing : setup ? ready && !blockers.length ? C.ready : null : doc.status === 'running' ? runningCopy(displayDate(doc.startedAt), people, daysRemaining(doc, Date.now())) : doc.status === 'decided' ? decidedCopy(displayDate(doc.decidedAt), winner) : C.archived;
109
+ const sentence = test.statusReadPending ? C.checking : transition.busy ? C.changing : setup ? ready && !blockers.length ? C.ready : null : doc.status === 'running' ? runningCopy(displayDate(doc.startedAt), people, daysRemaining(doc, Date.now())) : doc.status === 'decided' ? decidedCopy(displayDate(doc.decidedAt), winner) : C.archived;
109
110
  return /*#__PURE__*/ _jsxs("div", {
110
111
  className: `xp-readiness xp-readiness--${setup && ready && !blockers.length && !transition.busy ? 'ready' : 'neutral'} xp-readiness--bar xp-tests-container`,
111
112
  children: [
112
113
  setup && test.preflight?.checks.some((check)=>check.code === 'page-targets-unchecked' && check.warning) ? /*#__PURE__*/ _jsx("p", {
113
114
  children: C.uncheckedPages
114
115
  }) : null,
116
+ !test.statusReadPending && setup && hasBrowserWritablePrimary(test.preflight, doc.metrics?.primary) ? /*#__PURE__*/ _jsxs("p", {
117
+ className: "xp-readiness__warning",
118
+ children: [
119
+ /*#__PURE__*/ _jsx("span", {
120
+ "aria-hidden": "true",
121
+ children: "⚠ "
122
+ }),
123
+ METRICS_COPY.browserWritablePrimary
124
+ ]
125
+ }) : null,
115
126
  test.preflight?.checks.filter((check)=>check.code === 'make-content-unsupported' && check.warning).map((check)=>/*#__PURE__*/ _jsx("p", {
116
127
  children: READINESS[check.code].next(check.detail, doc)
117
128
  }, check.code)),
@@ -142,7 +153,7 @@ export function ReadinessContent({ test, surface, resultsVersion }) {
142
153
  note.message
143
154
  ]
144
155
  }, note.metricId)),
145
- doc.status === 'stopped' ? /*#__PURE__*/ _jsx("p", {
156
+ !test.statusReadPending && doc.status === 'stopped' ? /*#__PURE__*/ _jsx("p", {
146
157
  children: stoppedCopy(displayDate(doc.stoppedAt))
147
158
  }) : null,
148
159
  /*#__PURE__*/ _jsxs("div", {
@@ -179,13 +190,13 @@ export function ReadinessContent({ test, surface, resultsVersion }) {
179
190
  }),
180
191
  /*#__PURE__*/ _jsx("div", {
181
192
  className: "xp-readiness__actions",
182
- children: actions.map((item)=>{
183
- const reason = item.id === 'start' ? startReason : test.stale ? C.reloadFirst : unsaved ? C.saveFirst : item.id === 'allocate' && doc.allocation >= 100 ? C.everyone : undefined;
193
+ children: !test.statusReadPending && actions.map((item)=>{
194
+ const reason = item.id === 'start' ? startReason : item.id === 'allocate' && doc.allocation >= 100 ? C.everyone : undefined;
184
195
  const disabled = transition.busy || !!selected || !!reason || item.id === 'start' && !startEnabled;
185
196
  return /*#__PURE__*/ _jsxs("span", {
186
197
  title: reason,
187
198
  children: [
188
- reason && item.id !== 'start' ? /*#__PURE__*/ _jsx("span", {
199
+ reason && reason !== wait && item.id !== 'start' ? /*#__PURE__*/ _jsx("span", {
189
200
  className: "xp-readiness-action-reason",
190
201
  children: reason
191
202
  }) : null,
@@ -195,7 +206,7 @@ export function ReadinessContent({ test, surface, resultsVersion }) {
195
206
  disabled: disabled,
196
207
  onClick: ()=>{
197
208
  if (disabled) return;
198
- if (item.id === 'start' && doc.status === 'draft') void transition.run('start', ()=>createApi(surface.apiRoute).start(doc.id));
209
+ if (item.id === 'start' && doc.status === 'draft') void transition.run('start', ()=>createApi(surface.apiRoute).start(doc.id, doc.phase));
199
210
  else setSelected(item.id);
200
211
  },
201
212
  children: item.label
@@ -1,7 +1,8 @@
1
- import type { TestDocApi } from '../contracts.js';
2
- export declare function saveStatusMessage(test: TestDocApi): string | null;
1
+ import type { ActionTestApi } from '../contracts.js';
2
+ export declare function actionWaitMessage(test: Pick<ActionTestApi, 'stale' | 'hasUnsaved' | 'saving' | 'fieldDrafts'>): string | undefined;
3
+ export declare function saveStatusMessage(test: ActionTestApi): string | null;
3
4
  type Props = {
4
- test: TestDocApi;
5
+ test: ActionTestApi;
5
6
  messageInBlockerList?: boolean;
6
7
  };
7
8
  export declare function ReadinessReadStatus({ test, messageInBlockerList }: Props): import("react").JSX.Element;
@@ -3,15 +3,21 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
3
3
  import { readinessRead } from '../../readinessRead.js';
4
4
  import { useRef, useState } from 'react';
5
5
  import { Button } from '../../../ui/Button.js';
6
- import { READINESS_COPY as C } from '../../copy/readiness.js';
6
+ import { finishEditCopy, READINESS_COPY as C } from '../../copy/readiness.js';
7
+ export function actionWaitMessage(test) {
8
+ if (test.stale) return C.reloadFirst;
9
+ if (test.saving === 'saving') return C.saveFirst;
10
+ const draft = Object.values(test.fieldDrafts ?? {})[0];
11
+ return draft ? finishEditCopy(draft.label) : test.hasUnsaved ? C.finishEdits : undefined;
12
+ }
7
13
  export function saveStatusMessage(test) {
8
- return test.saving === 'saving' ? C.saving : test.saving === 'saved' || test.saving === 'idle' ? C.saved : test.saving === 'error' && !test.stale ? test.errors._section ? C.saveGeneralError : C.saveError : null;
14
+ return test.saving === 'saving' ? C.saving : test.hasUnsaved ? null : test.saving === 'saved' || test.saving === 'idle' ? C.saved : test.saving === 'error' && !test.stale ? test.errors._section ? C.saveGeneralError : C.saveError : null;
9
15
  }
10
16
  export function ReadinessReadStatus({ test, messageInBlockerList = false }) {
11
17
  const inFlight = useRef(false);
12
18
  const [retrying, setRetrying] = useState(false);
13
19
  async function retry() {
14
- if (inFlight.current || test.preflightPending || test.hasUnsaved || test.saving === 'saving') return;
20
+ if (inFlight.current || test.preflightPending) return;
15
21
  inFlight.current = true;
16
22
  setRetrying(true);
17
23
  try {
@@ -30,18 +36,12 @@ export function ReadinessReadStatus({ test, messageInBlockerList = false }) {
30
36
  children: read.message
31
37
  }) : null,
32
38
  ' ',
33
- test.hasUnsaved || test.saving === 'saving' ? /*#__PURE__*/ _jsx("p", {
34
- children: test.stale ? C.reloadFirst : C.saveFirst
35
- }) : null,
36
- read.retry ? /*#__PURE__*/ _jsx("span", {
37
- title: test.stale ? C.reloadFirst : test.hasUnsaved || test.saving === 'saving' ? C.saveFirst : undefined,
38
- children: /*#__PURE__*/ _jsx(Button, {
39
- disabled: retrying || test.preflightPending || test.hasUnsaved || test.saving === 'saving',
40
- onClick: ()=>{
41
- void retry();
42
- },
43
- children: C.retry
44
- })
39
+ read.retry ? /*#__PURE__*/ _jsx(Button, {
40
+ disabled: retrying || test.preflightPending,
41
+ onClick: ()=>{
42
+ void retry();
43
+ },
44
+ children: C.retry
45
45
  }) : null
46
46
  ]
47
47
  }) : null
@@ -4,16 +4,21 @@ import type { TestDocument } from '../testDocument.model.js';
4
4
  import type { SurfaceProps } from '../contracts.js';
5
5
  import { type SectionId } from '../contracts.js';
6
6
  export type ReadinessContext = Pick<TestDocument, 'arms' | 'unitType' | 'flagPoint'> & {
7
+ editorPage?: SurfaceProps['editorPage'];
7
8
  editorPlacementMessage?: string;
8
9
  collectionLabel?: string;
10
+ contentLocales?: PreflightResult['contentLocales'];
11
+ placements?: PreflightResult['placements'];
9
12
  pagePlacements?: PreflightResult['pagePlacements'];
10
13
  flagPoints?: readonly Pick<SerializedFlagPoint, 'id' | 'params'>[];
11
14
  };
15
+ /** Saved content guidance uses the same page refresh as the placement notice. */
16
+ export declare function editorContentNotice(preflight: PreflightResult | null, ctx: ReadinessContext): string | undefined;
12
17
  /** Exhaustive mapping of the checkStart ReadinessCode union, including all ten invariant checks. */
13
18
  export declare const READINESS: Record<ReadinessCode, {
14
19
  section: SectionId | 'header';
15
20
  next(detail: unknown, ctx: ReadinessContext): string | null;
16
- nextStep?: string | ((detail: unknown, ctx: ReadinessContext) => string);
21
+ nextStep?: string | ((detail: unknown, ctx: ReadinessContext) => string | undefined);
17
22
  }>;
18
23
  export declare function blockingSteps(preflight: PreflightResult | null, ctx: ReadinessContext): {
19
24
  arm?: import("../../../types/contracts.js").ArmKey | undefined;
@@ -2,7 +2,8 @@ import { nestedTestCopy } from '../../../puck/nestedTestCopy.js';
2
2
  import { SURFACE_COPY } from '../../copy/surface.js';
3
3
  import { formatDate } from '../../format/date.js';
4
4
  import { actionGroupLabel } from '../../actions/actions.model.js';
5
- import { unpublishedPlacementsCopy, asymmetricGoalsCopy, placementUncheckedCopy, interactingTestsCopy, sameAddressCopy, identicalVersionCopy, unsupportedContentCopy, versionPageUnavailableCopy, versionPageUncheckedCopy, placementFailureCopy, pageInUseCopy, unpublishedPageCopy, READINESS_COPY as C, attributeNext, contentNext, goalPeopleNext, parameterNext, placementNext, ruleNext, versionsNext } from '../../copy/readiness.js';
5
+ import { unpublishedPlacementsCopy, asymmetricGoalsCopy, placementUncheckedCopy, interactingTestsCopy, sameAddressCopy, identicalVersionCopy, unsupportedContentCopy, versionPageUnavailableCopy, versionPageUncheckedCopy, placementFailureCopy, pageInUseCopy, unpublishedPageCopy, READINESS_COPY as C, attributeNext, contentNext, draftContentNext, unsavedContentNext, partialContentNext, summaryContentNext, goalPeopleNext, parameterNext, placementNext, ruleNext, versionsNext } from '../../copy/readiness.js';
6
+ import { PLACEMENT_LANGUAGES, placementLanguageSuffix } from '../../copy/languages.js';
6
7
  import { normalisePath } from '../../../runtime/normalisePath.js';
7
8
  import { testPageCollection } from '../pagePicker/pagePicker.model.js';
8
9
  import { SECTION_ORDER } from '../contracts.js';
@@ -23,6 +24,104 @@ const row = (section, next)=>({
23
24
  next
24
25
  });
25
26
  const versions = row('versions', (detail)=>versionsNext(detailText(detail, C.versionFallback)));
27
+ const samePage = (detail, page)=>detail.collection === page.collection && String(detail.id) === String(page.id);
28
+ const strings = (value)=>Array.isArray(value) ? value.filter((item)=>typeof item === 'string') : [];
29
+ function emptyContentGuidance(detail, ctx) {
30
+ const placements = Array.isArray(detail) ? detail.map(object) : [];
31
+ const versions = ctx.arms.filter((arm)=>arm.kind !== 'holdout' && arm.key !== 'holdout');
32
+ if (!placements.length) {
33
+ const { missing, draftReady } = object(detail);
34
+ const missingKeys = strings(missing);
35
+ const draftKeys = strings(draftReady);
36
+ const affected = versions.filter((arm)=>missingKeys.includes(arm.key));
37
+ const labels = affected.filter((arm)=>!draftKeys.includes(arm.key)).map((arm)=>group(arm.key, ctx));
38
+ const draftLabels = affected.filter((arm)=>draftKeys.includes(arm.key)).map((arm)=>group(arm.key, ctx));
39
+ return [
40
+ {
41
+ sentence: summaryContentNext(labels, draftLabels) || C.summaryMissingVersionContent
42
+ }
43
+ ];
44
+ }
45
+ const localeLabels = ctx.contentLocales?.labels ?? {};
46
+ const labelFor = (code)=>{
47
+ const label = localeLabels[code] ?? code;
48
+ return Object.values(localeLabels).filter((value)=>value === label).length > 1 ? PLACEMENT_LANGUAGES.labelWithCode(label, code) : label;
49
+ };
50
+ const namedPages = placements.some(hasLanguages) || new Set(placements.map((page)=>JSON.stringify([
51
+ page.collection,
52
+ page.id
53
+ ]))).size > 1;
54
+ const guidance = placements.flatMap((page)=>{
55
+ const drafts = ctx.placements?.filter((row)=>row.detail === 'Draft' && samePage(page, row)) ?? [];
56
+ const live = ctx.editorPage && samePage(page, ctx.editorPage) ? ctx.editorPage.versionContent : undefined;
57
+ const localeCodes = strings(page.localeCodes);
58
+ const localized = hasLanguages(page);
59
+ const title = text(page.title, 'the page');
60
+ const suffix = placementLanguageSuffix({
61
+ allLocales: page.allLocales === true,
62
+ locales: strings(page.locales)
63
+ });
64
+ const baseTitle = suffix && title.endsWith(suffix) ? title.slice(0, -suffix.length) : title;
65
+ const published = object(page.slots);
66
+ return versions.flatMap((arm)=>{
67
+ const slot = arm.key;
68
+ if (slot === 'holdout' || Number(published[slot]) > 0) return [];
69
+ const label = group(arm.key, ctx);
70
+ const states = new Map();
71
+ for (const locale of localeCodes.length ? localeCodes : [
72
+ undefined
73
+ ]){
74
+ const matching = drafts.filter((row)=>locale === undefined ? !localized && !hasLanguages(row) : row.localeCodes?.includes(locale));
75
+ const liveState = !localized || locale !== undefined && locale === ctx.contentLocales?.selected ? live?.[slot] : undefined;
76
+ const hasContent = (row)=>(row.slots?.[slot] ?? 0) > 0;
77
+ // Multiple blocks on a page all need content in the matching saved draft.
78
+ const savedFilled = matching.length > 0 && matching.every(hasContent);
79
+ const state = liveState === 'empty' || liveState === 'partial' ? liveState : savedFilled ? 'draft' : liveState === 'filled' ? 'editor' : matching.some((row)=>hasContent(row) || row.partlyFilledSlots?.includes(slot)) ? 'partial' : 'empty';
80
+ const labels = states.get(state) ?? [];
81
+ if (locale !== undefined) labels.push(labelFor(locale));
82
+ states.set(state, labels);
83
+ }
84
+ return [
85
+ ...states
86
+ ].map(([state, labels])=>{
87
+ const pageTitle = labels.length && (states.size > 1 || page.allLocales !== true) ? `${baseTitle}${placementLanguageSuffix({
88
+ locales: labels
89
+ })}` : title;
90
+ if (state === 'draft') return {
91
+ sentence: draftContentNext(label, pageTitle),
92
+ nextStep: C.publishPage
93
+ };
94
+ if (state === 'editor') return {
95
+ sentence: unsavedContentNext(label),
96
+ nextStep: C.saveAndPublishPage
97
+ };
98
+ if (state === 'partial') return {
99
+ sentence: partialContentNext(label, pageTitle)
100
+ };
101
+ return {
102
+ sentence: contentNext(label, namedPages ? pageTitle : undefined)
103
+ };
104
+ });
105
+ });
106
+ });
107
+ if (!guidance.length) return [
108
+ {
109
+ sentence: C.addMissingVersionContent
110
+ }
111
+ ];
112
+ return [
113
+ ...new Map(guidance.map((item)=>[
114
+ item.sentence,
115
+ item
116
+ ])).values()
117
+ ];
118
+ }
119
+ /** Saved content guidance uses the same page refresh as the placement notice. */ export function editorContentNotice(preflight, ctx) {
120
+ const page = ctx.editorPage;
121
+ const detail = preflight?.checks.find((check)=>check.code === 'empty-slot' && !check.ok)?.detail;
122
+ if (!page || !Array.isArray(detail)) return;
123
+ return emptyContentGuidance(detail.filter((row)=>samePage(object(row), page)), ctx).find((item)=>item.nextStep)?.sentence;
124
+ }
26
125
  /** Exhaustive mapping of the checkStart ReadinessCode union, including all ten invariant checks. */ export const READINESS = {
27
126
  'make-content-unsupported': row('header', (detail)=>unsupportedContentCopy(text(detail, 'This page'))),
28
127
  'goal-in-some-versions': {
@@ -38,7 +137,7 @@ const versions = row('versions', (detail)=>versionsNext(detailText(detail, C.ver
38
137
  'placement-removed': row('what', ()=>C.placementRemoved),
39
138
  'placement-unpublished': {
40
139
  ...row('versions', unpublishedPlacementsCopy),
41
- nextStep: 'Publish the page'
140
+ nextStep: C.publishPage
42
141
  },
43
142
  'duplicate-version-row': {
44
143
  ...row('versions', (detail)=>detailRows(detail).map((value)=>`The Experiment block on ${text(object(value).title, 'this page')} has the same version twice. Remove one of them, then save.`).join('\n')),
@@ -49,15 +148,10 @@ const versions = row('versions', (detail)=>versionsNext(detailText(detail, C.ver
49
148
  ...row('versions', (detail)=>interactingTestsCopy(text(first(detail).path, 'this page'), text(first(detail).status, 'running'), text(first(detail).name, 'another test'), first(detail).version === true)),
50
149
  nextStep: (detail)=>`Open ${text(first(detail).name, 'the test')}${first(detail).version === true ? `\nEdit ${text(first(detail).path, 'this page')}` : ''}`
51
150
  },
52
- 'empty-slot': row('versions', (detail, ctx)=>{
53
- const placements = Array.isArray(detail) ? detail : [];
54
- if (placements.some(hasLanguages)) return placements.flatMap((placement)=>ctx.arms.filter((arm)=>arm.kind !== 'holdout' && (!arm.slot || !(Number(object(object(placement).slots)[arm.slot]) > 0))).map((arm)=>contentNext(group(arm.key, ctx), text(object(placement).title, 'the page')))).join('\n');
55
- const missing = ctx.arms.find((item)=>item.kind !== 'holdout' && placements.some((placement)=>{
56
- const slots = object(object(placement).slots);
57
- return !item.slot || !(typeof slots[item.slot] === 'number' && Number(slots[item.slot]) > 0);
58
- }));
59
- return contentNext(group(missing?.key ?? first(detail).arm, ctx));
60
- }),
151
+ 'empty-slot': {
152
+ ...row('versions', (detail, ctx)=>emptyContentGuidance(detail, ctx).map((item)=>item.sentence).join('\n') || null),
153
+ nextStep: (detail, ctx)=>emptyContentGuidance(detail, ctx)[0]?.nextStep
154
+ },
61
155
  'flag-no-point': row('what', ()=>C.noPoint),
62
156
  'flag-params-invalid': row('versions', (detail, ctx)=>{
63
157
  const issue = first(detail);
@@ -212,7 +306,10 @@ function pageArm(path, ctx) {
212
306
  export function pageReadinessContext(doc, preflight, surface) {
213
307
  return {
214
308
  ...doc,
309
+ editorPage: surface.editorPage,
215
310
  editorPlacementMessage: surface.editorPlacementMessage,
311
+ contentLocales: preflight?.contentLocales,
312
+ placements: preflight?.placements,
216
313
  flagPoints: surface.flagPoints,
217
314
  pagePlacements: preflight?.pagePlacements,
218
315
  collectionLabel: testPageCollection(surface.pageCollections, doc, preflight?.pagePlacements)?.label
@@ -1,14 +1,14 @@
1
1
  import type { ApiResult } from '../../api.js';
2
- import type { TestDocApi } from '../contracts.js';
2
+ import type { ActionTestApi } from '../contracts.js';
3
3
  import type { SurfaceProps } from '../contracts.js';
4
4
  import type { ActionId } from '../../actions/actions.model.js';
5
5
  /** The ref closes the gap before React renders the disabled button. */
6
- export declare function useTransition(test: TestDocApi, onSuccess?: () => void, surface?: SurfaceProps): {
6
+ export declare function useTransition(test: ActionTestApi, onSuccess?: () => void, surface?: SurfaceProps): {
7
7
  busy: boolean;
8
8
  checking: boolean;
9
9
  error: string | null;
10
- run: (kind: ActionId | "restart", request: () => Promise<ApiResult<unknown>>, { reloadOnSuccess }?: {
11
- reloadOnSuccess?: boolean | undefined;
10
+ run: (kind: ActionId | "restart", request: () => Promise<ApiResult<unknown>>, { closeOnSuccess }?: {
11
+ closeOnSuccess?: boolean | undefined;
12
12
  }) => Promise<void>;
13
13
  clearError: () => void;
14
14
  };
@@ -47,31 +47,31 @@ import { API_MESSAGES } from '../../copy/common.js';
47
47
  refusal.current = null;
48
48
  setError(null);
49
49
  }
50
- async function run(kind, request, { reloadOnSuccess = true } = {}) {
51
- if (inFlight.current || test.hasUnsaved || test.saving === 'saving') return;
50
+ async function run(kind, request, { closeOnSuccess = true } = {}) {
51
+ if (inFlight.current || test.statusReadPending || (kind === 'start' || kind === 'restart') && (test.hasUnsaved || test.saving === 'saving')) return;
52
52
  clearError();
53
53
  inFlight.current = true;
54
54
  setBusy(true);
55
55
  let refused = false;
56
+ let readDocument = false;
56
57
  try {
57
58
  const result = await request();
58
59
  if (result.ok) {
59
60
  test.acceptTransition?.(result.data);
60
- if (reloadOnSuccess) {
61
- await test.reload();
62
- onSuccess?.();
63
- // Keep the successful action locked until the reloaded document replaces this view.
64
- return;
65
- }
61
+ await test.reload();
62
+ if (closeOnSuccess) onSuccess?.();
63
+ // Keep successful actions latched until the dialog or old status goes away.
64
+ if (closeOnSuccess && kind !== 'allocate') return;
66
65
  } else {
67
66
  refused = true;
67
+ readDocument = result.status === 409 || result.status === 403 || result.status === 401 || result.status === 404 || result.code === 'invalid-status' || result.code === 'stale-draft';
68
68
  setError(result.message);
69
69
  }
70
70
  } catch {
71
71
  refused = true;
72
72
  setError(API_MESSAGES.network);
73
73
  }
74
- setBusy(false);
74
+ if (refused) setBusy(false);
75
75
  try {
76
76
  if (refused) {
77
77
  refusal.current = {
@@ -81,10 +81,12 @@ import { API_MESSAGES } from '../../copy/common.js';
81
81
  answer: latestAnswer.current
82
82
  };
83
83
  setChecking(true);
84
- await test.refreshPreflight(true);
84
+ if (readDocument) await test.reload();
85
+ else await test.refreshPreflight(true);
85
86
  }
86
87
  } finally{
87
88
  inFlight.current = false;
89
+ setBusy(false);
88
90
  setChecking(false);
89
91
  }
90
92
  }
@@ -1,11 +1,13 @@
1
1
  import type { DocId } from '../../../types/contracts.js';
2
2
  import { type PageReleaseDecision } from '../../results/releasePages.model.js';
3
- export declare function ReleasePagesDialog({ id, apiRoute, onClose, onSuccess, onRefusal }: {
3
+ export declare function ReleasePagesDialog({ id, phase, disabled, apiRoute, onClose, onSuccess, onRefusal }: {
4
4
  id: DocId;
5
+ phase?: number;
6
+ disabled?: boolean;
5
7
  apiRoute: string;
6
8
  onClose(): void;
7
9
  onSuccess(): void;
8
- onRefusal(message: string): void;
10
+ onRefusal(message: string, status: number): void;
9
11
  }): import("react").JSX.Element;
10
12
  /** An inaccessible or deleted author never hides the recorded release date. */
11
13
  export declare function PagesReleased({ decision, apiRoute, userId, userCollection: collection }: {