@delmaredigital/payload-experiments 0.4.0 → 0.5.0

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 (290) hide show
  1. package/README.md +10 -4
  2. package/dist/admin/blocks/model.js +2 -0
  3. package/dist/admin/copy/blocks.d.ts +1 -0
  4. package/dist/admin/copy/blocks.js +1 -0
  5. package/dist/admin/copy/status.d.ts +3 -0
  6. package/dist/admin/copy/status.js +3 -0
  7. package/dist/admin/placementStatus.model.js +3 -0
  8. package/dist/admin/status.model.d.ts +3 -2
  9. package/dist/admin/status.model.js +9 -3
  10. package/dist/admin/surface/ResultsRoute.js +2 -1
  11. package/dist/admin/surface/TestsHome.d.ts +2 -1
  12. package/dist/admin/surface/TestsHome.js +31 -11
  13. package/dist/admin/surface/TestsSurface.js +4 -0
  14. package/dist/admin/surface/home.model.d.ts +11 -6
  15. package/dist/admin/surface/home.model.js +19 -8
  16. package/dist/admin/surface/newTest/PageWizard.js +13 -3
  17. package/dist/admin/surface/results/ResultsHeader.js +43 -9
  18. package/dist/admin/surface/test/TestPage.js +11 -1
  19. package/dist/admin/useLayerUsage.d.ts +1 -1
  20. package/dist/admin/views/buildSurfaceProps.js +3 -0
  21. package/dist/cohorts/build.d.ts +35 -0
  22. package/dist/cohorts/build.js +134 -0
  23. package/dist/cohorts/key.d.ts +12 -0
  24. package/dist/cohorts/key.js +15 -0
  25. package/dist/cohorts/maintenance.d.ts +10 -0
  26. package/dist/cohorts/maintenance.js +70 -0
  27. package/dist/cohorts/readiness.d.ts +30 -0
  28. package/dist/cohorts/readiness.js +54 -0
  29. package/dist/cohorts/readinessData.d.ts +29 -0
  30. package/dist/cohorts/readinessData.js +123 -0
  31. package/dist/cohorts/rule.d.ts +33 -0
  32. package/dist/cohorts/rule.js +50 -0
  33. package/dist/collections/cohortMembers.d.ts +4 -0
  34. package/dist/collections/cohortMembers.js +95 -0
  35. package/dist/collections/experiments/config.js +157 -7
  36. package/dist/collections/experiments/editability.js +10 -6
  37. package/dist/collections/experiments/lockHook.js +39 -20
  38. package/dist/collections/index.js +4 -1
  39. package/dist/collections/phases.js +4 -1
  40. package/dist/constants.d.ts +2 -0
  41. package/dist/constants.js +2 -0
  42. package/dist/db/adapter.d.ts +1 -1
  43. package/dist/db/adapter.js +14 -4
  44. package/dist/db/appends.js +1 -1
  45. package/dist/db/cohortMembership.d.ts +11 -0
  46. package/dist/db/cohortMembership.js +31 -0
  47. package/dist/db/cohortPool.d.ts +9 -0
  48. package/dist/db/cohortPool.js +53 -0
  49. package/dist/db/cohortTransactions.d.ts +3 -0
  50. package/dist/db/cohortTransactions.js +52 -0
  51. package/dist/db/cohorts.d.ts +72 -0
  52. package/dist/db/cohorts.js +280 -0
  53. package/dist/db/erase.d.ts +2 -0
  54. package/dist/db/erase.js +21 -2
  55. package/dist/db/events.d.ts +2 -0
  56. package/dist/db/events.js +8 -0
  57. package/dist/db/executor.d.ts +2 -0
  58. package/dist/db/executor.js +8 -0
  59. package/dist/db/locks.d.ts +7 -0
  60. package/dist/db/locks.js +13 -1
  61. package/dist/db/names.d.ts +95 -1
  62. package/dist/db/names.js +95 -1
  63. package/dist/db/occupancy.d.ts +21 -0
  64. package/dist/db/occupancy.js +46 -0
  65. package/dist/db/pageOccupancy.d.ts +4 -4
  66. package/dist/db/pageOccupancy.js +13 -10
  67. package/dist/db/pgExecutor.d.ts +4 -0
  68. package/dist/db/pgExecutor.js +1 -1
  69. package/dist/db/placements.js +1 -1
  70. package/dist/db/results.d.ts +5 -2
  71. package/dist/db/results.js +32 -5
  72. package/dist/db/slices.d.ts +9 -2
  73. package/dist/db/slices.js +15 -8
  74. package/dist/db/snapshots.d.ts +16 -1
  75. package/dist/db/snapshots.js +27 -2
  76. package/dist/db/sql.d.ts +2 -2
  77. package/dist/db/sql.js +1 -2
  78. package/dist/endpoints/cohortSources.d.ts +16 -0
  79. package/dist/endpoints/cohortSources.js +335 -0
  80. package/dist/endpoints/contentLocale.d.ts +1 -1
  81. package/dist/endpoints/events.js +82 -18
  82. package/dist/endpoints/index.js +45 -1
  83. package/dist/endpoints/pausedBy.d.ts +14 -0
  84. package/dist/endpoints/pausedBy.js +94 -0
  85. package/dist/endpoints/preflight.js +4 -1
  86. package/dist/endpoints/previewToken.js +2 -0
  87. package/dist/endpoints/results.d.ts +2 -2
  88. package/dist/endpoints/results.js +111 -3
  89. package/dist/endpoints/routeId.d.ts +2 -1
  90. package/dist/endpoints/routeId.js +6 -2
  91. package/dist/endpoints/summary.js +24 -1
  92. package/dist/endpoints/transitions.d.ts +7 -0
  93. package/dist/endpoints/transitions.js +50 -1
  94. package/dist/events/rows.d.ts +1 -1
  95. package/dist/events/rows.js +5 -3
  96. package/dist/exports/index.d.ts +2 -0
  97. package/dist/exports/index.js +1 -0
  98. package/dist/exports/runtimeProxy.d.ts +1 -0
  99. package/dist/exports/runtimeProxy.js +1 -0
  100. package/dist/hooks/blockRemovalRule.js +7 -4
  101. package/dist/hooks/pageGuard.js +1 -1
  102. package/dist/labels/status.d.ts +15 -0
  103. package/dist/labels/status.js +12 -0
  104. package/dist/manifest/compile.d.ts +15 -4
  105. package/dist/manifest/compile.js +91 -3
  106. package/dist/onInit.js +4 -1
  107. package/dist/options.d.ts +1 -0
  108. package/dist/options.js +10 -0
  109. package/dist/proxy/consentFallback.d.ts +1 -1
  110. package/dist/proxy/consentFallback.js +4 -4
  111. package/dist/proxy/control.d.ts +1 -1
  112. package/dist/proxy/control.js +2 -2
  113. package/dist/proxy/pageRewrite.d.ts +1 -1
  114. package/dist/proxy/pageRewrite.js +3 -2
  115. package/dist/proxy/resolve.js +76 -17
  116. package/dist/puck/ExperimentPicker.js +2 -1
  117. package/dist/puck/copy.d.ts +6 -5
  118. package/dist/puck/copy.js +3 -7
  119. package/dist/puck/editor/ExperimentSlotEditor.js +16 -5
  120. package/dist/puck/editor/QuickTestActions.js +7 -1
  121. package/dist/puck/editor/armWrites.js +6 -1
  122. package/dist/puck/editor/copy.d.ts +3 -0
  123. package/dist/puck/editor/copy.js +3 -0
  124. package/dist/puck/editor/editor.css +2 -1
  125. package/dist/puck/editor/editor.model.d.ts +2 -1
  126. package/dist/puck/editor/editor.model.js +2 -0
  127. package/dist/puck/editor/placementsCache.d.ts +1 -1
  128. package/dist/puck/editor/placementsCache.js +6 -3
  129. package/dist/results/analyse.d.ts +3 -1
  130. package/dist/results/analyse.js +20 -3
  131. package/dist/results/health.d.ts +11 -0
  132. package/dist/results/health.js +38 -0
  133. package/dist/results/power.d.ts +1 -1
  134. package/dist/results/power.js +1 -1
  135. package/dist/results/snapshot.d.ts +8 -2
  136. package/dist/results/snapshot.js +23 -1
  137. package/dist/results/unitValues.d.ts +48 -0
  138. package/dist/results/unitValues.js +166 -0
  139. package/dist/runtime/assign.d.ts +7 -3
  140. package/dist/runtime/assign.js +12 -4
  141. package/dist/runtime/cohortCookie.d.ts +15 -0
  142. package/dist/runtime/cohortCookie.js +72 -0
  143. package/dist/runtime/cohortLookup.d.ts +9 -0
  144. package/dist/runtime/cohortLookup.js +25 -0
  145. package/dist/runtime/eligibility.d.ts +11 -5
  146. package/dist/runtime/eligibility.js +33 -7
  147. package/dist/runtime/header.d.ts +1 -0
  148. package/dist/runtime/header.js +1 -1
  149. package/dist/runtime/proxyRuntime.js +5 -1
  150. package/dist/runtime/targeting.d.ts +3 -2
  151. package/dist/runtime/targeting.js +2 -1
  152. package/dist/sanitizeReadinessDetail.d.ts +2 -2
  153. package/dist/sanitizeReadinessDetail.js +41 -4
  154. package/dist/schedule/activeTime.d.ts +28 -0
  155. package/dist/schedule/activeTime.js +322 -0
  156. package/dist/schedule/ranges.d.ts +13 -0
  157. package/dist/schedule/ranges.js +11 -0
  158. package/dist/schedule/roundTime.d.ts +10 -0
  159. package/dist/schedule/roundTime.js +45 -0
  160. package/dist/schedule/types.d.ts +29 -0
  161. package/dist/schedule/types.js +1 -0
  162. package/dist/server/cohortLookup.d.ts +3 -0
  163. package/dist/server/cohortLookup.js +7 -0
  164. package/dist/server/eraseUser.d.ts +1 -0
  165. package/dist/server/getAssignments.js +63 -40
  166. package/dist/server/previewDraft.d.ts +1 -1
  167. package/dist/server/previewDraft.js +3 -2
  168. package/dist/server/recordExposures.js +4 -2
  169. package/dist/server/runResults.js +97 -150
  170. package/dist/testSurface/actions/LifecycleAction.d.ts +2 -1
  171. package/dist/testSurface/actions/LifecycleAction.js +15 -5
  172. package/dist/testSurface/actions/actions.model.d.ts +13 -2
  173. package/dist/testSurface/actions/actions.model.js +38 -5
  174. package/dist/testSurface/api.d.ts +13 -1
  175. package/dist/testSurface/api.js +19 -0
  176. package/dist/testSurface/copy/actions.d.ts +13 -0
  177. package/dist/testSurface/copy/actions.js +13 -0
  178. package/dist/testSurface/copy/cohorts.d.ts +68 -0
  179. package/dist/testSurface/copy/cohorts.js +81 -0
  180. package/dist/testSurface/copy/common.d.ts +2 -3
  181. package/dist/testSurface/copy/common.js +4 -4
  182. package/dist/testSurface/copy/inputs.d.ts +3 -0
  183. package/dist/testSurface/copy/inputs.js +3 -0
  184. package/dist/testSurface/copy/readiness.d.ts +20 -6
  185. package/dist/testSurface/copy/readiness.js +42 -9
  186. package/dist/testSurface/copy/results.d.ts +1 -0
  187. package/dist/testSurface/copy/results.js +1 -0
  188. package/dist/testSurface/copy/schedule.d.ts +58 -0
  189. package/dist/testSurface/copy/schedule.js +150 -0
  190. package/dist/testSurface/copy/surface.d.ts +2 -0
  191. package/dist/testSurface/copy/surface.js +2 -0
  192. package/dist/testSurface/copy/testPage.d.ts +12 -2
  193. package/dist/testSurface/copy/testPage.js +17 -2
  194. package/dist/testSurface/format/roundProgress.d.ts +13 -1
  195. package/dist/testSurface/format/roundProgress.js +34 -5
  196. package/dist/testSurface/format/scheduleStatus.d.ts +34 -0
  197. package/dist/testSurface/format/scheduleStatus.js +93 -0
  198. package/dist/testSurface/format/useScheduleClock.d.ts +3 -0
  199. package/dist/testSurface/format/useScheduleClock.js +20 -0
  200. package/dist/testSurface/labels.d.ts +4 -9
  201. package/dist/testSurface/labels.js +2 -7
  202. package/dist/testSurface/lockedNotice.model.d.ts +2 -2
  203. package/dist/testSurface/lockedNotice.model.js +16 -3
  204. package/dist/testSurface/readPreflight.d.ts +3 -0
  205. package/dist/testSurface/readPreflight.js +14 -0
  206. package/dist/testSurface/readinessRead.d.ts +2 -2
  207. package/dist/testSurface/results/DataQualityPanel.js +7 -7
  208. package/dist/testSurface/results/results.model.d.ts +1 -1
  209. package/dist/testSurface/results/results.model.js +34 -6
  210. package/dist/testSurface/review/cohortEstimate.d.ts +11 -0
  211. package/dist/testSurface/review/cohortEstimate.js +32 -0
  212. package/dist/testSurface/surface/contracts.d.ts +2 -1
  213. package/dist/testSurface/surface/contracts.js +1 -0
  214. package/dist/testSurface/surface/editorPlacement.d.ts +1 -0
  215. package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +3 -2
  216. package/dist/testSurface/surface/readiness/ActionDialogs.js +121 -32
  217. package/dist/testSurface/surface/readiness/Banner.js +29 -11
  218. package/dist/testSurface/surface/readiness/readiness.model.d.ts +20 -2
  219. package/dist/testSurface/surface/readiness/readiness.model.js +35 -5
  220. package/dist/testSurface/surface/readiness/useTransition.js +17 -5
  221. package/dist/testSurface/surface/results/ResultsBody.js +46 -10
  222. package/dist/testSurface/surface/results/useResults.d.ts +16 -1
  223. package/dist/testSurface/surface/results/useResults.js +17 -6
  224. package/dist/testSurface/surface/test/CohortRuleEditor.d.ts +16 -0
  225. package/dist/testSurface/surface/test/CohortRuleEditor.js +492 -0
  226. package/dist/testSurface/surface/test/LengthSection.js +26 -6
  227. package/dist/testSurface/surface/test/ScheduleDateInput.d.ts +4 -0
  228. package/dist/testSurface/surface/test/ScheduleDateInput.js +15 -0
  229. package/dist/testSurface/surface/test/ScheduleSection.d.ts +2 -0
  230. package/dist/testSurface/surface/test/ScheduleSection.js +322 -0
  231. package/dist/testSurface/surface/test/Section.js +1 -1
  232. package/dist/testSurface/surface/test/TargetingSection.js +306 -182
  233. package/dist/testSurface/surface/test/TestSurface.js +9 -0
  234. package/dist/testSurface/surface/test/fields.d.ts +2 -1
  235. package/dist/testSurface/surface/test/fields.js +3 -3
  236. package/dist/testSurface/surface/test/jumpToSection.d.ts +1 -1
  237. package/dist/testSurface/surface/test/jumpToSection.js +4 -4
  238. package/dist/testSurface/surface/test/testPage.css +26 -0
  239. package/dist/testSurface/surface/testDocument.model.d.ts +12 -1
  240. package/dist/testSurface/surface/testDocument.model.js +2 -1
  241. package/dist/testSurface/surface/useTestDocument.js +11 -4
  242. package/dist/testSurface/targeting/targeting.model.d.ts +2 -1
  243. package/dist/testSurface/targeting/targeting.model.js +1 -1
  244. package/dist/testSurface/useApi.d.ts +12 -0
  245. package/dist/transitions/addMetric.js +5 -2
  246. package/dist/transitions/allocate.js +6 -1
  247. package/dist/transitions/assertNoOverlap.d.ts +9 -0
  248. package/dist/transitions/assertNoOverlap.js +24 -0
  249. package/dist/transitions/buildCohorts.d.ts +10 -0
  250. package/dist/transitions/buildCohorts.js +68 -0
  251. package/dist/transitions/cancelSchedule.d.ts +4 -0
  252. package/dist/transitions/cancelSchedule.js +42 -0
  253. package/dist/transitions/checkStart.d.ts +17 -3
  254. package/dist/transitions/checkStart.js +20 -7
  255. package/dist/transitions/decide.js +35 -11
  256. package/dist/transitions/kernel.d.ts +3 -1
  257. package/dist/transitions/kernel.js +5 -2
  258. package/dist/transitions/pause.d.ts +4 -0
  259. package/dist/transitions/pause.js +35 -0
  260. package/dist/transitions/phaseRecord.d.ts +19 -2
  261. package/dist/transitions/phaseRecord.js +50 -11
  262. package/dist/transitions/placementInteractions.js +1 -1
  263. package/dist/transitions/preflightData.d.ts +11 -3
  264. package/dist/transitions/preflightData.js +134 -81
  265. package/dist/transitions/reschedule.d.ts +4 -0
  266. package/dist/transitions/reschedule.js +58 -0
  267. package/dist/transitions/resume.d.ts +4 -0
  268. package/dist/transitions/resume.js +32 -0
  269. package/dist/transitions/scheduledRound.d.ts +18 -0
  270. package/dist/transitions/scheduledRound.js +42 -0
  271. package/dist/transitions/start.d.ts +4 -0
  272. package/dist/transitions/start.js +136 -55
  273. package/dist/transitions/startReads.d.ts +14 -0
  274. package/dist/transitions/startReads.js +27 -0
  275. package/dist/transitions/stop.d.ts +10 -0
  276. package/dist/transitions/stop.js +35 -22
  277. package/dist/types/admin.d.ts +1 -1
  278. package/dist/types/contracts.d.ts +7 -1
  279. package/dist/types/endpoints.d.ts +72 -3
  280. package/dist/types/manifest.d.ts +9 -0
  281. package/dist/types/runtime.d.ts +5 -0
  282. package/dist/types/snapshot.d.ts +10 -0
  283. package/dist/types/status.d.ts +1 -0
  284. package/dist/types/status.js +1 -0
  285. package/dist/types/surface.d.ts +1 -0
  286. package/dist/ui/Feedback.d.ts +9 -6
  287. package/dist/ui/Feedback.js +10 -9
  288. package/dist/ui/SelectControl.js +1 -1
  289. package/dist/ui/ui.css +2 -1
  290. package/package.json +2 -2
