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

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 (87) hide show
  1. package/dist/admin/surface/ResultsRoute.js +2 -10
  2. package/dist/admin/surface/newTest/PageWizard.js +10 -12
  3. package/dist/admin/surface/results/ResultsHeader.js +15 -8
  4. package/dist/goals/fairness.d.ts +1 -1
  5. package/dist/goals/fairness.js +1 -1
  6. package/dist/puck/editor/ConfigureTestDrawer.js +2 -2
  7. package/dist/puck/editor/CreateExperimentDrawer.js +4 -0
  8. package/dist/puck/editor/EditorControls.d.ts +1 -1
  9. package/dist/puck/editor/EditorControls.js +1 -1
  10. package/dist/puck/editor/ExperimentSlotEditor.js +425 -80
  11. package/dist/puck/editor/LeftoverVersions.d.ts +13 -0
  12. package/dist/puck/editor/LeftoverVersions.js +115 -0
  13. package/dist/puck/editor/PlacementNotice.d.ts +8 -0
  14. package/dist/puck/editor/PlacementNotice.js +22 -0
  15. package/dist/puck/editor/QuickTestActions.d.ts +3 -0
  16. package/dist/puck/editor/QuickTestActions.js +50 -0
  17. package/dist/puck/editor/ResultsReadout.js +5 -0
  18. package/dist/puck/editor/VersionBuilder.d.ts +20 -6
  19. package/dist/puck/editor/VersionBuilder.js +78 -48
  20. package/dist/puck/editor/armWrites.d.ts +3 -1
  21. package/dist/puck/editor/armWrites.js +2 -1
  22. package/dist/puck/editor/cloneSlot.d.ts +2 -0
  23. package/dist/puck/editor/cloneSlot.js +7 -0
  24. package/dist/puck/editor/copy.d.ts +24 -3
  25. package/dist/puck/editor/copy.js +24 -3
  26. package/dist/puck/editor/editor.chrome.css +11 -0
  27. package/dist/puck/editor/editor.css +29 -0
  28. package/dist/puck/editor/experimentOutlinePlugin.js +96 -28
  29. package/dist/puck/editor/outlineVersion.d.ts +5 -0
  30. package/dist/puck/editor/outlineVersion.js +36 -0
  31. package/dist/puck/editor/placementsCache.d.ts +33 -2
  32. package/dist/puck/editor/placementsCache.js +208 -33
  33. package/dist/puck/editor/sidebar.d.ts +12 -0
  34. package/dist/puck/editor/sidebar.js +77 -0
  35. package/dist/puck/editor/usePlacementNotice.d.ts +3 -0
  36. package/dist/puck/editor/usePlacementNotice.js +14 -0
  37. package/dist/testSurface/api.js +1 -1
  38. package/dist/testSurface/copy/common.d.ts +1 -1
  39. package/dist/testSurface/copy/common.js +3 -1
  40. package/dist/testSurface/copy/readiness.d.ts +17 -1
  41. package/dist/testSurface/copy/readiness.js +22 -1
  42. package/dist/testSurface/copy/testPage.d.ts +1 -0
  43. package/dist/testSurface/copy/testPage.js +1 -0
  44. package/dist/testSurface/readPreflight.d.ts +9 -0
  45. package/dist/testSurface/readPreflight.js +38 -0
  46. package/dist/testSurface/readinessRead.d.ts +50 -0
  47. package/dist/testSurface/readinessRead.js +46 -0
  48. package/dist/testSurface/surface/contracts.d.ts +6 -2
  49. package/dist/testSurface/surface/editorPlacement.d.ts +21 -0
  50. package/dist/testSurface/surface/editorPlacement.js +60 -0
  51. package/dist/testSurface/surface/pageBlock/parts.js +13 -3
  52. package/dist/testSurface/surface/readiness/ActionDialogs.js +37 -7
  53. package/dist/testSurface/surface/readiness/Banner.d.ts +1 -4
  54. package/dist/testSurface/surface/readiness/Banner.js +106 -68
  55. package/dist/testSurface/surface/readiness/BlockerList.d.ts +11 -0
  56. package/dist/testSurface/surface/readiness/BlockerList.js +31 -0
  57. package/dist/testSurface/surface/readiness/SaveStatus.d.ts +6 -2
  58. package/dist/testSurface/surface/readiness/SaveStatus.js +35 -22
  59. package/dist/testSurface/surface/readiness/parts.js +0 -2
  60. package/dist/testSurface/surface/readiness/readiness.model.d.ts +13 -0
  61. package/dist/testSurface/surface/readiness/readiness.model.js +51 -36
  62. package/dist/testSurface/surface/readiness/useTransition.d.ts +5 -2
  63. package/dist/testSurface/surface/readiness/useTransition.js +69 -7
  64. package/dist/testSurface/surface/test/AdvancedSection.js +1 -0
  65. package/dist/testSurface/surface/test/GoalSection.js +1 -0
  66. package/dist/testSurface/surface/test/LengthSection.d.ts +1 -1
  67. package/dist/testSurface/surface/test/LengthSection.js +2 -1
  68. package/dist/testSurface/surface/test/Rail.js +7 -4
  69. package/dist/testSurface/surface/test/ReadinessBar.js +1 -2
  70. package/dist/testSurface/surface/test/Section.d.ts +3 -1
  71. package/dist/testSurface/surface/test/Section.js +38 -6
  72. package/dist/testSurface/surface/test/TargetingSection.js +5 -0
  73. package/dist/testSurface/surface/test/TestSurface.d.ts +2 -1
  74. package/dist/testSurface/surface/test/TestSurface.js +68 -7
  75. package/dist/testSurface/surface/test/VersionsSection.js +1 -0
  76. package/dist/testSurface/surface/test/testPage.css +12 -0
  77. package/dist/testSurface/surface/useTestDocument.d.ts +5 -2
  78. package/dist/testSurface/surface/useTestDocument.js +61 -46
  79. package/dist/testSurface/useReadinessPolling.d.ts +3 -0
  80. package/dist/testSurface/useReadinessPolling.js +24 -0
  81. package/dist/transitions/preflightData.js +1 -1
  82. package/dist/ui/Card.d.ts +2 -1
  83. package/dist/ui/Card.js +4 -4
  84. package/dist/ui/Tabs.d.ts +2 -1
  85. package/dist/ui/Tabs.js +19 -6
  86. package/dist/ui/ui.css +18 -0
  87. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import { SURFACE_COPY } from '../../copy/surface.js';
