@delmaredigital/payload-experiments 0.4.0-rc.5 → 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 (65) 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/newTest/NewTest.js +16 -18
  4. package/dist/admin/surface/newTest/newTest.css +3 -1
  5. package/dist/blocks/bindings.js +6 -13
  6. package/dist/blocks/placementLocale.d.ts +2 -0
  7. package/dist/blocks/placementLocale.js +16 -12
  8. package/dist/goals/fairness.js +8 -6
  9. package/dist/hooks/blockRemovalRule.d.ts +2 -1
  10. package/dist/hooks/blockRemovalRule.js +27 -5
  11. package/dist/hooks/pageGuard.js +2 -2
  12. package/dist/puck/ExperimentPicker.d.ts +2 -1
  13. package/dist/puck/ExperimentPicker.js +34 -30
  14. package/dist/puck/ExperimentSlot.js +3 -1
  15. package/dist/puck/copy.d.ts +1 -0
  16. package/dist/puck/copy.js +1 -0
  17. package/dist/puck/editor/CreateExperimentDrawer.d.ts +2 -1
  18. package/dist/puck/editor/CreateExperimentDrawer.js +24 -20
  19. package/dist/puck/editor/EditorControls.d.ts +1 -1
  20. package/dist/puck/editor/EditorControls.js +1 -1
  21. package/dist/puck/editor/ExperimentSlotEditor.js +354 -374
  22. package/dist/puck/editor/LeftoverVersions.d.ts +3 -1
  23. package/dist/puck/editor/LeftoverVersions.js +45 -63
  24. package/dist/puck/editor/QuickTestActions.js +2 -2
  25. package/dist/puck/editor/VersionBuilder.d.ts +24 -13
  26. package/dist/puck/editor/VersionBuilder.js +264 -205
  27. package/dist/puck/editor/armWrites.d.ts +9 -2
  28. package/dist/puck/editor/armWrites.js +40 -2
  29. package/dist/puck/editor/armsCache.d.ts +1 -1
  30. package/dist/puck/editor/armsCache.js +2 -1
  31. package/dist/puck/editor/copy.d.ts +19 -25
  32. package/dist/puck/editor/copy.js +19 -25
  33. package/dist/puck/editor/createTest.d.ts +3 -0
  34. package/dist/puck/editor/createTest.js +33 -0
  35. package/dist/puck/editor/editor.chrome.css +24 -17
  36. package/dist/puck/editor/editor.css +33 -21
  37. package/dist/puck/editor/editor.model.d.ts +1 -1
  38. package/dist/puck/editor/editor.model.js +2 -2
  39. package/dist/puck/editor/experimentOutlinePlugin.js +1 -1
  40. package/dist/puck/editor/localPlacements.d.ts +4 -2
  41. package/dist/puck/editor/localPlacements.js +20 -18
  42. package/dist/puck/editor/sidebar.d.ts +2 -6
  43. package/dist/puck/editor/sidebar.js +3 -6
  44. package/dist/puck/visibility.d.ts +21 -0
  45. package/dist/puck/visibility.js +77 -0
  46. package/dist/server/recordContentChange.js +3 -1
  47. package/dist/server/resolveExperimentData.js +4 -1
  48. package/dist/testSurface/copy/readiness.d.ts +1 -0
  49. package/dist/testSurface/copy/readiness.js +1 -0
  50. package/dist/testSurface/copy/testPage.d.ts +7 -6
  51. package/dist/testSurface/copy/testPage.js +7 -6
  52. package/dist/testSurface/results/results.css +1 -1
  53. package/dist/testSurface/results/results.model.d.ts +1 -1
  54. package/dist/testSurface/surface/readiness/ActionDialogs.js +28 -34
  55. package/dist/testSurface/surface/test/GoalSection.js +101 -74
  56. package/dist/testSurface/surface/test/fields.d.ts +1 -3
  57. package/dist/testSurface/surface/test/fields.js +5 -35
  58. package/dist/transitions/makeContent.js +24 -5
  59. package/dist/transitions/placements.js +23 -34
  60. package/dist/types/puck.d.ts +1 -0
  61. package/dist/ui/Inputs.js +8 -5
  62. package/dist/ui/Tabs.d.ts +0 -1
  63. package/dist/ui/Tabs.js +28 -40
  64. package/dist/ui/ui.css +9 -4
  65. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { createPortal } from 'react-dom';
