@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
@@ -1,30 +1,45 @@
1
1
  'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { createUsePuck, useGetPuck } from '@puckeditor/core';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { createPortal } from 'react-dom';
4
+ import { createUsePuck, useGetPuck, FieldGroup } from '@puckeditor/core';
4
5
  import { useEffect, useRef, useState } from 'react';
6
+ import { defaultArms } from '../../arms/model.js';
7
+ import { readExperiment } from './armWrites.js';
8
+ import { publishOutlineVersion } from './outlineVersion.js';
9
+ import { LeftoverVersions } from './LeftoverVersions.js';
5
10
  import { Button } from '../../ui/Button.js';
6
11
  import { StatusChip } from '../../ui/StatusChip.js';
7
12
  import { Banner } from '../../ui/Banner.js';
8
13
  import { Tabs } from '../../ui/Tabs.js';
9
14
  import { Dialog } from '../../ui/Dialog.js';
10
15
  import { accentVariables, deriveAccent, validateAccent } from '../../ui/accent.js';
11
- import { createExperimentSlotField } from '../experimentSlotField.js';
16
+ import { ExperimentPicker } from '../ExperimentPicker.js';
17
+ import { TestSidebarField, useSidebarTargets } from './sidebar.js';
18
+ import { readPreflight } from '../../testSurface/readPreflight.js';
19
+ import { classifyReadinessRead } from '../../testSurface/readinessRead.js';
20
+ import { useReadinessPolling } from '../../testSurface/useReadinessPolling.js';
21
+ import { PlacementNotice } from './PlacementNotice.js';
22
+ import { QuickTestActions } from './QuickTestActions.js';
23
+ import { BlockerList } from '../../testSurface/surface/readiness/BlockerList.js';
12
24
  import { resolvePuckRoutes } from '../routes.js';
13
25
  import { PuckHostProvider, usePuckRoutes } from '../hostContext.js';
14
26
  import { pickerCopy, slotLabels } from '../copy.js';
15
27
  import { experimentSlotDefaultProps, experimentSlotFields, experimentSlotLabel } from '../slotConfig.js';
16
28
  import { armsFromBlock, bannerFor, currentPuckDocument, isSharedTest, tabsFor } from './editor.model.js';
17
- import { cloneSlot } from './cloneSlot.js';
29
+ import { cloneSlot, countSlotBlocks } from './cloneSlot.js';
18
30
  import { openCreateExperimentDrawer } from './CreateExperimentDrawer.js';
19
31
  import { editorCopy } from './copy.js';
20
32
  import { acquireArms, loadArms, publishExperiment, useArms } from './armsCache.js';
21
- import { AddVariant, RemoveVersion, VersionActions, VersionWeights, useArmWrites } from './VersionBuilder.js';
33
+ import { AddVariant, RemoveVersion, VersionName, VersionWeights, useArmWrites } from './VersionBuilder.js';
22
34
  import { ResultsReadout } from './ResultsReadout.js';
23
35
  import { EditorControls } from './EditorControls.js';
24
- import { acquirePlacements, invalidatePlacements, refreshPlacements } from './placementsCache.js';
25
- import { localPlacements } from './localPlacements.js';
36
+ import { acquirePlacements, cachedPreflight, cachedReadinessRead, placementsPending, placementsBlocking, placementReadError, invalidatePlacements, refreshPlacements, focusPlacements } from './placementsCache.js';
37
+ import { sidebarReadinessBlockers, editorPlacementMessage } from '../../testSurface/surface/editorPlacement.js';
38
+ import { localPlacements, localBlockVisibility } from './localPlacements.js';
39
+ import { usePlacementNotice } from './usePlacementNotice.js';
26
40
  import { useEditorSurface } from './editorSurface.js';
27
- import { ConfigureTestButton, ConfigureTestControl } from './ConfigureTestDrawer.js';
41
+ import { createBlockTest, CreateRefused } from './createTest.js';
42
+ import { ConfigureTestControl, openConfigureTestDrawer } from './ConfigureTestDrawer.js';
28
43
  import './editor.css';
29
44
  const usePuckSelector = createUsePuck();
