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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (254) hide show
  1. package/README.md +3 -7
  2. package/dist/admin/MetricSourceSelect.js +10 -3
  3. package/dist/admin/armSelect/armSelect.model.d.ts +1 -1
  4. package/dist/admin/blocks/BlockPanel.d.ts +1 -0
  5. package/dist/admin/blocks/BlockPanel.js +75 -29
  6. package/dist/admin/blocks/model.js +5 -4
  7. package/dist/admin/copy/blocks.d.ts +14 -11
  8. package/dist/admin/copy/blocks.js +33 -22
  9. package/dist/admin/copy/goals.d.ts +15 -8
  10. package/dist/admin/copy/goals.js +18 -8
  11. package/dist/admin/copy/newTest.d.ts +10 -7
  12. package/dist/admin/copy/newTest.js +14 -7
  13. package/dist/admin/copy/status.d.ts +1 -1
  14. package/dist/admin/copy/status.js +2 -1
  15. package/dist/admin/pageCollections.d.ts +1 -0
  16. package/dist/admin/pageCollections.js +3 -0
  17. package/dist/admin/placementStatus.model.js +5 -3
  18. package/dist/admin/status.model.d.ts +1 -0
  19. package/dist/admin/status.model.js +2 -1
  20. package/dist/admin/surface/ResultsRoute.js +4 -8
  21. package/dist/admin/surface/SurfaceShell.d.ts +4 -2
  22. package/dist/admin/surface/SurfaceShell.js +28 -3
  23. package/dist/admin/surface/TestRowMenu.d.ts +13 -0
  24. package/dist/admin/surface/TestRowMenu.js +163 -0
  25. package/dist/admin/surface/TestsHome.d.ts +4 -3
  26. package/dist/admin/surface/TestsHome.js +186 -47
  27. package/dist/admin/surface/TestsSurface.js +2 -1
  28. package/dist/admin/surface/goals/DeleteGoalDialog.d.ts +7 -0
  29. package/dist/admin/surface/goals/DeleteGoalDialog.js +42 -0
  30. package/dist/admin/surface/goals/GoalForm.d.ts +1 -0
  31. package/dist/admin/surface/goals/GoalForm.js +280 -198
  32. package/dist/admin/surface/goals/GoalsList.js +102 -33
  33. package/dist/admin/surface/goals/data.d.ts +2 -0
  34. package/dist/admin/surface/goals/data.js +9 -0
  35. package/dist/admin/surface/goals/goals.css +3 -2
  36. package/dist/admin/surface/goals/goals.model.d.ts +2 -2
  37. package/dist/admin/surface/goals/goals.model.js +7 -12
  38. package/dist/admin/surface/home.model.d.ts +15 -8
  39. package/dist/admin/surface/home.model.js +22 -18
  40. package/dist/admin/surface/newTest/NewTest.d.ts +3 -3
  41. package/dist/admin/surface/newTest/NewTest.js +156 -96
  42. package/dist/admin/surface/newTest/PageWizard.d.ts +4 -1
  43. package/dist/admin/surface/newTest/PageWizard.js +93 -68
  44. package/dist/admin/surface/newTest/newTest.css +28 -11
  45. package/dist/admin/surface/results/ResultsHeader.d.ts +1 -1
  46. package/dist/admin/surface/results/ResultsHeader.js +90 -63
  47. package/dist/admin/surface/surface.css +29 -0
  48. package/dist/admin/surface/test/TestPage.js +46 -38
  49. package/dist/admin/surface/useXpStepNav.d.ts +11 -0
  50. package/dist/admin/surface/useXpStepNav.js +14 -0
  51. package/dist/admin/views/TestsSurfaceClient.js +27 -3
  52. package/dist/admin/views/buildSurfaceProps.js +18 -66
  53. package/dist/arms/copy.d.ts +13 -3
  54. package/dist/arms/copy.js +5 -4
  55. package/dist/blocks/createExperimentBlock.js +1 -1
  56. package/dist/blocks/formState.js +1 -1
  57. package/dist/collections/experiments/armInvariants.js +8 -5
  58. package/dist/collections/metrics.js +12 -5
  59. package/dist/collections/serialize.js +3 -2
  60. package/dist/db/pageCopies.d.ts +5 -0
  61. package/dist/db/pageCopies.js +31 -0
  62. package/dist/db/snapshots.d.ts +1 -0
  63. package/dist/endpoints/duplicateOriginal.d.ts +38 -0
  64. package/dist/endpoints/duplicateOriginal.js +414 -0
  65. package/dist/endpoints/editorSurface.js +1 -1
  66. package/dist/endpoints/index.js +20 -0
  67. package/dist/endpoints/pages.js +245 -66
  68. package/dist/endpoints/placementStatus.js +1 -0
  69. package/dist/endpoints/results.js +3 -0
  70. package/dist/endpoints/testVersion.d.ts +2 -0
  71. package/dist/endpoints/testVersion.js +38 -0
  72. package/dist/endpoints/transitions.js +4 -5
  73. package/dist/exports/index.d.ts +1 -1
  74. package/dist/goals/picker/copy.js +1 -1
  75. package/dist/goals/sourceLabel.d.ts +2 -0
  76. package/dist/goals/sourceLabel.js +4 -0
  77. package/dist/hooks/trackPageCopies.d.ts +11 -0
  78. package/dist/hooks/trackPageCopies.js +7 -0
  79. package/dist/labels/arms.d.ts +3 -0
  80. package/dist/labels/arms.js +8 -0
  81. package/dist/options.d.ts +2 -0
  82. package/dist/options.js +18 -2
  83. package/dist/plugin.js +56 -2
  84. package/dist/puck/editor/ConfigureTestDrawer.d.ts +7 -7
  85. package/dist/puck/editor/ConfigureTestDrawer.js +36 -26
  86. package/dist/puck/editor/ExperimentSlotEditor.d.ts +2 -1
  87. package/dist/puck/editor/ExperimentSlotEditor.js +219 -106
  88. package/dist/puck/editor/LeftoverVersions.js +17 -32
  89. package/dist/puck/editor/QuickTestActions.d.ts +2 -2
  90. package/dist/puck/editor/QuickTestActions.js +44 -34
  91. package/dist/puck/editor/ResultsReadout.d.ts +3 -1
  92. package/dist/puck/editor/ResultsReadout.js +28 -16
  93. package/dist/puck/editor/VersionBuilder.d.ts +4 -2
  94. package/dist/puck/editor/VersionBuilder.js +42 -63
  95. package/dist/puck/editor/armWrites.js +1 -1
  96. package/dist/puck/editor/copy.d.ts +10 -6
  97. package/dist/puck/editor/copy.js +22 -12
  98. package/dist/puck/editor/editor.chrome.css +9 -8
  99. package/dist/puck/editor/editor.css +14 -9
  100. package/dist/puck/editor/placementsCache.d.ts +1 -1
  101. package/dist/puck/editor/placementsCache.js +9 -17
  102. package/dist/puck/editor/usePageSaveReadiness.d.ts +1 -4
  103. package/dist/puck/editor/usePageSaveReadiness.js +18 -21
  104. package/dist/puck/editor/usePlacementNotice.d.ts +2 -2
  105. package/dist/puck/editor/usePlacementNotice.js +4 -5
  106. package/dist/puck/nestedTestCopy.js +2 -2
  107. package/dist/puck/slotConfig.d.ts +1 -1
  108. package/dist/puck/slotConfig.js +1 -1
  109. package/dist/results/analyse.d.ts +2 -0
  110. package/dist/results/analyse.js +2 -2
  111. package/dist/results/verdict.d.ts +4 -4
  112. package/dist/results/verdict.js +13 -10
  113. package/dist/server/runResults.js +2 -1
  114. package/dist/testSurface/PreviewLinks.d.ts +2 -1
  115. package/dist/testSurface/PreviewLinks.js +3 -3
  116. package/dist/testSurface/actions/DecideDialog.d.ts +7 -4
  117. package/dist/testSurface/actions/DecideDialog.js +71 -59
  118. package/dist/testSurface/actions/LifecycleAction.d.ts +17 -0
  119. package/dist/testSurface/actions/LifecycleAction.js +107 -0
  120. package/dist/testSurface/actions/MakeContentResult.js +1 -1
  121. package/dist/testSurface/actions/actions.model.d.ts +13 -5
  122. package/dist/testSurface/actions/actions.model.js +75 -22
  123. package/dist/testSurface/actions/decide.model.d.ts +1 -0
  124. package/dist/testSurface/actions/decide.model.js +1 -0
  125. package/dist/testSurface/allocation.model.js +6 -3
  126. package/dist/testSurface/api.d.ts +4 -1
  127. package/dist/testSurface/api.js +22 -14
  128. package/dist/testSurface/copy/actions.d.ts +36 -14
  129. package/dist/testSurface/copy/actions.js +39 -17
  130. package/dist/testSurface/copy/advanced.d.ts +10 -0
  131. package/dist/testSurface/copy/advanced.js +10 -0
  132. package/dist/testSurface/copy/arms.d.ts +1 -1
  133. package/dist/testSurface/copy/arms.js +1 -1
  134. package/dist/testSurface/copy/audience.d.ts +4 -3
  135. package/dist/testSurface/copy/audience.js +5 -4
  136. package/dist/testSurface/copy/common.d.ts +6 -6
  137. package/dist/testSurface/copy/common.js +6 -6
  138. package/dist/testSurface/copy/metrics.d.ts +6 -0
  139. package/dist/testSurface/copy/metrics.js +8 -0
  140. package/dist/testSurface/copy/pages.d.ts +67 -7
  141. package/dist/testSurface/copy/pages.js +74 -7
  142. package/dist/testSurface/copy/readiness.d.ts +8 -6
  143. package/dist/testSurface/copy/readiness.js +19 -10
  144. package/dist/testSurface/copy/recommendation.d.ts +1 -22
  145. package/dist/testSurface/copy/recommendation.js +2 -22
  146. package/dist/testSurface/copy/results.d.ts +16 -10
  147. package/dist/testSurface/copy/results.js +19 -11
  148. package/dist/testSurface/copy/review.d.ts +13 -10
  149. package/dist/testSurface/copy/review.js +14 -10
  150. package/dist/testSurface/copy/setting.d.ts +1 -2
  151. package/dist/testSurface/copy/setting.js +1 -2
  152. package/dist/testSurface/copy/surface.d.ts +11 -2
  153. package/dist/testSurface/copy/surface.js +14 -11
  154. package/dist/testSurface/copy/testPage.d.ts +16 -10
  155. package/dist/testSurface/copy/testPage.js +24 -18
  156. package/dist/testSurface/format/date.d.ts +5 -2
  157. package/dist/testSurface/format/date.js +24 -8
  158. package/dist/testSurface/format/roundProgress.d.ts +6 -0
  159. package/dist/testSurface/format/roundProgress.js +15 -0
  160. package/dist/testSurface/format/useDateFormatter.d.ts +3 -0
  161. package/dist/testSurface/format/useDateFormatter.js +8 -0
  162. package/dist/testSurface/labels.d.ts +1 -2
  163. package/dist/testSurface/labels.js +2 -3
  164. package/dist/testSurface/lockedNotice.model.d.ts +2 -0
  165. package/dist/testSurface/lockedNotice.model.js +31 -0
  166. package/dist/testSurface/readPreflight.d.ts +0 -1
  167. package/dist/testSurface/readPreflight.js +0 -1
  168. package/dist/testSurface/results/CiChart.js +2 -1
  169. package/dist/testSurface/results/DataTable.d.ts +1 -1
  170. package/dist/testSurface/results/DataTable.js +4 -3
  171. package/dist/testSurface/results/VerdictHero.d.ts +1 -1
  172. package/dist/testSurface/results/legacy.d.ts +0 -5
  173. package/dist/testSurface/results/legacy.js +0 -14
  174. package/dist/testSurface/results/results.css +2 -2
  175. package/dist/testSurface/results/results.model.d.ts +8 -3
  176. package/dist/testSurface/results/results.model.js +25 -21
  177. package/dist/testSurface/results/snapshot.d.ts +2 -0
  178. package/dist/testSurface/results/snapshot.js +3 -0
  179. package/dist/testSurface/surface/contracts.d.ts +6 -1
  180. package/dist/testSurface/surface/editorPlacement.d.ts +1 -1
  181. package/dist/testSurface/surface/editorPlacement.js +1 -1
  182. package/dist/testSurface/surface/pageBlock/pageBlock.model.js +1 -1
  183. package/dist/testSurface/surface/pageBlock/parts.js +25 -12
  184. package/dist/testSurface/surface/pagePicker/CopyRoute.d.ts +8 -1
  185. package/dist/testSurface/surface/pagePicker/CopyRoute.js +243 -22
  186. package/dist/testSurface/surface/pagePicker/PageCombobox.d.ts +15 -4
  187. package/dist/testSurface/surface/pagePicker/PageCombobox.js +298 -209
  188. package/dist/testSurface/surface/pagePicker/pagePicker.css +73 -10
  189. package/dist/testSurface/surface/pagePicker/pagePicker.model.d.ts +5 -3
  190. package/dist/testSurface/surface/pagePicker/pagePicker.model.js +17 -2
  191. package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +5 -3
  192. package/dist/testSurface/surface/readiness/ActionDialogs.js +213 -207
  193. package/dist/testSurface/surface/readiness/Banner.d.ts +5 -1
  194. package/dist/testSurface/surface/readiness/Banner.js +109 -148
  195. package/dist/testSurface/surface/readiness/SaveStatus.d.ts +5 -2
  196. package/dist/testSurface/surface/readiness/SaveStatus.js +8 -7
  197. package/dist/testSurface/surface/readiness/readiness.model.d.ts +14 -5
  198. package/dist/testSurface/surface/readiness/readiness.model.js +62 -12
  199. package/dist/testSurface/surface/readiness/useTransition.d.ts +3 -1
  200. package/dist/testSurface/surface/readiness/useTransition.js +49 -8
  201. package/dist/testSurface/surface/results/ReleasePages.d.ts +4 -3
  202. package/dist/testSurface/surface/results/ReleasePages.js +41 -41
  203. package/dist/testSurface/surface/results/ResultsBody.d.ts +7 -2
  204. package/dist/testSurface/surface/results/ResultsBody.js +170 -110
  205. package/dist/testSurface/surface/results/recommendation.model.d.ts +6 -9
  206. package/dist/testSurface/surface/results/recommendation.model.js +15 -59
  207. package/dist/testSurface/surface/results/useResults.d.ts +6 -2
  208. package/dist/testSurface/surface/setting/parts.js +31 -28
  209. package/dist/testSurface/surface/setting/setting.css +2 -1
  210. package/dist/testSurface/surface/test/AdvancedSection.js +10 -4
  211. package/dist/testSurface/surface/test/DeleteTest.d.ts +5 -1
  212. package/dist/testSurface/surface/test/DeleteTest.js +63 -55
  213. package/dist/testSurface/surface/test/GoalSection.js +11 -11
  214. package/dist/testSurface/surface/test/LengthSection.js +21 -13
  215. package/dist/testSurface/surface/test/PageHoldout.d.ts +1 -1
  216. package/dist/testSurface/surface/test/PageHoldout.js +7 -7
  217. package/dist/testSurface/surface/test/ReadinessBar.d.ts +2 -1
  218. package/dist/testSurface/surface/test/ReadinessBar.js +4 -10
  219. package/dist/testSurface/surface/test/Section.js +8 -0
  220. package/dist/testSurface/surface/test/TargetingSection.js +7 -2
  221. package/dist/testSurface/surface/test/TestSurface.js +17 -43
  222. package/dist/testSurface/surface/test/VersionsSection.js +93 -70
  223. package/dist/testSurface/surface/test/fields.d.ts +4 -3
  224. package/dist/testSurface/surface/test/fields.js +10 -16
  225. package/dist/testSurface/surface/test/pageParts.js +13 -7
  226. package/dist/testSurface/surface/test/testPage.css +9 -2
  227. package/dist/testSurface/surface/useTestDocument.d.ts +1 -3
  228. package/dist/testSurface/surface/useTestDocument.js +110 -52
  229. package/dist/testSurface/surface/watchTestDocument.d.ts +15 -0
  230. package/dist/testSurface/surface/watchTestDocument.js +181 -0
  231. package/dist/testSurface/surfaceUrls.d.ts +1 -0
  232. package/dist/testSurface/surfaceUrls.js +4 -0
  233. package/dist/testSurface/useApi.d.ts +3 -0
  234. package/dist/transitions/addMetric.d.ts +1 -1
  235. package/dist/transitions/addMetric.js +5 -1
  236. package/dist/transitions/kernel.d.ts +2 -0
  237. package/dist/transitions/kernel.js +1 -1
  238. package/dist/transitions/pageAddress.d.ts +6 -0
  239. package/dist/transitions/pageAddress.js +71 -0
  240. package/dist/transitions/pageVersions.d.ts +1 -1
  241. package/dist/transitions/preflightData.js +10 -2
  242. package/dist/transitions/start.d.ts +1 -1
  243. package/dist/transitions/start.js +8 -5
  244. package/dist/types/armKey.d.ts +2 -0
  245. package/dist/types/armKey.js +1 -0
  246. package/dist/types/contracts.d.ts +11 -1
  247. package/dist/types/endpoints.d.ts +38 -9
  248. package/dist/types/endpoints.js +1 -1
  249. package/dist/types/surface.d.ts +7 -9
  250. package/dist/ui/Dialog.d.ts +21 -2
  251. package/dist/ui/Dialog.js +101 -4
  252. package/dist/ui/Inputs.js +0 -1
  253. package/dist/ui/ui.css +5 -1
  254. package/package.json +2 -2