2
2
  import { formatDate } from '../../format/date.js';
3
3
  import { actionGroupLabel } from '../../actions/actions.model.js';
4
- import { 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';
4
+ 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
5
  import { normalisePath } from '../../../runtime/normalisePath.js';
6
6
  import { testPageCollection } from '../pagePicker/pagePicker.model.js';
7
7
  import { SECTION_ORDER } from '../contracts.js';
@@ -29,12 +29,10 @@ const versions = row('versions', (detail)=>versionsNext(detailText(detail, C.ver
29
29
  nextStep: (detail)=>`Open ${text(object(detail).title ?? object(detail).path, 'the page')}`
30
30
  },
31
31
  'invalid-status': row('header', ()=>null),
32
- 'no-placements': row('what', (detail)=>detail === undefined ? C.noPlacements : placementFailureCopy(detail)),
32
+ 'no-placements': row('what', (detail, ctx)=>ctx.editorPlacementMessage ?? (detail === undefined ? C.noPlacements : placementFailureCopy(detail))),
33
33
  'placement-removed': row('what', ()=>C.placementRemoved),
34
34
  'placement-unpublished': {
35
- ...row('versions', (detail)=>(Array.isArray(detail) && detail.length ? detail : [
36
- detail
37
- ]).map((placement)=>`The block you're testing is only on a draft of ${text(object(placement).title, 'this page')}. Publish the page before you start.`).join('\n')),
35
+ ...row('versions', unpublishedPlacementsCopy),
38
36
  nextStep: 'Publish the page'
39
37
  },
40
38
  'duplicate-version-row': {
@@ -136,44 +134,60 @@ const versions = row('versions', (detail)=>versionsNext(detailText(detail, C.ver
136
134
  'slot-required': versions,
137
135
  'duplicate-slot': versions
138
136
  };
139
- export function nextStep(preflight, ctx) {
140
- for (const section of [
137
+ export function blockingSteps(preflight, ctx) {
138
+ return [
141
139
  'header',
142
140
  ...SECTION_ORDER
143
- ]){
144
- for (const check of preflight?.checks ?? []){
145
- if (!Object.hasOwn(READINESS, check.code)) {
146
- if (!check.ok && section === SECTION_ORDER[0]) return {
147
- section,
148
- sentence: SURFACE_COPY.next,
149
- code: check.code
150
- };
151
- continue;
152
- }
153
- const mapping = READINESS[check.code];
154
- if (check.ok || mapping.section !== section) continue;
155
- const sentence = mapping.next(check.detail, ctx);
156
- const nextStep = typeof mapping.nextStep === 'function' ? mapping.nextStep(check.detail, ctx) : mapping.nextStep;
141
+ ].flatMap((section)=>(preflight?.checks ?? []).flatMap((check)=>{
142
+ const mapping = Object.hasOwn(READINESS, check.code) ? READINESS[check.code] : undefined;
143
+ if (check.ok || (mapping?.section ?? 'what') !== section) return [];
144
+ const sentence = mapping ? mapping.next(check.detail, ctx) : SURFACE_COPY.next;
157
145
  const arm = readinessArm(check.code, check.detail, ctx);
158
- if (sentence) return {
159
- section,
160
- sentence,
161
- code: check.code,
162
- ...arm ? {
163
- arm
164
- } : {},
165
- ...nextStep ? {
166
- nextStep
167
- } : {}
168
- };
169
- }
170
- }
171
- return null;
146
+ return sentence ? [
147
+ {
148
+ section,
149
+ sentence,
150
+ code: check.code,
151
+ ...arm ? {
152
+ arm
153
+ } : {}
154
+ }
155
+ ] : [];
156
+ }));
157
+ }
158
+ export function nextStep(preflight, ctx) {
159
+ const next = blockingSteps(preflight, ctx)[0];
160
+ if (!next) return null;
161
+ const mapping = READINESS[next.code];
162
+ const detail = preflight?.checks.find((check)=>!check.ok && check.code === next.code)?.detail;
163
+ const action = mapping && (typeof mapping.nextStep === 'function' ? mapping.nextStep(detail, ctx) : mapping.nextStep);
164
+ return {
165
+ ...next,
166
+ ...action ? {
167
+ nextStep: action
168
+ } : {}
169
+ };
170
+ }
171
+ export function errorSection(path) {
172
+ if ([
173
+ 'name',
174
+ 'hypothesis',
175
+ 'flagPoint'
176
+ ].some((field)=>path === field || path.startsWith(`${field}.`))) return 'what';
177
+ if (/^(arms|pageCollection|allocation)(\.|$)/.test(path)) return 'versions';
178
+ if (/^metrics(\.|$)/.test(path)) return 'win';
179
+ if (/^(targeting)(\.|$)/.test(path)) return 'who';
180
+ if (/^analysis\.(plannedDurationDays|reachPerDay)(\.|$)/.test(path)) return 'length';
181
+ if (/^(analysis|exposurePolicy|layer)(\.|$)/.test(path)) return 'advanced';
182
+ }
183
+ export function sectionBlocked(test, section) {
184
+ if (Object.keys(test.errors ?? {}).some((path)=>errorSection(path) === section)) return true;
185
+ return !!test.preflight?.checks.some((check)=>!check.ok && (Object.hasOwn(READINESS, check.code) ? READINESS[check.code].section : 'what') === section);
172
186
  }
173
187
  export function sectionDone(test) {
174
188
  return Object.fromEntries(SECTION_ORDER.map((section)=>[
175
189
  section,
176
- test.preflight ? !test.preflight.checks.some((check)=>!check.ok && (Object.hasOwn(READINESS, check.code) ? READINESS[check.code].section : SECTION_ORDER[0]) === section) : section === 'who' || section === 'advanced'
190
+ section === 'who' && test.doc && !test.doc.targeting?.length ? false : test.preflight ? !test.preflight.checks.some((check)=>!check.ok && (Object.hasOwn(READINESS, check.code) ? READINESS[check.code].section : SECTION_ORDER[0]) === section) : section === 'advanced'
177
191
  ]));
178
192
  }
179
193
  export function displayDate(value) {
@@ -191,6 +205,7 @@ function pageArm(path, ctx) {
191
205
  export function pageReadinessContext(doc, preflight, surface) {
192
206
  return {
193
207
  ...doc,
208
+ editorPlacementMessage: surface.editorPlacementMessage,
194
209
  flagPoints: surface.flagPoints,
195
210
  pagePlacements: preflight?.pagePlacements,
196
211
  collectionLabel: testPageCollection(surface.pageCollections, doc, preflight?.pagePlacements)?.label
@@ -1,10 +1,13 @@
1
1
  import type { ApiResult } from '../../api.js';
2
2
  import type { TestDocApi } from '../contracts.js';
3
+ import type { SurfaceProps } from '../contracts.js';
4
+ import type { ActionId } from '../../actions/actions.model.js';
3
5
  /** The ref closes the gap before React renders the disabled button. */
4
- export declare function useTransition(test: TestDocApi, onSuccess?: () => void): {
6
+ export declare function useTransition(test: TestDocApi, onSuccess?: () => void, surface?: SurfaceProps): {
5
7
  busy: boolean;
8
+ checking: boolean;
6
9
  error: string | null;
7
- run: (request: () => Promise<ApiResult<unknown>>, { reloadOnSuccess }?: {
10
+ run: (kind: ActionId | "restart", request: () => Promise<ApiResult<unknown>>, { reloadOnSuccess }?: {
8
11
  reloadOnSuccess?: boolean | undefined;
9
12
  }) => Promise<void>;
10
13
  clearError: () => void;
@@ -1,15 +1,58 @@
1
1
  'use client';
2
- import { useRef, useState } from 'react';
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { blockingSteps, pageReadinessContext } from './readiness.model.js';
3
4
  import { API_MESSAGES } from '../../copy/common.js';
4
- /** The ref closes the gap before React renders the disabled button. */ export function useTransition(test, onSuccess) {
5
+ /** The ref closes the gap before React renders the disabled button. */ export function useTransition(test, onSuccess, surface) {
5
6
  const inFlight = useRef(false);
6
7
  const [busy, setBusy] = useState(false);
8
+ const [checking, setChecking] = useState(false);
7
9
  const [error, setError] = useState(null);
8
- async function run(request, { reloadOnSuccess = true } = {}) {
10
+ const refusal = useRef(null);
11
+ const answer = test.preflightRead?.answer ?? test.preflight;
12
+ const latestAnswer = useRef(answer);
13
+ latestAnswer.current = answer;
14
+ // Dismissal mutates the lifetime once; a later ready answer cannot revive it.
15
+ useEffect(()=>{
16
+ if (!refusal.current) return;
17
+ if (refusal.current.status !== test.doc?.status) {
18
+ clearError();
19
+ return;
20
+ }
21
+ if (refusal.current.kind !== 'start' && refusal.current.kind !== 'restart') return;
22
+ const successful = !!answer && !test.preflightError;
23
+ const explained = successful && !test.preflightRead?.failed && test.doc && [
24
+ 'draft',
25
+ 'stopped'
26
+ ].includes(test.doc.status) && blockingSteps(answer, surface ? pageReadinessContext(test.doc, answer, surface) : test.doc).length > 0;
27
+ if (refusal.current.phase === 'rereading') {
28
+ // Observe the answer even if another shared read has already begun.
29
+ if (!checking || successful && answer !== refusal.current.answer) {
30
+ refusal.current = {
31
+ ...refusal.current,
32
+ phase: 'waiting',
33
+ answer
34
+ };
35
+ if (explained) clearError();
36
+ }
37
+ } else if (explained && answer !== refusal.current.answer) clearError();
38
+ }, [
39
+ answer,
40
+ checking,
41
+ error,
42
+ test.preflightPending,
43
+ test.preflightError,
44
+ test.doc?.status
45
+ ]);
46
+ function clearError() {
47
+ refusal.current = null;
48
+ setError(null);
49
+ }
50
+ async function run(kind, request, { reloadOnSuccess = true } = {}) {
9
51
  if (inFlight.current || test.hasUnsaved || test.saving === 'saving') return;
52
+ clearError();
10
53
  inFlight.current = true;
11
54
  setBusy(true);
12
- setError(null);
55
+ let refused = false;
13
56
  try {
14
57
  const result = await request();
15
58
  if (result.ok) {
@@ -20,17 +63,36 @@ import { API_MESSAGES } from '../../copy/common.js';
20
63
  // Keep the successful action locked until the reloaded document replaces this view.
21
64
  return;
22
65
  }
23
- } else setError(result.message);
66
+ } else {
67
+ refused = true;
68
+ setError(result.message);
69
+ }
24
70
  } catch {
71
+ refused = true;
25
72
  setError(API_MESSAGES.network);
26
73
  }
27
- inFlight.current = false;
28
74
  setBusy(false);
75
+ try {
76
+ if (refused) {
77
+ refusal.current = {
78
+ kind,
79
+ status: test.doc?.status,
80
+ phase: 'rereading',
81
+ answer: latestAnswer.current
82
+ };
83
+ setChecking(true);
84
+ await test.refreshPreflight(true);
85
+ }
86
+ } finally{
87
+ inFlight.current = false;
88
+ setChecking(false);
89
+ }
29
90
  }
30
91
  return {
31
92
  busy,
93
+ checking,
32
94
  error,
33
95
  run,
34
- clearError: ()=>setError(null)
96
+ clearError
35
97
  };
36
98
  }
@@ -38,6 +38,7 @@ export function AdvancedSection({ test, surface }) {
38
38
  ]
39
39
  ];
40
40
  return /*#__PURE__*/ _jsxs(Section, {
41
+ surface: surface,
41
42
  test: test,
42
43
  sectionId: "advanced",
43
44
  children: [
@@ -195,6 +195,7 @@ export function GoalSection({ test, surface, embedded = false }) {
195
195
  primaryMetricKind: kind
196
196
  }).baseline : null;
197
197
  return /*#__PURE__*/ _jsxs(Section, {
198
+ surface: surface,
198
199
  test: test,
199
200
  sectionId: "win",
200
201
  children: [
@@ -1,2 +1,2 @@
1
1
  import type { SectionProps } from '../contracts.js';
2
- export declare function LengthSection({ test }: SectionProps): import("react").JSX.Element;
2
+ export declare function LengthSection({ test, surface }: SectionProps): import("react").JSX.Element;
@@ -5,7 +5,7 @@ import { TEST_PAGE as C, suggestedWeeks, weeksHint } from '../../copy/testPage.j
5
5
  import { durationSuggestion } from './testPage.model.js';
6
6
  import { FieldErrors, positiveInteger, reasonFor, save, TextEdit } from './fields.js';
7
7
  import { Section } from './Section.js';
8
- export function LengthSection({ test }) {
8
+ export function LengthSection({ test, surface }) {
9
9
  const doc = test.doc;
10
10
  const reason = reasonFor(test, 'analysis');
11
11
  const suggestion = durationSuggestion(test.preflight, doc.analysis?.plannedDurationDays);
@@ -20,6 +20,7 @@ export function LengthSection({ test }) {
20
20
  }
21
21
  }));
22
22
  return /*#__PURE__*/ _jsxs(Section, {
23
+ surface: surface,
23
24
  test: test,
24
25
  sectionId: "length",
25
26
  children: [
@@ -2,13 +2,16 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { useEffect, useRef, useState } from 'react';
4
4
  import { SECTION_ORDER } from '../contracts.js';
5
+ import { sectionBlocked } from '../readiness/readiness.model.js';
5
6
  import { readinessParts } from '../readiness/parts.js';
6
7
  import { TEST_PAGE as C } from '../../copy/testPage.js';
8
+ import { READINESS_COPY } from '../../copy/readiness.js';
7
9
  import { jumpToSection } from './jumpToSection.js';
8
10
  export function Rail({ test }) {
9
11
  const [active, setActive] = useState('what');
10
12
  const ref = useRef(null);
11
13
  const done = readinessParts.sectionDone(test);
14
+ const blocked = (id)=>(test.doc?.status === 'draft' || test.doc?.status === 'stopped') && sectionBlocked(test, id);
12
15
  useEffect(()=>{
13
16
  if (typeof IntersectionObserver === 'undefined') return;
14
17
  const visible = new Map();
@@ -53,7 +56,7 @@ export function Rail({ test }) {
53
56
  children: SECTION_ORDER.map((id)=>/*#__PURE__*/ _jsx("li", {
54
57
  children: /*#__PURE__*/ _jsxs("a", {
55
58
  href: `#section-${id}`,
56
- className: `xp-test-rail-item${id === 'advanced' ? ' xp-test-rail-item--advanced' : ''}${active === id ? ' is-active' : ''}`,
59
+ className: `xp-test-rail-item${blocked(id) ? ' is-blocked' : ''}${id === 'advanced' ? ' xp-test-rail-item--advanced' : ''}${active === id ? ' is-active' : ''}`,
57
60
  "aria-current": active === id ? 'location' : undefined,
58
61
  onClick: (event)=>{
59
62
  event.preventDefault();
@@ -65,12 +68,12 @@ export function Rail({ test }) {
65
68
  children: [
66
69
  /*#__PURE__*/ _jsx("span", {
67
70
  "aria-hidden": "true",
68
- className: done[id] ? 'xp-test-rail-mark xp-test-rail-mark--done' : 'xp-test-rail-mark',
69
- children: done[id] ? C.completeMark : C.incompleteMark
71
+ className: blocked(id) ? 'xp-test-rail-mark xp-test-rail-mark--blocked' : done[id] ? 'xp-test-rail-mark xp-test-rail-mark--done' : 'xp-test-rail-mark',
72
+ children: blocked(id) ? '!' : done[id] ? C.completeMark : C.incompleteMark
70
73
  }),
71
74
  /*#__PURE__*/ _jsx("span", {
72
75
  className: "xp-test-sr-only",
73
- children: done[id] ? C.completePrefix : C.incompletePrefix
76
+ children: blocked(id) ? READINESS_COPY.needsAttentionPrefix : done[id] ? C.completePrefix : C.incompletePrefix
74
77
  })
75
78
  ]
76
79
  }) : null,
@@ -26,8 +26,7 @@ import { ReadinessContent } from '../readiness/Banner.js';
26
26
  role: "region",
27
27
  "aria-label": C.label,
28
28
  children: props.test.doc ? /*#__PURE__*/ _jsx(ReadinessContent, {
29
- ...props,
30
- bar: true
29
+ ...props
31
30
  }, `${props.test.doc.id}/${props.test.doc.status}`) : null
32
31
  });
33
32
  }
@@ -1,7 +1,9 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import type { SectionId, TestDocApi } from '../contracts.js';
3
- export declare function Section({ test, sectionId, children }: {
3
+ import type { SurfaceProps } from '../contracts.js';
4
+ export declare function Section({ test, sectionId, children, surface }: {
4
5
  test: TestDocApi;
5
6
  sectionId: SectionId;
6
7
  children: ReactNode;
8
+ surface?: SurfaceProps;
7
9
  }): import("react").JSX.Element;
@@ -1,11 +1,13 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useState } from 'react';
4
+ import { blockingSteps, pageReadinessContext, sectionBlocked } from '../readiness/readiness.model.js';
4
5
  import { readinessParts } from '../readiness/parts.js';
5
6
  import { SectionCard } from '../../../ui/SectionCard.js';
6
7
  import { SECTION_ORDER } from '../contracts.js';
8
+ import { fixFieldsNext } from '../../copy/readiness.js';
7
9
  import { TEST_PAGE as C } from '../../copy/testPage.js';
8
- export function Section({ test, sectionId, children }) {
10
+ export function Section({ test, sectionId, children, surface }) {
9
11
  const hasAdvancedError = Object.keys(test.errors).some((path)=>path.startsWith('analysis.') && ![
10
12
  'analysis.reachPerDay',
11
13
  'analysis.plannedDurationDays'
@@ -16,11 +18,34 @@ export function Section({ test, sectionId, children }) {
16
18
  setPrevHasAdvancedError(hasAdvancedError);
17
19
  if (hasAdvancedError) setOpen(true);
18
20
  }
21
+ const setup = test.doc?.status === 'draft' || test.doc?.status === 'stopped';
22
+ const blocked = setup && sectionBlocked(test, sectionId);
23
+ const blockers = setup && test.doc ? blockingSteps(test.preflight, surface ? pageReadinessContext(test.doc, test.preflight, surface) : test.doc).filter((step)=>step.section === sectionId) : [];
19
24
  const done = readinessParts.sectionDone(test)[sectionId];
25
+ const blockerLines = blockers.map((step, index)=>/*#__PURE__*/ _jsxs("p", {
26
+ className: "xp-ui-error xp-test-blocker",
27
+ children: [
28
+ /*#__PURE__*/ _jsx("span", {
29
+ "aria-hidden": "true",
30
+ children: "⊗ "
31
+ }),
32
+ step.sentence
33
+ ]
34
+ }, `${step.code}-${index}`));
35
+ if (setup && sectionId === 'advanced' && hasAdvancedError) blockerLines.push(/*#__PURE__*/ _jsxs("p", {
36
+ className: "xp-ui-error xp-test-blocker",
37
+ children: [
38
+ /*#__PURE__*/ _jsx("span", {
39
+ "aria-hidden": "true",
40
+ children: "⊗ "
41
+ }),
42
+ fixFieldsNext(C.sections.advanced)
43
+ ]
44
+ }, "advanced-validation"));
20
45
  if (sectionId === 'advanced') return /*#__PURE__*/ _jsxs("details", {
21
46
  open: open,
22
47
  onToggle: (event)=>setOpen(event.currentTarget.open),
23
- className: "xp-test-advanced",
48
+ className: `xp-test-advanced${blocked ? ' xp-ui-section--blocked' : ''}`,
24
49
  id: "section-advanced",
25
50
  children: [
26
51
  /*#__PURE__*/ _jsx("summary", {
@@ -30,19 +55,26 @@ export function Section({ test, sectionId, children }) {
30
55
  children: C.sections.advanced
31
56
  })
32
57
  }),
33
- /*#__PURE__*/ _jsx("div", {
58
+ /*#__PURE__*/ _jsxs("div", {
34
59
  className: "xp-ui-section-body",
35
- children: children
60
+ children: [
61
+ children,
62
+ blockerLines
63
+ ]
36
64
  })
37
65
  ]
38
66
  });
39
- return /*#__PURE__*/ _jsx(SectionCard, {
67
+ return /*#__PURE__*/ _jsxs(SectionCard, {
40
68
  number: SECTION_ORDER.indexOf(sectionId) + 1,
41
69
  title: C.sections[sectionId],
42
70
  complete: done,
71
+ blocked: blocked,
43
72
  id: `section-${sectionId}`,
44
73
  headingId: `title-${sectionId}`,
45
74
  className: "xp-test-section",
46
- children: children
75
+ children: [
76
+ children,
77
+ blockerLines
78
+ ]
47
79
  });
48
80
  }
@@ -22,6 +22,7 @@ export function TargetingSection({ test, surface }) {
22
22
  const blockPath = (key)=>test.doc.kind === 'block' && key === 'path';
23
23
  const keys = Object.keys(surface.attributeKeys).filter((key)=>!blockPath(key));
24
24
  return /*#__PURE__*/ _jsxs(Section, {
25
+ surface: surface,
25
26
  test: test,
26
27
  sectionId: "who",
27
28
  children: [
@@ -179,6 +180,10 @@ export function TargetingSection({ test, surface }) {
179
180
  ]
180
181
  }, `${rowsRevision}-${index}`);
181
182
  }),
183
+ !reason && !keys.length ? /*#__PURE__*/ _jsx("p", {
184
+ className: "xp-ui-help",
185
+ children: C.noAudienceRules
186
+ }) : null,
182
187
  !reason ? /*#__PURE__*/ _jsx("div", {
183
188
  className: "xp-ui-button-group",
184
189
  children: /*#__PURE__*/ _jsx(Button, {
@@ -4,7 +4,7 @@ import type { SurfaceProps, TestDocApi } from '../contracts.js';
4
4
  import type { TestDocument } from '../testDocument.model.js';
5
5
  import type { PreflightResult } from '../../../types/endpoints.js';
6
6
  import './testPage.css';
7
- export declare function TestSurface({ id, surface, onTitleChange, renderFrame, embedded, onDocument, onPreflight }: {
7
+ export declare function TestSurface({ id, surface, onTitleChange, renderFrame, embedded, onDocument, onPreflight, requestPreflight }: {
8
8
  id: DocId;
9
9
  surface: SurfaceProps;
10
10
  onTitleChange?: (title: string) => void;
@@ -15,4 +15,5 @@ export declare function TestSurface({ id, surface, onTitleChange, renderFrame, e
15
15
  }) => ReactNode;
16
16
  onDocument?: (doc: TestDocument) => void;
17
17
  onPreflight?: (preflight: PreflightResult) => void;
18
+ requestPreflight?: (signal: AbortSignal, supersede?: boolean) => Promise<Response>;
18
19
  }): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null | undefined;
@@ -1,7 +1,8 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useEffect, useState } from 'react';
3
+ import { useEffect, useState, useRef } from 'react';
4
4
  import { useTestDocument } from '../useTestDocument.js';
5
+ import { API_MESSAGES } from '../../copy/common.js';
5
6
  import { TEST_PAGE as C } from '../../copy/testPage.js';
6
7
  import { pageBlockParts } from '../pageBlock/parts.js';
7
8
  import { settingParts } from '../setting/parts.js';
@@ -18,10 +19,14 @@ import { Banner } from '../../../ui/Feedback.js';
18
19
  import { Rail } from './Rail.js';
19
20
  import { ReadinessBar } from './ReadinessBar.js';
20
21
  import { ResultsBody } from '../results/ResultsBody.js';
22
+ import { usePlacementNotice } from '../../../puck/editor/usePlacementNotice.js';
23
+ import { subscribePlacements, cachedPreflight, cachedReadinessRead, placementsPending, placementsBlocking, placementReadError } from '../../../puck/editor/placementsCache.js';
24
+ import { currentPuckDocument } from '../../../puck/editor/editor.model.js';
25
+ import { editorPlacementMessage, editorPreflight } from '../editorPlacement.js';
21
26
  import './testPage.css';
22
- export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded = false, onDocument, onPreflight }) {
27
+ export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded = false, onDocument, onPreflight, requestPreflight }) {
23
28
  const [barHeight, setBarHeight] = useState();
24
- const test = useTestDocument(id, {
29
+ const documentState = useTestDocument(id, {
25
30
  apiRoute: surface.apiRoute,
26
31
  refetchPreflightOnFocus: true,
27
32
  ...!surface.canManage ? {
@@ -32,8 +37,63 @@ export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded
32
37
  } : {},
33
38
  ...onPreflight ? {
34
39
  onPreflight
40
+ } : {},
41
+ ...requestPreflight ? {
42
+ requestPreflight
35
43
  } : {}
36
44
  });
45
+ const [placementRead, setPlacementRead] = useState();
46
+ const placementKey = JSON.stringify([
47
+ surface.apiRoute,
48
+ String(id)
49
+ ]);
50
+ const watching = embedded && surface.canManage && documentState.loadState === 'ready';
51
+ useEffect(()=>{
52
+ if (!embedded || !surface.canManage) return;
53
+ return subscribePlacements(surface.apiRoute, id, ()=>setPlacementRead({
54
+ key: placementKey,
55
+ preflight: cachedPreflight(surface.apiRoute, id),
56
+ read: cachedReadinessRead(surface.apiRoute, id),
57
+ pending: placementsPending(surface.apiRoute, id),
58
+ blocking: placementsBlocking(surface.apiRoute, id),
59
+ error: placementReadError(surface.apiRoute, id)
60
+ }));
61
+ }, [
62
+ surface.apiRoute,
63
+ id,
64
+ embedded,
65
+ surface.canManage,
66
+ placementKey
67
+ ]);
68
+ const currentRead = documentState.loadState === 'ready' && placementRead?.key === placementKey ? placementRead : undefined;
69
+ const preflight = currentRead ? currentRead.preflight ?? (currentRead.pending && !currentRead.error ? documentState.preflight : null) : documentState.preflight;
70
+ const sharedDocument = currentRead ? {
71
+ ...documentState,
72
+ preflight,
73
+ preflightRead: currentRead.read,
74
+ preflightPending: currentRead.pending || documentState.preflightPending,
75
+ preflightError: !preflight ? currentRead.read?.message ?? null : null
76
+ } : documentState;
77
+ const placementFailed = preflight?.checks.some((check)=>!check.ok && check.code === 'no-placements' && check.detail !== undefined);
78
+ const lastPlacements = useRef(undefined);
79
+ if (preflight?.placements && !placementFailed) lastPlacements.current = {
80
+ key: placementKey,
81
+ value: preflight.placements
82
+ };
83
+ const placements = !placementFailed && !sharedDocument.preflightError && lastPlacements.current?.key === placementKey ? lastPlacements.current.value : undefined;
84
+ const editorPage = embedded ? currentPuckDocument(window.location.pathname, surface.adminRoute, placements) ?? surface.editorPage : surface.editorPage;
85
+ const message = editorPlacementMessage(placements, editorPage, documentState.doc?.status);
86
+ surface = {
87
+ ...surface,
88
+ editorPage,
89
+ editorPlacementMessage: message
90
+ };
91
+ usePlacementNotice(surface.apiRoute, id, watching ? sharedDocument.preflightError ?? (placementFailed ? placementReadError(surface.apiRoute, id) : message) : undefined);
92
+ const setup = documentState.doc?.status === 'draft' || documentState.doc?.status === 'stopped';
93
+ const test = setup ? {
94
+ ...sharedDocument,
95
+ preflight: editorPreflight(preflight, surface)
96
+ } : sharedDocument;
37
97
  useEffect(()=>{
38
98
  if (test.doc?.name) onTitleChange?.(test.doc.name);
39
99
  }, [
@@ -60,9 +120,9 @@ export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded
60
120
  role: test.loadState === 'error' ? 'alert' : 'status',
61
121
  children: [
62
122
  /*#__PURE__*/ _jsx("p", {
63
- children: test.loadState === 'forbidden' ? C.forbidden : test.loadState === 'missing' ? C.missing : test.loadState === 'error' ? C.error : C.loading
123
+ children: test.preflightRead?.kind === 'signed-out' ? API_MESSAGES.unauthenticated : test.loadState === 'forbidden' ? C.forbidden : test.loadState === 'missing' ? C.missing : test.loadState === 'error' ? C.error : C.loading
64
124
  }),
65
- test.loadState === 'error' ? /*#__PURE__*/ _jsx(Button, {
125
+ test.preflightRead?.retry ?? test.loadState === 'error' ? /*#__PURE__*/ _jsx(Button, {
66
126
  onClick: ()=>void test.reload(),
67
127
  children: C.retry
68
128
  }) : null
@@ -90,13 +150,14 @@ export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded
90
150
  children: [
91
151
  test.errors._section ? /*#__PURE__*/ _jsx(Banner, {
92
152
  tone: "error",
93
- action: test.stale ? /*#__PURE__*/ _jsx(Button, {
153
+ action: /*#__PURE__*/ _jsx(Button, {
94
154
  onClick: ()=>void test.reload(),
95
155
  children: C.reload
96
- }) : undefined,
156
+ }),
97
157
  children: test.errors._section
98
158
  }) : null,
99
159
  /*#__PURE__*/ _jsxs(Section, {
160
+ surface: surface,
100
161
  test: test,
101
162
  sectionId: "what",
102
163
  children: [
@@ -48,6 +48,7 @@ export function VersionsSection({ test, surface, parts, contentOnCanvas = false
48
48
  }));
49
49
  };
50
50
  return /*#__PURE__*/ _jsxs(Section, {
51
+ surface: surface,
51
52
  test: test,
52
53
  sectionId: "versions",
53
54
  children: [
@@ -90,3 +90,15 @@
90
90
 
91
91
  :where(.xp-test-surface) .xp-ui-checkbox-list > .xp-ui-field:has(input[type="search"]) { flex-basis: 100%; }
92
92
  :where(.xp-test-surface) .xp-targeting-row .xp-ui-chips { margin-block: 0; }
93
+
94
+ :where(.xp-test-surface) .xp-test-rail-mark--blocked { color: var(--xp-error); }
95
+ :where(.xp-test-surface) .xp-test-rail-item.is-blocked { border-color: var(--xp-error-border); }
96
+ :where(.xp-test-surface) .xp-ui-section--blocked h2:focus, :where(.xp-test-surface) .xp-test-rail-item.is-blocked:focus-visible { outline-color: var(--xp-error); }
97
+ :where(.xp-test-surface) .xp-readiness__warning { color: var(--xp-warning); border-inline-start: 3px solid var(--xp-warning-border); padding-inline-start: var(--xp-space-2); }
98
+
99
+ :where(.xp-test-surface) .xp-readiness--bar { grid-template-columns: minmax(0, 1fr); }
100
+ :where(.xp-test-surface) .xp-readiness--bar > .xp-readiness__actions { grid-column: 1; grid-row: auto; justify-content: flex-start; }
101
+ :where(.xp-test-surface) .xp-readiness-action-reason { display: block; }
102
+
103
+ :where(.xp-test-surface) .xp-test-advanced.xp-ui-section--blocked { border-color: var(--xp-error-border); }
104
+ :where(.xp-test-surface) .xp-test-rail-mark--blocked { display: grid; place-items: center; width: 20px; height: 20px; border: 1px solid var(--xp-error-border); border-radius: 50%; }
@@ -1,18 +1,20 @@
1
1
  import type { Arm, DocId } from '../../types/contracts.js';
2
2
  import type { PreflightResult } from '../../types/endpoints.js';
3
+ import { type ReadinessRead } from '../readinessRead.js';
3
4
  import type { TestDocument, TestDocumentPatch } from './testDocument.model.js';
4
5
  /** Section data only: staging never saves. Call commit on blur or a section action. */
5
- export declare function useTestDocument(id: DocId, { apiRoute, refetchPreflightOnFocus, enabled, onDocument, onPreflight }: {
6
+ export declare function useTestDocument(id: DocId, { apiRoute, refetchPreflightOnFocus, enabled, onDocument, onPreflight, requestPreflight }: {
6
7
  apiRoute: string;
7
8
  refetchPreflightOnFocus?: boolean;
8
9
  enabled?: boolean;
9
10
  onDocument?: (doc: TestDocument) => void;
10
11
  onPreflight?: (preflight: PreflightResult) => void;
12
+ requestPreflight?: (signal: AbortSignal, supersede?: boolean) => Promise<Response>;
11
13
  }): {
12
14
  stage: (partial: TestDocumentPatch) => void;
13
15
  commit: () => Promise<void>;
14
16
  reload: () => Promise<void>;
15
- refreshPreflight: () => Promise<void>;
17
+ refreshPreflight: (supersede?: boolean) => Promise<void>;
16
18
  choosePage: (arm: Arm["key"], page: {
17
19
  id: DocId;
18
20
  path: string;
@@ -27,6 +29,7 @@ export declare function useTestDocument(id: DocId, { apiRoute, refetchPreflightO
27
29
  }>>;
28
30
  doc: TestDocument | null;
29
31
  preflight: PreflightResult | null;
32
+ preflightRead?: ReadinessRead;
30
33
  preflightError: string | null;
31
34
  preflightPending: boolean;
32
35
  /** Includes staged edits and all queued or in-flight PATCHes. */