@@ -0,0 +1,492 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useLayoutEffect, useId, useMemo, useRef, useState } from 'react';
4
+ import { Button } from '../../../ui/Button.js';
5
+ import { Select, TextInput } from '../../../ui/Inputs.js';
6
+ import { StatusChip } from '../../../ui/StatusChip.js';
7
+ import { createApi } from '../../api.js';
8
+ import { COHORT_COPY, COHORT_EDITOR as C, cohortGrowth, cohortRoundCount, cohortRoundLabel, cohortRuleSummary, cohortSizeLabel, latestCohortRound } from '../../copy/cohorts.js';
9
+ import { TEST_PAGE } from '../../copy/testPage.js';
10
+ import { PAGE_COPY } from '../../copy/pages.js';
11
+ import { cohortSize, selectedCohortRound } from '../../review/cohortEstimate.js';
12
+ import { FieldErrors, SavedValueChanged, useFieldDraft } from './fields.js';
13
+ import '../pagePicker/pagePicker.css';
14
+ export const EMPTY_COHORT_RULE = {
15
+ kind: 'cohort',
16
+ experiment: '',
17
+ phase: 'latest',
18
+ arms: [],
19
+ include: true
20
+ };
21
+ export function CohortRuleEditor({ test, surface, index, pending = false, draftId, saved, sourceFor, onSource, onSave, onRemove, onDiscard }) {
22
+ const id = useId();
23
+ const savedValue = JSON.stringify(saved);
24
+ const edit = useFieldDraft(test, draftId, C.draftLabel, savedValue);
25
+ const { trackDraft, mountDraft } = test;
26
+ useLayoutEffect(()=>{
27
+ if (!pending || !mountDraft) return;
28
+ const key = `${draftId}:pending`;
29
+ const unmount = mountDraft(key);
30
+ trackDraft(key, {
31
+ label: C.draftLabel,
32
+ base: '',
33
+ value: savedValue
34
+ });
35
+ return ()=>{
36
+ trackDraft(key, null);
37
+ unmount?.();
38
+ };
39
+ }, [
40
+ pending,
41
+ draftId,
42
+ mountDraft,
43
+ trackDraft,
44
+ savedValue
45
+ ]);
46
+ const rule = JSON.parse(edit.value);
47
+ const source = sourceFor(rule.experiment);
48
+ const round = selectedCohortRound(source, rule.phase);
49
+ const open = round != null && (round.closedAt == null || Date.parse(round.closedAt) > Date.now());
50
+ const live = source && [
51
+ 'running',
52
+ 'paused',
53
+ 'scheduled'
54
+ ].includes(source.status) && round?.endedAt === null;
55
+ const size = cohortSize(rule, source);
56
+ const locked = Boolean(test.stale || test.statusReadPending || test.saving === 'saving' || edit.saving);
57
+ const needsChoice = !edit.saving && (edit.conflict || edit.retry);
58
+ const disabled = locked || needsChoice;
59
+ const update = (next)=>{
60
+ const value = JSON.stringify(next);
61
+ if (value === savedValue && !edit.retry) {
62
+ edit.discard();
63
+ return;
64
+ }
65
+ edit.change(value);
66
+ if (next.experiment && next.arms.length) edit.submit(()=>onSave(next));
67
+ };
68
+ return /*#__PURE__*/ _jsxs("div", {
69
+ className: "xp-targeting-row xp-cohort-row",
70
+ id: pending ? undefined : `xp-targeting-${index}`,
71
+ tabIndex: -1,
72
+ children: [
73
+ /*#__PURE__*/ _jsx(CohortSourceCombobox, {
74
+ apiRoute: surface.apiRoute,
75
+ exclude: test.doc.id,
76
+ value: source,
77
+ disabled: disabled,
78
+ focusOnMount: pending,
79
+ onChoose: (choice)=>{
80
+ onSource(choice);
81
+ if (rule.experiment !== String(choice.id)) update({
82
+ ...EMPTY_COHORT_RULE,
83
+ experiment: String(choice.id),
84
+ include: rule.include
85
+ });
86
+ }
87
+ }),
88
+ /*#__PURE__*/ _jsxs(Select, {
89
+ label: C.round,
90
+ id: `${id}-round`,
91
+ value: rule.phase,
92
+ disabled: disabled || !source,
93
+ onChange: (event)=>update({
94
+ ...rule,
95
+ phase: event.target.value === 'latest' ? 'latest' : Number(event.target.value),
96
+ arms: [],
97
+ goal: undefined
98
+ }),
99
+ children: [
100
+ /*#__PURE__*/ _jsx("option", {
101
+ value: "latest",
102
+ children: source?.rounds[0] ? latestCohortRound(source.rounds[0].phase) : C.chooseTestFirst
103
+ }),
104
+ rule.phase !== 'latest' && !round ? /*#__PURE__*/ _jsxs("option", {
105
+ value: rule.phase,
106
+ children: [
107
+ C.round,
108
+ " ",
109
+ rule.phase
110
+ ]
111
+ }) : null,
112
+ source?.rounds.flatMap((item)=>item.phase == null || item.startedAt == null ? [] : [
113
+ /*#__PURE__*/ _jsx("option", {
114
+ value: item.phase,
115
+ children: cohortRoundLabel({
116
+ ...item,
117
+ phase: item.phase,
118
+ startedAt: item.startedAt
119
+ }, surface.timeZone || undefined)
120
+ }, item.phase)
121
+ ])
122
+ ]
123
+ }),
124
+ /*#__PURE__*/ _jsxs("fieldset", {
125
+ className: "xp-cohort-options",
126
+ disabled: disabled || !round,
127
+ "aria-describedby": !rule.arms.length ? `${id}-versions-error` : undefined,
128
+ children: [
129
+ /*#__PURE__*/ _jsx("legend", {
130
+ children: C.versions
131
+ }),
132
+ /*#__PURE__*/ _jsx("div", {
133
+ className: "xp-ui-button-group",
134
+ children: round?.arms.map(({ key, label })=>/*#__PURE__*/ _jsx(Button, {
135
+ size: "sm",
136
+ "aria-pressed": rule.arms.includes(key),
137
+ onClick: ()=>update({
138
+ ...rule,
139
+ arms: rule.arms.includes(key) ? rule.arms.filter((arm)=>arm !== key) : [
140
+ ...rule.arms,
141
+ key
142
+ ]
143
+ }),
144
+ children: label
145
+ }, key))
146
+ }),
147
+ !rule.arms.length ? /*#__PURE__*/ _jsx("p", {
148
+ id: `${id}-versions-error`,
149
+ className: "xp-field-error",
150
+ role: "alert",
151
+ children: COHORT_COPY.arms
152
+ }) : null
153
+ ]
154
+ }),
155
+ /*#__PURE__*/ _jsxs(Select, {
156
+ label: C.outcome,
157
+ id: `${id}-outcome`,
158
+ value: rule.goal?.metricId ?? '',
159
+ disabled: disabled || !round,
160
+ onChange: (event)=>{
161
+ const metricId = event.target.value;
162
+ update({
163
+ ...rule,
164
+ goal: metricId ? {
165
+ metricId,
166
+ completed: true
167
+ } : undefined
168
+ });
169
+ },
170
+ children: [
171
+ /*#__PURE__*/ _jsx("option", {
172
+ value: "",
173
+ children: C.any
174
+ }),
175
+ rule.goal && !round?.goals.some((goal)=>String(goal.metricId) === rule.goal?.metricId) ? /*#__PURE__*/ _jsx("option", {
176
+ value: rule.goal.metricId,
177
+ children: COHORT_COPY.goal
178
+ }) : null,
179
+ round?.goals.map((goal)=>/*#__PURE__*/ _jsx("option", {
180
+ value: goal.metricId,
181
+ children: goal.name
182
+ }, goal.metricId))
183
+ ]
184
+ }),
185
+ rule.goal ? /*#__PURE__*/ _jsxs("div", {
186
+ children: [
187
+ /*#__PURE__*/ _jsxs("div", {
188
+ className: "xp-ui-button-group",
189
+ role: "group",
190
+ "aria-label": C.outcome,
191
+ children: [
192
+ /*#__PURE__*/ _jsx(Button, {
193
+ size: "sm",
194
+ disabled: disabled || !round,
195
+ "aria-pressed": rule.goal.completed,
196
+ onClick: ()=>update({
197
+ ...rule,
198
+ goal: {
199
+ metricId: rule.goal.metricId,
200
+ completed: true
201
+ }
202
+ }),
203
+ children: C.completed
204
+ }),
205
+ /*#__PURE__*/ _jsx(Button, {
206
+ size: "sm",
207
+ disabled: disabled || !round || open,
208
+ "aria-pressed": !rule.goal.completed,
209
+ "aria-describedby": open ? `${id}-open` : undefined,
210
+ onClick: ()=>update({
211
+ ...rule,
212
+ goal: {
213
+ metricId: rule.goal.metricId,
214
+ completed: false
215
+ }
216
+ }),
217
+ children: C.notCompleted
218
+ })
219
+ ]
220
+ }),
221
+ open ? /*#__PURE__*/ _jsx("p", {
222
+ id: `${id}-open`,
223
+ className: "xp-ui-help",
224
+ children: COHORT_COPY.open
225
+ }) : null
226
+ ]
227
+ }) : null,
228
+ /*#__PURE__*/ _jsxs("div", {
229
+ className: "xp-ui-button-group",
230
+ role: "group",
231
+ "aria-label": C.participation,
232
+ children: [
233
+ /*#__PURE__*/ _jsx(Button, {
234
+ size: "sm",
235
+ disabled: disabled,
236
+ "aria-pressed": rule.include,
237
+ onClick: ()=>update({
238
+ ...rule,
239
+ include: true
240
+ }),
241
+ children: C.include
242
+ }),
243
+ /*#__PURE__*/ _jsx(Button, {
244
+ size: "sm",
245
+ disabled: disabled,
246
+ "aria-pressed": !rule.include,
247
+ onClick: ()=>update({
248
+ ...rule,
249
+ include: false
250
+ }),
251
+ children: C.exclude
252
+ })
253
+ ]
254
+ }),
255
+ source ? /*#__PURE__*/ _jsxs("div", {
256
+ "aria-live": "polite",
257
+ children: [
258
+ size !== undefined ? /*#__PURE__*/ _jsx("p", {
259
+ children: cohortSizeLabel(size, rule.include)
260
+ }) : !round?.estimate || rule.arms.length ? /*#__PURE__*/ _jsx("p", {
261
+ children: C.noEstimate
262
+ }) : null,
263
+ live ? /*#__PURE__*/ _jsx("p", {
264
+ className: "xp-ui-help",
265
+ children: cohortGrowth(source.name)
266
+ }) : null
267
+ ]
268
+ }) : null,
269
+ needsChoice ? /*#__PURE__*/ _jsx(SavedValueChanged, {
270
+ id: `${id}-draft-choice`,
271
+ value: saved.experiment ? cohortRuleSummary(saved) : '',
272
+ conflict: edit.conflict,
273
+ announce: 0,
274
+ onKeep: !locked && rule.arms.length && rule.experiment ? ()=>edit.submit(()=>onSave(rule)) : undefined,
275
+ onDiscard: ()=>{
276
+ edit.discard();
277
+ onDiscard?.();
278
+ }
279
+ }) : null,
280
+ !pending || edit.retry ? /*#__PURE__*/ _jsx(FieldErrors, {
281
+ test: test,
282
+ path: `targeting.${index}`
283
+ }) : null,
284
+ /*#__PURE__*/ _jsx("div", {
285
+ className: "xp-ui-button-group",
286
+ children: /*#__PURE__*/ _jsx(Button, {
287
+ size: "sm",
288
+ variant: "link",
289
+ disabled: test.saving === 'saving' || edit.saving,
290
+ onClick: ()=>{
291
+ edit.discard();
292
+ onRemove();
293
+ },
294
+ children: TEST_PAGE.removeRule
295
+ })
296
+ })
297
+ ]
298
+ });
299
+ }
300
+ /** Match the page picker’s focus, keyboard and result feedback in the shared popup. */ function CohortSourceCombobox({ apiRoute, exclude, value, disabled, focusOnMount, onChoose }) {
301
+ const id = useId();
302
+ const root = useRef(null);
303
+ const api = useMemo(()=>createApi(apiRoute), [
304
+ apiRoute
305
+ ]);
306
+ const [open, setOpen] = useState(false);
307
+ const [search, setSearch] = useState('');
308
+ const [active, setActive] = useState(-1);
309
+ const [retry, setRetry] = useState(0);
310
+ const [settled, setSettled] = useState();
311
+ const shown = open && !disabled;
312
+ const query = search.trim();
313
+ const result = settled?.query === query && settled.retry === retry ? settled : undefined;
314
+ const rows = result?.rows ?? [];
315
+ const activeId = active >= 0 && active < rows.length ? `${id}-option-${active}` : undefined;
316
+ useEffect(()=>{
317
+ if (focusOnMount) root.current?.querySelector('input')?.focus();
318
+ }, [
319
+ focusOnMount
320
+ ]);
321
+ useEffect(()=>{
322
+ if (!shown) return;
323
+ const controller = new AbortController();
324
+ const timer = setTimeout(async ()=>{
325
+ const response = await api.cohortSources(query, exclude, controller.signal);
326
+ if (!controller.signal.aborted) setSettled({
327
+ query,
328
+ retry,
329
+ rows: response.ok && Array.isArray(response.data?.docs) ? response.data.docs : undefined
330
+ });
331
+ }, query ? 250 : 0);
332
+ return ()=>{
333
+ clearTimeout(timer);
334
+ controller.abort();
335
+ };
336
+ }, [
337
+ shown,
338
+ api,
339
+ query,
340
+ exclude,
341
+ retry
342
+ ]);
343
+ useEffect(()=>{
344
+ if (shown && activeId) root.current?.ownerDocument.getElementById(activeId)?.scrollIntoView?.({
345
+ block: 'nearest'
346
+ });
347
+ }, [
348
+ shown,
349
+ activeId
350
+ ]);
351
+ const show = (text = '')=>{
352
+ if (!disabled && !open) {
353
+ setSearch(text);
354
+ setActive(-1);
355
+ setRetry((count)=>count + 1);
356
+ setOpen(true);
357
+ }
358
+ };
359
+ const close = ()=>{
360
+ setOpen(false);
361
+ setActive(-1);
362
+ };
363
+ const choose = (row)=>{
364
+ if (!disabled) {
365
+ onChoose(row);
366
+ close();
367
+ root.current?.querySelector('input')?.focus();
368
+ }
369
+ };
370
+ return /*#__PURE__*/ _jsxs("div", {
371
+ ref: root,
372
+ className: "xp-page-combobox",
373
+ onBlur: (event)=>{
374
+ if (!event.currentTarget.contains(event.relatedTarget)) close();
375
+ },
376
+ children: [
377
+ /*#__PURE__*/ _jsx(TextInput, {
378
+ id: id,
379
+ label: C.test,
380
+ role: "combobox",
381
+ "aria-autocomplete": "list",
382
+ "aria-expanded": shown,
383
+ disabled: disabled,
384
+ "aria-controls": shown ? `${id}-list` : undefined,
385
+ "aria-activedescendant": shown ? activeId : undefined,
386
+ autoComplete: "off",
387
+ maxLength: 100,
388
+ value: shown ? search : value?.name ?? '',
389
+ placeholder: C.search,
390
+ onClick: ()=>show(),
391
+ onPaste: (event)=>{
392
+ if (!open) {
393
+ event.preventDefault();
394
+ show(event.clipboardData.getData('text/plain').slice(0, 100));
395
+ }
396
+ },
397
+ onChange: (event)=>{
398
+ if (!open) show(event.currentTarget.value);
399
+ else {
400
+ setSearch(event.currentTarget.value);
401
+ setActive(-1);
402
+ }
403
+ },
404
+ onKeyDown: (event)=>{
405
+ if (event.key === 'Escape' && shown) {
406
+ event.preventDefault();
407
+ event.stopPropagation();
408
+ close();
409
+ return;
410
+ }
411
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
412
+ event.preventDefault();
413
+ if (!shown) {
414
+ show();
415
+ return;
416
+ }
417
+ if (rows.length) setActive(event.key === 'ArrowDown' ? Math.min(active + 1, rows.length - 1) : active < 0 ? rows.length - 1 : Math.max(0, active - 1));
418
+ } else if (shown && activeId && (event.key === 'Home' || event.key === 'End')) {
419
+ event.preventDefault();
420
+ setActive(event.key === 'Home' ? 0 : rows.length - 1);
421
+ } else if (shown && activeId && event.key === 'Enter' && !event.nativeEvent.isComposing && event.nativeEvent.keyCode !== 229) {
422
+ event.preventDefault();
423
+ choose(rows[active]);
424
+ } else if (!shown && event.key.length === 1 && !event.altKey && !event.ctrlKey && !event.metaKey) {
425
+ event.preventDefault();
426
+ show(event.key);
427
+ }
428
+ }
429
+ }),
430
+ shown ? /*#__PURE__*/ _jsx("div", {
431
+ className: "xp-page-combobox-popup",
432
+ children: /*#__PURE__*/ _jsxs("div", {
433
+ className: "xp-page-results",
434
+ "aria-busy": !result,
435
+ children: [
436
+ /*#__PURE__*/ _jsx("div", {
437
+ id: `${id}-list`,
438
+ role: "listbox",
439
+ "aria-label": C.test,
440
+ children: rows.map((row, index)=>/*#__PURE__*/ _jsxs("div", {
441
+ id: `${id}-option-${index}`,
442
+ role: "option",
443
+ "aria-selected": row.id === value?.id,
444
+ "data-active": index === active || undefined,
445
+ className: "xp-page-option",
446
+ onMouseDown: (event)=>event.preventDefault(),
447
+ onClick: ()=>choose(row),
448
+ children: [
449
+ /*#__PURE__*/ _jsx("span", {
450
+ className: "xp-page-option-main",
451
+ children: row.name
452
+ }),
453
+ /*#__PURE__*/ _jsx(StatusChip, {
454
+ status: row.status
455
+ }),
456
+ row.rounds.every((round)=>round.phase != null) ? /*#__PURE__*/ _jsx("span", {
457
+ className: "xp-page-option-detail",
458
+ children: cohortRoundCount(row.rounds.length)
459
+ }) : null
460
+ ]
461
+ }, row.id))
462
+ }),
463
+ !result ? /*#__PURE__*/ _jsx("p", {
464
+ className: "xp-page-message",
465
+ role: "status",
466
+ children: C.loading
467
+ }) : !result.rows ? /*#__PURE__*/ _jsxs("div", {
468
+ className: "xp-page-message",
469
+ role: "alert",
470
+ children: [
471
+ C.searchError,
472
+ ' ',
473
+ /*#__PURE__*/ _jsx(Button, {
474
+ size: "sm",
475
+ onClick: ()=>{
476
+ root.current?.querySelector('input')?.focus();
477
+ setRetry((count)=>count + 1);
478
+ },
479
+ children: PAGE_COPY.retry
480
+ })
481
+ ]
482
+ }) : !rows.length ? /*#__PURE__*/ _jsx("p", {
483
+ className: "xp-page-message",
484
+ role: "status",
485
+ children: query ? C.noMatches : C.empty
486
+ }) : null
487
+ ]
488
+ })
489
+ }) : null
490
+ ]
491
+ });
492
+ }
@@ -1,7 +1,10 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { Button } from '../../../ui/Button.js';
4
- import { TEST_PAGE as C, suggestedWeeks, weeksHint } from '../../copy/testPage.js';
4
+ import { TEST_PAGE as C, scheduledEstimateCopy, suggestedWeeks, weeksHint } from '../../copy/testPage.js';
5
+ import { activeWeek } from '../../../schedule/activeTime.js';
6
+ import { roundProgress } from '../../format/roundProgress.js';
7
+ import { createDateFormatter } from '../../format/date.js';
5
8
  import { durationSuggestion } from './testPage.model.js';