30
45
  class TestReadError extends Error {
@@ -44,9 +59,11 @@ function isExperiment(value) {
44
59
  }
45
60
  function EditorRender(props) {
46
61
  const getPuck = useGetPuck();
62
+ const sidebar = useSidebarTargets(props.id);
47
63
  const { admin, api } = usePuckRoutes();
48
64
  const access = useEditorSurface(api);
49
65
  const root = useRef(null);
66
+ const [readAttempt, setReadAttempt] = useState(0);
50
67
  const [mode, setMode] = useState('light');
51
68
  useEffect(()=>{
52
69
  const node = root.current;
@@ -86,24 +103,45 @@ function EditorRender(props) {
86
103
  }, []);
87
104
  const isCurrentBinding = ()=>binding.current.live && binding.current.key === bindingKey;
88
105
  const knownArms = useArms(experimentId);
106
+ const [preflight, setPreflight] = useState();
107
+ const [placements, setPlacements] = useState();
89
108
  const [loaded, setLoaded] = useState();
109
+ const [documentPending, setDocumentPending] = useState(false);
110
+ const documentFailures = useRef({
111
+ key: bindingKey,
112
+ failures: 0
113
+ });
114
+ if (documentFailures.current.key !== bindingKey) documentFailures.current = {
115
+ key: bindingKey,
116
+ failures: 0
117
+ };
118
+ useReadinessPolling(loaded?.id === experimentId ? loaded?.read : undefined, ()=>setReadAttempt((value)=>value + 1), true, documentPending);
90
119
  const [active, setActive] = useState();
91
- const [openMenu, setOpenMenu] = useState(null);
120
+ const [choosing, setChoosing] = useState(false);
92
121
  const [clearError, setClearError] = useState(null);
122
+ const setupBusy = useRef(false);
123
+ const [settingUp, setSettingUp] = useState(false);
124
+ const [setupError, setSetupError] = useState('');
125
+ const configuration = useRef(undefined);
126
+ useEffect(()=>()=>configuration.current?.close(), []);
93
127
  const creation = useRef(undefined);
94
128
  useEffect(()=>()=>creation.current?.closeIfIdle(), []);
95
- const [detaching, setDetaching] = useState(null);
96
129
  // A non-empty variant is only overwritten after an explicit second confirmation.
97
130
  const [confirming, setConfirming] = useState(null);
98
- // Keep a failed removal open even if the recovery read no longer contains that version.
131
+ // A Remove refusal stays with its open dialog, even if the version disappears or the test locks.
132
+ // Close on a binding change, Cancel/Escape, or success; only then discard its refusal.
133
+ // Split/Add refusals survive the locking read, then clear on a later status change;
134
+ // Add also clears when three variants leave no room for another version.
99
135
  const [removing, setRemoving] = useState(null);
100
136
  const pageTitle = usePuckSelector((state)=>typeof state.appState.data.root.props?.title === 'string' ? state.appState.data.root.props.title : '');
101
137
  // Selection only changes the chrome's appearance; actions always resolve this block by id.
138
+ const dragging = usePuckSelector((state)=>state.appState.ui?.isDragging ?? false);
102
139
  const isSelected = usePuckSelector((state)=>state.selectedItem?.props.id === props.id);
103
140
  const originalEmpty = usePuckSelector((state)=>{
104
141
  const content = state.getItemById(props.id)?.props.control;
105
142
  return !Array.isArray(content) || content.length === 0;
106
143
  });
144
+ const testVersions = (knownArms?.arms.length ? knownArms.arms : undefined) ?? (loaded?.id === experimentId ? loaded?.doc?.arms.map((arm)=>arm.key) : undefined);
107
145
  const orphanSlots = usePuckSelector((state)=>{
108
146
  const item = state.getItemById(props.id);
109
147
  return [
@@ -112,7 +150,7 @@ function EditorRender(props) {
112
150
  'variantC'
113
151
  ].filter((slot)=>{
114
152
  const content = item?.props[slot];
115
- return knownArms && !knownArms.arms.includes(slot) && Array.isArray(content) && content.length > 0;
153
+ return testVersions && !testVersions.includes(slot) && Array.isArray(content) && content.length > 0;
116
154
  }).join(',');
117
155
  }).split(',').filter(Boolean);
118
156
  useEffect(()=>{
@@ -123,18 +161,20 @@ function EditorRender(props) {
123
161
  const releaseArms = acquireArms(experimentId);
124
162
  async function load() {
125
163
  const revision = ++request;
164
+ setDocumentPending(true);
126
165
  try {
127
166
  const doc = await loadArms(experimentId, async (signal)=>{
128
- const response = await fetch(`${api}/xp-experiments/${encodeURIComponent(experimentId)}?depth=0`, {
129
- credentials: 'include',
130
- signal
131
- });
167
+ const { response, body } = await readPreflight((boundedSignal)=>fetch(`${api}/xp-experiments/${encodeURIComponent(experimentId)}?depth=0`, {
168
+ credentials: 'include',
169
+ signal: boundedSignal
170
+ }), signal);
132
171
  if (!response.ok) throw new TestReadError(response.status);
133
- const doc = await response.json();
172
+ const doc = body;
134
173
  if (!isExperiment(doc)) throw new Error('document');
135
174
  return doc;
136
175
  }, controller.signal);
137
176
  if (current && revision === request) {
177
+ documentFailures.current.failures = 0;
138
178
  setLoaded((value)=>({
139
179
  id: experimentId,
140
180
  doc,
@@ -143,16 +183,23 @@ function EditorRender(props) {
143
183
  }
144
184
  } catch (cause) {
145
185
  if (current && revision === request) {
146
- const forbidden = cause instanceof TestReadError && (cause.status === 401 || cause.status === 403);
147
- const missing = cause instanceof TestReadError && cause.status === 404;
186
+ const read = classifyReadinessRead(cause instanceof TestReadError ? cause.status : 0, undefined, ++documentFailures.current.failures, {
187
+ kind: 'document',
188
+ surface: 'editor'
189
+ });
190
+ const forbidden = read.loadState === 'forbidden';
191
+ const missing = read.loadState === 'missing';
148
192
  setLoaded((value)=>({
149
193
  id: experimentId,
194
+ read,
150
195
  forbidden,
151
196
  missing,
152
197
  error: !forbidden && !missing,
153
198
  shared: value?.id === experimentId ? value?.shared : undefined
154
199
  }));
155
200
  }
201
+ } finally{
202
+ if (current && revision === request) setDocumentPending(false);
156
203
  }
157
204
  }
158
205
  void load();
@@ -169,27 +216,54 @@ function EditorRender(props) {
169
216
  };
170
217
  }, [
171
218
  experimentId,
172
- api
219
+ api,
220
+ readAttempt
173
221
  ]);
174
222
  const cachedExperiment = loaded?.id === experimentId && !loaded?.forbidden && !loaded?.missing ? knownArms?.doc : undefined;
175
223
  const status = cachedExperiment?.status ?? (loaded?.id === experimentId ? loaded?.doc?.status : undefined);
176
224
  useEffect(()=>{
177
- if (experimentId === undefined || !status) return;
178
- return acquirePlacements(api, experimentId, (placements)=>{
225
+ if (experimentId === undefined || !status || !access.surface?.canManage) return;
226
+ const release = acquirePlacements(api, experimentId, (placements)=>{
227
+ // Retain guidance only while revalidating; failures must show their own message.
228
+ setPlacements((current)=>placements === undefined && placementsPending(api, experimentId) && current?.id === experimentId ? current : {
229
+ id: experimentId,
230
+ value: placements
231
+ });
232
+ setPreflight({
233
+ id: experimentId,
234
+ value: cachedPreflight(api, experimentId),
235
+ pending: placementsPending(api, experimentId),
236
+ blocking: placementsBlocking(api, experimentId)
237
+ });
179
238
  const shared = placements === undefined ? undefined : isSharedTest(placements, currentPuckDocument(window.location.pathname, admin, placements));
180
239
  setLoaded((value)=>({
181
240
  ...value?.id === experimentId ? value : {},
182
241
  id: experimentId,
183
- shared
242
+ shared: shared ?? (value?.id === experimentId ? value.shared : undefined)
184
243
  }));
185
- }, status === 'running');
244
+ });
245
+ const focus = ()=>{
246
+ void focusPlacements(api, experimentId);
247
+ };
248
+ window.addEventListener('focus', focus);
249
+ return ()=>{
250
+ release();
251
+ window.removeEventListener('focus', focus);
252
+ };
186
253
  }, [
187
254
  api,
188
255
  admin,
189
256
  experimentId,
190
- status
257
+ status,
258
+ access.surface?.canManage
191
259
  ]);
192
- const locallyShared = usePuckSelector((state)=>experimentId !== undefined && (localPlacements(state.appState.data, state.config).get(String(experimentId))?.size ?? 0) > 1);
260
+ const blockVisibility = usePuckSelector((state)=>{
261
+ const visibility = localBlockVisibility(state.appState.data, props.id);
262
+ return visibility?.hidden ? 'hidden' : visibility?.hideOn.join(' and ') ?? '';
263
+ });
264
+ const hidden = blockVisibility === 'hidden';
265
+ const visibilityNotice = hidden ? editorCopy.hidden : blockVisibility ? editorCopy.hiddenOn(blockVisibility) : undefined;
266
+ const locallyShared = usePuckSelector((state)=>experimentId !== undefined && (localPlacements(state.appState.data).get(String(experimentId))?.size ?? 0) > 1);
193
267
  const result = experimentId === undefined || loaded?.id !== experimentId ? undefined : loaded;
194
268
  const shared = locallyShared || result?.shared === true;
195
269
  const experiment = cachedExperiment ?? result?.doc;
@@ -197,6 +271,7 @@ function EditorRender(props) {
197
271
  const resultsOnly = access.surface?.canReadResults === true && !access.surface.canManage;
198
272
  const unavailable = result?.forbidden || result?.missing;
199
273
  const canManage = access.surface?.canManage === true && !unavailable;
274
+ const canSetUp = access.surface?.canManage === true && (experimentId === undefined || result?.missing === true);
200
275
  const editable = canManage && (experiment?.status === 'draft' || experiment?.status === 'stopped');
201
276
  const [removed, setRemoved] = useState(null);
202
277
  useEffect(()=>{
@@ -206,14 +281,58 @@ function EditorRender(props) {
206
281
  removed,
207
282
  bindingKey
208
283
  ]);
209
- const writes = useArmWrites(`${api}/xp-experiments/${encodeURIComponent(String(experimentId))}`, (doc)=>{
210
- publishExperiment(experimentId, doc);
211
- if (isCurrentBinding()) setLoaded((value)=>({
212
- id: experimentId,
213
- doc,
214
- shared: value?.id === experimentId ? value?.shared : undefined
215
- }));
216
- }, isCurrentBinding, ()=>setClearError(null));
284
+ const splitIntent = useRef(false);
285
+ const [weightEdits, setWeightEdits] = useState({});
286
+ const armKeys = experiment?.arms.map((arm)=>arm.key).join(',');
287
+ useEffect(()=>{
288
+ if (!armKeys) return;
289
+ const keys = new Set(armKeys.split(','));
290
+ setWeightEdits((current)=>Object.fromEntries(Object.entries(current).filter(([key])=>keys.has(key))));
291
+ }, [
292
+ armKeys
293
+ ]);
294
+ useEffect(()=>{
295
+ setWeightEdits({});
296
+ splitIntent.current = false;
297
+ }, [
298
+ bindingKey,
299
+ status
300
+ ]);
301
+ useEffect(()=>{
302
+ setRemoving((current)=>current?.key === bindingKey ? current : null);
303
+ }, [
304
+ bindingKey
305
+ ]);
306
+ const writes = useArmWrites({
307
+ url: `${api}/xp-experiments/${encodeURIComponent(String(experimentId))}`,
308
+ bindingKey,
309
+ status,
310
+ controlKeys: [
311
+ 'split',
312
+ ...experiment && experiment.arms.filter((arm)=>arm.kind === 'variant').length < 3 ? [
313
+ 'add'
314
+ ] : [],
315
+ ...experiment?.arms.map((arm)=>`remove:${arm.key}`) ?? [],
316
+ ...removing?.key === bindingKey ? [
317
+ `remove:${removing.arm.key}`
318
+ ] : [],
319
+ ...orphanSlots.map((slot)=>`leftover:${slot}`)
320
+ ],
321
+ publish: (doc)=>{
322
+ const accepted = publishExperiment(experimentId, doc);
323
+ if (isCurrentBinding()) setLoaded((value)=>({
324
+ id: experimentId,
325
+ doc: accepted,
326
+ shared: value?.id === experimentId ? value?.shared : undefined
327
+ }));
328
+ return accepted;
329
+ },
330
+ isCurrent: isCurrentBinding,
331
+ onWrite: ()=>setClearError(null),
332
+ onSaved: ()=>{
333
+ invalidatePlacements(api, experimentId);
334
+ }
335
+ });
217
336
  // The slot arrays belong to the page; reading the test is unnecessary to edit them.
218
337
  const pageSlots = usePuckSelector((state)=>[
219
338
  'control',
@@ -234,19 +353,34 @@ function EditorRender(props) {
234
353
  slots: new Set()
235
354
  };
236
355
  for (const slot of pageSlots.split(','))observedSlots.current.slots.add(slot);
237
- const tabs = unavailable ? [
356
+ const tabs = unavailable || !experiment ? [
238
357
  ...observedSlots.current.slots
239
358
  ].sort((a, b)=>a.localeCompare(b)).map((slot)=>({
240
359
  slot: slot,
241
360
  label: slotLabels[slot]
242
- })) : tabsFor(experiment);
361
+ })) : [
362
+ ...tabsFor(experiment),
363
+ ...orphanSlots.map((slot)=>({
364
+ slot,
365
+ label: editorCopy.outsideTest(slotLabels[slot])
366
+ }))
367
+ ];
243
368
  const activeSlot = active && active.id === experimentId ? active.slot : undefined;
244
369
  const slot = tabs.find((tab)=>tab.slot === activeSlot)?.slot ?? tabs[0]?.slot ?? 'control';
245
370
  const slotEmpty = usePuckSelector((state)=>{
246
371
  const content = state.getItemById(props.id)?.props[slot];
247
372
  return !Array.isArray(content) || content.length === 0;
248
373
  });
374
+ useEffect(()=>{
375
+ publishOutlineVersion(getPuck, props.id, slot);
376
+ return ()=>publishOutlineVersion(getPuck, props.id);
377
+ }, [
378
+ getPuck,
379
+ props.id,
380
+ slot
381
+ ]);
249
382
  const Slot = props[slot];
383
+ const originalLabel = tabs.find((tab)=>tab.slot === 'control')?.label ?? slotLabels.control;
250
384
  const winnerKey = experiment?.decision?.winnerArm;
251
385
  const winner = tabs.find((tab)=>tab.slot === winnerKey)?.label;
252
386
  function selectBlock() {
@@ -297,6 +431,18 @@ function EditorRender(props) {
297
431
  return;
298
432
  }
299
433
  setClearError(null);
434
+ if (countSlotBlocks(item.props[slot]) === 0) {
435
+ setRemoved((current)=>({
436
+ key: bindingKey,
437
+ revision: (current?.revision ?? 0) + 1,
438
+ contentRemoved: false
439
+ }));
440
+ setActive({
441
+ id: experimentId,
442
+ slot: 'control'
443
+ });
444
+ return;
445
+ }
300
446
  dispatch({
301
447
  type: 'replace',
302
448
  destinationIndex: selector.index,
@@ -311,7 +457,8 @@ function EditorRender(props) {
311
457
  });
312
458
  setRemoved((current)=>({
313
459
  key: bindingKey,
314
- revision: (current?.revision ?? 0) + 1
460
+ revision: (current?.revision ?? 0) + 1,
461
+ contentRemoved: true
315
462
  }));
316
463
  setActive({
317
464
  id: experimentId,
@@ -341,16 +488,28 @@ function EditorRender(props) {
341
488
  }
342
489
  async function newTestArms() {
343
490
  if (!isCurrentBinding()) throw new Error('binding');
491
+ const item = getPuck().getItemById(props.id);
492
+ if (!item) throw new Error('binding');
493
+ if (experimentId === undefined || result?.missing || result?.forbidden || result?.error) return armsFromBlock({
494
+ arms: [
495
+ defaultArms('block')[0]
496
+ ]
497
+ }, item.props);
344
498
  // Another placement can rename or add a version while this dialog is open.
345
499
  const response = await fetch(`${api}/xp-experiments/${encodeURIComponent(String(experimentId))}?depth=0`, {
346
500
  credentials: 'include',
347
501
  cache: 'no-store'
348
502
  });
503
+ if (response.status === 403 || response.status === 404) return armsFromBlock({
504
+ arms: [
505
+ defaultArms('block')[0]
506
+ ]
507
+ }, item.props);
349
508
  if (!response.ok) throw new Error('load');
350
509
  const doc = await response.json();
351
- const item = getPuck().getItemById(props.id);
352
- if (!isCurrentBinding() || !isExperiment(doc) || !item) throw new Error('binding');
353
- return armsFromBlock(doc, item.props);
510
+ const latest = getPuck().getItemById(props.id);
511
+ if (!isCurrentBinding() || !isExperiment(doc) || !latest) throw new Error('binding');
512
+ return armsFromBlock(doc, latest.props);
354
513
  }
355
514
  function createFromBlock() {
356
515
  if (!root.current) return;
@@ -359,89 +518,419 @@ function EditorRender(props) {
359
518
  api
360
519
  }, {
361
520
  initialName: pageTitle,
362
- arms: experimentId === undefined ? undefined : newTestArms,
363
- label: experimentId === undefined ? editorCopy.createLabel : editorCopy.newTest,
521
+ arms: newTestArms,
364
522
  onCreate: bind
365
523
  });
366
524
  }
367
- const canDetach = !!result?.forbidden || !!result?.missing || !!experiment && (experiment.status !== 'running' || result?.shared !== undefined && shared);
368
- const [checkingDetach, setCheckingDetach] = useState(false);
369
- const detachBusy = useRef(false);
370
- async function requestDetach(confirm = false) {
371
- if (detachBusy.current || experimentId === undefined) return;
372
- detachBusy.current = true;
373
- setCheckingDetach(true);
374
- setClearError(null);
525
+ async function setUpTest() {
526
+ if (setupBusy.current || !canSetUp || !root.current) return;
527
+ const source = root.current;
528
+ setupBusy.current = true;
529
+ setSettingUp(true);
530
+ setSetupError('');
375
531
  try {
376
- const response = await fetch(`${api}/xp-experiments/${encodeURIComponent(String(experimentId))}?depth=0`, {
377
- credentials: 'include',
378
- cache: 'no-store'
532
+ const created = await createBlockTest(api, pageTitle, await newTestArms());
533
+ if (bind(created)) configuration.current = openConfigureTestDrawer(source, {
534
+ admin,
535
+ api
536
+ }, created.id);
537
+ else creation.current = openCreateExperimentDrawer(source, {
538
+ admin,
539
+ api
540
+ }, {
541
+ created,
542
+ onCreate: ()=>false
379
543
  });
380
- const current = response.ok ? await response.json() : null;
381
- if (!isCurrentBinding()) return;
382
- if (![
383
- 401,
384
- 403,
385
- 404
386
- ].includes(response.status) && !isExperiment(current)) {
387
- setClearError({
388
- key: bindingKey,
389
- message: editorCopy.placementsError
390
- });
391
- setDetaching(null);
392
- return;
393
- }
394
- if (isExperiment(current)) publishExperiment(experimentId, current);
395
- if (isExperiment(current) && current.status === 'running') {
396
- const placements = await refreshPlacements(api, experimentId);
397
- if (!isCurrentBinding()) return;
398
- if (!placements) {
399
- setClearError({
400
- key: bindingKey,
401
- message: editorCopy.placementsError
402
- });
403
- setDetaching(null);
404
- return;
405
- }
406
- const local = getPuck();
407
- const anotherLocal = (localPlacements(local.appState.data, local.config).get(String(experimentId))?.size ?? 0) > 1;
408
- if (!anotherLocal && !isSharedTest(placements, currentPuckDocument(window.location.pathname, admin, placements))) {
409
- setClearError({
410
- key: bindingKey,
411
- message: editorCopy.stopToDetach
412
- });
413
- setDetaching(null);
414
- return;
415
- }
416
- }
417
- if (!isCurrentBinding()) return;
418
- if (confirm) {
419
- bind(null);
420
- setDetaching(null);
421
- } else setDetaching(bindingKey);
422
- } catch {
423
- if (isCurrentBinding()) {
424
- setClearError({
425
- key: bindingKey,
426
- message: editorCopy.placementsError
427
- });
428
- setDetaching(null);
429
- }
544
+ } catch (cause) {
545
+ if (isCurrentBinding()) setSetupError(cause instanceof CreateRefused ? cause.message : editorCopy.createError);
430
546
  } finally{
431
- detachBusy.current = false;
432
- setCheckingDetach(false);
547
+ setupBusy.current = false;
548
+ if (isCurrentBinding()) setSettingUp(false);
433
549
  }
434
550
  }
435
- const newTestButton = experimentId !== undefined && canManage ? /*#__PURE__*/ _jsx(Button, {
436
- disabled: !experiment,
437
- onClick: createFromBlock,
438
- children: editorCopy.newTest
551
+ const placementMessage = hidden ? undefined : editorPlacementMessage(placements && placements.id === experimentId ? placements.value : undefined, currentPuckDocument(window.location.pathname, admin, placements && placements.id === experimentId ? placements.value : undefined), experiment?.status);
552
+ const currentPreflight = preflight && preflight.id === experimentId && Array.isArray(preflight.value?.checks) ? preflight.value : null;
553
+ const editorPage = currentPuckDocument(window.location.pathname, admin, placements?.value);
554
+ const surface = access.surface ? {
555
+ ...access.surface,
556
+ editorPage,
557
+ apiRoute: api,
558
+ adminRoute: admin,
559
+ editorPlacementMessage: placementMessage
560
+ } : undefined;
561
+ const quickTest = {
562
+ doc: experiment ? {
563
+ ...experiment,
564
+ id: experimentId,
565
+ kind: 'block'
566
+ } : null,
567
+ preflight: currentPreflight,
568
+ preflightRead: experimentId === undefined ? undefined : cachedReadinessRead(api, experimentId),
569
+ preflightError: !currentPreflight ? placementReadError(api, experimentId) ?? null : null,
570
+ preflightPending: documentPending || !preflight || preflight.id !== experimentId || preflight.pending,
571
+ hasUnsaved: writes.busy || Object.keys(weightEdits).length > 0,
572
+ saving: writes.busy ? 'saving' : 'idle',
573
+ stale: false,
574
+ errors: {},
575
+ chosenPages: {},
576
+ loadState: 'ready',
577
+ stage: ()=>{},
578
+ commit: async ()=>{},
579
+ choosePage: async ()=>{},
580
+ refreshPreflight: async (supersede)=>{
581
+ if (experimentId !== undefined) {
582
+ if (supersede) invalidatePlacements(api, experimentId);
583
+ await refreshPlacements(api, experimentId);
584
+ }
585
+ },
586
+ reload: async ()=>{
587
+ if (experimentId === undefined) return;
588
+ // A transition may succeed without a readable response body; recover its document too.
589
+ publishExperiment(experimentId, await readExperiment(`${api}/xp-experiments/${encodeURIComponent(experimentId)}?depth=0`));
590
+ invalidatePlacements(api, experimentId);
591
+ await refreshPlacements(api, experimentId);
592
+ },
593
+ acceptTransition: (result)=>{
594
+ const doc = result?.doc;
595
+ if (doc && experimentId !== undefined) publishExperiment(experimentId, doc);
596
+ }
597
+ };
598
+ const placementNotice = quickTest.preflightRead?.message ?? placementMessage;
599
+ usePlacementNotice(api, experimentId, canManage ? placementNotice : undefined);
600
+ const placementNoticeView = /*#__PURE__*/ _jsxs(_Fragment, {
601
+ children: [
602
+ visibilityNotice ? /*#__PURE__*/ _jsx(Banner, {
603
+ tone: "info",
604
+ children: visibilityNotice
605
+ }) : null,
606
+ canManage ? /*#__PURE__*/ _jsx(PlacementNotice, {
607
+ read: quickTest.preflightRead,
608
+ message: placementMessage,
609
+ running: experiment?.status === 'running',
610
+ onRetry: ()=>{
611
+ if (experimentId !== undefined) void refreshPlacements(api, experimentId);
612
+ }
613
+ }) : null
614
+ ]
615
+ });
616
+ const sidebarBlockers = surface ? sidebarReadinessBlockers(quickTest, surface) : [];
617
+ const leftoverControls = experiment && orphanSlots.length ? /*#__PURE__*/ _jsx(LeftoverVersions, {
618
+ slots: orphanSlots,
619
+ active: slot,
620
+ dragging: dragging,
621
+ experiment: experiment,
622
+ writes: writes,
623
+ canManage: canManage,
624
+ countBlocks: (slot)=>countSlotBlocks(getPuck().getItemById(props.id)?.props[slot]),
625
+ onDelete: removeContent,
626
+ onSelect: (slot)=>{
627
+ if (isCurrentBinding()) setActive({
628
+ id: experimentId,
629
+ slot
630
+ });
631
+ }
632
+ }) : null;
633
+ const documentRead = result?.read ? classifyReadinessRead(result.read.status, undefined, documentFailures.current.failures, {
634
+ kind: 'document',
635
+ surface: 'editor',
636
+ resultsOnly
637
+ }) : undefined;
638
+ const accessNotice = result?.missing ? /*#__PURE__*/ _jsx("p", {
639
+ className: "xp-ui-help",
640
+ children: editorCopy.deleted
641
+ }) : documentRead ? documentRead.retry ? /*#__PURE__*/ _jsx(Banner, {
642
+ tone: "error",
643
+ action: /*#__PURE__*/ _jsx(Button, {
644
+ onClick: ()=>setReadAttempt((value)=>value + 1),
645
+ children: editorCopy.retrySetup
646
+ }),
647
+ children: documentRead.message
648
+ }) : /*#__PURE__*/ _jsx("p", {
649
+ className: "xp-ui-help",
650
+ children: documentRead.message
651
+ }) : !access.surface && !access.error ? /*#__PURE__*/ _jsx("p", {
652
+ className: "xp-ui-help",
653
+ role: "status",
654
+ children: editorCopy.loading
655
+ }) : access.error === 'unavailable' ? /*#__PURE__*/ _jsxs("p", {
656
+ className: "xp-ui-help",
657
+ children: [
658
+ editorCopy.controlsUnavailable,
659
+ " ",
660
+ /*#__PURE__*/ _jsx(Button, {
661
+ onClick: access.retry,
662
+ children: editorCopy.retrySetup
663
+ })
664
+ ]
665
+ }) : experimentId === undefined && resultsOnly ? /*#__PURE__*/ _jsx("p", {
666
+ className: "xp-ui-help",
667
+ children: editorCopy.setupForbidden
668
+ }) : experimentId === undefined && noAccess ? /*#__PURE__*/ _jsx("p", {
669
+ className: "xp-ui-help",
670
+ children: pickerCopy.forbiddenUnbound
671
+ }) : experimentId !== undefined && (noAccess || unavailable || resultsOnly) ? /*#__PURE__*/ _jsx("p", {
672
+ className: "xp-ui-help",
673
+ children: resultsOnly ? pickerCopy.resultsOnly : pickerCopy.forbidden
674
+ }) : /*#__PURE__*/ _jsx(Banner, {
675
+ tone: experiment?.status === 'running' ? 'warning' : 'info',
676
+ children: experimentId === undefined ? bannerFor() : experiment ? bannerFor(experiment.status, winner, originalLabel) : editorCopy.loading
677
+ });
678
+ const removeDialog = removing?.key === bindingKey ? /*#__PURE__*/ _jsx(RemoveVersion, {
679
+ count: countSlotBlocks(getPuck().getItemById(props.id)?.props[removing.arm.key]),
680
+ shared: locallyShared ? true : result?.shared,
681
+ arm: removing.arm,
682
+ writes: writes,
683
+ onRemove: removeContent,
684
+ onClose: ()=>setRemoving(null)
439
685
  }) : null;
440
686
  return /*#__PURE__*/ _jsxs("section", {
441
687
  ref: root,
442
688
  className: "xp-slot-root xp-slot-editor",
443
689
  style: props.accent ? accentVariables(props.accent[mode]) : undefined,
444
690
  children: [
691
+ sidebar ? /*#__PURE__*/ _jsxs(_Fragment, {
692
+ children: [
693
+ /*#__PURE__*/ createPortal(/*#__PURE__*/ _jsx("div", {
694
+ onClick: (event)=>event.stopPropagation(),
695
+ onKeyDown: (event)=>event.stopPropagation(),
696
+ children: /*#__PURE__*/ _jsx("section", {
697
+ "aria-label": editorCopy.testGroup,
698
+ children: /*#__PURE__*/ _jsxs(FieldGroup, {
699
+ label: editorCopy.testGroup,
700
+ collapsible: false,
701
+ children: [
702
+ experiment ? /*#__PURE__*/ _jsxs(_Fragment, {
703
+ children: [
704
+ /*#__PURE__*/ _jsx("strong", {
705
+ children: experiment.name
706
+ }),
707
+ /*#__PURE__*/ _jsx(StatusChip, {
708
+ status: experiment.status
709
+ })
710
+ ]
711
+ }) : null,
712
+ accessNotice,
713
+ shared ? /*#__PURE__*/ _jsx(Banner, {
714
+ tone: "info",
715
+ children: editorCopy.sharedTest
716
+ }) : null,
717
+ placementNoticeView,
718
+ canManage ? /*#__PURE__*/ _jsx(_Fragment, {
719
+ children: experiment?.status === 'draft' || experiment?.status === 'stopped' ? /*#__PURE__*/ _jsx(BlockerList, {
720
+ steps: sidebarBlockers
721
+ }) : null
722
+ }) : null,
723
+ experimentId !== undefined && access.surface && !result?.missing && !result?.error && !noAccess && (!unavailable || resultsOnly) ? /*#__PURE__*/ _jsx(ConfigureTestControl, {
724
+ id: experimentId,
725
+ routes: {
726
+ admin,
727
+ api
728
+ }
729
+ }) : null,
730
+ canManage && experiment && surface ? /*#__PURE__*/ _jsx(QuickTestActions, {
731
+ test: quickTest,
732
+ surface: surface
733
+ }, `${experimentId}/${experiment.status}`) : null,
734
+ canSetUp ? /*#__PURE__*/ _jsx(Button, {
735
+ variant: "primary",
736
+ busy: settingUp,
737
+ disabled: settingUp,
738
+ onClick: ()=>void setUpTest(),
739
+ children: editorCopy.createLabel
740
+ }) : null,
741
+ experimentId === undefined && canManage ? /*#__PURE__*/ _jsx(Button, {
742
+ disabled: settingUp,
743
+ onClick: ()=>setChoosing(true),
744
+ children: editorCopy.existingTest
745
+ }) : null,
746
+ setupError && canSetUp ? /*#__PURE__*/ _jsx("p", {
747
+ role: "alert",
748
+ children: setupError
749
+ }) : null
750
+ ]
751
+ })
752
+ })
753
+ }), sidebar.test),
754
+ /*#__PURE__*/ createPortal(/*#__PURE__*/ _jsxs("div", {
755
+ onClick: (event)=>event.stopPropagation(),
756
+ onKeyDown: (event)=>event.stopPropagation(),
757
+ children: [
758
+ experiment && access.surface && !noAccess ? /*#__PURE__*/ _jsx("section", {
759
+ "aria-label": editorCopy.versionsGroup,
760
+ children: /*#__PURE__*/ _jsxs(FieldGroup, {
761
+ label: editorCopy.versionsGroup,
762
+ collapsible: false,
763
+ children: [
764
+ !editable ? /*#__PURE__*/ _jsx("p", {
765
+ className: "xp-ui-help",
766
+ children: canManage ? editorCopy.locked[experiment.status] ?? editorCopy.lockedGeneric : editorCopy.readOnlyVersions
767
+ }) : null,
768
+ /*#__PURE__*/ _jsx(VersionWeights, {
769
+ edits: weightEdits,
770
+ setEdits: setWeightEdits,
771
+ groupId: props.id,
772
+ splitIntent: splitIntent,
773
+ experiment: experiment,
774
+ writes: writes,
775
+ editable: editable,
776
+ beforeSplit: /*#__PURE__*/ _jsxs(_Fragment, {
777
+ children: [
778
+ leftoverControls,
779
+ editable ? /*#__PURE__*/ _jsx(AddVariant, {
780
+ experiment: experiment,
781
+ writes: writes,
782
+ onSelect: (slot)=>{
783
+ if (isCurrentBinding()) setActive({
784
+ id: experimentId,
785
+ slot
786
+ });
787
+ }
788
+ }) : null
789
+ ]
790
+ }),
791
+ renderRow: (arm, input)=>/*#__PURE__*/ _jsx("div", {
792
+ className: "xp-slot-version-group",
793
+ "data-active": slot === arm.key,
794
+ role: "group",
795
+ "aria-label": arm.label,
796
+ children: /*#__PURE__*/ _jsxs(FieldGroup, {
797
+ variant: "card",
798
+ collapsible: false,
799
+ children: [
800
+ /*#__PURE__*/ _jsx(Button, {
801
+ variant: "quiet",
802
+ "aria-pressed": slot === arm.key,
803
+ disabled: arm.kind === 'holdout' || dragging,
804
+ onClick: ()=>setActive({
805
+ id: experimentId,
806
+ slot: arm.key
807
+ }),
808
+ children: arm.label
809
+ }),
810
+ /*#__PURE__*/ _jsx(VersionName, {
811
+ arm: arm,
812
+ writes: writes,
813
+ editable: editable
814
+ }, `${experimentId}-${arm.key}`),
815
+ input,
816
+ arm.kind === 'variant' ? /*#__PURE__*/ _jsxs(_Fragment, {
817
+ children: [
818
+ /*#__PURE__*/ _jsx(Button, {
819
+ disabled: originalEmpty,
820
+ "aria-disabled": writes.busy || undefined,
821
+ onClick: ()=>{
822
+ if (!writes.busy) requestCopy(arm.key);
823
+ },
824
+ children: editorCopy.copy(originalLabel)
825
+ }),
826
+ originalEmpty ? /*#__PURE__*/ _jsx("p", {
827
+ className: "xp-ui-help",
828
+ children: editorCopy.copyEmpty(originalLabel)
829
+ }) : null
830
+ ]
831
+ }) : null,
832
+ editable && arm.kind !== 'control' ? /*#__PURE__*/ _jsx(Button, {
833
+ "aria-disabled": writes.busy || undefined,
834
+ onClick: ()=>{
835
+ if (!writes.busy) setRemoving({
836
+ key: bindingKey,
837
+ arm
838
+ });
839
+ },
840
+ children: editorCopy.removeVersion
841
+ }) : null
842
+ ]
843
+ })
844
+ })
845
+ }, bindingKey)
846
+ ]
847
+ })
848
+ }) : null,
849
+ access.surface?.canManage && experimentId !== undefined ? /*#__PURE__*/ _jsx(FieldGroup, {
850
+ label: editorCopy.moreGroup,
851
+ defaultExpanded: false,
852
+ children: /*#__PURE__*/ _jsx(Button, {
853
+ onClick: ()=>setChoosing(true),
854
+ children: editorCopy.differentTest
855
+ })
856
+ }) : null,
857
+ writes.busy ? /*#__PURE__*/ _jsx("p", {
858
+ role: "status",
859
+ children: editorCopy.savingVersions
860
+ }) : null,
861
+ writes.error ? /*#__PURE__*/ _jsx("p", {
862
+ role: "alert",
863
+ children: writes.error
864
+ }) : null,
865
+ clearError?.key === bindingKey ? /*#__PURE__*/ _jsx("p", {
866
+ role: "alert",
867
+ children: clearError.message
868
+ }) : null,
869
+ removed?.key === bindingKey && removed.contentRemoved ? /*#__PURE__*/ _jsx("p", {
870
+ children: editorCopy.removed
871
+ }) : null,
872
+ experiment && experiment.status !== 'draft' ? /*#__PURE__*/ _jsx(ResultsReadout, {
873
+ id: experimentId,
874
+ api: api,
875
+ experiment: experiment
876
+ }, `results-${experimentId}`) : null,
877
+ confirming ? /*#__PURE__*/ _jsxs("div", {
878
+ className: "xp-slot-copy-confirm",
879
+ role: "alert",
880
+ children: [
881
+ /*#__PURE__*/ _jsx("p", {
882
+ children: editorCopy.replaceConfirm(tabs.find((tab)=>tab.slot === confirming)?.label ?? confirming, originalLabel)
883
+ }),
884
+ /*#__PURE__*/ _jsxs("div", {
885
+ className: "xp-ui-button-group",
886
+ children: [
887
+ /*#__PURE__*/ _jsx(Button, {
888
+ variant: "primary",
889
+ onClick: ()=>copyTo(confirming),
890
+ children: editorCopy.replace
891
+ }),
892
+ /*#__PURE__*/ _jsx(Button, {
893
+ onClick: ()=>setConfirming(null),
894
+ children: editorCopy.cancel
895
+ })
896
+ ]
897
+ })
898
+ ]
899
+ }) : null,
900
+ removeDialog,
901
+ choosing ? /*#__PURE__*/ _jsx(Dialog, {
902
+ open: true,
903
+ title: experimentId === undefined ? editorCopy.existingTest : editorCopy.differentTest,
904
+ onClose: ()=>setChoosing(false),
905
+ children: /*#__PURE__*/ _jsxs("div", {
906
+ className: "xp-slot-drawer",
907
+ children: [
908
+ /*#__PURE__*/ _jsx(ExperimentPicker, {
909
+ value: props.experiment ?? null,
910
+ allowEmpty: false,
911
+ onChange: (value)=>{
912
+ if (value && bind(value)) setChoosing(false);
913
+ }
914
+ }),
915
+ /*#__PURE__*/ _jsx(Button, {
916
+ disabled: experimentId !== undefined && !experiment && !unavailable && !result?.error,
917
+ onClick: ()=>{
918
+ setChoosing(false);
919
+ createFromBlock();
920
+ },
921
+ children: editorCopy.createAnother
922
+ }),
923
+ /*#__PURE__*/ _jsx(Button, {
924
+ onClick: ()=>setChoosing(false),
925
+ children: editorCopy.cancel
926
+ })
927
+ ]
928
+ })
929
+ }) : null
930
+ ]
931
+ }), sidebar.controls)
932
+ ]
933
+ }) : null,
445
934
  /*#__PURE__*/ _jsxs(EditorControls, {
446
935
  className: "xp-slot-chrome",
447
936
  selected: isSelected,
@@ -459,210 +948,49 @@ function EditorRender(props) {
459
948
  },
460
949
  children: [
461
950
  /*#__PURE__*/ _jsx("h3", {
462
- className: "xp-slot-title",
463
- children: experiment?.name ?? experimentSlotLabel
951
+ className: experimentId === undefined || result?.missing ? "xp-slot-title xp-slot-title-sentence" : "xp-slot-title",
952
+ title: experimentId === undefined ? editorCopy.unbound : result?.missing ? editorCopy.deleted : experiment?.name ?? experimentSlotLabel,
953
+ children: experimentId === undefined ? editorCopy.unbound : result?.missing ? editorCopy.deleted : experiment?.name ?? experimentSlotLabel
464
954
  }),
465
955
  experiment ? /*#__PURE__*/ _jsx(StatusChip, {
466
956
  status: experiment.status
467
- }) : experimentId === undefined ? /*#__PURE__*/ _jsx("span", {
468
- className: "xp-ui-status",
469
- children: editorCopy.notSetUp
470
957
  }) : null
471
958
  ]
472
959
  }),
473
- result?.missing ? /*#__PURE__*/ _jsx("p", {
474
- className: "xp-ui-help",
475
- children: pickerCopy.unavailable
476
- }) : !access.surface && !access.error ? /*#__PURE__*/ _jsx("p", {
477
- className: "xp-ui-help",
478
- role: "status",
479
- children: editorCopy.loading
480
- }) : access.error === 'unavailable' ? /*#__PURE__*/ _jsxs("p", {
481
- className: "xp-ui-help",
482
- children: [
483
- editorCopy.controlsUnavailable,
484
- " ",
485
- /*#__PURE__*/ _jsx(Button, {
486
- onClick: access.retry,
487
- children: editorCopy.retrySetup
488
- })
489
- ]
490
- }) : experimentId === undefined && resultsOnly ? /*#__PURE__*/ _jsx("p", {
491
- className: "xp-ui-help",
492
- children: editorCopy.setupForbidden
493
- }) : experimentId === undefined && noAccess ? /*#__PURE__*/ _jsx("p", {
494
- className: "xp-ui-help",
495
- children: pickerCopy.forbiddenUnbound
496
- }) : experimentId !== undefined && (noAccess || unavailable || resultsOnly) ? /*#__PURE__*/ _jsx("p", {
497
- className: "xp-ui-help",
498
- children: resultsOnly ? pickerCopy.resultsOnly : pickerCopy.forbidden
499
- }) : /*#__PURE__*/ _jsx(Banner, {
500
- tone: result?.error ? 'error' : experiment?.status === 'running' ? 'warning' : 'info',
501
- children: experimentId === undefined ? bannerFor() : result?.error ? editorCopy.loadError : experiment ? bannerFor(experiment.status, winner) : editorCopy.loading
502
- }),
503
- orphanSlots.map((slot)=>/*#__PURE__*/ _jsx(Banner, {
504
- tone: "warning",
505
- children: editorCopy.orphan(slotLabels[slot])
506
- }, slot)),
960
+ canSetUp || result?.missing ? null : accessNotice,
507
961
  shared ? /*#__PURE__*/ _jsx(Banner, {
508
962
  tone: "info",
509
- action: newTestButton,
510
963
  children: editorCopy.sharedTest
511
964
  }) : null,
512
- /*#__PURE__*/ _jsxs("div", {
513
- className: "xp-ui-button-group",
514
- children: [
515
- experimentId === undefined && canManage ? /*#__PURE__*/ _jsx(Button, {
516
- variant: "primary",
517
- onClick: createFromBlock,
518
- children: editorCopy.createLabel
519
- }) : null,
520
- experimentId !== undefined && access.surface && !result?.missing && !noAccess && (!unavailable || resultsOnly) ? /*#__PURE__*/ _jsx(ConfigureTestControl, {
521
- id: experimentId,
522
- routes: {
523
- admin,
524
- api
525
- }
526
- }) : null,
527
- !shared ? newTestButton : null,
528
- experimentId !== undefined && canDetach ? /*#__PURE__*/ _jsx(Button, {
529
- disabled: checkingDetach,
530
- onClick: ()=>void requestDetach(),
531
- children: editorCopy.detach
532
- }) : null,
533
- experiment && editable ? /*#__PURE__*/ _jsx(AddVariant, {
534
- experiment: experiment,
535
- writes: writes,
536
- onSelect: (slot)=>{
537
- if (isCurrentBinding()) setActive({
538
- id: experimentId,
539
- slot
540
- });
541
- }
542
- }) : null
543
- ]
544
- }),
545
- experiment?.status === 'running' && result?.shared !== undefined && !shared ? /*#__PURE__*/ _jsx("p", {
546
- className: "xp-ui-help",
547
- children: editorCopy.stopToDetach
548
- }) : null,
549
- experiment && !editable ? /*#__PURE__*/ _jsx("p", {
550
- className: "xp-ui-help",
551
- children: editorCopy.locked[experiment.status]
552
- }) : null,
553
- experiment && editable ? /*#__PURE__*/ _jsx(VersionWeights, {
554
- experiment: experiment,
555
- writes: writes
556
- }, `weights-${experimentId}`) : null,
557
- writes.error ? /*#__PURE__*/ _jsx("p", {
558
- role: "alert",
559
- className: "xp-ui-error",
560
- children: writes.error
561
- }) : null,
562
- clearError?.key === bindingKey ? /*#__PURE__*/ _jsx("p", {
563
- role: "alert",
564
- className: "xp-ui-error",
565
- children: clearError.message
566
- }) : null,
567
- removed?.key === bindingKey ? /*#__PURE__*/ _jsx("p", {
568
- className: "xp-ui-help",
569
- children: editorCopy.removed
570
- }) : null,
571
- experiment && experiment.status !== 'draft' ? /*#__PURE__*/ _jsx(ResultsReadout, {
572
- id: experimentId,
573
- api: api,
574
- experiment: experiment
575
- }, `results-${experimentId}`) : null,
576
- removing?.key === bindingKey ? /*#__PURE__*/ _jsx(RemoveVersion, {
577
- arm: removing.arm,
578
- writes: writes,
579
- onRemove: removeContent,
580
- onClose: ()=>setRemoving(null)
581
- }) : null,
582
- detaching === bindingKey && canDetach ? /*#__PURE__*/ _jsx(Dialog, {
583
- open: true,
584
- title: editorCopy.detachTitle,
585
- initialFocus: "cancel",
586
- onClose: ()=>setDetaching(null),
587
- children: /*#__PURE__*/ _jsxs("div", {
588
- className: "xp-slot-drawer",
589
- children: [
590
- /*#__PURE__*/ _jsx("p", {
591
- children: experiment?.status === 'running' && shared ? editorCopy.detachRunningHelp : editorCopy.detachHelp
592
- }),
593
- /*#__PURE__*/ _jsxs("div", {
594
- className: "xp-ui-button-group",
595
- children: [
596
- /*#__PURE__*/ _jsx(Button, {
597
- "data-dialog-cancel": true,
598
- onClick: ()=>setDetaching(null),
599
- children: editorCopy.cancel
600
- }),
601
- /*#__PURE__*/ _jsx(Button, {
602
- disabled: checkingDetach,
603
- onClick: ()=>void requestDetach(true),
604
- children: editorCopy.detach
605
- })
606
- ]
607
- })
608
- ]
609
- })
965
+ placementNoticeView,
966
+ setupError && canSetUp ? /*#__PURE__*/ _jsx("p", {
967
+ role: sidebar ? undefined : 'alert',
968
+ children: setupError
610
969
  }) : null,
611
- confirming ? /*#__PURE__*/ _jsxs("div", {
612
- className: "xp-slot-confirm",
613
- role: "alert",
614
- children: [
615
- /*#__PURE__*/ _jsx("p", {
616
- children: editorCopy.replaceConfirm(tabs.find((tab)=>tab.slot === confirming)?.label ?? confirming)
617
- }),
618
- /*#__PURE__*/ _jsxs("div", {
619
- className: "xp-ui-button-group",
620
- children: [
621
- /*#__PURE__*/ _jsx(Button, {
622
- variant: "primary",
623
- onClick: ()=>copyTo(confirming),
624
- children: editorCopy.replace
625
- }),
626
- /*#__PURE__*/ _jsx(Button, {
627
- onClick: ()=>setConfirming(null),
628
- children: editorCopy.cancel
629
- })
630
- ]
631
- })
632
- ]
970
+ canSetUp ? /*#__PURE__*/ _jsx(Button, {
971
+ variant: "primary",
972
+ busy: settingUp,
973
+ disabled: settingUp,
974
+ onClick: ()=>void setUpTest(),
975
+ children: editorCopy.createLabel
633
976
  }) : null
634
977
  ]
635
978
  }),
636
979
  /*#__PURE__*/ _jsx(Tabs, {
980
+ disabled: dragging,
637
981
  label: editorCopy.tabs,
638
982
  value: slot,
639
983
  renderHeader: (children)=>/*#__PURE__*/ _jsx(EditorControls, {
640
984
  className: "xp-ui-tabs-header",
641
985
  children: children
642
986
  }),
643
- onChange: (value)=>{
644
- setOpenMenu(null);
645
- setActive({
987
+ onChange: (value)=>setActive({
646
988
  id: experimentId,
647
989
  slot: value
648
- });
649
- },
990
+ }),
650
991
  items: tabs.map((tab)=>({
651
992
  id: tab.slot,
652
993
  label: tab.label,
653
- actions: experiment ? /*#__PURE__*/ _jsx(VersionActions, {
654
- arm: experiment.arms.find((arm)=>arm.key === tab.slot),
655
- writes: writes,
656
- editable: editable,
657
- open: openMenu === tab.slot,
658
- onOpenChange: (open)=>setOpenMenu(open ? tab.slot : null),
659
- canCopy: !originalEmpty,
660
- onCopy: requestCopy,
661
- onRequestRemove: ()=>setRemoving({
662
- key: bindingKey,
663
- arm: experiment.arms.find((arm)=>arm.key === tab.slot)
664
- })
665
- }, `${experimentId}-${tab.slot}`) : undefined,
666
994
  content: tab.slot === slot ? /*#__PURE__*/ _jsxs("div", {
667
995
  className: slotEmpty ? 'xp-slot-panel xp-slot-panel-empty' : 'xp-slot-panel',
668
996
  children: [
@@ -671,7 +999,7 @@ function EditorRender(props) {
671
999
  }),
672
1000
  slotEmpty ? /*#__PURE__*/ _jsx("span", {
673
1001
  className: "xp-slot-drop-label",
674
- children: editorCopy.dropZone(slot)
1002
+ children: editorCopy.dropZone(tabs.find((tab)=>tab.slot === slot)?.label ?? slotLabels[slot])
675
1003
  }) : null
676
1004
  ]
677
1005
  }) : null
@@ -688,17 +1016,14 @@ export function createExperimentSlotEditor({ routes: inputRoutes, accent } = {})
688
1016
  label: experimentSlotLabel,
689
1017
  fields: {
690
1018
  ...experimentSlotFields,
691
- experiment: createExperimentSlotField({
692
- routes,
693
- renderActions: (test)=>/*#__PURE__*/ _jsx(ConfigureTestButton, {
694
- id: test.id,
695
- routes: routes
696
- }),
697
- onBind: (previous, next)=>{
698
- if (previous) invalidatePlacements(routes.api, previous.id);
699
- if (next) invalidatePlacements(routes.api, next.id);
700
- }
701
- })
1019
+ experiment: {
1020
+ type: 'custom',
1021
+ label: pickerCopy.label,
1022
+ render: ()=>/*#__PURE__*/ _jsx(PuckHostProvider, {
1023
+ routes: routes,
1024
+ children: /*#__PURE__*/ _jsx(TestSidebarField, {})
1025
+ })
1026
+ }
702
1027
  },
703
1028
  defaultProps: experimentSlotDefaultProps,
704
1029
  render: (props)=>/*#__PURE__*/ _jsx(PuckHostProvider, {