4
- import { createUsePuck, useGetPuck } from '@puckeditor/core';
4
+ import { createUsePuck, useGetPuck, FieldGroup } from '@puckeditor/core';
5
5
  import { useEffect, useRef, useState } from 'react';
6
6
  import { defaultArms } from '../../arms/model.js';
7
7
  import { readExperiment } from './armWrites.js';
@@ -30,15 +30,16 @@ import { cloneSlot, countSlotBlocks } from './cloneSlot.js';
30
30
  import { openCreateExperimentDrawer } from './CreateExperimentDrawer.js';
31
31
  import { editorCopy } from './copy.js';
32
32
  import { acquireArms, loadArms, publishExperiment, useArms } from './armsCache.js';
33
- import { AddVariant, RemoveVersion, VersionActions, VersionWeights, useArmWrites } from './VersionBuilder.js';
33
+ import { AddVariant, RemoveVersion, VersionName, VersionWeights, useArmWrites } from './VersionBuilder.js';
34
34
  import { ResultsReadout } from './ResultsReadout.js';
35
35
  import { EditorControls } from './EditorControls.js';
36
- import { acquirePlacements, subscribePlacements, cachedPreflight, cachedReadinessRead, placementsPending, placementsBlocking, placementReadError, invalidatePlacements, refreshPlacements, focusPlacements } from './placementsCache.js';
36
+ import { acquirePlacements, cachedPreflight, cachedReadinessRead, placementsPending, placementsBlocking, placementReadError, invalidatePlacements, refreshPlacements, focusPlacements } from './placementsCache.js';
37
37
  import { sidebarReadinessBlockers, editorPlacementMessage } from '../../testSurface/surface/editorPlacement.js';
38
- import { localPlacements } from './localPlacements.js';
38
+ import { localPlacements, localBlockVisibility } from './localPlacements.js';
39
39
  import { usePlacementNotice } from './usePlacementNotice.js';
40
40
  import { useEditorSurface } from './editorSurface.js';
41
- import { ConfigureTestControl } from './ConfigureTestDrawer.js';
41
+ import { createBlockTest, CreateRefused } from './createTest.js';
42
+ import { ConfigureTestControl, openConfigureTestDrawer } from './ConfigureTestDrawer.js';
42
43
  import './editor.css';
43
44
  const usePuckSelector = createUsePuck();
44
45
  class TestReadError extends Error {
@@ -116,14 +117,21 @@ function EditorRender(props) {
116
117
  };
117
118
  useReadinessPolling(loaded?.id === experimentId ? loaded?.read : undefined, ()=>setReadAttempt((value)=>value + 1), true, documentPending);
118
119
  const [active, setActive] = useState();
119
- const [openMenu, setOpenMenu] = useState(null);
120
+ const [choosing, setChoosing] = useState(false);
120
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(), []);
121
127
  const creation = useRef(undefined);
122
128
  useEffect(()=>()=>creation.current?.closeIfIdle(), []);
123
- const [detaching, setDetaching] = useState(null);
124
129
  // A non-empty variant is only overwritten after an explicit second confirmation.
125
130
  const [confirming, setConfirming] = useState(null);
126
- // 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.
127
135
  const [removing, setRemoving] = useState(null);
128
136
  const pageTitle = usePuckSelector((state)=>typeof state.appState.data.root.props?.title === 'string' ? state.appState.data.root.props.title : '');
129
137
  // Selection only changes the chrome's appearance; actions always resolve this block by id.
@@ -249,7 +257,13 @@ function EditorRender(props) {
249
257
  status,
250
258
  access.surface?.canManage
251
259
  ]);
252
- 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);
253
267
  const result = experimentId === undefined || loaded?.id !== experimentId ? undefined : loaded;
254
268
  const shared = locallyShared || result?.shared === true;
255
269
  const experiment = cachedExperiment ?? result?.doc;
