@delmaredigital/payload-experiments 0.4.0-rc.4 → 0.4.0-rc.6

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 (123) hide show
  1. package/dist/admin/copy/newTest.d.ts +1 -1
  2. package/dist/admin/copy/newTest.js +1 -1
  3. package/dist/admin/surface/ResultsRoute.js +2 -10
  4. package/dist/admin/surface/newTest/NewTest.js +16 -18
  5. package/dist/admin/surface/newTest/PageWizard.js +10 -12
  6. package/dist/admin/surface/newTest/newTest.css +3 -1
  7. package/dist/admin/surface/results/ResultsHeader.js +15 -8
  8. package/dist/blocks/bindings.js +6 -13
  9. package/dist/blocks/placementLocale.d.ts +2 -0
  10. package/dist/blocks/placementLocale.js +16 -12
  11. package/dist/goals/fairness.d.ts +1 -1
  12. package/dist/goals/fairness.js +9 -7
  13. package/dist/hooks/blockRemovalRule.d.ts +2 -1
  14. package/dist/hooks/blockRemovalRule.js +27 -5
  15. package/dist/hooks/pageGuard.js +2 -2
  16. package/dist/puck/ExperimentPicker.d.ts +2 -1
  17. package/dist/puck/ExperimentPicker.js +34 -30
  18. package/dist/puck/ExperimentSlot.js +3 -1
  19. package/dist/puck/copy.d.ts +1 -0
  20. package/dist/puck/copy.js +1 -0
  21. package/dist/puck/editor/ConfigureTestDrawer.js +2 -2
  22. package/dist/puck/editor/CreateExperimentDrawer.d.ts +2 -1
  23. package/dist/puck/editor/CreateExperimentDrawer.js +24 -16
  24. package/dist/puck/editor/EditorControls.d.ts +1 -1
  25. package/dist/puck/editor/EditorControls.js +1 -1
  26. package/dist/puck/editor/ExperimentSlotEditor.js +624 -299
  27. package/dist/puck/editor/LeftoverVersions.d.ts +15 -0
  28. package/dist/puck/editor/LeftoverVersions.js +97 -0
  29. package/dist/puck/editor/PlacementNotice.d.ts +8 -0
  30. package/dist/puck/editor/PlacementNotice.js +22 -0
  31. package/dist/puck/editor/QuickTestActions.d.ts +3 -0
  32. package/dist/puck/editor/QuickTestActions.js +50 -0
  33. package/dist/puck/editor/ResultsReadout.js +5 -0
  34. package/dist/puck/editor/VersionBuilder.d.ts +37 -12
  35. package/dist/puck/editor/VersionBuilder.js +273 -184
  36. package/dist/puck/editor/armWrites.d.ts +11 -2
  37. package/dist/puck/editor/armWrites.js +42 -3
  38. package/dist/puck/editor/armsCache.d.ts +1 -1
  39. package/dist/puck/editor/armsCache.js +2 -1
  40. package/dist/puck/editor/cloneSlot.d.ts +2 -0
  41. package/dist/puck/editor/cloneSlot.js +7 -0
  42. package/dist/puck/editor/copy.d.ts +35 -20
  43. package/dist/puck/editor/copy.js +35 -20
  44. package/dist/puck/editor/createTest.d.ts +3 -0
  45. package/dist/puck/editor/createTest.js +33 -0
  46. package/dist/puck/editor/editor.chrome.css +32 -14
  47. package/dist/puck/editor/editor.css +58 -17
  48. package/dist/puck/editor/editor.model.d.ts +1 -1
  49. package/dist/puck/editor/editor.model.js +2 -2
  50. package/dist/puck/editor/experimentOutlinePlugin.js +96 -28
  51. package/dist/puck/editor/localPlacements.d.ts +4 -2
  52. package/dist/puck/editor/localPlacements.js +20 -18
  53. package/dist/puck/editor/outlineVersion.d.ts +5 -0
  54. package/dist/puck/editor/outlineVersion.js +36 -0
  55. package/dist/puck/editor/placementsCache.d.ts +33 -2
  56. package/dist/puck/editor/placementsCache.js +208 -33
  57. package/dist/puck/editor/sidebar.d.ts +8 -0
  58. package/dist/puck/editor/sidebar.js +74 -0
  59. package/dist/puck/editor/usePlacementNotice.d.ts +3 -0
  60. package/dist/puck/editor/usePlacementNotice.js +14 -0
  61. package/dist/puck/visibility.d.ts +21 -0
  62. package/dist/puck/visibility.js +77 -0
  63. package/dist/server/recordContentChange.js +3 -1
  64. package/dist/server/resolveExperimentData.js +4 -1
  65. package/dist/testSurface/api.js +1 -1
  66. package/dist/testSurface/copy/common.d.ts +1 -1
  67. package/dist/testSurface/copy/common.js +3 -1
  68. package/dist/testSurface/copy/readiness.d.ts +18 -1
  69. package/dist/testSurface/copy/readiness.js +23 -1
  70. package/dist/testSurface/copy/testPage.d.ts +8 -6
  71. package/dist/testSurface/copy/testPage.js +8 -6
  72. package/dist/testSurface/readPreflight.d.ts +9 -0
  73. package/dist/testSurface/readPreflight.js +38 -0
  74. package/dist/testSurface/readinessRead.d.ts +50 -0
  75. package/dist/testSurface/readinessRead.js +46 -0
  76. package/dist/testSurface/results/results.css +1 -1
  77. package/dist/testSurface/results/results.model.d.ts +1 -1
  78. package/dist/testSurface/surface/contracts.d.ts +6 -2
  79. package/dist/testSurface/surface/editorPlacement.d.ts +21 -0
  80. package/dist/testSurface/surface/editorPlacement.js +60 -0
  81. package/dist/testSurface/surface/pageBlock/parts.js +13 -3
  82. package/dist/testSurface/surface/readiness/ActionDialogs.js +65 -41
  83. package/dist/testSurface/surface/readiness/Banner.d.ts +1 -4
  84. package/dist/testSurface/surface/readiness/Banner.js +106 -68
  85. package/dist/testSurface/surface/readiness/BlockerList.d.ts +11 -0
  86. package/dist/testSurface/surface/readiness/BlockerList.js +31 -0
  87. package/dist/testSurface/surface/readiness/SaveStatus.d.ts +6 -2
  88. package/dist/testSurface/surface/readiness/SaveStatus.js +35 -22
  89. package/dist/testSurface/surface/readiness/parts.js +0 -2
  90. package/dist/testSurface/surface/readiness/readiness.model.d.ts +13 -0
  91. package/dist/testSurface/surface/readiness/readiness.model.js +51 -36
  92. package/dist/testSurface/surface/readiness/useTransition.d.ts +5 -2
  93. package/dist/testSurface/surface/readiness/useTransition.js +69 -7
  94. package/dist/testSurface/surface/test/AdvancedSection.js +1 -0
  95. package/dist/testSurface/surface/test/GoalSection.js +102 -74
  96. package/dist/testSurface/surface/test/LengthSection.d.ts +1 -1
  97. package/dist/testSurface/surface/test/LengthSection.js +2 -1
  98. package/dist/testSurface/surface/test/Rail.js +7 -4
  99. package/dist/testSurface/surface/test/ReadinessBar.js +1 -2
  100. package/dist/testSurface/surface/test/Section.d.ts +3 -1
  101. package/dist/testSurface/surface/test/Section.js +38 -6
  102. package/dist/testSurface/surface/test/TargetingSection.js +5 -0
  103. package/dist/testSurface/surface/test/TestSurface.d.ts +2 -1
  104. package/dist/testSurface/surface/test/TestSurface.js +68 -7
  105. package/dist/testSurface/surface/test/VersionsSection.js +1 -0
  106. package/dist/testSurface/surface/test/fields.d.ts +1 -3
  107. package/dist/testSurface/surface/test/fields.js +5 -35
  108. package/dist/testSurface/surface/test/testPage.css +12 -0
  109. package/dist/testSurface/surface/useTestDocument.d.ts +5 -2
  110. package/dist/testSurface/surface/useTestDocument.js +61 -46
  111. package/dist/testSurface/useReadinessPolling.d.ts +3 -0
  112. package/dist/testSurface/useReadinessPolling.js +24 -0
  113. package/dist/transitions/makeContent.js +24 -5
  114. package/dist/transitions/placements.js +23 -34
  115. package/dist/transitions/preflightData.js +1 -1
  116. package/dist/types/puck.d.ts +1 -0
  117. package/dist/ui/Card.d.ts +2 -1
  118. package/dist/ui/Card.js +4 -4
  119. package/dist/ui/Inputs.js +8 -5
  120. package/dist/ui/Tabs.d.ts +2 -2
  121. package/dist/ui/Tabs.js +33 -32
  122. package/dist/ui/ui.css +26 -3
  123. package/package.json +1 -1