@@ -4,34 +4,48 @@ import { canStartTest, readyToStart } from '../../readinessRead.js';
4
4
  import { DocsResponseError, fetchAllDocs } from '../../../lib/fetchAllDocs.js';
5
5
  import { usePlacementLabels, placementDetailKey } from '../../placements/usePlacementLabels.js';
6
6
  import { placementUncheckedCopy } from '../../copy/readiness.js';
7
- import { useEffect, useState } from 'react';
8
- import { Button } from '../../../ui/Button.js';
7
+ import { useEffect, useId, useState } from 'react';
9
8
  import { TextInput, Select } from '../../../ui/Inputs.js';
10
- import { Dialog } from '../../../ui/Dialog.js';
9
+ import { ConfirmDialog } from '../../../ui/Dialog.js';
10
+ import { isDestructiveAction } from '../../actions/actions.model.js';
11
11
  import { MakeContentResult } from '../../actions/MakeContentResult.js';
12
12
  import { expectedConfirm, matchesConfirm } from '../../../transitions/confirmPhrases.js';
13
- import { ACTIONS_COPY as A, addMetricWarningCopy } from '../../copy/actions.js';
13
+ import { ACTIONS_COPY as A, actionTitle, addMetricWarningCopy } from '../../copy/actions.js';
14
14
  import { REVIEW_COPY as R } from '../../copy/review.js';
