@delmaredigital/payload-experiments 0.4.0-rc.2 → 0.4.0-rc.4
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.
- package/README.md +283 -775
- package/dist/admin/LayerUsage.js +1 -1
- package/dist/admin/MetricSourceSelect.js +2 -2
- package/dist/admin/PlacementStatus.js +1 -1
- package/dist/admin/TestsDashboardCards.js +2 -2
- package/dist/admin/TestsNavLink.js +2 -2
- package/dist/admin/blocks/BlockPanel.js +3 -3
- package/dist/admin/blocks/TestBlockField.js +3 -3
- package/dist/admin/blocks/formApi.js +1 -1
- package/dist/admin/blocks/model.js +1 -1
- package/dist/admin/blocks/statusCache.js +1 -1
- package/dist/admin/components/RootViewMessage.js +1 -1
- package/dist/admin/copy/blocks.d.ts +2 -2
- package/dist/admin/copy/blocks.js +3 -2
- package/dist/admin/copy/goals.d.ts +6 -1
- package/dist/admin/copy/goals.js +10 -3
- package/dist/admin/goals/XpGoalField.js +155 -129
- package/dist/admin/goals/xpGoalField.css +2 -3
- package/dist/admin/status.model.js +1 -1
- package/dist/admin/surface/ResultsRoute.d.ts +2 -1
- package/dist/admin/surface/ResultsRoute.js +4 -3
- package/dist/admin/surface/SurfaceShell.js +2 -2
- package/dist/admin/surface/TestsHome.d.ts +1 -1
- package/dist/admin/surface/TestsHome.js +3 -3
- package/dist/admin/surface/TestsSurface.js +2 -2
- package/dist/admin/surface/goals/GoalForm.d.ts +1 -1
- package/dist/admin/surface/goals/GoalForm.js +69 -15
- package/dist/admin/surface/goals/GoalsList.d.ts +1 -1
- package/dist/admin/surface/goals/GoalsList.js +4 -4
- package/dist/admin/surface/goals/data.js +2 -2
- package/dist/admin/surface/goals/goals.css +7 -0
- package/dist/admin/surface/goals/goals.model.d.ts +11 -1
- package/dist/admin/surface/goals/goals.model.js +43 -0
- package/dist/admin/surface/home.model.d.ts +1 -1
- package/dist/admin/surface/home.model.js +5 -5
- package/dist/admin/surface/newTest/NewTest.d.ts +1 -1
- package/dist/admin/surface/newTest/NewTest.js +1 -1
- package/dist/admin/surface/newTest/PageWizard.d.ts +1 -1
- package/dist/admin/surface/newTest/PageWizard.js +13 -13
- package/dist/admin/surface/results/ResultsHeader.d.ts +2 -2
- package/dist/admin/surface/results/ResultsHeader.js +8 -8
- package/dist/admin/surface/test/TestPage.d.ts +1 -2
- package/dist/admin/surface/test/TestPage.js +45 -156
- package/dist/admin/views/ExperimentsRootView.js +1 -1
- package/dist/admin/views/TestsNavLinkServer.js +1 -1
- package/dist/admin/views/renderCollectionList.js +1 -1
- package/dist/admin/views/renderTestsSurface.js +1 -1
- package/dist/blocks/placementLocale.d.ts +21 -0
- package/dist/blocks/placementLocale.js +115 -0
- package/dist/collections/experiments/config.js +1 -1
- package/dist/collections/metrics.js +1 -1
- package/dist/db/bulkPlacementRemoval.d.ts +30 -0
- package/dist/db/bulkPlacementRemoval.js +107 -0
- package/dist/db/placements.d.ts +2 -0
- package/dist/db/placements.js +8 -0
- package/dist/endpoints/editorSurface.d.ts +3 -0
- package/dist/endpoints/editorSurface.js +31 -0
- package/dist/endpoints/index.js +28 -1
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fields/xpGoal.js +1 -1
- package/dist/goals/picker/clickGoalPicker.model.d.ts +8 -1
- package/dist/goals/picker/clickGoalPicker.model.js +20 -2
- package/dist/goals/picker/copy.d.ts +6 -2
- package/dist/goals/picker/copy.js +11 -2
- package/dist/goals/picker/useClickGoalPicker.d.ts +1 -1
- package/dist/goals/picker/useClickGoalPicker.js +4 -2
- package/dist/goals/validate.js +3 -2
- package/dist/hooks/blockRemovalRule.d.ts +29 -0
- package/dist/hooks/blockRemovalRule.js +141 -0
- package/dist/hooks/pageGuard.d.ts +24 -2
- package/dist/hooks/pageGuard.js +178 -24
- package/dist/hooks/puckGoals.d.ts +2 -0
- package/dist/hooks/puckGoals.js +34 -10
- package/dist/lib/placementPages.d.ts +9 -0
- package/dist/{admin/previewLinks.model.js → lib/placementPages.js} +1 -4
- package/dist/onInit.js +22 -0
- package/dist/plugin.js +2 -1
- package/dist/puck/ExperimentPicker.js +25 -10
- package/dist/puck/copy.d.ts +4 -1
- package/dist/puck/copy.js +4 -1
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +21 -0
- package/dist/puck/editor/ConfigureTestDrawer.js +147 -0
- package/dist/puck/editor/CreateExperimentDrawer.d.ts +11 -2
- package/dist/puck/editor/CreateExperimentDrawer.js +69 -9
- package/dist/puck/editor/EditorControls.d.ts +14 -0
- package/dist/puck/editor/EditorControls.js +99 -0
- package/dist/puck/editor/ExperimentSlotEditor.js +317 -51
- package/dist/puck/editor/ResultsReadout.js +3 -5
- package/dist/puck/editor/VersionBuilder.js +2 -2
- package/dist/puck/editor/armsCache.d.ts +3 -1
- package/dist/puck/editor/armsCache.js +20 -3
- package/dist/puck/editor/copy.d.ts +18 -2
- package/dist/puck/editor/copy.js +19 -3
- package/dist/puck/editor/editor.chrome.css +33 -0
- package/dist/puck/editor/editor.css +39 -0
- package/dist/puck/editor/editor.model.d.ts +14 -0
- package/dist/puck/editor/editor.model.js +58 -1
- package/dist/puck/editor/editorSurface.d.ts +10 -0
- package/dist/puck/editor/editorSurface.js +65 -0
- package/dist/puck/editor/localPlacements.d.ts +2 -0
- package/dist/puck/editor/localPlacements.js +29 -0
- package/dist/puck/editor/placementsCache.d.ts +19 -0
- package/dist/puck/editor/placementsCache.js +83 -0
- package/dist/puck/editor/xpGoalPuckEditorField.js +109 -98
- package/dist/puck/experimentSlotField.d.ts +3 -0
- package/dist/puck/experimentSlotField.js +15 -4
- package/dist/{admin → testSurface}/actions/DecideDialog.d.ts +2 -1
- package/dist/{admin → testSurface}/actions/DecideDialog.js +6 -4
- package/dist/{admin → testSurface}/api.js +4 -5
- package/dist/{admin → testSurface}/copy/common.d.ts +2 -0
- package/dist/{admin → testSurface}/copy/common.js +2 -0
- package/dist/{admin → testSurface}/copy/readiness.d.ts +3 -0
- package/dist/{admin → testSurface}/copy/readiness.js +3 -0
- package/dist/{admin → testSurface}/copy/testPage.d.ts +3 -0
- package/dist/{admin → testSurface}/copy/testPage.js +7 -2
- package/dist/testSurface/format/adminURL.d.ts +7 -0
- package/dist/testSurface/format/adminURL.js +9 -0
- package/dist/{admin → testSurface}/placements/placementLabels.js +1 -1
- package/dist/{admin → testSurface}/previewLinks.model.d.ts +1 -6
- package/dist/testSurface/previewLinks.model.js +4 -0
- package/dist/testSurface/results/results.css +64 -0
- package/dist/{admin → testSurface}/surface/contracts.d.ts +1 -0
- package/dist/{admin → testSurface}/surface/pageBlock/parts.js +6 -6
- package/dist/testSurface/surface/pagePicker/pagePicker.css +10 -0
- package/dist/{admin → testSurface}/surface/readiness/useTransition.js +1 -0
- package/dist/{admin → testSurface}/surface/results/ResultsBody.d.ts +2 -2
- package/dist/{admin → testSurface}/surface/results/ResultsBody.js +18 -11
- package/dist/testSurface/surface/setting/setting.css +17 -0
- package/dist/testSurface/surface/test/GoalSection.d.ts +4 -0
- package/dist/{admin → testSurface}/surface/test/GoalSection.js +3 -2
- package/dist/{admin → testSurface}/surface/test/Section.js +9 -8
- package/dist/testSurface/surface/test/TestSurface.d.ts +18 -0
- package/dist/testSurface/surface/test/TestSurface.js +152 -0
- package/dist/testSurface/surface/test/VersionsSection.d.ts +5 -0
- package/dist/{admin → testSurface}/surface/test/VersionsSection.js +12 -6
- package/dist/testSurface/surface/test/testPage.css +92 -0
- package/dist/{admin → testSurface}/surface/useTestDocument.d.ts +5 -1
- package/dist/{admin → testSurface}/surface/useTestDocument.js +34 -3
- package/dist/{admin → testSurface}/surfaceUrls.js +1 -1
- package/dist/transitions/placementInteractions.js +1 -1
- package/dist/transitions/placements.d.ts +27 -8
- package/dist/transitions/placements.js +77 -6
- package/dist/transitions/start.js +2 -2
- package/dist/types/endpoints.d.ts +1 -1
- package/dist/ui/Dialog.d.ts +4 -1
- package/dist/ui/Dialog.js +41 -3
- package/dist/ui/Drawer.d.ts +10 -0
- package/dist/ui/Drawer.js +29 -0
- package/dist/ui/Tabs.d.ts +3 -3
- package/dist/ui/Tabs.js +35 -33
- package/dist/ui/ui.css +6 -0
- package/package.json +1 -1
- package/dist/admin/actions/ConfirmDialog.d.ts +0 -19
- package/dist/admin/actions/ConfirmDialog.js +0 -149
- package/dist/admin/results/results.css +0 -64
- package/dist/admin/styles.css +0 -10
- package/dist/admin/styles.d.ts +0 -2
- package/dist/admin/styles.js +0 -3
- package/dist/admin/surface/pagePicker/pagePicker.css +0 -10
- package/dist/admin/surface/setting/setting.css +0 -17
- package/dist/admin/surface/test/GoalSection.d.ts +0 -2
- package/dist/admin/surface/test/VersionsSection.d.ts +0 -4
- package/dist/admin/surface/test/testPage.css +0 -92
- /package/dist/{admin → testSurface}/PreviewLinks.d.ts +0 -0
- /package/dist/{admin → testSurface}/PreviewLinks.js +0 -0
- /package/dist/{admin → testSurface}/actions/MakeContentResult.d.ts +0 -0
- /package/dist/{admin → testSurface}/actions/MakeContentResult.js +0 -0
- /package/dist/{admin → testSurface}/actions/actions.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/actions/actions.model.js +0 -0
- /package/dist/{admin → testSurface}/actions/decide.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/actions/decide.model.js +0 -0
- /package/dist/{admin → testSurface}/allocation.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/allocation.model.js +0 -0
- /package/dist/{admin → testSurface}/api.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/arms.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/arms.model.js +0 -0
- /package/dist/{admin → testSurface}/arms/pageTarget.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/pageTarget.model.js +0 -0
- /package/dist/{admin → testSurface}/arms/params.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/params.model.js +0 -0
- /package/dist/{admin → testSurface}/copy/actions.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/actions.js +0 -0
- /package/dist/{admin → testSurface}/copy/advanced.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/advanced.js +0 -0
- /package/dist/{admin → testSurface}/copy/arms.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/arms.js +0 -0
- /package/dist/{admin → testSurface}/copy/audience.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/audience.js +0 -0
- /package/dist/{admin → testSurface}/copy/metrics.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/metrics.js +0 -0
- /package/dist/{admin → testSurface}/copy/pages.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/pages.js +0 -0
- /package/dist/{admin → testSurface}/copy/recommendation.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/recommendation.js +0 -0
- /package/dist/{admin → testSurface}/copy/results.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/results.js +0 -0
- /package/dist/{admin → testSurface}/copy/review.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/review.js +0 -0
- /package/dist/{admin → testSurface}/copy/setting.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/setting.js +0 -0
- /package/dist/{admin → testSurface}/copy/surface.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/surface.js +0 -0
- /package/dist/{admin → testSurface}/format/date.d.ts +0 -0
- /package/dist/{admin → testSurface}/format/date.js +0 -0
- /package/dist/{admin → testSurface}/labels.d.ts +0 -0
- /package/dist/{admin → testSurface}/labels.js +0 -0
- /package/dist/{admin → testSurface}/lockedNotice.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/lockedNotice.model.js +0 -0
- /package/dist/{admin → testSurface}/metricSource.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/metricSource.model.js +0 -0
- /package/dist/{admin → testSurface}/placements/placementLabels.d.ts +0 -0
- /package/dist/{admin → testSurface}/placements/placementLabels.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/placements/placementLabels.model.js +0 -0
- /package/dist/{admin → testSurface}/placements/usePlacementLabels.d.ts +0 -0
- /package/dist/{admin → testSurface}/placements/usePlacementLabels.js +0 -0
- /package/dist/{admin → testSurface}/reload.d.ts +0 -0
- /package/dist/{admin → testSurface}/reload.js +0 -0
- /package/dist/{admin → testSurface}/results/CappedCell.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/CappedCell.js +0 -0
- /package/dist/{admin → testSurface}/results/CiChart.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/CiChart.js +0 -0
- /package/dist/{admin → testSurface}/results/DataQualityPanel.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/DataQualityPanel.js +0 -0
- /package/dist/{admin → testSurface}/results/DataTable.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/DataTable.js +0 -0
- /package/dist/{admin → testSurface}/results/StatTile.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/StatTile.js +0 -0
- /package/dist/{admin → testSurface}/results/VerdictHero.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/VerdictHero.js +0 -0
- /package/dist/{admin → testSurface}/results/chart.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/chart.model.js +0 -0
- /package/dist/{admin → testSurface}/results/format.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/format.js +0 -0
- /package/dist/{admin → testSurface}/results/legacy.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/legacy.js +0 -0
- /package/dist/{admin → testSurface}/results/releasePages.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/releasePages.model.js +0 -0
- /package/dist/{admin → testSurface}/results/results.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/results.model.js +0 -0
- /package/dist/{admin → testSurface}/results/snapshot.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/snapshot.js +0 -0
- /package/dist/{admin → testSurface}/review/review.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/review/review.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/contracts.js +0 -0
- /package/dist/{admin → testSurface}/surface/pageBlock/pageBlock.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pageBlock/pageBlock.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/pageBlock/parts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/CopyRoute.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/CopyRoute.js +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/PageCombobox.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/PageCombobox.js +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/pagePicker.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/pagePicker.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/ActionDialogs.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/ActionDialogs.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/Banner.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/Banner.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/SaveStatus.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/SaveStatus.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/parts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/parts.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/readiness.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/readiness.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/useTransition.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/results/ReleasePages.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/results/ReleasePages.js +0 -0
- /package/dist/{admin → testSurface}/surface/results/recommendation.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/results/recommendation.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/results/useResults.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/results/useResults.js +0 -0
- /package/dist/{admin → testSurface}/surface/setting/parts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/setting/parts.js +0 -0
- /package/dist/{admin → testSurface}/surface/setting/setting.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/setting/setting.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/AdvancedSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/AdvancedSection.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/LengthSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/LengthSection.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/PageHoldout.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/PageHoldout.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/Rail.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/Rail.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/ReadinessBar.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/ReadinessBar.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/Section.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/TargetingSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/TargetingSection.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/fields.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/fields.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/jumpToSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/jumpToSection.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/pageParts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/pageParts.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/testPage.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/testPage.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/testDocument.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/testDocument.model.js +0 -0
- /package/dist/{admin → testSurface}/surfaceUrls.d.ts +0 -0
- /package/dist/{admin → testSurface}/targeting/targeting.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/targeting/targeting.model.js +0 -0
- /package/dist/{admin → testSurface}/theme.d.ts +0 -0
- /package/dist/{admin → testSurface}/theme.js +0 -0
- /package/dist/{admin → testSurface}/useApi.d.ts +0 -0
- /package/dist/{admin → testSurface}/useApi.js +0 -0
|
@@ -1,30 +1,38 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { createUsePuck,
|
|
3
|
+
import { createUsePuck, useGetPuck } from '@puckeditor/core';
|
|
4
4
|
import { useEffect, useRef, useState } from 'react';
|
|
5
5
|
import { Button } from '../../ui/Button.js';
|
|
6
6
|
import { StatusChip } from '../../ui/StatusChip.js';
|
|
7
7
|
import { Banner } from '../../ui/Banner.js';
|
|
8
8
|
import { Tabs } from '../../ui/Tabs.js';
|
|
9
|
+
import { Dialog } from '../../ui/Dialog.js';
|
|
9
10
|
import { accentVariables, deriveAccent, validateAccent } from '../../ui/accent.js';
|
|
10
11
|
import { createExperimentSlotField } from '../experimentSlotField.js';
|
|
11
12
|
import { resolvePuckRoutes } from '../routes.js';
|
|
12
13
|
import { PuckHostProvider, usePuckRoutes } from '../hostContext.js';
|
|
13
14
|
import { pickerCopy, slotLabels } from '../copy.js';
|
|
14
15
|
import { experimentSlotDefaultProps, experimentSlotFields, experimentSlotLabel } from '../slotConfig.js';
|
|
15
|
-
import { bannerFor, tabsFor } from './editor.model.js';
|
|
16
|
+
import { armsFromBlock, bannerFor, currentPuckDocument, isSharedTest, tabsFor } from './editor.model.js';
|
|
16
17
|
import { cloneSlot } from './cloneSlot.js';
|
|
17
|
-
import {
|
|
18
|
+
import { openCreateExperimentDrawer } from './CreateExperimentDrawer.js';
|
|
18
19
|
import { editorCopy } from './copy.js';
|
|
19
|
-
import { acquireArms, loadArms,
|
|
20
|
+
import { acquireArms, loadArms, publishExperiment, useArms } from './armsCache.js';
|
|
20
21
|
import { AddVariant, RemoveVersion, VersionActions, VersionWeights, useArmWrites } from './VersionBuilder.js';
|
|
21
22
|
import { ResultsReadout } from './ResultsReadout.js';
|
|
23
|
+
import { EditorControls } from './EditorControls.js';
|
|
24
|
+
import { acquirePlacements, invalidatePlacements, refreshPlacements } from './placementsCache.js';
|
|
25
|
+
import { localPlacements } from './localPlacements.js';
|
|
26
|
+
import { useEditorSurface } from './editorSurface.js';
|
|
27
|
+
import { ConfigureTestButton, ConfigureTestControl } from './ConfigureTestDrawer.js';
|
|
22
28
|
import './editor.css';
|
|
23
29
|
const usePuckSelector = createUsePuck();
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
class TestReadError extends Error {
|
|
31
|
+
status;
|
|
32
|
+
constructor(status){
|
|
33
|
+
super('load'), this.status = status;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
28
36
|
function isExperiment(value) {
|
|
29
37
|
if (!value || typeof value !== 'object') return false;
|
|
30
38
|
const doc = value;
|
|
@@ -37,6 +45,7 @@ function isExperiment(value) {
|
|
|
37
45
|
function EditorRender(props) {
|
|
38
46
|
const getPuck = useGetPuck();
|
|
39
47
|
const { admin, api } = usePuckRoutes();
|
|
48
|
+
const access = useEditorSurface(api);
|
|
40
49
|
const root = useRef(null);
|
|
41
50
|
const [mode, setMode] = useState('light');
|
|
42
51
|
useEffect(()=>{
|
|
@@ -81,13 +90,16 @@ function EditorRender(props) {
|
|
|
81
90
|
const [active, setActive] = useState();
|
|
82
91
|
const [openMenu, setOpenMenu] = useState(null);
|
|
83
92
|
const [clearError, setClearError] = useState(null);
|
|
84
|
-
const
|
|
93
|
+
const creation = useRef(undefined);
|
|
94
|
+
useEffect(()=>()=>creation.current?.closeIfIdle(), []);
|
|
95
|
+
const [detaching, setDetaching] = useState(null);
|
|
85
96
|
// A non-empty variant is only overwritten after an explicit second confirmation.
|
|
86
97
|
const [confirming, setConfirming] = useState(null);
|
|
87
98
|
// Keep a failed removal open even if the recovery read no longer contains that version.
|
|
88
99
|
const [removing, setRemoving] = useState(null);
|
|
89
100
|
const pageTitle = usePuckSelector((state)=>typeof state.appState.data.root.props?.title === 'string' ? state.appState.data.root.props.title : '');
|
|
90
|
-
|
|
101
|
+
// Selection only changes the chrome's appearance; actions always resolve this block by id.
|
|
102
|
+
const isSelected = usePuckSelector((state)=>state.selectedItem?.props.id === props.id);
|
|
91
103
|
const originalEmpty = usePuckSelector((state)=>{
|
|
92
104
|
const content = state.getItemById(props.id)?.props.control;
|
|
93
105
|
return !Array.isArray(content) || content.length === 0;
|
|
@@ -117,23 +129,29 @@ function EditorRender(props) {
|
|
|
117
129
|
credentials: 'include',
|
|
118
130
|
signal
|
|
119
131
|
});
|
|
120
|
-
if (!response.ok) throw new
|
|
132
|
+
if (!response.ok) throw new TestReadError(response.status);
|
|
121
133
|
const doc = await response.json();
|
|
122
134
|
if (!isExperiment(doc)) throw new Error('document');
|
|
123
135
|
return doc;
|
|
124
136
|
}, controller.signal);
|
|
125
137
|
if (current && revision === request) {
|
|
126
|
-
setLoaded({
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
setLoaded((value)=>({
|
|
139
|
+
id: experimentId,
|
|
140
|
+
doc,
|
|
141
|
+
shared: value?.id === experimentId ? value?.shared : undefined
|
|
142
|
+
}));
|
|
130
143
|
}
|
|
131
|
-
} catch
|
|
144
|
+
} catch (cause) {
|
|
132
145
|
if (current && revision === request) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
146
|
+
const forbidden = cause instanceof TestReadError && (cause.status === 401 || cause.status === 403);
|
|
147
|
+
const missing = cause instanceof TestReadError && cause.status === 404;
|
|
148
|
+
setLoaded((value)=>({
|
|
149
|
+
id: experimentId,
|
|
150
|
+
forbidden,
|
|
151
|
+
missing,
|
|
152
|
+
error: !forbidden && !missing,
|
|
153
|
+
shared: value?.id === experimentId ? value?.shared : undefined
|
|
154
|
+
}));
|
|
137
155
|
}
|
|
138
156
|
}
|
|
139
157
|
}
|
|
@@ -153,9 +171,33 @@ function EditorRender(props) {
|
|
|
153
171
|
experimentId,
|
|
154
172
|
api
|
|
155
173
|
]);
|
|
174
|
+
const cachedExperiment = loaded?.id === experimentId && !loaded?.forbidden && !loaded?.missing ? knownArms?.doc : undefined;
|
|
175
|
+
const status = cachedExperiment?.status ?? (loaded?.id === experimentId ? loaded?.doc?.status : undefined);
|
|
176
|
+
useEffect(()=>{
|
|
177
|
+
if (experimentId === undefined || !status) return;
|
|
178
|
+
return acquirePlacements(api, experimentId, (placements)=>{
|
|
179
|
+
const shared = placements === undefined ? undefined : isSharedTest(placements, currentPuckDocument(window.location.pathname, admin, placements));
|
|
180
|
+
setLoaded((value)=>({
|
|
181
|
+
...value?.id === experimentId ? value : {},
|
|
182
|
+
id: experimentId,
|
|
183
|
+
shared
|
|
184
|
+
}));
|
|
185
|
+
}, status === 'running');
|
|
186
|
+
}, [
|
|
187
|
+
api,
|
|
188
|
+
admin,
|
|
189
|
+
experimentId,
|
|
190
|
+
status
|
|
191
|
+
]);
|
|
192
|
+
const locallyShared = usePuckSelector((state)=>experimentId !== undefined && (localPlacements(state.appState.data, state.config).get(String(experimentId))?.size ?? 0) > 1);
|
|
156
193
|
const result = experimentId === undefined || loaded?.id !== experimentId ? undefined : loaded;
|
|
157
|
-
const
|
|
158
|
-
const
|
|
194
|
+
const shared = locallyShared || result?.shared === true;
|
|
195
|
+
const experiment = cachedExperiment ?? result?.doc;
|
|
196
|
+
const noAccess = access.error === 'forbidden' || !!access.surface && !access.surface.canManage && !access.surface.canReadResults;
|
|
197
|
+
const resultsOnly = access.surface?.canReadResults === true && !access.surface.canManage;
|
|
198
|
+
const unavailable = result?.forbidden || result?.missing;
|
|
199
|
+
const canManage = access.surface?.canManage === true && !unavailable;
|
|
200
|
+
const editable = canManage && (experiment?.status === 'draft' || experiment?.status === 'stopped');
|
|
159
201
|
const [removed, setRemoved] = useState(null);
|
|
160
202
|
useEffect(()=>{
|
|
161
203
|
// Dialog cleanup must close the native modal before an outside tab can receive focus.
|
|
@@ -165,13 +207,39 @@ function EditorRender(props) {
|
|
|
165
207
|
bindingKey
|
|
166
208
|
]);
|
|
167
209
|
const writes = useArmWrites(`${api}/xp-experiments/${encodeURIComponent(String(experimentId))}`, (doc)=>{
|
|
168
|
-
|
|
169
|
-
if (isCurrentBinding()) setLoaded({
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
210
|
+
publishExperiment(experimentId, doc);
|
|
211
|
+
if (isCurrentBinding()) setLoaded((value)=>({
|
|
212
|
+
id: experimentId,
|
|
213
|
+
doc,
|
|
214
|
+
shared: value?.id === experimentId ? value?.shared : undefined
|
|
215
|
+
}));
|
|
173
216
|
}, isCurrentBinding, ()=>setClearError(null));
|
|
174
|
-
|
|
217
|
+
// The slot arrays belong to the page; reading the test is unnecessary to edit them.
|
|
218
|
+
const pageSlots = usePuckSelector((state)=>[
|
|
219
|
+
'control',
|
|
220
|
+
'variantA',
|
|
221
|
+
'variantB',
|
|
222
|
+
'variantC'
|
|
223
|
+
].filter((slot)=>{
|
|
224
|
+
const content = state.getItemById(props.id)?.props[slot];
|
|
225
|
+
return slot === 'control' || Array.isArray(content) && content.length > 0;
|
|
226
|
+
}).join(','));
|
|
227
|
+
// Keep a page-observed version reachable while its last child is replaced.
|
|
228
|
+
const observedSlots = useRef({
|
|
229
|
+
key: bindingKey,
|
|
230
|
+
slots: new Set()
|
|
231
|
+
});
|
|
232
|
+
if (observedSlots.current.key !== bindingKey) observedSlots.current = {
|
|
233
|
+
key: bindingKey,
|
|
234
|
+
slots: new Set()
|
|
235
|
+
};
|
|
236
|
+
for (const slot of pageSlots.split(','))observedSlots.current.slots.add(slot);
|
|
237
|
+
const tabs = unavailable ? [
|
|
238
|
+
...observedSlots.current.slots
|
|
239
|
+
].sort((a, b)=>a.localeCompare(b)).map((slot)=>({
|
|
240
|
+
slot: slot,
|
|
241
|
+
label: slotLabels[slot]
|
|
242
|
+
})) : tabsFor(experiment);
|
|
175
243
|
const activeSlot = active && active.id === experimentId ? active.slot : undefined;
|
|
176
244
|
const slot = tabs.find((tab)=>tab.slot === activeSlot)?.slot ?? tabs[0]?.slot ?? 'control';
|
|
177
245
|
const slotEmpty = usePuckSelector((state)=>{
|
|
@@ -181,16 +249,27 @@ function EditorRender(props) {
|
|
|
181
249
|
const Slot = props[slot];
|
|
182
250
|
const winnerKey = experiment?.decision?.winnerArm;
|
|
183
251
|
const winner = tabs.find((tab)=>tab.slot === winnerKey)?.label;
|
|
252
|
+
function selectBlock() {
|
|
253
|
+
const { dispatch, getSelectorForId } = getPuck();
|
|
254
|
+
const itemSelector = getSelectorForId(props.id);
|
|
255
|
+
if (itemSelector) dispatch({
|
|
256
|
+
type: 'setUi',
|
|
257
|
+
ui: {
|
|
258
|
+
itemSelector
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}
|
|
184
262
|
function requestCopy(variant) {
|
|
185
|
-
const
|
|
186
|
-
const target = item?.props
|
|
263
|
+
const item = getPuck().getItemById(props.id);
|
|
264
|
+
const target = item?.props[variant];
|
|
187
265
|
if (Array.isArray(target) && target.length) setConfirming(variant);
|
|
188
266
|
else copyTo(variant);
|
|
189
267
|
}
|
|
190
268
|
function copyTo(variant) {
|
|
191
269
|
setConfirming(null);
|
|
192
|
-
const {
|
|
193
|
-
|
|
270
|
+
const { getItemById, dispatch, getSelectorForId } = getPuck();
|
|
271
|
+
const item = getItemById(props.id);
|
|
272
|
+
if (!item || !Array.isArray(item.props.control) || !item.props.control.length) return;
|
|
194
273
|
const selector = getSelectorForId(props.id);
|
|
195
274
|
if (!selector) return;
|
|
196
275
|
dispatch({
|
|
@@ -240,9 +319,12 @@ function EditorRender(props) {
|
|
|
240
319
|
});
|
|
241
320
|
}
|
|
242
321
|
function bind(experiment) {
|
|
322
|
+
if (!isCurrentBinding()) return false;
|
|
243
323
|
const { getItemById, dispatch, getSelectorForId } = getPuck();
|
|
244
324
|
const item = getItemById(props.id), selector = getSelectorForId(props.id);
|
|
245
|
-
if (!item || !selector) return;
|
|
325
|
+
if (!item || !selector || String(item.props.experiment?.id) !== String(experimentId)) return false;
|
|
326
|
+
if (experimentId !== undefined) invalidatePlacements(api, experimentId);
|
|
327
|
+
if (experiment) invalidatePlacements(api, experiment.id);
|
|
246
328
|
dispatch({
|
|
247
329
|
type: 'replace',
|
|
248
330
|
destinationIndex: selector.index,
|
|
@@ -255,18 +337,126 @@ function EditorRender(props) {
|
|
|
255
337
|
}
|
|
256
338
|
}
|
|
257
339
|
});
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
async function newTestArms() {
|
|
343
|
+
if (!isCurrentBinding()) throw new Error('binding');
|
|
344
|
+
// Another placement can rename or add a version while this dialog is open.
|
|
345
|
+
const response = await fetch(`${api}/xp-experiments/${encodeURIComponent(String(experimentId))}?depth=0`, {
|
|
346
|
+
credentials: 'include',
|
|
347
|
+
cache: 'no-store'
|
|
348
|
+
});
|
|
349
|
+
if (!response.ok) throw new Error('load');
|
|
350
|
+
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);
|
|
354
|
+
}
|
|
355
|
+
function createFromBlock() {
|
|
356
|
+
if (!root.current) return;
|
|
357
|
+
creation.current = openCreateExperimentDrawer(root.current, {
|
|
358
|
+
admin,
|
|
359
|
+
api
|
|
360
|
+
}, {
|
|
361
|
+
initialName: pageTitle,
|
|
362
|
+
arms: experimentId === undefined ? undefined : newTestArms,
|
|
363
|
+
label: experimentId === undefined ? editorCopy.createLabel : editorCopy.newTest,
|
|
364
|
+
onCreate: bind
|
|
365
|
+
});
|
|
258
366
|
}
|
|
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);
|
|
375
|
+
try {
|
|
376
|
+
const response = await fetch(`${api}/xp-experiments/${encodeURIComponent(String(experimentId))}?depth=0`, {
|
|
377
|
+
credentials: 'include',
|
|
378
|
+
cache: 'no-store'
|
|
379
|
+
});
|
|
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
|
+
}
|
|
430
|
+
} finally{
|
|
431
|
+
detachBusy.current = false;
|
|
432
|
+
setCheckingDetach(false);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
const newTestButton = experimentId !== undefined && canManage ? /*#__PURE__*/ _jsx(Button, {
|
|
436
|
+
disabled: !experiment,
|
|
437
|
+
onClick: createFromBlock,
|
|
438
|
+
children: editorCopy.newTest
|
|
439
|
+
}) : null;
|
|
259
440
|
return /*#__PURE__*/ _jsxs("section", {
|
|
260
441
|
ref: root,
|
|
261
442
|
className: "xp-slot-root xp-slot-editor",
|
|
262
443
|
style: props.accent ? accentVariables(props.accent[mode]) : undefined,
|
|
263
444
|
children: [
|
|
264
|
-
/*#__PURE__*/ _jsxs(
|
|
445
|
+
/*#__PURE__*/ _jsxs(EditorControls, {
|
|
265
446
|
className: "xp-slot-chrome",
|
|
266
|
-
|
|
447
|
+
selected: isSelected,
|
|
448
|
+
onSelect: selectBlock,
|
|
267
449
|
children: [
|
|
268
450
|
/*#__PURE__*/ _jsxs("header", {
|
|
269
451
|
className: "xp-slot-header",
|
|
452
|
+
tabIndex: 0,
|
|
453
|
+
"aria-label": editorCopy.selectBlock,
|
|
454
|
+
onKeyDown: (event)=>{
|
|
455
|
+
if (event.target === event.currentTarget && (event.key === 'Enter' || event.key === ' ')) {
|
|
456
|
+
event.preventDefault();
|
|
457
|
+
selectBlock();
|
|
458
|
+
}
|
|
459
|
+
},
|
|
270
460
|
children: [
|
|
271
461
|
/*#__PURE__*/ _jsx("h3", {
|
|
272
462
|
className: "xp-slot-title",
|
|
@@ -280,7 +470,33 @@ function EditorRender(props) {
|
|
|
280
470
|
}) : null
|
|
281
471
|
]
|
|
282
472
|
}),
|
|
283
|
-
/*#__PURE__*/ _jsx(
|
|
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, {
|
|
284
500
|
tone: result?.error ? 'error' : experiment?.status === 'running' ? 'warning' : 'info',
|
|
285
501
|
children: experimentId === undefined ? bannerFor() : result?.error ? editorCopy.loadError : experiment ? bannerFor(experiment.status, winner) : editorCopy.loading
|
|
286
502
|
}),
|
|
@@ -288,20 +504,31 @@ function EditorRender(props) {
|
|
|
288
504
|
tone: "warning",
|
|
289
505
|
children: editorCopy.orphan(slotLabels[slot])
|
|
290
506
|
}, slot)),
|
|
507
|
+
shared ? /*#__PURE__*/ _jsx(Banner, {
|
|
508
|
+
tone: "info",
|
|
509
|
+
action: newTestButton,
|
|
510
|
+
children: editorCopy.sharedTest
|
|
511
|
+
}) : null,
|
|
291
512
|
/*#__PURE__*/ _jsxs("div", {
|
|
292
513
|
className: "xp-ui-button-group",
|
|
293
514
|
children: [
|
|
294
|
-
experimentId === undefined ? /*#__PURE__*/ _jsx(Button, {
|
|
515
|
+
experimentId === undefined && canManage ? /*#__PURE__*/ _jsx(Button, {
|
|
295
516
|
variant: "primary",
|
|
296
|
-
|
|
297
|
-
onClick: ()=>setCreating(true),
|
|
517
|
+
onClick: createFromBlock,
|
|
298
518
|
children: editorCopy.createLabel
|
|
299
519
|
}) : null,
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
|
305
532
|
}) : null,
|
|
306
533
|
experiment && editable ? /*#__PURE__*/ _jsx(AddVariant, {
|
|
307
534
|
experiment: experiment,
|
|
@@ -315,6 +542,10 @@ function EditorRender(props) {
|
|
|
315
542
|
}) : null
|
|
316
543
|
]
|
|
317
544
|
}),
|
|
545
|
+
experiment?.status === 'running' && result?.shared !== undefined && !shared ? /*#__PURE__*/ _jsx("p", {
|
|
546
|
+
className: "xp-ui-help",
|
|
547
|
+
children: editorCopy.stopToDetach
|
|
548
|
+
}) : null,
|
|
318
549
|
experiment && !editable ? /*#__PURE__*/ _jsx("p", {
|
|
319
550
|
className: "xp-ui-help",
|
|
320
551
|
children: editorCopy.locked[experiment.status]
|
|
@@ -348,10 +579,34 @@ function EditorRender(props) {
|
|
|
348
579
|
onRemove: removeContent,
|
|
349
580
|
onClose: ()=>setRemoving(null)
|
|
350
581
|
}) : null,
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
+
})
|
|
355
610
|
}) : null,
|
|
356
611
|
confirming ? /*#__PURE__*/ _jsxs("div", {
|
|
357
612
|
className: "xp-slot-confirm",
|
|
@@ -381,7 +636,10 @@ function EditorRender(props) {
|
|
|
381
636
|
/*#__PURE__*/ _jsx(Tabs, {
|
|
382
637
|
label: editorCopy.tabs,
|
|
383
638
|
value: slot,
|
|
384
|
-
|
|
639
|
+
renderHeader: (children)=>/*#__PURE__*/ _jsx(EditorControls, {
|
|
640
|
+
className: "xp-ui-tabs-header",
|
|
641
|
+
children: children
|
|
642
|
+
}),
|
|
385
643
|
onChange: (value)=>{
|
|
386
644
|
setOpenMenu(null);
|
|
387
645
|
setActive({
|
|
@@ -398,7 +656,7 @@ function EditorRender(props) {
|
|
|
398
656
|
editable: editable,
|
|
399
657
|
open: openMenu === tab.slot,
|
|
400
658
|
onOpenChange: (open)=>setOpenMenu(open ? tab.slot : null),
|
|
401
|
-
canCopy:
|
|
659
|
+
canCopy: !originalEmpty,
|
|
402
660
|
onCopy: requestCopy,
|
|
403
661
|
onRequestRemove: ()=>setRemoving({
|
|
404
662
|
key: bindingKey,
|
|
@@ -431,7 +689,15 @@ export function createExperimentSlotEditor({ routes: inputRoutes, accent } = {})
|
|
|
431
689
|
fields: {
|
|
432
690
|
...experimentSlotFields,
|
|
433
691
|
experiment: createExperimentSlotField({
|
|
434
|
-
routes
|
|
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
|
+
}
|
|
435
701
|
})
|
|
436
702
|
},
|
|
437
703
|
defaultProps: experimentSlotDefaultProps,
|
|
@@ -2,11 +2,8 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { useEffect, useRef, useState } from 'react';
|
|
4
4
|
import { Button } from '../../ui/Button.js';
|
|
5
|
+
import { formatCount } from '../../testSurface/results/format.js';
|
|
5
6
|
import { editorCopy as C } from './copy.js';
|
|
6
|
-
// Matches admin/results/format.ts formatCount; importing it would pull admin copy into this bundle.
|
|
7
|
-
const formatCount = (value)=>typeof value === 'number' && Number.isFinite(value) ? new Intl.NumberFormat('en-US', {
|
|
8
|
-
maximumFractionDigits: 0
|
|
9
|
-
}).format(value) : '—';
|
|
10
7
|
export function ResultsReadout({ id, api, experiment }) {
|
|
11
8
|
const [data, setData] = useState(null);
|
|
12
9
|
const [refresh, setRefresh] = useState(0);
|
|
@@ -56,7 +53,8 @@ export function ResultsReadout({ id, api, experiment }) {
|
|
|
56
53
|
}, [
|
|
57
54
|
id,
|
|
58
55
|
api,
|
|
59
|
-
refresh
|
|
56
|
+
refresh,
|
|
57
|
+
experiment.status
|
|
60
58
|
]);
|
|
61
59
|
return /*#__PURE__*/ _jsxs("div", {
|
|
62
60
|
className: "xp-slot-readout",
|
|
@@ -76,10 +76,10 @@ export function VersionActions({ arm, writes, editable, open, onOpenChange, canC
|
|
|
76
76
|
// Focus leaving the canvas iframe (Puck's own panels) or the window fires window blur, not a document pointerdown.
|
|
77
77
|
const leave = ()=>onOpenChange(false);
|
|
78
78
|
const view = doc?.defaultView;
|
|
79
|
-
doc?.addEventListener('pointerdown', outside);
|
|
79
|
+
doc?.addEventListener('pointerdown', outside, true);
|
|
80
80
|
view?.addEventListener('blur', leave);
|
|
81
81
|
return ()=>{
|
|
82
|
-
doc?.removeEventListener('pointerdown', outside);
|
|
82
|
+
doc?.removeEventListener('pointerdown', outside, true);
|
|
83
83
|
view?.removeEventListener('blur', leave);
|
|
84
84
|
};
|
|
85
85
|
}, [
|
|
@@ -2,13 +2,15 @@ import type { DocId } from '../../types/contracts.js';
|
|
|
2
2
|
import type { EditorExperiment } from './editor.model.js';
|
|
3
3
|
type Arms = {
|
|
4
4
|
arms: string[];
|
|
5
|
+
doc?: EditorExperiment;
|
|
5
6
|
};
|
|
6
7
|
/** Only the first mounted block discards a document left by an earlier editor. */
|
|
7
8
|
export declare function acquireArms(testId: DocId): () => void;
|
|
8
9
|
/** Share the request, but abort it only after its last mounted consumer leaves. */
|
|
9
10
|
export declare function loadArms(testId: DocId, load: (signal: AbortSignal) => Promise<EditorExperiment>, signal: AbortSignal): Promise<EditorExperiment>;
|
|
10
11
|
export declare function subscribe(listener: () => void): () => void;
|
|
11
|
-
|
|
12
|
+
export declare function publishExperiment(testId: DocId, doc: EditorExperiment): void;
|
|
13
|
+
/** undefined means unknown. */
|
|
12
14
|
export declare function setArms(testId: DocId, arms: string[] | undefined): void;
|
|
13
15
|
export declare function useArms(testId: DocId | undefined): Arms | undefined;
|
|
14
16
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useSyncExternalStore } from 'react';
|
|
3
3
|
const cache = new Map();
|
|
4
|
+
const revisions = new Map();
|
|
4
5
|
const listeners = new Set();
|
|
5
6
|
const pending = new Map();
|
|
6
7
|
const mounted = new Map();
|
|
@@ -29,11 +30,14 @@ const mounted = new Map();
|
|
|
29
30
|
promise: undefined
|
|
30
31
|
};
|
|
31
32
|
const entry = request;
|
|
33
|
+
const revision = revisions.get(key) ?? 0;
|
|
32
34
|
entry.promise = load(controller.signal).then((doc)=>{
|
|
33
|
-
if (
|
|
35
|
+
if ((revisions.get(key) ?? 0) !== revision) return cache.get(key)?.doc ?? doc;
|
|
36
|
+
if (!controller.signal.aborted) publishExperiment(testId, doc);
|
|
34
37
|
return doc;
|
|
35
38
|
}, (error)=>{
|
|
36
|
-
if (
|
|
39
|
+
if ((revisions.get(key) ?? 0) !== revision && cache.get(key)?.doc) return cache.get(key).doc;
|
|
40
|
+
if (!controller.signal.aborted && (revisions.get(key) ?? 0) === revision) setArms(testId, undefined);
|
|
37
41
|
throw error;
|
|
38
42
|
}).finally(()=>{
|
|
39
43
|
if (pending.get(key) === entry) pending.delete(key);
|
|
@@ -63,7 +67,20 @@ export function subscribe(listener) {
|
|
|
63
67
|
listeners.delete(listener);
|
|
64
68
|
};
|
|
65
69
|
}
|
|
66
|
-
|
|
70
|
+
export function publishExperiment(testId, doc) {
|
|
71
|
+
const previous = cache.get(String(testId))?.doc;
|
|
72
|
+
// Surface reads and chrome writes share this producer too. A GET that began
|
|
73
|
+
// before a save cannot overwrite its newer server timestamp when it finishes.
|
|
74
|
+
if (previous?.updatedAt && doc.updatedAt && Date.parse(previous.updatedAt) > Date.parse(doc.updatedAt)) return;
|
|
75
|
+
revisions.set(String(testId), (revisions.get(String(testId)) ?? 0) + 1);
|
|
76
|
+
cache.set(String(testId), {
|
|
77
|
+
arms: doc.arms.map((arm)=>arm.key),
|
|
78
|
+
doc
|
|
79
|
+
});
|
|
80
|
+
for (const listener of listeners)listener();
|
|
81
|
+
}
|
|
82
|
+
/** undefined means unknown. */ export function setArms(testId, arms) {
|
|
83
|
+
revisions.set(String(testId), (revisions.get(String(testId)) ?? 0) + 1);
|
|
67
84
|
if (arms) cache.set(String(testId), {
|
|
68
85
|
arms: [
|
|
69
86
|
...arms
|