@@ -9,6 +9,12 @@ export declare const SECTION_ORDER: readonly SectionId[];
9
9
  export type TestDocApi = ReturnType<typeof useTestDocument>;
10
10
  /** Serialisable props the server root view passes to the surface (ADM-20). */
11
11
  export interface SurfaceProps {
12
+ /** Present only when configuring a block from its page editor. */
13
+ editorPage?: {
14
+ collection: string;
15
+ id: string;
16
+ };
17
+ editorPlacementMessage?: string;
12
18
  adminRoute: string;
13
19
  apiRoute: string;
14
20
  collectionTitles?: Record<string, string>;
@@ -40,8 +46,6 @@ export interface KindParts {
40
46
  }
41
47
  /** Readiness pieces (ADM-23). */
42
48
  export interface ReadinessParts {
43
- /** Sticky-header banner incl. Start / status sentence. */
44
- Banner: ComponentType<SectionProps>;
45
49
  /** "Saving…" / "Saved" / error indicator for the header. */
46
50
  SaveStatus: ComponentType<{
47
51
  test: TestDocApi;
@@ -0,0 +1,21 @@
1
+ import type { PreflightResult } from '../../types/endpoints.js';
2
+ import type { Status } from '../../types/contracts.js';
3
+ import type { TestDocApi, SurfaceProps } from './contracts.js';
4
+ export { SAVE_PAGE, PUBLISH_PAGE, RUNNING_PUBLISH_PAGE, RUNNING_SAVE_PAGE } from '../copy/readiness.js';
5
+ /** Replace only the guidance represented by this page's local notice. */
6
+ export declare function editorPlacementChecks(checks: PreflightResult['checks'], page: NonNullable<SurfaceProps['editorPage']>): PreflightResult['checks'];
7
+ /** Editor context is a hint for guidance only; Start still runs server preflight. */
8
+ export declare function editorPlacementMessage(placements: PreflightResult['placements'] | undefined, page: SurfaceProps['editorPage'], status: Status | undefined): string | undefined;
9
+ /** Replace this page's checks once, retaining every other page's blocker. */
10
+ export declare function editorPreflight(answer: PreflightResult | null, surface: SurfaceProps, includeLocalBlocker?: boolean): PreflightResult | null;
11
+ /** Shared sidebar policy; the bounded list renders these steps verbatim. */
12
+ export declare function sidebarReadinessBlockers(test: TestDocApi, surface: SurfaceProps): ({
13
+ arm?: import("../../types/contracts.js").ArmKey | undefined;
14
+ section: "header" | import("./contracts.js").SectionId;
15
+ sentence: string;
16
+ code: import("../../transitions/checkStart.js").ReadinessCode;
17
+ } | {
18
+ sentence: "Wait for your changes to save.";
19
+ })[] | {
20
+ sentence: "Checking readiness…";
21
+ }[];
@@ -0,0 +1,60 @@
1
+ import { SAVE_PAGE, PUBLISH_PAGE, RUNNING_PUBLISH_PAGE, RUNNING_SAVE_PAGE } from '../copy/readiness.js';
2
+ import { blockingSteps, pageReadinessContext } from './readiness/readiness.model.js';
3
+ import { READINESS_COPY } from '../copy/readiness.js';
4
+ export { SAVE_PAGE, PUBLISH_PAGE, RUNNING_PUBLISH_PAGE, RUNNING_SAVE_PAGE } from '../copy/readiness.js';
5
+ /** Replace only the guidance represented by this page's local notice. */ export function editorPlacementChecks(checks, page) {
6
+ return checks.flatMap((check)=>{
7
+ if (check.code === 'no-placements') return [];
8
+ if (check.code !== 'placement-unpublished' || check.ok) return [
9
+ check
10
+ ];
11
+ const detail = (Array.isArray(check.detail) ? check.detail : [
12
+ check.detail
13
+ ]).filter((value)=>{
14
+ if (!value || typeof value !== 'object') return true;
15
+ const row = value;
16
+ return row.collection !== page.collection || String(row.id) !== String(page.id);
17
+ });
18
+ return detail.length ? [
19
+ {
20
+ ...check,
21
+ detail
22
+ }
23
+ ] : [];
24
+ });
25
+ }
26
+ /** Editor context is a hint for guidance only; Start still runs server preflight. */ export function editorPlacementMessage(placements, page, status) {
27
+ if (!page || !placements || !status || status === 'decided' || status === 'archived') return;
28
+ const here = placements.filter((p)=>p.collection === page.collection && String(p.id) === String(page.id));
29
+ if (!here.length) return status === 'running' ? RUNNING_SAVE_PAGE : SAVE_PAGE;
30
+ if (!here.some((p)=>p.detail === 'Published')) return status === 'running' ? RUNNING_PUBLISH_PAGE : PUBLISH_PAGE;
31
+ }
32
+ /** Replace this page's checks once, retaining every other page's blocker. */ export function editorPreflight(answer, surface, includeLocalBlocker = true) {
33
+ return answer && surface.editorPlacementMessage && surface.editorPage ? {
34
+ ...answer,
35
+ checks: [
36
+ ...editorPlacementChecks(answer.checks, surface.editorPage),
37
+ ...includeLocalBlocker ? [
38
+ {
39
+ code: 'no-placements',
40
+ ok: false
41
+ }
42
+ ] : []
43
+ ]
44
+ } : answer;
45
+ }
46
+ /** Shared sidebar policy; the bounded list renders these steps verbatim. */ export function sidebarReadinessBlockers(test, surface) {
47
+ const answer = editorPreflight(test.preflight, surface, false);
48
+ const blockers = test.doc ? blockingSteps(answer, pageReadinessContext(test.doc, test.preflight, surface)) : [];
49
+ const notice = test.preflightRead?.message ?? surface.editorPlacementMessage;
50
+ return test.hasUnsaved ? [
51
+ {
52
+ sentence: READINESS_COPY.saveFirst
53
+ },
54
+ ...blockers
55
+ ] : !answer && !notice ? [
56
+ {
57
+ sentence: READINESS_COPY.checking
58
+ }
59
+ ] : blockers.filter((step)=>step.sentence !== notice);
60
+ }
@@ -1,14 +1,24 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { Banner } from '../../../ui/Banner.js';
3
4
  import { Button } from '../../../ui/Button.js';
4
5
  import { placementPages } from '../../../lib/placementPages.js';
5
6
  import { TEST_PAGE as C, placementCount } from '../../copy/testPage.js';
6
7
  import { placementLine, slotReady } from './pageBlock.model.js';
7
- function Binding({ test }) {
8
+ function Binding({ test, surface }) {
8
9
  const placements = test.preflight?.placements ?? [];
9
10
  return /*#__PURE__*/ _jsx("div", {
10
11
  className: "xp-page-binding",
11
- children: placements.length ? /*#__PURE__*/ _jsxs(_Fragment, {
12
+ children: surface.editorPlacementMessage ? test.doc?.status === 'running' ? /*#__PURE__*/ _jsxs(Banner, {
13
+ tone: "warning",
14
+ children: [
15
+ /*#__PURE__*/ _jsx("span", {
16
+ "aria-hidden": "true",
17
+ children: "⚠ "
18
+ }),
19
+ surface.editorPlacementMessage
20
+ ]
21
+ }) : null : placements.length ? /*#__PURE__*/ _jsxs(_Fragment, {
12
22
  children: [
13
23
  placementPages(placements).map((placement)=>/*#__PURE__*/ _jsxs("p", {
14
24
  className: "xp-ui-button-group",
@@ -28,7 +38,7 @@ function Binding({ test }) {
28
38
  children: C.editedOnPage
29
39
  })
30
40
  ]
31
- }) : /*#__PURE__*/ _jsx("p", {
41
+ }) : test.preflight?.checks.some((check)=>!check.ok && check.code === 'no-placements') ? null : /*#__PURE__*/ _jsx("p", {
32
42
  children: C.notPlaced
33
43
  })
34
44
  });
@@ -1,11 +1,12 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { canStartTest, readyToStart } from '../../readinessRead.js';
3
4
  import { DocsResponseError, fetchAllDocs } from '../../../lib/fetchAllDocs.js';
4
5
  import { usePlacementLabels, placementDetailKey } from '../../placements/usePlacementLabels.js';
5
6
  import { placementUncheckedCopy } from '../../copy/readiness.js';
6
7
  import { useEffect, useState } from 'react';
7
8
  import { Button } from '../../../ui/Button.js';
8
- import { TextInput } from '../../../ui/Inputs.js';
9
+ import { TextInput, Select } from '../../../ui/Inputs.js';
9
10
  import { Dialog } from '../../../ui/Dialog.js';
10
11
  import { MakeContentResult } from '../../actions/MakeContentResult.js';
11
12
  import { expectedConfirm, matchesConfirm } from '../../../transitions/confirmPhrases.js';
@@ -14,20 +15,21 @@ import { REVIEW_COPY as R } from '../../copy/review.js';
14
15
  import { READINESS_COPY as C } from '../../copy/readiness.js';
15
16
  import { API_MESSAGES, refusalMessage } from '../../copy/common.js';
16
17
  import { createApi } from '../../api.js';
18
+ import { blockingSteps, pageReadinessContext } from './readiness.model.js';
17
19
  import { useTransition } from './useTransition.js';
18
20
  /** Prop-driven ConfirmDialog adapter: same model/copy, section reload instead of a page reload. */ export function ConfirmAction({ test, surface, action, winnerLabel, onClose }) {
19
21
  const api = createApi(surface.apiRoute);
20
22
  const [typed, setTyped] = useState('');
21
23
  const [content, setContent] = useState(null);
22
24
  const [reportBusy, setReportBusy] = useState(false);
23
- const transition = useTransition(test, onClose);
25
+ const transition = useTransition(test, onClose, surface);
24
26
  const phrase = action.confirm.phrase ? expectedConfirm(action.confirm.phrase.action, winnerLabel) : null;
25
- const ready = action.id !== 'start' || Boolean(test.preflight && !test.preflightPending && !test.preflightError && test.preflight.checks.every((check)=>check.ok));
27
+ const ready = action.id !== 'start' || !transition.checking && canStartTest(test, surface.editorPlacementMessage);
26
28
  const enabled = ready && !transition.busy && !test.hasUnsaved && test.saving !== 'saving' && (!phrase || matchesConfirm(phrase, typed));
27
29
  async function submit(finish = false) {
28
30
  if (!enabled || !test.doc) return;
29
31
  const id = test.doc.id;
30
- await transition.run(async ()=>{
32
+ await transition.run(finish ? 'archive' : action.id === 'start' && test.doc.status === 'stopped' ? 'restart' : action.id, async ()=>{
31
33
  if (finish) return api.archive(id, {
32
34
  mode: 'after-content'
33
35
  });
@@ -105,11 +107,21 @@ import { useTransition } from './useTransition.js';
105
107
  }) : null
106
108
  ]
107
109
  }),
110
+ transition.busy ? /*#__PURE__*/ _jsx("p", {
111
+ role: "status",
112
+ children: C.changing
113
+ }) : null,
108
114
  transition.error ? /*#__PURE__*/ _jsx("p", {
109
115
  role: "alert",
110
116
  children: transition.error
111
117
  }) : null,
118
+ !content && (test.hasUnsaved || test.saving === 'saving') ? /*#__PURE__*/ _jsx("p", {
119
+ children: test.stale ? C.reloadFirst : C.saveFirst
120
+ }) : !content && action.id === 'start' && !readyToStart(test, surface.editorPlacementMessage) ? /*#__PURE__*/ _jsx("p", {
121
+ children: test.preflightError ? test.preflightError : test.doc ? blockingSteps(test.preflight, pageReadinessContext(test.doc, test.preflight, surface))[0]?.sentence ?? C.checking : C.checking
122
+ }) : null,
112
123
  !content ? /*#__PURE__*/ _jsx(Button, {
124
+ busy: transition.busy,
113
125
  disabled: !enabled,
114
126
  onClick: ()=>{
115
127
  void submit();
@@ -128,7 +140,7 @@ import { useTransition } from './useTransition.js';
128
140
  /** AllocateDialog's validation and copy, with data supplied by the test document. */ export function AllocateAction({ test, surface, onClose }) {
129
141
  const current = test.doc?.allocation ?? 100;
130
142
  const [value, setValue] = useState(String(Math.min(100, current + 1)));
131
- const transition = useTransition(test, onClose);
143
+ const transition = useTransition(test, onClose, surface);
132
144
  const allocation = Number(value);
133
145
  const valid = value.trim() !== '' && Number.isInteger(allocation) && allocation > current && allocation <= 100;
134
146
  const disabled = transition.busy || test.hasUnsaved || test.saving === 'saving';
@@ -157,18 +169,26 @@ import { useTransition } from './useTransition.js';
157
169
  })
158
170
  ]
159
171
  }),
172
+ test.hasUnsaved || test.saving === 'saving' ? /*#__PURE__*/ _jsx("p", {
173
+ children: test.stale ? C.reloadFirst : C.saveFirst
174
+ }) : null,
160
175
  !valid ? /*#__PURE__*/ _jsx("p", {
161
176
  children: R.allocationInvalid
162
177
  }) : null,
178
+ transition.busy ? /*#__PURE__*/ _jsx("p", {
179
+ role: "status",
180
+ children: C.changing
181
+ }) : null,
163
182
  transition.error ? /*#__PURE__*/ _jsx("p", {
164
183
  role: "alert",
165
184
  children: transition.error
166
185
  }) : null,
167
186
  /*#__PURE__*/ _jsx(Button, {
187
+ busy: transition.busy,
168
188
  disabled: disabled || !valid,
169
189
  onClick: ()=>{
170
190
  // Not-found can also mean the experiment is missing; use round copy for the missing phase record.
171
- if (valid && test.doc) void transition.run(()=>createApi(surface.apiRoute).allocate(test.doc.id, {
191
+ if (valid && test.doc) void transition.run('allocate', ()=>createApi(surface.apiRoute).allocate(test.doc.id, {
172
192
  allocation
173
193
  }, {
174
194
  notFound: API_MESSAGES.roundChanged
@@ -196,7 +216,7 @@ import { useTransition } from './useTransition.js';
196
216
  ...surface
197
217
  });
198
218
  const [role, setRole] = useState('secondary');
199
- const transition = useTransition(test, onClose);
219
+ const transition = useTransition(test, onClose, surface);
200
220
  useEffect(()=>{
201
221
  const controller = new AbortController();
202
222
  void (async ()=>{
@@ -253,58 +273,62 @@ import { useTransition } from './useTransition.js';
253
273
  role: "status",
254
274
  children: R.loadingMetrics
255
275
  }) : null,
256
- /*#__PURE__*/ _jsxs("label", {
276
+ /*#__PURE__*/ _jsxs(Select, {
277
+ id: "xp-add-goal-role",
278
+ label: R.role,
279
+ value: role,
280
+ disabled: disabled,
281
+ onChange: (event)=>setRole(event.target.value),
257
282
  children: [
258
- R.role,
259
- /*#__PURE__*/ _jsxs("select", {
260
- value: role,
261
- disabled: disabled,
262
- onChange: (event)=>setRole(event.target.value),
263
- children: [
264
- /*#__PURE__*/ _jsx("option", {
265
- value: "secondary",
266
- children: R.supporting
267
- }),
268
- /*#__PURE__*/ _jsx("option", {
269
- value: "guardrail",
270
- children: R.guardrail
271
- })
272
- ]
283
+ /*#__PURE__*/ _jsx("option", {
284
+ value: "secondary",
285
+ children: R.supporting
286
+ }),
287
+ /*#__PURE__*/ _jsx("option", {
288
+ value: "guardrail",
289
+ children: R.guardrail
273
290
  })
274
291
  ]
275
292
  }),
276
- /*#__PURE__*/ _jsxs("label", {
293
+ /*#__PURE__*/ _jsxs(Select, {
294
+ id: "xp-add-goal-metric",
295
+ label: R.metric,
296
+ value: metric,
297
+ disabled: disabled || loading,
298
+ onChange: (event)=>setMetric(event.target.value),
277
299
  children: [
278
- R.metric,
279
- /*#__PURE__*/ _jsxs("select", {
280
- value: metric,
281
- disabled: disabled || loading,
282
- onChange: (event)=>setMetric(event.target.value),
283
- children: [
284
- /*#__PURE__*/ _jsx("option", {
285
- value: "",
286
- children: R.chooseMetric
287
- }),
288
- available.map((item)=>/*#__PURE__*/ _jsx("option", {
289
- value: String(item.id),
290
- children: item.name
291
- }, item.id))
292
- ]
293
- })
300
+ /*#__PURE__*/ _jsx("option", {
301
+ value: "",
302
+ children: R.chooseMetric
303
+ }),
304
+ available.map((item)=>/*#__PURE__*/ _jsx("option", {
305
+ value: String(item.id),
306
+ children: item.name
307
+ }, item.id))
294
308
  ]
295
309
  }),
296
310
  !loading && !loadError && !available.length ? /*#__PURE__*/ _jsx("p", {
297
311
  children: R.noMetrics
298
312
  }) : null,
313
+ transition.busy ? /*#__PURE__*/ _jsx("p", {
314
+ role: "status",
315
+ children: C.changing
316
+ }) : null,
299
317
  loadError || transition.error ? /*#__PURE__*/ _jsx("p", {
300
318
  role: "alert",
301
319
  children: loadError ?? transition.error
302
320
  }) : 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", {
324
+ children: C.chooseGoalToAdd
325
+ }) : null,
303
326
  /*#__PURE__*/ _jsx(Button, {
327
+ busy: transition.busy,
304
328
  disabled: disabled || loading || !!loadError || !selected,
305
329
  onClick: ()=>{
306
330
  // Goal and phase lookups share not-found; prefer the more likely missing goal without reading server text.
307
- if (selected && test.doc) void transition.run(async ()=>{
331
+ if (selected && test.doc) void transition.run('add-metric', async ()=>{
308
332
  const result = await createApi(surface.apiRoute).addMetric(test.doc.id, {
309
333
  metric: selected.id,
310
334
  role
@@ -1,5 +1,2 @@
1
1
  import type { SectionProps } from '../contracts.js';
2
- export declare function Banner(props: SectionProps): import("react").JSX.Element | null;
3
- export declare function ReadinessContent({ test, surface, resultsVersion, bar }: SectionProps & {
4
- bar?: boolean;
5
- }): import("react").JSX.Element;
2
+ export declare function ReadinessContent({ test, surface, resultsVersion }: SectionProps): import("react").JSX.Element;
@@ -1,31 +1,29 @@
1
1
  'use client';
2
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { canStartTest, readyToStart } from '../../readinessRead.js';
3
4
  import { useEffect, useState } from 'react';
4
5
  import { Button } from '../../../ui/Button.js';
5
6
  import { SaveStatus, saveStatusMessage } from './SaveStatus.js';
6
7
  import { jumpToSection } from '../test/jumpToSection.js';
7
8
  import { actionGroupLabel, availableActions } from '../../actions/actions.model.js';
8
9
  import { createApi } from '../../api.js';
9
- import { READINESS_COPY as C, decidedCopy, nextCopy, runningCopy, stoppedCopy } from '../../copy/readiness.js';
10
- import { READINESS, daysRemaining, displayDate, nextStep, pageReadinessContext } from './readiness.model.js';
10
+ import { TEST_PAGE } from '../../copy/testPage.js';
11
+ import { READINESS_COPY as C, decidedCopy, fixFieldsNext, runningCopy, stoppedCopy } from '../../copy/readiness.js';
12
+ import { READINESS, daysRemaining, displayDate, blockingSteps, pageReadinessContext, errorSection } from './readiness.model.js';
11
13
  import { AddMetricAction, AllocateAction, ConfirmAction } from './ActionDialogs.js';
12
14
  import { preflightPlacementLabel } from '../../placements/placementLabels.js';
13
15
  import { placementUncheckedCopy } from '../../copy/readiness.js';
14
16
  import { useTransition } from './useTransition.js';
17
+ import { BlockerList } from './BlockerList.js';
15
18
  const RUNNING_ACTIONS = [
16
19
  'stop',
17
20
  'add-metric',
18
21
  'allocate'
19
22
  ];
20
- export function Banner(props) {
21
- return props.test.doc ? /*#__PURE__*/ _jsx(ReadinessContent, {
22
- ...props
23
- }, `${props.test.doc.id}/${props.test.doc.status}`) : null;
24
- }
25
- export function ReadinessContent({ test, surface, resultsVersion, bar = false }) {
23
+ export function ReadinessContent({ test, surface, resultsVersion }) {
26
24
  const [selected, setSelected] = useState(null);
27
25
  const [people, setPeople] = useState(null);
28
- const transition = useTransition(test);
26
+ const transition = useTransition(test, undefined, surface);
29
27
  const doc = test.doc;
30
28
  useEffect(()=>{
31
29
  let active = true;
@@ -61,11 +59,38 @@ export function ReadinessContent({ test, surface, resultsVersion, bar = false })
61
59
  }
62
60
  } : check)
63
61
  } : null;
64
- const next = nextStep(labelledPreflight, pageReadinessContext(doc, test.preflight, surface));
62
+ const readinessBlockers = blockingSteps(labelledPreflight, pageReadinessContext(doc, test.preflight, surface));
65
63
  const setup = doc.status === 'draft' || doc.status === 'stopped';
66
- const ready = Boolean(test.preflight && !test.preflightPending && !test.preflightError && test.preflight.checks.every((check)=>check.ok));
64
+ const ready = readyToStart(test, surface.editorPlacementMessage);
65
+ const startEnabled = !transition.checking && canStartTest(test, surface.editorPlacementMessage);
67
66
  const unsaved = test.hasUnsaved || test.saving === 'saving';
68
- const startReason = unsaved ? C.saveFirst : next?.sentence ?? (!ready ? test.preflightError ? C.checkError : C.checking : undefined);
67
+ const blockers = [
68
+ ...readinessBlockers
69
+ ];
70
+ if (unsaved && !test.stale) blockers.unshift({
71
+ section: 'header',
72
+ sentence: C.saveFirst,
73
+ code: 'unsaved'
74
+ });
75
+ else if (!test.preflight && !test.preflightError) blockers.unshift({
76
+ section: 'header',
77
+ sentence: C.checking,
78
+ code: 'checking'
79
+ });
80
+ const errorSections = [
81
+ ...new Set(Object.keys(test.errors).filter((path)=>path !== '_section').map((path)=>errorSection(path) ?? 'what'))
82
+ ];
83
+ for (const section of errorSections.reverse())blockers.unshift({
84
+ section,
85
+ sentence: test.stale ? C.reloadFirst : fixFieldsNext(TEST_PAGE.sections[section]),
86
+ code: `validation:${section}`
87
+ });
88
+ if (test.errors._section || test.stale) blockers.unshift({
89
+ section: 'what',
90
+ sentence: test.stale ? C.reloadFirst : C.reloadAfterError,
91
+ code: 'save-error'
92
+ });
93
+ const startReason = blockers[0]?.sentence ?? test.preflightError ?? (!ready ? C.checking : undefined);
69
94
  const actions = availableActions({
70
95
  status: doc.status,
71
96
  kind: doc.kind,
@@ -80,48 +105,10 @@ export function ReadinessContent({ test, surface, resultsVersion, bar = false })
80
105
  label: C.allocate
81
106
  } : action);
82
107
  const action = actions.find((item)=>item.id === selected);
83
- const sentence = setup ? bar && test.preflightError ? null : ready ? C.ready : next ? nextCopy(next.sentence) : test.preflightError ? C.checkError : C.checking : doc.status === 'running' ? runningCopy(displayDate(doc.startedAt), people, daysRemaining(doc, Date.now())) : doc.status === 'decided' ? decidedCopy(displayDate(doc.decidedAt), winner) : C.archived;
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;
84
109
  return /*#__PURE__*/ _jsxs("div", {
85
- className: `xp-readiness xp-readiness--${setup && ready ? 'ready' : 'neutral'}${bar ? ' xp-readiness--bar xp-tests-container' : ''}`,
110
+ className: `xp-readiness xp-readiness--${setup && ready && !blockers.length && !transition.busy ? 'ready' : 'neutral'} xp-readiness--bar xp-tests-container`,
86
111
  children: [
87
- /*#__PURE__*/ _jsxs("div", {
88
- className: "xp-readiness__state",
89
- children: [
90
- bar ? /*#__PURE__*/ _jsxs(_Fragment, {
91
- children: [
92
- /*#__PURE__*/ _jsx(SaveStatus, {
93
- test: test
94
- }),
95
- sentence && (saveStatusMessage(test) || test.preflightError) ? /*#__PURE__*/ _jsx("span", {
96
- className: "xp-readiness__separator",
97
- "aria-hidden": "true",
98
- children: "·"
99
- }) : null
100
- ]
101
- }) : null,
102
- sentence ? /*#__PURE__*/ _jsx("p", {
103
- role: "status",
104
- children: setup && next && !ready && next.section !== 'header' ? /*#__PURE__*/ _jsxs("a", {
105
- href: `#section-${next.section}`,
106
- onClick: (event)=>{
107
- event.preventDefault();
108
- if (next.section !== 'header') jumpToSection(next.section, next.arm);
109
- },
110
- children: [
111
- sentence,
112
- next.nextStep ? /*#__PURE__*/ _jsxs(_Fragment, {
113
- children: [
114
- /*#__PURE__*/ _jsx("br", {}),
115
- /*#__PURE__*/ _jsx("span", {
116
- children: next.nextStep
117
- })
118
- ]
119
- }) : null
120
- ]
121
- }) : sentence
122
- }) : null
123
- ]
124
- }),
125
112
  setup && test.preflight?.checks.some((check)=>check.code === 'page-targets-unchecked' && check.warning) ? /*#__PURE__*/ _jsx("p", {
126
113
  children: C.uncheckedPages
127
114
  }) : null,
@@ -140,29 +127,80 @@ export function ReadinessContent({ test, surface, resultsVersion, bar = false })
140
127
  }) : placementUncheckedCopy(placement.title) : READINESS[check.code].next(check.detail, doc)
141
128
  }, `${check.code}:${index}`);
142
129
  }),
143
- test.preflight?.goalNotes?.map((note)=>/*#__PURE__*/ _jsx("p", {
144
- children: note.message
130
+ [
131
+ ...new Map(test.preflight?.goalNotes?.map((note)=>[
132
+ String(note.metricId),
133
+ note
134
+ ])).values()
135
+ ].map((note)=>/*#__PURE__*/ _jsxs("p", {
136
+ className: "xp-readiness__warning",
137
+ children: [
138
+ /*#__PURE__*/ _jsx("span", {
139
+ "aria-hidden": "true",
140
+ children: "⚠ "
141
+ }),
142
+ note.message
143
+ ]
145
144
  }, note.metricId)),
146
145
  doc.status === 'stopped' ? /*#__PURE__*/ _jsx("p", {
147
146
  children: stoppedCopy(displayDate(doc.stoppedAt))
148
147
  }) : null,
148
+ /*#__PURE__*/ _jsxs("div", {
149
+ className: "xp-readiness__state",
150
+ children: [
151
+ /*#__PURE__*/ _jsx(SaveStatus, {
152
+ test: test,
153
+ messageInBlockerList: setup && !!test.preflight && !test.preflightError
154
+ }),
155
+ sentence && (saveStatusMessage(test) || test.preflightError) ? /*#__PURE__*/ _jsx("span", {
156
+ className: "xp-readiness__separator",
157
+ "aria-hidden": "true",
158
+ children: "·"
159
+ }) : null,
160
+ sentence ? /*#__PURE__*/ _jsx("p", {
161
+ role: "status",
162
+ children: sentence
163
+ }) : null,
164
+ setup ? /*#__PURE__*/ _jsx(BlockerList, {
165
+ steps: blockers,
166
+ renderSentence: (_, index)=>{
167
+ const step = blockers[index];
168
+ return step.section === 'header' ? step.sentence : /*#__PURE__*/ _jsx("a", {
169
+ href: `#section-${step.section}`,
170
+ onClick: (event)=>{
171
+ event.preventDefault();
172
+ if (step.section !== 'header') jumpToSection(step.section, step.arm);
173
+ },
174
+ children: step.sentence
175
+ });
176
+ }
177
+ }) : null
178
+ ]
179
+ }),
149
180
  /*#__PURE__*/ _jsx("div", {
150
181
  className: "xp-readiness__actions",
151
182
  children: actions.map((item)=>{
152
- const reason = item.id === 'start' ? startReason : unsaved ? C.saveFirst : item.id === 'allocate' && doc.allocation >= 100 ? C.everyone : undefined;
153
- const disabled = transition.busy || !!selected || !!reason;
154
- return /*#__PURE__*/ _jsx("span", {
183
+ const reason = item.id === 'start' ? startReason : test.stale ? C.reloadFirst : unsaved ? C.saveFirst : item.id === 'allocate' && doc.allocation >= 100 ? C.everyone : undefined;
184
+ const disabled = transition.busy || !!selected || !!reason || item.id === 'start' && !startEnabled;
185
+ return /*#__PURE__*/ _jsxs("span", {
155
186
  title: reason,
156
- children: /*#__PURE__*/ _jsx(Button, {
157
- variant: item.tone === 'primary' || bar && item.id === 'stop' ? 'primary' : 'secondary',
158
- disabled: disabled,
159
- onClick: ()=>{
160
- if (disabled) return;
161
- if (item.id === 'start' && doc.status === 'draft') void transition.run(()=>createApi(surface.apiRoute).start(doc.id));
162
- else setSelected(item.id);
163
- },
164
- children: item.label
165
- })
187
+ children: [
188
+ reason && item.id !== 'start' ? /*#__PURE__*/ _jsx("span", {
189
+ className: "xp-readiness-action-reason",
190
+ children: reason
191
+ }) : null,
192
+ /*#__PURE__*/ _jsx(Button, {
193
+ busy: transition.busy,
194
+ variant: item.tone === 'primary' || item.id === 'stop' ? 'primary' : 'secondary',
195
+ disabled: disabled,
196
+ onClick: ()=>{
197
+ if (disabled) return;
198
+ if (item.id === 'start' && doc.status === 'draft') void transition.run('start', ()=>createApi(surface.apiRoute).start(doc.id));
199
+ else setSelected(item.id);
200
+ },
201
+ children: item.label
202
+ })
203
+ ]
166
204
  }, item.id);
167
205
  })
168
206
  }),
@@ -0,0 +1,11 @@
1
+ import '../../../ui/ui.css';
2
+ import type { ReactNode } from 'react';
3
+ /** The footer and sidebar show the same bounded list, including other pages. */
4
+ export declare function BlockerList({ steps, renderSentence }: {
5
+ steps: readonly {
6
+ sentence: string;
7
+ }[];
8
+ renderSentence?: (step: {
9
+ sentence: string;
10
+ }, index: number) => ReactNode;
11
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,31 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import '../../../ui/ui.css';
4
+ import { READINESS_COPY, moreBlockers } from '../../copy/readiness.js';
5
+ /** The footer and sidebar show the same bounded list, including other pages. */ export function BlockerList({ steps, renderSentence = (step)=>step.sentence }) {
6
+ return steps.length ? /*#__PURE__*/ _jsxs("div", {
7
+ className: "xp-readiness__blockers",
8
+ role: "status",
9
+ children: [
10
+ /*#__PURE__*/ _jsx("strong", {
11
+ children: READINESS_COPY.beforeStart
12
+ }),
13
+ /*#__PURE__*/ _jsxs("ul", {
14
+ children: [
15
+ steps.slice(0, 3).map((step, index)=>/*#__PURE__*/ _jsxs("li", {
16
+ children: [
17
+ /*#__PURE__*/ _jsx("span", {
18
+ "aria-hidden": "true",
19
+ children: "⊗ "
20
+ }),
21
+ renderSentence(step, index)
22
+ ]
23
+ }, index)),
24
+ steps.length > 3 ? /*#__PURE__*/ _jsx("li", {
25
+ children: moreBlockers(steps.length - 3)
26
+ }) : null
27
+ ]
28
+ })
29
+ ]
30
+ }) : null;
31
+ }
@@ -1,5 +1,9 @@
1
1
  import type { TestDocApi } from '../contracts.js';
2
2
  export declare function saveStatusMessage(test: TestDocApi): string | null;
3
- export declare function SaveStatus({ test }: {
3
+ type Props = {
4
4
  test: TestDocApi;
5
- }): import("react").JSX.Element;
5
+ messageInBlockerList?: boolean;
6
+ };
7
+ export declare function ReadinessReadStatus({ test, messageInBlockerList }: Props): import("react").JSX.Element;
8
+ export declare function SaveStatus({ test, messageInBlockerList }: Props): import("react").JSX.Element;
9
+ export {};