15
15
  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
- import { blockingSteps, pageReadinessContext } from './readiness.model.js';
18
+ import { blockingSteps, pageReadinessContext, readinessCaveats } from './readiness.model.js';
19
19
  import { actionWaitMessage } from './SaveStatus.js';
20
+ import { surfaceUrls } from '../../surfaceUrls.js';
21
+ import { Button } from '../../../ui/Button.js';
20
22
  import { useTransition } from './useTransition.js';
21
- /** Prop-driven ConfirmDialog adapter: same model/copy, section reload instead of a page reload. */ export function ConfirmAction({ test, surface, action, winnerLabel, onClose }) {
23
+ export function dialogTitle(label, test) {
24
+ return test.doc?.name ? actionTitle(label, test.doc.name) : label;
25
+ }
26
+ /** Prop-driven ConfirmDialog adapter: same model/copy, section reload instead of a page reload. */ export function ConfirmAction({ test, surface, action, winnerLabel, onClose, onSuccess }) {
22
27
  const api = createApi(surface.apiRoute);
23
28
  const [openedPhase] = useState(test.doc?.phase);
29
+ const [openedStatus] = useState(test.doc?.status);
30
+ const confirmationId = useId();
24
31
  const [typed, setTyped] = useState('');
25
32
  const [content, setContent] = useState(null);
26
33
  const [reportBusy, setReportBusy] = useState(false);
27
- const transition = useTransition(test, onClose, surface);
34
+ const transition = useTransition(test, ()=>{
35
+ onClose();
36
+ onSuccess?.();
37
+ }, surface, true);
38
+ const changed = test.doc?.phase !== openedPhase || test.doc?.status !== openedStatus;
28
39
  const wait = action.id === 'start' ? actionWaitMessage(test) : undefined;
29
40
  const phrase = action.confirm.phrase ? expectedConfirm(action.confirm.phrase.action, winnerLabel) : null;
30
41
  const ready = action.id !== 'start' || !transition.checking && canStartTest(test, surface.editorPlacementMessage);
31
- const enabled = ready && !test.statusReadPending && !transition.busy && !wait && (!phrase || matchesConfirm(phrase, typed));
42
+ const blocker = action.id === 'start' && !readyToStart(test, surface.editorPlacementMessage) ? test.preflightError ?? (test.doc ? blockingSteps(test.preflight, pageReadinessContext(test.doc, test.preflight, surface))[0]?.sentence : undefined) ?? C.checking : undefined;
43
+ const startMessage = wait ?? blocker;
44
+ const enabled = surface.canManage && !changed && ready && !test.statusReadPending && !transition.busy && !transition.reloadRequired && !wait && (!phrase || matchesConfirm(phrase, typed));
32
45
  async function submit(finish = false) {
33
46
  if (!enabled || !test.doc) return;
34
- const { id, phase } = test.doc;
47
+ const { id } = test.doc;
48
+ const phase = openedPhase;
35
49
  await transition.run(finish ? 'archive' : action.id === 'start' && test.doc.status === 'stopped' ? 'restart' : action.id, async ()=>{
36
50
  if (finish) return api.archive(id, {
37
51
  mode: 'after-content',
@@ -53,6 +67,7 @@ import { useTransition } from './useTransition.js';
53
67
  return result;
54
68
  }
55
69
  if (result.ok) {
70
+ test.acceptTransition?.(undefined);
56
71
  await test.reload();
57
72
  return {
58
73
  ok: false,
@@ -69,13 +84,39 @@ import { useTransition } from './useTransition.js';
69
84
  function close() {
70
85
  if (transition.busy || reportBusy) return;
71
86
  onClose();
87
+ transition.refreshAfterDismissal();
72
88
  }
73
- return /*#__PURE__*/ _jsxs(Dialog, {
74
- open: true,
75
- initialFocus: action.id === 'start' ? undefined : 'cancel',
76
- dismissible: !transition.busy && !reportBusy,
77
- title: action.confirm.title,
89
+ const label = action.confirm.label ?? action.label;
90
+ const caveats = action.id === 'start' ? readinessCaveats(test, surface.adminRoute) : [];
91
+ const description = caveats.length ? /*#__PURE__*/ _jsxs(_Fragment, {
92
+ children: [
93
+ /*#__PURE__*/ _jsx("p", {
94
+ children: action.confirm.body
95
+ }),
96
+ /*#__PURE__*/ _jsx("ul", {
97
+ children: caveats.map(({ key, sentence, href })=>/*#__PURE__*/ _jsx("li", {
98
+ children: href && !transition.busy ? /*#__PURE__*/ _jsx("a", {
99
+ href: href,
100
+ children: sentence
101
+ }) : sentence
102
+ }, key))
103
+ })
104
+ ]
105
+ }) : action.confirm.body;
106
+ return /*#__PURE__*/ _jsxs(ConfirmDialog, {
107
+ title: action.confirm.title === label ? dialogTitle(label, test) : action.confirm.title,
78
108
  onClose: close,
109
+ description: content ? undefined : description,
110
+ busy: transition.busy || reportBusy,
111
+ busyLabel: C.changing,
112
+ cancelLabel: content ? A.done : A.cancel,
113
+ error: transition.error ?? (changed && !transition.busy && !content ? A.actionChanged : null),
114
+ confirm: content ? undefined : {
115
+ label,
116
+ disabled: !enabled,
117
+ destructive: isDestructiveAction(action.id),
118
+ onClick: ()=>submit()
119
+ },
79
120
  children: [
80
121
  content ? /*#__PURE__*/ _jsx(MakeContentResult, {
81
122
  result: content,
@@ -92,60 +133,31 @@ import { useTransition } from './useTransition.js';
92
133
  if (result.ok) test.acceptTransition?.(result.data);
93
134
  await test.reload();
94
135
  }
95
- }) : /*#__PURE__*/ _jsxs(_Fragment, {
96
- children: [
97
- /*#__PURE__*/ _jsx("p", {
98
- children: action.confirm.body
99
- }),
100
- phrase ? /*#__PURE__*/ _jsxs(_Fragment, {
101
- children: [
102
- /*#__PURE__*/ _jsxs("p", {
103
- children: [
104
- A.typePhrase,
105
- " ",
106
- /*#__PURE__*/ _jsx("strong", {
107
- children: phrase
108
- })
109
- ]
110
- }),
111
- /*#__PURE__*/ _jsx(TextInput, {
112
- id: "xp-confirmation",
113
- label: A.confirmation,
114
- value: typed,
115
- readOnly: transition.busy,
116
- onChange: (event)=>setTyped(event.target.value)
117
- })
118
- ]
119
- }) : null
120
- ]
136
+ }) : /*#__PURE__*/ _jsx(_Fragment, {
137
+ children: phrase ? /*#__PURE__*/ _jsxs(_Fragment, {
138
+ children: [
139
+ /*#__PURE__*/ _jsxs("p", {
140
+ children: [
141
+ A.typePhrase,
142
+ " ",
143
+ /*#__PURE__*/ _jsx("strong", {
144
+ children: phrase
145
+ })
146
+ ]
147
+ }),
148
+ /*#__PURE__*/ _jsx(TextInput, {
149
+ id: confirmationId,
150
+ label: A.confirmation,
151
+ value: typed,
152
+ readOnly: transition.busy,
153
+ onChange: (event)=>setTyped(event.target.value)
154
+ })
155
+ ]
156
+ }) : null
121
157
  }),
122
- transition.busy ? /*#__PURE__*/ _jsx("p", {
123
- role: "status",
124
- children: C.changing
125
- }) : null,
126
- transition.error ? /*#__PURE__*/ _jsx("p", {
127
- role: "alert",
128
- children: transition.error
129
- }) : null,
130
- !content && wait ? /*#__PURE__*/ _jsx("p", {
131
- children: wait
132
- }) : !content && action.id === 'start' && !readyToStart(test, surface.editorPlacementMessage) ? /*#__PURE__*/ _jsx("p", {
133
- children: test.preflightError ? test.preflightError : test.doc ? blockingSteps(test.preflight, pageReadinessContext(test.doc, test.preflight, surface))[0]?.sentence ?? C.checking : C.checking
134
- }) : null,
135
- !content ? /*#__PURE__*/ _jsx(Button, {
136
- busy: transition.busy,
137
- disabled: !enabled,
138
- onClick: ()=>{
139
- void submit();
140
- },
141
- children: action.label
142
- }) : null,
143
- /*#__PURE__*/ _jsx(Button, {
144
- "data-dialog-cancel": true,
145
- disabled: transition.busy || reportBusy,
146
- onClick: close,
147
- children: content ? A.done : A.cancel
148
- })
158
+ !content && startMessage && startMessage !== transition.error ? /*#__PURE__*/ _jsx("p", {
159
+ children: startMessage
160
+ }) : null
149
161
  ]
150
162
  });
151
163
  }
@@ -153,21 +165,35 @@ import { useTransition } from './useTransition.js';
153
165
  const current = test.doc?.allocation ?? 100;
154
166
  const [openedPhase] = useState(test.doc?.phase);
155
167
  const [value, setValue] = useState(String(Math.min(100, current + 1)));
156
- const transition = useTransition(test, onClose, surface);
168
+ const transition = useTransition(test, onClose, surface, true);
157
169
  const allocation = Number(value);
158
170
  const valid = value.trim() !== '' && Number.isInteger(allocation) && allocation > current && allocation <= 100;
159
- const disabled = transition.busy || test.statusReadPending;
160
- return /*#__PURE__*/ _jsxs(Dialog, {
161
- open: true,
162
- dismissible: !transition.busy,
163
- title: C.allocate,
171
+ const changed = test.doc?.status !== 'running' || test.doc?.phase !== openedPhase;
172
+ const disabled = transition.busy || test.statusReadPending || changed || transition.reloadRequired;
173
+ return /*#__PURE__*/ _jsxs(ConfirmDialog, {
174
+ title: dialogTitle(A.titleLead.allocate, test),
175
+ description: R.allocationBody,
164
176
  onClose: ()=>{
165
- if (!transition.busy) onClose();
177
+ onClose();
178
+ transition.refreshAfterDismissal();
179
+ },
180
+ busy: transition.busy,
181
+ busyLabel: C.changing,
182
+ cancelLabel: A.cancel,
183
+ error: transition.error ?? (changed && !transition.busy ? A.actionChanged : null),
184
+ confirm: {
185
+ label: C.allocate,
186
+ disabled: disabled || !valid,
187
+ onClick: ()=>{
188
+ if (valid && test.doc) return transition.run('allocate', ()=>createApi(surface.apiRoute).allocate(test.doc.id, {
189
+ allocation,
190
+ phase: openedPhase
191
+ }, {
192
+ notFound: API_MESSAGES.roundChanged
193
+ }));
194
+ }
166
195
  },
167
196
  children: [
168
- /*#__PURE__*/ _jsx("p", {
169
- children: R.allocationBody
170
- }),
171
197
  /*#__PURE__*/ _jsxs("label", {
172
198
  children: [
173
199
  C.participation,
@@ -184,38 +210,12 @@ import { useTransition } from './useTransition.js';
184
210
  }),
185
211
  !valid ? /*#__PURE__*/ _jsx("p", {
186
212
  children: R.allocationInvalid
187
- }) : null,
188
- transition.busy ? /*#__PURE__*/ _jsx("p", {
189
- role: "status",
190
- children: C.changing
191
- }) : null,
192
- transition.error ? /*#__PURE__*/ _jsx("p", {
193
- role: "alert",
194
- children: transition.error
195
- }) : null,
196
- /*#__PURE__*/ _jsx(Button, {
197
- busy: transition.busy,
198
- disabled: disabled || !valid,
199
- onClick: ()=>{
200
- // Not-found can also mean the experiment is missing; use round copy for the missing phase record.
201
- if (valid && test.doc) void transition.run('allocate', ()=>createApi(surface.apiRoute).allocate(test.doc.id, {
202
- allocation,
203
- phase: openedPhase
204
- }, {
205
- notFound: API_MESSAGES.roundChanged
206
- }));
207
- },
208
- children: C.allocate
209
- }),
210
- /*#__PURE__*/ _jsx(Button, {
211
- disabled: transition.busy,
212
- onClick: onClose,
213
- children: A.cancel
214
- })
213
+ }) : null
215
214
  ]
216
215
  });
217
216
  }
218
- /** AddMetricDialog adapter; the primary goal is deliberately absent from the role picker. */ export function AddMetricAction({ test, surface, onClose }) {
217
+ /** AddMetricDialog adapter; the current round’s main goal is fixed. */ export function AddMetricAction({ test, surface, onClose }) {
218
+ const [openedPhase] = useState(test.doc?.phase);
219
219
  const [metrics, setMetrics] = useState([]);
220
220
  const [loading, setLoading] = useState(true);
221
221
  const [loadError, setLoadError] = useState(null);
@@ -227,7 +227,7 @@ import { useTransition } from './useTransition.js';
227
227
  ...surface
228
228
  });
229
229
  const [role, setRole] = useState('secondary');
230
- const transition = useTransition(test, onClose, surface);
230
+ const transition = useTransition(test, onClose, surface, true);
231
231
  useEffect(()=>{
232
232
  const controller = new AbortController();
233
233
  void (async ()=>{
@@ -254,113 +254,119 @@ import { useTransition } from './useTransition.js';
254
254
  ...test.doc?.metrics?.guardrails ?? []
255
255
  ].filter((id)=>id != null).map(String));
256
256
  const available = metrics.filter((item)=>!attached.has(String(item.id)));
257
+ const empty = !loading && !loadError && !available.length;
257
258
  const selected = available.find((item)=>String(item.id) === metric);
258
- const disabled = transition.busy || test.statusReadPending;
259
+ const changed = test.doc?.status !== 'running' || test.doc?.phase !== openedPhase;
260
+ const disabled = transition.busy || test.statusReadPending || changed || transition.reloadRequired && transition.error !== API_MESSAGES.goalNotFound;
259
261
  function close() {
260
262
  if (transition.busy) return;
261
263
  onClose();
264
+ transition.refreshAfterDismissal();
262
265
  }
263
- return /*#__PURE__*/ _jsxs(Dialog, {
264
- open: true,
265
- dismissible: !transition.busy,
266
+ return /*#__PURE__*/ _jsx(ConfirmDialog, {
266
267
  title: C.addGoal,
268
+ description: warnings || empty ? undefined : C.addMetric,
267
269
  onClose: close,
268
- children: [
269
- warnings ? warnings.map((warning, index)=>{
270
- const placement = warning.code === 'placement-unchecked' ? placementLabels.get(placementDetailKey(warning.detail)) : undefined;
271
- return /*#__PURE__*/ _jsx("p", {
272
- children: placement ? placement.href ? /*#__PURE__*/ _jsx("a", {
273
- href: placement.href,
274
- children: placementUncheckedCopy(placement.title)
275
- }) : placementUncheckedCopy(placement.title) : addMetricWarningCopy(warning)
276
- }, index);
277
- }) : /*#__PURE__*/ _jsxs(_Fragment, {
278
- children: [
279
- /*#__PURE__*/ _jsx("p", {
280
- children: C.addMetric
281
- }),
282
- loading ? /*#__PURE__*/ _jsx("p", {
283
- role: "status",
284
- children: R.loadingMetrics
285
- }) : null,
286
- /*#__PURE__*/ _jsxs(Select, {
287
- id: "xp-add-goal-role",
288
- label: R.role,
289
- value: role,
290
- disabled: disabled,
291
- onChange: (event)=>setRole(event.target.value),
292
- children: [
293
- /*#__PURE__*/ _jsx("option", {
294
- value: "secondary",
295
- children: R.supporting
296
- }),
297
- /*#__PURE__*/ _jsx("option", {
298
- value: "guardrail",
299
- children: R.guardrail
300
- })
301
- ]
302
- }),
303
- /*#__PURE__*/ _jsxs(Select, {
304
- id: "xp-add-goal-metric",
305
- label: R.metric,
306
- value: metric,
307
- disabled: disabled || loading,
308
- onChange: (event)=>setMetric(event.target.value),
309
- children: [
310
- /*#__PURE__*/ _jsx("option", {
311
- value: "",
312
- children: R.chooseMetric
270
+ busy: transition.busy,
271
+ busyLabel: C.changing,
272
+ cancelLabel: warnings ? A.done : A.cancel,
273
+ error: warnings ? undefined : loadError ?? transition.error ?? (changed ? A.actionChanged : null),
274
+ confirm: warnings || empty ? undefined : {
275
+ label: C.addGoal,
276
+ disabled: disabled || loading || !!loadError || !selected,
277
+ onClick: ()=>{
278
+ // Goal and phase lookups share not-found; prefer the more likely missing goal without reading server text.
279
+ if (selected && test.doc) return transition.run('add-metric', async ()=>{
280
+ const result = await createApi(surface.apiRoute).addMetric(test.doc.id, {
281
+ metric: selected.id,
282
+ role,
283
+ phase: openedPhase
284
+ }, {
285
+ notFound: API_MESSAGES.goalNotFound
286
+ });
287
+ if (result.ok) {
288
+ if (result.data?.warnings?.length) setWarnings(result.data.warnings);
289
+ else onClose();
290
+ }
291
+ return result;
292
+ }, {
293
+ closeOnSuccess: false
294
+ });
295
+ }
296
+ },
297
+ children: warnings ? warnings.map((warning, index)=>{
298
+ const placement = warning.code === 'placement-unchecked' ? placementLabels.get(placementDetailKey(warning.detail)) : undefined;
299
+ return /*#__PURE__*/ _jsx("p", {
300
+ children: placement ? placement.href ? /*#__PURE__*/ _jsx("a", {
301
+ href: placement.href,
302
+ children: placementUncheckedCopy(placement.title)
303
+ }) : placementUncheckedCopy(placement.title) : addMetricWarningCopy(warning)
304
+ }, index);
305
+ }) : /*#__PURE__*/ _jsxs(_Fragment, {
306
+ children: [
307
+ loading ? /*#__PURE__*/ _jsx("p", {
308
+ role: "status",
309
+ children: R.loadingMetrics
310
+ }) : null,
311
+ empty ? /*#__PURE__*/ _jsxs(_Fragment, {
312
+ children: [
313
+ /*#__PURE__*/ _jsx("p", {
314
+ children: metrics.length ? R.allMetricsAttached : R.noMetrics
315
+ }),
316
+ /*#__PURE__*/ _jsx(Button, {
317
+ href: surfaceUrls.newGoal(surface.adminRoute, {
318
+ return: test.doc ? String(test.doc.id) : undefined
313
319
  }),
314
- available.map((item)=>/*#__PURE__*/ _jsx("option", {
315
- value: String(item.id),
316
- children: item.name
317
- }, item.id))
318
- ]
319
- }),
320
- !loading && !loadError && !available.length ? /*#__PURE__*/ _jsx("p", {
321
- children: R.noMetrics
322
- }) : null,
323
- transition.busy ? /*#__PURE__*/ _jsx("p", {
324
- role: "status",
325
- children: C.changing
326
- }) : null,
327
- loadError || transition.error ? /*#__PURE__*/ _jsx("p", {
328
- role: "alert",
329
- children: loadError ?? transition.error
330
- }) : null,
331
- !loading && !loadError && available.length > 0 && !selected ? /*#__PURE__*/ _jsx("p", {
332
- children: C.chooseGoalToAdd
333
- }) : null,
334
- /*#__PURE__*/ _jsx(Button, {
335
- busy: transition.busy,
336
- disabled: disabled || loading || !!loadError || !selected,
337
- onClick: ()=>{
338
- // Goal and phase lookups share not-found; prefer the more likely missing goal without reading server text.
339
- if (selected && test.doc) void transition.run('add-metric', async ()=>{
340
- const result = await createApi(surface.apiRoute).addMetric(test.doc.id, {
341
- metric: selected.id,
342
- role
343
- }, {
344
- notFound: API_MESSAGES.goalNotFound
345
- });
346
- if (result.ok) {
347
- if (result.data?.warnings?.length) setWarnings(result.data.warnings);
348
- else onClose();
349
- }
350
- return result;
351
- }, {
352
- closeOnSuccess: false
353
- });
354
- },
355
- children: C.addGoal
356
- })
357
- ]
358
- }),
359
- /*#__PURE__*/ _jsx(Button, {
360
- disabled: transition.busy,
361
- onClick: close,
362
- children: warnings ? A.done : A.cancel
363
- })
364
- ]
320
+ children: R.createGoal
321
+ })
322
+ ]
323
+ }) : /*#__PURE__*/ _jsxs(_Fragment, {
324
+ children: [
325
+ /*#__PURE__*/ _jsxs(Select, {
326
+ id: "xp-add-goal-metric",
327
+ label: R.metric,
328
+ value: metric,
329
+ disabled: disabled || loading,
330
+ onChange: (event)=>setMetric(event.target.value),
331
+ children: [
332
+ /*#__PURE__*/ _jsx("option", {
333
+ value: "",
334
+ children: R.chooseMetric
335
+ }),
336
+ available.map((item)=>/*#__PURE__*/ _jsx("option", {
337
+ value: String(item.id),
338
+ children: item.name
339
+ }, item.id))
340
+ ]
341
+ }),
342
+ /*#__PURE__*/ _jsxs(Select, {
343
+ id: "xp-add-goal-role",
344
+ label: R.role,
345
+ value: role,
346
+ disabled: disabled,
347
+ onChange: (event)=>setRole(event.target.value),
348
+ children: [
349
+ /*#__PURE__*/ _jsx("option", {
350
+ value: "primary",
351
+ disabled: true,
352
+ children: R.primary
353
+ }),
354
+ /*#__PURE__*/ _jsx("option", {
355
+ value: "secondary",
356
+ children: R.supporting
357
+ }),
358
+ /*#__PURE__*/ _jsx("option", {
359
+ value: "guardrail",
360
+ children: R.guardrail
361
+ })
362
+ ]
363
+ })
364
+ ]
365
+ }),
366
+ !loading && !loadError && available.length > 0 && !selected ? /*#__PURE__*/ _jsx("p", {
367
+ children: C.chooseGoalToAdd
368
+ }) : null
369
+ ]
370
+ })
365
371
  });
366
372
  }
@@ -1,2 +1,6 @@
1
+ import { type Ref } from 'react';
1
2
  import type { SectionProps } from '../contracts.js';
2
- export declare function ReadinessContent({ test, surface, resultsVersion }: SectionProps): import("react").JSX.Element;
3
+ export declare function ReadinessContent({ test, surface, resultsVersion, embedded, barRef }: SectionProps & {
4
+ embedded?: boolean;
5
+ barRef?: Ref<HTMLDivElement>;
6
+ }): import("react").JSX.Element;