6
9
  import { FieldErrors, positiveInteger, ReadOnly, reasonFor, save, TextEdit } from './fields.js';
7
10
  import { useDateFormatter } from '../../format/useDateFormatter.js';
@@ -12,7 +15,24 @@ export function LengthSection({ test, surface }) {
12
15
  const reason = reasonFor(test, 'analysis');
13
16
  const days = doc.analysis?.plannedDurationDays ?? 28;
14
17
  const suggestion = !reason ? durationSuggestion(test.preflight, days) : null;
15
- const end = typeof doc.startedAt === 'string' ? Date.parse(doc.startedAt) + days * 86_400_000 : NaN;
18
+ const windows = doc.schedule?.windows ?? [];
19
+ const week = activeWeek(windows);
20
+ const zone = doc.schedule?.timeZone || surface.timeZone || test.preflight?.scheduleTimeZone;
21
+ const schedule = zone && (windows.length || doc.schedule?.startAt || doc.schedule?.endAt) ? {
22
+ startAt: doc.schedule?.startAt ?? undefined,
23
+ endAt: doc.schedule?.endAt ?? undefined,
24
+ timeZone: zone,
25
+ windows
26
+ } : undefined;
27
+ const pauses = doc.status === 'paused' && doc.pausedAt ? [
28
+ {
29
+ from: doc.pausedAt
30
+ }
31
+ ] : [];
32
+ const progress = roundProgress(doc.startedAt, days, Date.now(), undefined, {
33
+ schedule,
34
+ pauses
35
+ });
16
36
  const required = [
17
37
  'manual',
18
38
  'viewport'
@@ -58,14 +78,14 @@ export function LengthSection({ test, surface }) {
58
78
  children: [
59
79
  /*#__PURE__*/ _jsx(TextEdit, {
60
80
  test: test,
61
- label: C.duration,
81
+ label: schedule ? C.activeDuration : C.duration,
62
82
  value: days,
63
83
  type: "number",
64
84
  min: 1,
65
85
  reason: reason,
66
86
  isValid: positiveInteger,
67
87
  onCommit: (value)=>change('plannedDurationDays', value),
68
- help: !reason ? weeksHint(days) : undefined
88
+ help: !reason ? weeksHint(days, week.days, week.weekendsOnly) : undefined
69
89
  }),
70
90
  /*#__PURE__*/ _jsx(FieldErrors, {
71
91
  test: test,
@@ -75,7 +95,7 @@ export function LengthSection({ test, surface }) {
75
95
  }, "duration"),
76
96
  reason ? /*#__PURE__*/ _jsx(ReadOnly, {
77
97
  label: C.endDate,
78
- value: formatDate(end)
98
+ value: (zone ? createDateFormatter(zone) : formatDate)(progress.end)
79
99
  }) : null
80
100
  ]
81
101
  }),
@@ -83,7 +103,7 @@ export function LengthSection({ test, surface }) {
83
103
  className: "xp-duration-suggestion xp-ui-button-group",
84
104
  children: [
85
105
  /*#__PURE__*/ _jsx("p", {
86
- children: suggestedWeeks(suggestion.weeks)
106
+ children: zone && windows.length ? scheduledEstimateCopy(suggestion.weeks, week.weekendsOnly, windows, zone, new Date()) : suggestedWeeks(suggestion.weeks)
87
107
  }),
88
108
  /*#__PURE__*/ _jsx(Button, {
89
109
  onClick: ()=>save(test, 'analysis', ()=>({
@@ -0,0 +1,4 @@
1
+ import { type TextInputProps } from '../../../ui/Inputs.js';
2
+ export declare function ScheduleDateInput({ timeZone, ...props }: Omit<TextInputProps, 'id' | 'type'> & {
3
+ timeZone: string;
4
+ }): import("react").JSX.Element;
@@ -0,0 +1,15 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useId } from 'react';
4
+ import { TextInput } from '../../../ui/Inputs.js';
5
+ import { SCHEDULE_COPY as C } from '../../copy/schedule.js';
6
+ export function ScheduleDateInput({ timeZone, ...props }) {
7
+ const id = useId();
8
+ return /*#__PURE__*/ _jsx(TextInput, {
9
+ ...props,
10
+ id: id,
11
+ type: "datetime-local",
12
+ step: "0.001",
13
+ help: timeZone || C.noZone
14
+ });
15
+ }
@@ -0,0 +1,2 @@
1
+ import type { SectionProps } from '../contracts.js';
2
+ export declare function ScheduleSection({ test, surface }: SectionProps): import("react").JSX.Element;