@@ -257,6 +271,7 @@ function EditorRender(props) {
257
271
  const resultsOnly = access.surface?.canReadResults === true && !access.surface.canManage;
258
272
  const unavailable = result?.forbidden || result?.missing;
259
273
  const canManage = access.surface?.canManage === true && !unavailable;
274
+ const canSetUp = access.surface?.canManage === true && (experimentId === undefined || result?.missing === true);
260
275
  const editable = canManage && (experiment?.status === 'draft' || experiment?.status === 'stopped');
261
276
  const [removed, setRemoved] = useState(null);
262
277
  useEffect(()=>{
@@ -268,6 +283,14 @@ function EditorRender(props) {
268
283
  ]);
269
284
  const splitIntent = useRef(false);
270
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
+ ]);
271
294
  useEffect(()=>{
272
295
  setWeightEdits({});
273
296
  splitIntent.current = false;
@@ -275,16 +298,40 @@ function EditorRender(props) {
275
298
  bindingKey,
276
299
  status
277
300
  ]);
278
- const writes = useArmWrites(`${api}/xp-experiments/${encodeURIComponent(String(experimentId))}`, (doc)=>{
279
- publishExperiment(experimentId, doc);
280
- if (isCurrentBinding()) setLoaded((value)=>({
281
- id: experimentId,
282
- doc,
283
- shared: value?.id === experimentId ? value?.shared : undefined
284
- }));
285
- }, isCurrentBinding, ()=>setClearError(null), ()=>{
286
- if (isCurrentBinding()) setWeightEdits({});
287
- invalidatePlacements(api, experimentId);
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
+ }
288
335
  });
289
336
  // The slot arrays belong to the page; reading the test is unnecessary to edit them.
290
337
  const pageSlots = usePuckSelector((state)=>[
@@ -333,6 +380,7 @@ function EditorRender(props) {
333
380
  slot
334
381
  ]);
335
382
  const Slot = props[slot];
383
+ const originalLabel = tabs.find((tab)=>tab.slot === 'control')?.label ?? slotLabels.control;
336
384
  const winnerKey = experiment?.decision?.winnerArm;
337
385
  const winner = tabs.find((tab)=>tab.slot === winnerKey)?.label;
338
386
  function selectBlock() {
@@ -442,14 +490,21 @@ function EditorRender(props) {
442
490
  if (!isCurrentBinding()) throw new Error('binding');
443
491
  const item = getPuck().getItemById(props.id);
444
492
  if (!item) throw new Error('binding');
445
- if (experimentId === undefined) return armsFromBlock({
446
- arms: defaultArms('block')
493
+ if (experimentId === undefined || result?.missing || result?.forbidden || result?.error) return armsFromBlock({
494
+ arms: [
495
+ defaultArms('block')[0]
496
+ ]
447
497
  }, item.props);
448
498
  // Another placement can rename or add a version while this dialog is open.
449
499
  const response = await fetch(`${api}/xp-experiments/${encodeURIComponent(String(experimentId))}?depth=0`, {
450
500
  credentials: 'include',
451
501
  cache: 'no-store'
452
502
  });
503
+ if (response.status === 403 || response.status === 404) return armsFromBlock({
504
+ arms: [
505
+ defaultArms('block')[0]
506
+ ]
507
+ }, item.props);
453
508
  if (!response.ok) throw new Error('load');
454
509
  const doc = await response.json();
455
510
  const latest = getPuck().getItemById(props.id);
@@ -464,88 +519,36 @@ function EditorRender(props) {
464
519
  }, {
465
520
  initialName: pageTitle,
466
521
  arms: newTestArms,
467
- label: experimentId === undefined ? editorCopy.createLabel : editorCopy.newTest,
468
522
  onCreate: bind
469
523
  });
470
524
  }
471
- const canDetach = !!result?.forbidden || !!result?.missing || !!experiment && (experiment.status !== 'running' || result?.shared !== undefined && shared);
472
- const [checkingDetach, setCheckingDetach] = useState(false);
473
- const detachBusy = useRef(false);
474
- async function requestDetach(confirm = false) {
475
- if (detachBusy.current || experimentId === undefined) return;
476
- detachBusy.current = true;
477
- setCheckingDetach(true);
478
- setClearError(null);
479
- let releasePlacements;
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('');
480
531
  try {
481
- const response = await fetch(`${api}/xp-experiments/${encodeURIComponent(String(experimentId))}?depth=0`, {
482
- credentials: 'include',
483
- 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
484
543
  });
485
- const current = response.ok ? await response.json() : null;
486
- if (!isCurrentBinding()) return;
487
- if (![
488
- 401,
489
- 403,
490
- 404
491
- ].includes(response.status) && !isExperiment(current)) {
492
- setClearError({
493
- key: bindingKey,
494
- message: editorCopy.placementsError
495
- });
496
- setDetaching(null);
497
- return;
498
- }
499
- // A status change replaces the display subscription; keep the explicit running check alive.
500
- if (isExperiment(current) && current.status === 'running') releasePlacements = subscribePlacements(api, experimentId, ()=>{});
501
- if (isExperiment(current)) publishExperiment(experimentId, current);
502
- if (isExperiment(current) && current.status === 'running') {
503
- const placements = await refreshPlacements(api, experimentId);
504
- if (!isCurrentBinding()) return;
505
- if (!placements) {
506
- setClearError({
507
- key: bindingKey,
508
- message: editorCopy.placementsError
509
- });
510
- setDetaching(null);
511
- return;
512
- }
513
- const local = getPuck();
514
- const anotherLocal = (localPlacements(local.appState.data, local.config).get(String(experimentId))?.size ?? 0) > 1;
515
- if (!anotherLocal && !isSharedTest(placements, currentPuckDocument(window.location.pathname, admin, placements))) {
516
- setClearError({
517
- key: bindingKey,
518
- message: editorCopy.stopToDetach
519
- });
520
- setDetaching(null);
521
- return;
522
- }
523
- }
524
- if (!isCurrentBinding()) return;
525
- if (confirm) {
526
- bind(null);
527
- setDetaching(null);
528
- } else setDetaching(bindingKey);
529
- } catch {
530
- if (isCurrentBinding()) {
531
- setClearError({
532
- key: bindingKey,
533
- message: editorCopy.placementsError
534
- });
535
- setDetaching(null);
536
- }
544
+ } catch (cause) {
545
+ if (isCurrentBinding()) setSetupError(cause instanceof CreateRefused ? cause.message : editorCopy.createError);
537
546
  } finally{
538
- releasePlacements?.();
539
- detachBusy.current = false;
540
- setCheckingDetach(false);
547
+ setupBusy.current = false;
548
+ if (isCurrentBinding()) setSettingUp(false);
541
549
  }
542
550
  }
543
- const placementMessage = editorPlacementMessage(placements && placements.id === experimentId ? placements.value : undefined, currentPuckDocument(window.location.pathname, admin, placements && placements.id === experimentId ? placements.value : undefined), experiment?.status);
544
- const newTestButton = experimentId !== undefined && canManage ? /*#__PURE__*/ _jsx(Button, {
545
- disabled: !experiment,
546
- onClick: createFromBlock,
547
- children: editorCopy.newTest
548
- }) : null;
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);
549
552
  const currentPreflight = preflight && preflight.id === experimentId && Array.isArray(preflight.value?.checks) ? preflight.value : null;
550
553
  const editorPage = currentPuckDocument(window.location.pathname, admin, placements?.value);
551
554
  const surface = access.surface ? {
@@ -594,17 +597,27 @@ function EditorRender(props) {
594
597
  };
595
598
  const placementNotice = quickTest.preflightRead?.message ?? placementMessage;
596
599
  usePlacementNotice(api, experimentId, canManage ? placementNotice : undefined);
597
- const placementNoticeView = /*#__PURE__*/ _jsx(PlacementNotice, {
598
- read: quickTest.preflightRead,
599
- message: placementMessage,
600
- running: experiment?.status === 'running',
601
- onRetry: ()=>{
602
- if (experimentId !== undefined) void refreshPlacements(api, experimentId);
603
- }
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
+ ]
604
615
  });
605
616
  const sidebarBlockers = surface ? sidebarReadinessBlockers(quickTest, surface) : [];
606
617
  const leftoverControls = experiment && orphanSlots.length ? /*#__PURE__*/ _jsx(LeftoverVersions, {
607
618
  slots: orphanSlots,
619
+ active: slot,
620
+ dragging: dragging,
608
621
  experiment: experiment,
609
622
  writes: writes,
610
623
  canManage: canManage,
@@ -622,7 +635,10 @@ function EditorRender(props) {
622
635
  surface: 'editor',
623
636
  resultsOnly
624
637
  }) : undefined;
625
- const accessNotice = documentRead ? documentRead.retry ? /*#__PURE__*/ _jsx(Banner, {
638
+ const accessNotice = result?.missing ? /*#__PURE__*/ _jsx("p", {
639
+ className: "xp-ui-help",
640
+ children: editorCopy.deleted
641
+ }) : documentRead ? documentRead.retry ? /*#__PURE__*/ _jsx(Banner, {
626
642
  tone: "error",
627
643
  action: /*#__PURE__*/ _jsx(Button, {
628
644
  onClick: ()=>setReadAttempt((value)=>value + 1),
@@ -657,7 +673,7 @@ function EditorRender(props) {
657
673
  children: resultsOnly ? pickerCopy.resultsOnly : pickerCopy.forbidden
658
674
  }) : /*#__PURE__*/ _jsx(Banner, {
659
675
  tone: experiment?.status === 'running' ? 'warning' : 'info',
660
- children: experimentId === undefined ? bannerFor() : experiment ? bannerFor(experiment.status, winner) : editorCopy.loading
676
+ children: experimentId === undefined ? bannerFor() : experiment ? bannerFor(experiment.status, winner, originalLabel) : editorCopy.loading
661
677
  });
662
678
  const removeDialog = removing?.key === bindingKey ? /*#__PURE__*/ _jsx(RemoveVersion, {
663
679
  count: countSlotBlocks(getPuck().getItemById(props.id)?.props[removing.arm.key]),
@@ -677,103 +693,34 @@ function EditorRender(props) {
677
693
  /*#__PURE__*/ createPortal(/*#__PURE__*/ _jsx("div", {
678
694
  onClick: (event)=>event.stopPropagation(),
679
695
  onKeyDown: (event)=>event.stopPropagation(),
680
- children: /*#__PURE__*/ _jsxs("section", {
696
+ children: /*#__PURE__*/ _jsx("section", {
681
697
  "aria-label": editorCopy.testGroup,
682
- children: [
683
- /*#__PURE__*/ _jsx("h4", {
684
- children: editorCopy.testGroup
685
- }),
686
- access.surface?.canManage ? /*#__PURE__*/ _jsx(ExperimentPicker, {
687
- value: props.experiment ?? null,
688
- onChange: sidebar.onChange
689
- }) : null,
690
- experiment ? /*#__PURE__*/ _jsx(StatusChip, {
691
- status: experiment.status
692
- }) : experimentId === undefined ? /*#__PURE__*/ _jsx("span", {
693
- className: "xp-ui-status",
694
- children: editorCopy.notSetUp
695
- }) : null,
696
- accessNotice,
697
- canManage ? /*#__PURE__*/ _jsxs(_Fragment, {
698
- children: [
699
- placementNoticeView,
700
- experiment?.status === 'draft' || experiment?.status === 'stopped' ? /*#__PURE__*/ _jsx(BlockerList, {
701
- steps: sidebarBlockers
702
- }) : null
703
- ]
704
- }) : null
705
- ]
706
- })
707
- }), sidebar.test),
708
- /*#__PURE__*/ createPortal(/*#__PURE__*/ _jsxs("div", {
709
- onClick: (event)=>event.stopPropagation(),
710
- onKeyDown: (event)=>event.stopPropagation(),
711
- children: [
712
- experiment && canManage ? /*#__PURE__*/ _jsxs("section", {
713
- "aria-label": editorCopy.versionsGroup,
698
+ children: /*#__PURE__*/ _jsxs(FieldGroup, {
699
+ label: editorCopy.testGroup,
700
+ collapsible: false,
714
701
  children: [
715
- /*#__PURE__*/ _jsx("h4", {
716
- children: editorCopy.versionsGroup
717
- }),
718
- /*#__PURE__*/ _jsx(VersionWeights, {
719
- edits: weightEdits,
720
- setEdits: setWeightEdits,
721
- groupId: props.id,
722
- splitIntent: splitIntent,
723
- experiment: experiment,
724
- writes: writes,
725
- editable: editable,
726
- beforeSplit: /*#__PURE__*/ _jsxs(_Fragment, {
727
- children: [
728
- leftoverControls,
729
- editable ? /*#__PURE__*/ _jsx(AddVariant, {
730
- experiment: experiment,
731
- writes: writes,
732
- onSelect: (slot)=>{
733
- if (isCurrentBinding()) setActive({
734
- id: experimentId,
735
- slot
736
- });
737
- }
738
- }) : null
739
- ]
740
- }),
741
- actions: (arm)=>/*#__PURE__*/ _jsxs(_Fragment, {
742
- children: [
743
- /*#__PURE__*/ _jsx(VersionActions, {
744
- arm: arm,
745
- writes: writes,
746
- editable: editable,
747
- running: experiment.status === 'running',
748
- open: openMenu === `sidebar-${arm.key}`,
749
- onOpenChange: (open)=>setOpenMenu(open ? `sidebar-${arm.key}` : null),
750
- canCopy: !originalEmpty,
751
- onCopy: requestCopy,
752
- onRequestRemove: ()=>setRemoving({
753
- key: bindingKey,
754
- arm
755
- })
756
- }),
757
- editable && arm.kind !== 'control' ? /*#__PURE__*/ _jsx(Button, {
758
- disabled: writes.busy,
759
- onClick: ()=>setRemoving({
760
- key: bindingKey,
761
- arm
762
- }),
763
- children: editorCopy.remove
764
- }) : null
765
- ]
702
+ experiment ? /*#__PURE__*/ _jsxs(_Fragment, {
703
+ children: [
704
+ /*#__PURE__*/ _jsx("strong", {
705
+ children: experiment.name
706
+ }),
707
+ /*#__PURE__*/ _jsx(StatusChip, {
708
+ status: experiment.status
766
709
  })
767
- })
768
- ]
769
- }) : null,
770
- /*#__PURE__*/ _jsxs("section", {
771
- "aria-label": editorCopy.actionsGroup,
772
- children: [
773
- /*#__PURE__*/ _jsx("h4", {
774
- children: editorCopy.actionsGroup
775
- }),
776
- experimentId !== undefined && access.surface && !result?.missing && !noAccess && (!unavailable || resultsOnly) ? /*#__PURE__*/ _jsx(ConfigureTestControl, {
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, {
777
724
  id: experimentId,
778
725
  routes: {
779
726
  admin,
@@ -784,18 +731,202 @@ function EditorRender(props) {
784
731
  test: quickTest,
785
732
  surface: surface
786
733
  }, `${experimentId}/${experiment.status}`) : null,
787
- experimentId === undefined && canManage ? /*#__PURE__*/ _jsx(Button, {
734
+ canSetUp ? /*#__PURE__*/ _jsx(Button, {
788
735
  variant: "primary",
789
- onClick: createFromBlock,
736
+ busy: settingUp,
737
+ disabled: settingUp,
738
+ onClick: ()=>void setUpTest(),
790
739
  children: editorCopy.createLabel
791
740
  }) : null,
792
- writes.error ? /*#__PURE__*/ _jsx("p", {
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", {
793
747
  role: "alert",
794
- children: writes.error
748
+ children: setupError
795
749
  }) : null
796
750
  ]
797
- }),
798
- removeDialog
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
799
930
  ]
800
931
  }), sidebar.controls)
801
932
  ]
@@ -817,159 +948,31 @@ function EditorRender(props) {
817
948
  },
818
949
  children: [
819
950
  /*#__PURE__*/ _jsx("h3", {
820
- className: "xp-slot-title",
821
- 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
822
954
  }),
823
955
  experiment ? /*#__PURE__*/ _jsx(StatusChip, {
824
956
  status: experiment.status
825
- }) : experimentId === undefined ? /*#__PURE__*/ _jsx("span", {
826
- className: "xp-ui-status",
827
- children: editorCopy.notSetUp
828
957
  }) : null
829
958
  ]
830
959
  }),
831
- accessNotice,
832
- leftoverControls,
960
+ canSetUp || result?.missing ? null : accessNotice,
833
961
  shared ? /*#__PURE__*/ _jsx(Banner, {
834
962
  tone: "info",
835
- action: newTestButton,
836
963
  children: editorCopy.sharedTest
837
964
  }) : null,
838
- canManage ? placementNoticeView : null,
839
- experimentId !== undefined && canManage && !experiment && !result?.error ? /*#__PURE__*/ _jsx("p", {
840
- className: "xp-ui-help",
841
- children: editorCopy.loadingBeforeNew
842
- }) : null,
843
- checkingDetach ? /*#__PURE__*/ _jsx("p", {
844
- role: "status",
845
- className: "xp-ui-help",
846
- children: editorCopy.checkingRemoval
847
- }) : null,
848
- /*#__PURE__*/ _jsxs("div", {
849
- className: "xp-ui-button-group",
850
- children: [
851
- experimentId === undefined && canManage ? /*#__PURE__*/ _jsx(Button, {
852
- variant: "primary",
853
- onClick: createFromBlock,
854
- children: editorCopy.createLabel
855
- }) : null,
856
- experimentId !== undefined && access.surface && !result?.missing && !noAccess && (!unavailable || resultsOnly) ? /*#__PURE__*/ _jsx(ConfigureTestControl, {
857
- id: experimentId,
858
- routes: {
859
- admin,
860
- api
861
- }
862
- }) : null,
863
- !shared ? newTestButton : null,
864
- experimentId !== undefined && canDetach ? /*#__PURE__*/ _jsx(Button, {
865
- disabled: checkingDetach,
866
- onClick: ()=>void requestDetach(),
867
- children: editorCopy.detach
868
- }) : null,
869
- experiment && editable ? /*#__PURE__*/ _jsx(AddVariant, {
870
- experiment: experiment,
871
- writes: writes,
872
- onSelect: (slot)=>{
873
- if (isCurrentBinding()) setActive({
874
- id: experimentId,
875
- slot
876
- });
877
- }
878
- }) : null
879
- ]
880
- }),
881
- experiment?.status === 'running' && result?.shared !== undefined && !shared ? /*#__PURE__*/ _jsx("p", {
882
- className: "xp-ui-help",
883
- children: editorCopy.stopToDetach
884
- }) : null,
885
- experiment && !editable ? /*#__PURE__*/ _jsx("p", {
886
- className: "xp-ui-help",
887
- children: editorCopy.locked[experiment.status]
888
- }) : null,
889
- experiment && editable ? /*#__PURE__*/ _jsx(VersionWeights, {
890
- edits: weightEdits,
891
- setEdits: setWeightEdits,
892
- groupId: props.id,
893
- splitIntent: splitIntent,
894
- experiment: experiment,
895
- writes: writes
896
- }, `weights-${experimentId}`) : null,
897
- writes.busy ? /*#__PURE__*/ _jsx("p", {
898
- role: "status",
899
- className: "xp-ui-help",
900
- children: editorCopy.savingVersions
901
- }) : null,
902
- writes.error ? /*#__PURE__*/ _jsx("p", {
903
- role: "alert",
904
- className: "xp-ui-error",
905
- children: writes.error
906
- }) : null,
907
- clearError?.key === bindingKey ? /*#__PURE__*/ _jsx("p", {
908
- role: "alert",
909
- className: "xp-ui-error",
910
- children: clearError.message
965
+ placementNoticeView,
966
+ setupError && canSetUp ? /*#__PURE__*/ _jsx("p", {
967
+ role: sidebar ? undefined : 'alert',
968
+ children: setupError
911
969
  }) : null,
912
- removed?.key === bindingKey && removed.contentRemoved ? /*#__PURE__*/ _jsx("p", {
913
- className: "xp-ui-help",
914
- children: editorCopy.removed
915
- }) : null,
916
- experiment && experiment.status !== 'draft' ? /*#__PURE__*/ _jsx(ResultsReadout, {
917
- id: experimentId,
918
- api: api,
919
- experiment: experiment
920
- }, `results-${experimentId}`) : null,
921
- !sidebar ? removeDialog : null,
922
- detaching === bindingKey && canDetach ? /*#__PURE__*/ _jsx(Dialog, {
923
- open: true,
924
- title: editorCopy.detachTitle,
925
- initialFocus: "cancel",
926
- onClose: ()=>setDetaching(null),
927
- children: /*#__PURE__*/ _jsxs("div", {
928
- className: "xp-slot-drawer",
929
- children: [
930
- /*#__PURE__*/ _jsx("p", {
931
- children: experiment?.status === 'running' && shared ? editorCopy.detachRunningHelp : editorCopy.detachHelp
932
- }),
933
- /*#__PURE__*/ _jsxs("div", {
934
- className: "xp-ui-button-group",
935
- children: [
936
- /*#__PURE__*/ _jsx(Button, {
937
- "data-dialog-cancel": true,
938
- onClick: ()=>setDetaching(null),
939
- children: editorCopy.cancel
940
- }),
941
- /*#__PURE__*/ _jsx(Button, {
942
- disabled: checkingDetach,
943
- onClick: ()=>void requestDetach(true),
944
- children: editorCopy.detach
945
- })
946
- ]
947
- })
948
- ]
949
- })
950
- }) : null,
951
- confirming ? /*#__PURE__*/ _jsxs("div", {
952
- className: "xp-slot-confirm",
953
- role: "alert",
954
- children: [
955
- /*#__PURE__*/ _jsx("p", {
956
- children: editorCopy.replaceConfirm(tabs.find((tab)=>tab.slot === confirming)?.label ?? confirming)
957
- }),
958
- /*#__PURE__*/ _jsxs("div", {
959
- className: "xp-ui-button-group",
960
- children: [
961
- /*#__PURE__*/ _jsx(Button, {
962
- variant: "primary",
963
- onClick: ()=>copyTo(confirming),
964
- children: editorCopy.replace
965
- }),
966
- /*#__PURE__*/ _jsx(Button, {
967
- onClick: ()=>setConfirming(null),
968
- children: editorCopy.cancel
969
- })
970
- ]
971
- })
972
- ]
970
+ canSetUp ? /*#__PURE__*/ _jsx(Button, {
971
+ variant: "primary",
972
+ busy: settingUp,
973
+ disabled: settingUp,
974
+ onClick: ()=>void setUpTest(),
975
+ children: editorCopy.createLabel
973
976
  }) : null
974
977
  ]
975
978
  }),
@@ -981,30 +984,13 @@ function EditorRender(props) {
981
984
  className: "xp-ui-tabs-header",
982
985
  children: children
983
986
  }),
984
- onChange: (value)=>{
985
- setOpenMenu(null);
986
- setActive({
987
+ onChange: (value)=>setActive({
987
988
  id: experimentId,
988
989
  slot: value
989
- });
990
- },
990
+ }),
991
991
  items: tabs.map((tab)=>({
992
992
  id: tab.slot,
993
993
  label: tab.label,
994
- actions: experiment?.arms.some((arm)=>arm.key === tab.slot) ? /*#__PURE__*/ _jsx(VersionActions, {
995
- arm: experiment.arms.find((arm)=>arm.key === tab.slot),
996
- writes: writes,
997
- editable: editable,
998
- running: experiment.status === 'running',
999
- open: openMenu === tab.slot,
1000
- onOpenChange: (open)=>setOpenMenu(open ? tab.slot : null),
1001
- canCopy: !originalEmpty,
1002
- onCopy: requestCopy,
1003
- onRequestRemove: ()=>setRemoving({
1004
- key: bindingKey,
1005
- arm: experiment.arms.find((arm)=>arm.key === tab.slot)
1006
- })
1007
- }, `${experimentId}-${tab.slot}`) : undefined,
1008
994
  content: tab.slot === slot ? /*#__PURE__*/ _jsxs("div", {
1009
995
  className: slotEmpty ? 'xp-slot-panel xp-slot-panel-empty' : 'xp-slot-panel',
1010
996
  children: [
@@ -1013,7 +999,7 @@ function EditorRender(props) {
1013
999
  }),
1014
1000
  slotEmpty ? /*#__PURE__*/ _jsx("span", {
1015
1001
  className: "xp-slot-drop-label",
1016
- children: editorCopy.dropZone(slot)
1002
+ children: editorCopy.dropZone(tabs.find((tab)=>tab.slot === slot)?.label ?? slotLabels[slot])
1017
1003
  }) : null
1018
1004
  ]
1019
1005
  }) : null
@@ -1033,15 +1019,9 @@ export function createExperimentSlotEditor({ routes: inputRoutes, accent } = {})
1033
1019
  experiment: {
1034
1020
  type: 'custom',
1035
1021
  label: pickerCopy.label,
1036
- render: ({ value, onChange })=>/*#__PURE__*/ _jsx(PuckHostProvider, {
1022
+ render: ()=>/*#__PURE__*/ _jsx(PuckHostProvider, {
1037
1023
  routes: routes,
1038
- children: /*#__PURE__*/ _jsx(TestSidebarField, {
1039
- onChange: (next)=>{
1040
- if (value) invalidatePlacements(routes.api, value.id);
1041
- if (next) invalidatePlacements(routes.api, next.id);
1042
- onChange(next);
1043
- }
1044
- })
1024
+ children: /*#__PURE__*/ _jsx(TestSidebarField, {})
1045
1025
  })
1046
1026
  }
1047
1027
  },