@delmaredigital/payload-experiments 0.4.0-rc.6 → 0.4.0-rc.9
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 +12 -12
- package/dist/admin/blocks/BlockPanel.js +6 -4
- package/dist/admin/blocks/inject.js +1 -0
- package/dist/admin/blocks/model.d.ts +3 -2
- package/dist/admin/blocks/model.js +9 -5
- package/dist/admin/copy/blocks.d.ts +3 -2
- package/dist/admin/copy/blocks.js +8 -7
- package/dist/admin/surface/ResultsRoute.js +18 -11
- package/dist/admin/surface/TestsHome.d.ts +2 -1
- package/dist/admin/surface/TestsHome.js +131 -44
- package/dist/admin/surface/TestsSurface.js +3 -0
- package/dist/admin/surface/home.model.d.ts +2 -0
- package/dist/admin/surface/newTest/PageWizard.js +9 -2
- package/dist/admin/surface/newTest/newTest.css +1 -1
- package/dist/admin/surface/results/ResultsHeader.js +11 -6
- package/dist/admin/surface/test/TestPage.js +3 -3
- package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
- package/dist/admin/views/TestsSurfaceClient.js +11 -0
- package/dist/admin/views/buildSurfaceProps.js +10 -3
- package/dist/blocks/bindings.js +3 -2
- package/dist/blocks/formState.js +1 -1
- package/dist/blocks/placementLanguages.d.ts +7 -0
- package/dist/blocks/placementLanguages.js +27 -0
- package/dist/blocks/placementLocale.d.ts +21 -7
- package/dist/blocks/placementLocale.js +218 -67
- package/dist/collections/experiments/config.js +8 -3
- package/dist/collections/experiments/deleteGuard.js +2 -2
- package/dist/collections/experiments/lockHook.js +21 -2
- package/dist/collections/experiments/pickSlug.js +2 -0
- package/dist/collections/metricsGuards.js +2 -0
- package/dist/collections/serialize.js +5 -4
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/db/adapter.d.ts +9 -1
- package/dist/db/adapter.js +77 -1
- package/dist/db/appends.d.ts +13 -0
- package/dist/db/appends.js +49 -0
- package/dist/db/bulkPlacementRemoval.js +8 -4
- package/dist/db/delete.d.ts +1 -1
- package/dist/db/delete.js +2 -4
- package/dist/db/events.d.ts +9 -0
- package/dist/db/events.js +42 -8
- package/dist/db/executor.d.ts +7 -1
- package/dist/db/executor.js +7 -3
- package/dist/db/results.d.ts +5 -1
- package/dist/db/results.js +21 -5
- package/dist/db/snapshots.d.ts +1 -0
- package/dist/endpoints/contentLocale.d.ts +6 -0
- package/dist/endpoints/contentLocale.js +15 -0
- package/dist/endpoints/deleteImpact.d.ts +6 -0
- package/dist/endpoints/deleteImpact.js +207 -0
- package/dist/endpoints/events.js +103 -39
- package/dist/endpoints/index.js +9 -8
- package/dist/endpoints/pages.js +7 -3
- package/dist/endpoints/placementStatus.js +13 -5
- package/dist/endpoints/preflight.d.ts +1 -1
- package/dist/endpoints/preflight.js +17 -2
- package/dist/endpoints/results.d.ts +1 -1
- package/dist/endpoints/results.js +6 -2
- package/dist/endpoints/routeId.d.ts +2 -2
- package/dist/endpoints/routeId.js +11 -5
- package/dist/endpoints/summary.js +46 -12
- package/dist/endpoints/transitions.js +37 -24
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +6 -0
- package/dist/events/request.d.ts +6 -2
- package/dist/events/request.js +35 -8
- package/dist/events/rows.d.ts +1 -1
- package/dist/events/rows.js +24 -8
- package/dist/events/writable.d.ts +9 -0
- package/dist/events/writable.js +13 -0
- package/dist/exports/adminClient.d.ts +1 -1
- package/dist/exports/adminClient.js +1 -1
- package/dist/exports/index.d.ts +1 -1
- package/dist/exports/rsc.d.ts +1 -0
- package/dist/exports/rsc.js +1 -0
- package/dist/goals/fairness.js +38 -31
- package/dist/hooks/blockRemovalRule.d.ts +2 -2
- package/dist/hooks/blockRemovalRule.js +16 -14
- package/dist/hooks/hostHook.js +6 -2
- package/dist/hooks/pageGuard.d.ts +3 -0
- package/dist/hooks/pageGuard.js +37 -23
- package/dist/hooks/puckNestedTests.d.ts +8 -0
- package/dist/hooks/puckNestedTests.js +36 -0
- package/dist/lib/fetchAllDocs.d.ts +1 -1
- package/dist/lib/placementPages.d.ts +2 -1
- package/dist/lib/placementPages.js +10 -2
- package/dist/manifest/compile.d.ts +2 -1
- package/dist/manifest/compile.js +13 -6
- package/dist/onInit.js +14 -0
- package/dist/options.js +5 -0
- package/dist/proxy/pageNavigation.d.ts +4 -0
- package/dist/proxy/pageNavigation.js +28 -0
- package/dist/proxy/resolve.js +52 -25
- package/dist/puck/ExperimentPicker.js +40 -37
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
- package/dist/puck/editor/ConfigureTestDrawer.js +5 -2
- package/dist/puck/editor/ExperimentSlotEditor.js +313 -158
- package/dist/puck/editor/LeftoverVersions.d.ts +1 -1
- package/dist/puck/editor/LeftoverVersions.js +40 -43
- package/dist/puck/editor/QuickTestActions.d.ts +5 -2
- package/dist/puck/editor/QuickTestActions.js +16 -4
- package/dist/puck/editor/ResultsReadout.d.ts +2 -1
- package/dist/puck/editor/ResultsReadout.js +2 -1
- package/dist/puck/editor/VersionBuilder.d.ts +31 -3
- package/dist/puck/editor/VersionBuilder.js +336 -74
- package/dist/puck/editor/armWrites.js +1 -1
- package/dist/puck/editor/armsCache.js +1 -3
- package/dist/puck/editor/blockClipboard.d.ts +16 -0
- package/dist/puck/editor/blockClipboard.js +20 -0
- package/dist/puck/editor/copy.d.ts +12 -2
- package/dist/puck/editor/copy.js +13 -2
- package/dist/puck/editor/editor.chrome.css +118 -3
- package/dist/puck/editor/editor.css +131 -8
- package/dist/puck/editor/editor.model.d.ts +3 -1
- package/dist/puck/editor/editor.model.js +2 -2
- package/dist/puck/editor/localPlacements.d.ts +1 -0
- package/dist/puck/editor/localPlacements.js +12 -0
- package/dist/puck/editor/placementsCache.d.ts +22 -12
- package/dist/puck/editor/placementsCache.js +62 -49
- package/dist/puck/editor/usePageSaveReadiness.d.ts +9 -0
- package/dist/puck/editor/usePageSaveReadiness.js +34 -0
- package/dist/puck/editor/usePlacementNotice.d.ts +2 -2
- package/dist/puck/editor/usePlacementNotice.js +6 -4
- package/dist/puck/experimentSlug.d.ts +2 -0
- package/dist/puck/experimentSlug.js +3 -0
- package/dist/puck/nestedTestCopy.d.ts +8 -0
- package/dist/puck/nestedTestCopy.js +22 -0
- package/dist/puck/nestedTests.d.ts +17 -0
- package/dist/puck/nestedTests.js +30 -0
- package/dist/puck/slotConfig.d.ts +1 -1
- package/dist/puck/slotConfig.js +17 -4
- package/dist/puck/visibility.d.ts +2 -3
- package/dist/puck/visibility.js +11 -7
- package/dist/results/aggregate.d.ts +6 -3
- package/dist/results/aggregate.js +9 -9
- package/dist/results/health.d.ts +8 -0
- package/dist/results/health.js +28 -0
- package/dist/results/identityCredit.d.ts +1 -0
- package/dist/results/identityCredit.js +4 -1
- package/dist/results/verdict.js +2 -1
- package/dist/runtime/cookie.d.ts +10 -2
- package/dist/runtime/cookie.js +38 -6
- package/dist/runtime/cookieOptions.d.ts +6 -0
- package/dist/runtime/cookieOptions.js +14 -0
- package/dist/runtime/proxyRuntime.d.ts +1 -0
- package/dist/runtime/proxyRuntime.js +18 -8
- package/dist/runtime/signing.d.ts +1 -0
- package/dist/runtime/signing.js +5 -0
- package/dist/sanitizeReadinessDetail.d.ts +2 -2
- package/dist/sanitizeReadinessDetail.js +20 -2
- package/dist/server/getAssignments.js +11 -10
- package/dist/server/recordContentChange.d.ts +1 -1
- package/dist/server/recordContentChange.js +45 -21
- package/dist/server/resolveExperimentBlocks.js +2 -4
- package/dist/server/resolveExperimentData.js +4 -7
- package/dist/server/runResults.js +52 -14
- package/dist/server/startExperiment.d.ts +20 -0
- package/dist/server/startExperiment.js +70 -0
- package/dist/server/trackConversion.js +10 -13
- package/dist/testSurface/PreviewLinks.js +6 -2
- package/dist/testSurface/actions/DecideDialog.d.ts +4 -1
- package/dist/testSurface/actions/DecideDialog.js +32 -14
- package/dist/testSurface/actions/MakeContentResult.d.ts +4 -3
- package/dist/testSurface/actions/MakeContentResult.js +9 -1
- package/dist/testSurface/api.d.ts +11 -8
- package/dist/testSurface/api.js +27 -11
- package/dist/testSurface/contentLocaleURL.d.ts +2 -0
- package/dist/testSurface/contentLocaleURL.js +3 -0
- package/dist/testSurface/copy/actions.d.ts +1 -0
- package/dist/testSurface/copy/actions.js +1 -0
- package/dist/testSurface/copy/common.d.ts +6 -0
- package/dist/testSurface/copy/common.js +11 -5
- package/dist/testSurface/copy/languages.d.ts +12 -0
- package/dist/testSurface/copy/languages.js +8 -0
- package/dist/testSurface/copy/metrics.d.ts +1 -0
- package/dist/testSurface/copy/metrics.js +1 -0
- package/dist/testSurface/copy/readiness.d.ts +13 -2
- package/dist/testSurface/copy/readiness.js +19 -2
- package/dist/testSurface/copy/results.d.ts +5 -2
- package/dist/testSurface/copy/results.js +5 -2
- package/dist/testSurface/copy/testPage.d.ts +40 -1
- package/dist/testSurface/copy/testPage.js +53 -1
- package/dist/testSurface/placementLabel.d.ts +8 -0
- package/dist/testSurface/placementLabel.js +24 -0
- package/dist/testSurface/placements/placementLabels.d.ts +2 -0
- package/dist/testSurface/placements/placementLabels.js +2 -1
- package/dist/testSurface/readPreflight.d.ts +5 -0
- package/dist/testSurface/readPreflight.js +7 -0
- package/dist/testSurface/readinessRead.d.ts +3 -0
- package/dist/testSurface/readinessRead.js +4 -0
- package/dist/testSurface/results/VerdictHero.d.ts +2 -1
- package/dist/testSurface/results/VerdictHero.js +5 -1
- package/dist/testSurface/results/results.css +1 -1
- package/dist/testSurface/results/results.model.d.ts +1 -1
- package/dist/testSurface/results/results.model.js +6 -2
- package/dist/testSurface/surface/contracts.d.ts +10 -1
- package/dist/testSurface/surface/editorPlacement.d.ts +7 -2
- package/dist/testSurface/surface/editorPlacement.js +19 -1
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +4 -3
- package/dist/testSurface/surface/pageBlock/parts.js +24 -6
- package/dist/testSurface/surface/pagePicker/PageCombobox.js +20 -6
- package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +4 -2
- package/dist/testSurface/surface/readiness/ActionDialogs.js +39 -34
- package/dist/testSurface/surface/readiness/Banner.js +23 -12
- package/dist/testSurface/surface/readiness/SaveStatus.d.ts +4 -3
- package/dist/testSurface/surface/readiness/SaveStatus.js +15 -15
- package/dist/testSurface/surface/readiness/readiness.model.d.ts +6 -1
- package/dist/testSurface/surface/readiness/readiness.model.js +116 -12
- package/dist/testSurface/surface/readiness/useTransition.d.ts +4 -4
- package/dist/testSurface/surface/readiness/useTransition.js +12 -10
- package/dist/testSurface/surface/results/ReleasePages.d.ts +4 -2
- package/dist/testSurface/surface/results/ReleasePages.js +5 -4
- package/dist/testSurface/surface/results/ResultsBody.d.ts +4 -2
- package/dist/testSurface/surface/results/ResultsBody.js +86 -43
- package/dist/testSurface/surface/results/useResults.d.ts +11 -7
- package/dist/testSurface/surface/results/useResults.js +3 -2
- package/dist/testSurface/surface/setting/parts.js +58 -18
- package/dist/testSurface/surface/test/AdvancedSection.js +1 -0
- package/dist/testSurface/surface/test/DeleteTest.d.ts +19 -0
- package/dist/testSurface/surface/test/DeleteTest.js +262 -0
- package/dist/testSurface/surface/test/GoalSection.js +7 -3
- package/dist/testSurface/surface/test/LengthSection.js +3 -0
- package/dist/testSurface/surface/test/PageHoldout.js +4 -1
- package/dist/testSurface/surface/test/ReadinessBar.js +1 -1
- package/dist/testSurface/surface/test/TargetingSection.js +77 -12
- package/dist/testSurface/surface/test/TestSurface.js +97 -15
- package/dist/testSurface/surface/test/VersionsSection.js +56 -29
- package/dist/testSurface/surface/test/fields.d.ts +29 -4
- package/dist/testSurface/surface/test/fields.js +159 -39
- package/dist/testSurface/surface/test/pageParts.js +14 -5
- package/dist/testSurface/surface/test/testPage.model.d.ts +1 -0
- package/dist/testSurface/surface/test/testPage.model.js +6 -0
- package/dist/testSurface/surface/testDocument.model.d.ts +3 -0
- package/dist/testSurface/surface/testDocument.model.js +4 -1
- package/dist/testSurface/surface/useTestDocument.d.ts +23 -4
- package/dist/testSurface/surface/useTestDocument.js +425 -162
- package/dist/testSurface/useApi.d.ts +9 -6
- package/dist/testSurface/useOnTestReturn.d.ts +2 -0
- package/dist/testSurface/useOnTestReturn.js +27 -0
- package/dist/testSurface/useReadinessPolling.js +3 -1
- package/dist/transitions/addMetric.d.ts +1 -4
- package/dist/transitions/allocate.d.ts +2 -2
- package/dist/transitions/allocate.js +3 -1
- package/dist/transitions/archive.d.ts +1 -1
- package/dist/transitions/archive.js +3 -2
- package/dist/transitions/checkStart.d.ts +5 -1
- package/dist/transitions/checkStart.js +130 -16
- package/dist/transitions/contentFields.js +9 -5
- package/dist/transitions/decide.d.ts +1 -1
- package/dist/transitions/decide.js +5 -3
- package/dist/transitions/deleteExperiment.d.ts +2 -2
- package/dist/transitions/deleteExperiment.js +17 -7
- package/dist/transitions/kernel.d.ts +2 -0
- package/dist/transitions/kernel.js +9 -4
- package/dist/transitions/makeContent.d.ts +2 -1
- package/dist/transitions/makeContent.js +17 -12
- package/dist/transitions/nestedPlacementNames.d.ts +5 -0
- package/dist/transitions/nestedPlacementNames.js +32 -0
- package/dist/transitions/pageVersions.js +3 -1
- package/dist/transitions/phaseRecord.d.ts +2 -0
- package/dist/transitions/phaseRecord.js +5 -0
- package/dist/transitions/placementInteractions.d.ts +3 -3
- package/dist/transitions/placementInteractions.js +15 -11
- package/dist/transitions/placements.d.ts +28 -1
- package/dist/transitions/placements.js +223 -60
- package/dist/transitions/preflightData.d.ts +5 -3
- package/dist/transitions/preflightData.js +126 -37
- package/dist/transitions/releaseHoldout.d.ts +2 -1
- package/dist/transitions/releaseHoldout.js +3 -1
- package/dist/transitions/releasePages.d.ts +2 -1
- package/dist/transitions/releasePages.js +3 -1
- package/dist/transitions/resolveCaps.d.ts +2 -4
- package/dist/transitions/start.d.ts +6 -8
- package/dist/transitions/start.js +70 -34
- package/dist/transitions/startReads.d.ts +7 -0
- package/dist/transitions/startReads.js +28 -0
- package/dist/transitions/stop.d.ts +2 -1
- package/dist/transitions/stop.js +3 -2
- package/dist/types/contracts.d.ts +6 -3
- package/dist/types/endpoints.d.ts +86 -9
- package/dist/types/endpoints.js +1 -1
- package/dist/types/runtime.d.ts +15 -9
- package/dist/types/snapshot.d.ts +2 -0
- package/dist/types/surface.d.ts +2 -0
- package/dist/ui/Button.js +2 -2
- package/dist/ui/ChipsInput.d.ts +8 -1
- package/dist/ui/ChipsInput.js +17 -4
- package/dist/ui/Inputs.d.ts +4 -3
- package/dist/ui/Inputs.js +9 -9
- package/dist/ui/SelectControl.d.ts +33 -0
- package/dist/ui/SelectControl.js +504 -0
- package/dist/ui/ui.css +13 -5
- package/package.json +3 -2
|
@@ -6,6 +6,7 @@ import { EDITABLE_BY_STATUS, isEditable } from '../../../collections/experiments
|
|
|
6
6
|
import { coerceParam, paramIssue, paramsForArm, setParam } from '../../arms/params.model.js';
|
|
7
7
|
import { SETTING_COPY } from '../../copy/setting.js';
|
|
8
8
|
import { lockedReason } from '../../lockedNotice.model.js';
|
|
9
|
+
import { SavedValueChanged, useDraftAnnouncement, useFieldDraft } from '../test/fields.js';
|
|
9
10
|
import { bindSetting, displayParam, paramCheckMessage, paramControl } from './setting.model.js';
|
|
10
11
|
import './setting.css';
|
|
11
12
|
function Binding({ test, surface }) {
|
|
@@ -69,40 +70,47 @@ function Binding({ test, surface }) {
|
|
|
69
70
|
}
|
|
70
71
|
function Parameter({ test, surface, armIndex, paramKey, field }) {
|
|
71
72
|
const id = useId();
|
|
72
|
-
// Only the edited scalar stays local; the complete group is rebuilt on commit.
|
|
73
|
-
const [draft, setDraft] = useState(null);
|
|
74
73
|
const [touched, setTouched] = useState(false);
|
|
75
74
|
const doc = test.doc;
|
|
76
75
|
const arm = doc?.arms[armIndex];
|
|
76
|
+
const point = surface.flagPoints.find((point)=>point.id === doc?.flagPoint);
|
|
77
|
+
const persisted = arm && paramsForArm(arm, point)[paramKey];
|
|
78
|
+
const saved = typeof persisted === 'string' || typeof persisted === 'number' ? String(persisted) : '';
|
|
79
|
+
// Only the edited scalar stays local; the complete group is rebuilt on commit.
|
|
80
|
+
const draft = useFieldDraft(test, `params:${doc?.flagPoint}:${arm?.key}:${paramKey}`, field.label, saved);
|
|
81
|
+
const [announcement, announce] = useDraftAnnouncement();
|
|
77
82
|
if (!doc || !arm) return null;
|
|
78
|
-
const
|
|
79
|
-
const value = draft ? draft.value : paramsForArm(arm, point)[paramKey];
|
|
83
|
+
const value = draft.dirty ? draft.value : persisted;
|
|
80
84
|
const path = `arms.${armIndex}.params.${paramKey}`;
|
|
81
85
|
const editable = surface.canManage && isEditable(doc.status, 'arms');
|
|
82
86
|
const reason = lockedReason(doc.status, 'arms', EDITABLE_BY_STATUS);
|
|
83
87
|
const failed = test.preflight?.checks.find((check)=>check.code === 'flag-params-invalid' && !check.ok);
|
|
84
88
|
const error = test.errors[path] ?? test.errors[`arms.${armIndex}.params`];
|
|
85
89
|
const preflightIssue = paramCheckMessage(failed?.detail, arm.key, paramKey, field);
|
|
86
|
-
const issue = error ?? (touched || preflightIssue ? paramIssue(field, draft ? coerceParam(field, value) : value) : null) ?? preflightIssue;
|
|
90
|
+
const issue = error ?? (touched || preflightIssue ? paramIssue(field, draft.dirty ? coerceParam(field, value) : value) : null) ?? preflightIssue;
|
|
87
91
|
const save = (next)=>{
|
|
88
92
|
const current = test.doc;
|
|
89
93
|
const currentArm = current?.arms[armIndex];
|
|
90
|
-
if (!current || currentArm?.kind !== 'variant' || currentArm.key !== arm.key || !surface.canManage || !isEditable(current.status, 'arms') || current.flagPoint !== point?.id) return;
|
|
94
|
+
if (!current || currentArm?.kind !== 'variant' || currentArm.key !== arm.key || !surface.canManage || !isEditable(current.status, 'arms') || current.flagPoint !== point?.id) return false;
|
|
91
95
|
setTouched(true);
|
|
92
96
|
const arms = current.arms.map((item, index)=>index === armIndex ? {
|
|
93
97
|
...item,
|
|
94
98
|
params: setParam(paramsForArm(item, point), paramKey, field, next)
|
|
95
99
|
} : item);
|
|
96
|
-
test.stage({
|
|
100
|
+
if (!test.stage({
|
|
97
101
|
arms
|
|
98
|
-
});
|
|
102
|
+
})) return false;
|
|
99
103
|
void test.commit();
|
|
104
|
+
return true;
|
|
100
105
|
};
|
|
101
|
-
const
|
|
102
|
-
if (draft)
|
|
103
|
-
|
|
104
|
-
|
|
106
|
+
const commit = (confirmed = false)=>{
|
|
107
|
+
if (!draft.dirty || draft.saving) return;
|
|
108
|
+
if (!editable || test.stale || (draft.conflict || draft.retry) && !confirmed) {
|
|
109
|
+
announce();
|
|
110
|
+
return;
|
|
105
111
|
}
|
|
112
|
+
if (draft.value === saved) draft.discard();
|
|
113
|
+
else draft.submit(()=>save(draft.value));
|
|
106
114
|
};
|
|
107
115
|
const control = paramControl(field);
|
|
108
116
|
const shared = {
|
|
@@ -116,17 +124,37 @@ function Parameter({ test, surface, armIndex, paramKey, field }) {
|
|
|
116
124
|
children: issue
|
|
117
125
|
}) : null;
|
|
118
126
|
const editDraft = (value)=>{
|
|
127
|
+
if (!editable || test.stale || draft.saving) return;
|
|
119
128
|
setTouched(true);
|
|
120
|
-
|
|
121
|
-
value
|
|
122
|
-
});
|
|
129
|
+
draft.change(value);
|
|
123
130
|
};
|
|
124
131
|
const text = typeof value === 'string' ? value : '';
|
|
132
|
+
const readOnly = !editable || test.stale || draft.saving;
|
|
133
|
+
const conflictId = draft.dirty && !draft.saving && (draft.conflict || draft.retry || !editable) ? `${id}-new-value` : undefined;
|
|
134
|
+
const draftInput = {
|
|
135
|
+
readOnly,
|
|
136
|
+
'aria-describedby': conflictId
|
|
137
|
+
};
|
|
125
138
|
return /*#__PURE__*/ _jsxs("div", {
|
|
126
139
|
className: "xp-setting-parameter",
|
|
127
|
-
onBlur:
|
|
140
|
+
onBlur: (event)=>{
|
|
141
|
+
if (event.target.matches('input, textarea')) commit();
|
|
142
|
+
},
|
|
143
|
+
onKeyDown: (event)=>{
|
|
144
|
+
if (event.key === 'Enter' && !event.nativeEvent.isComposing && (conflictId || event.target.matches('input[type="text"], input[type="number"]'))) {
|
|
145
|
+
if (event.target.matches('input, textarea')) {
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
commit();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (event.key === 'Escape' && draft.dirty && !draft.saving) {
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
event.stopPropagation();
|
|
153
|
+
draft.discard();
|
|
154
|
+
}
|
|
155
|
+
},
|
|
128
156
|
children: [
|
|
129
|
-
arm.kind === 'control' || !editable ? /*#__PURE__*/ _jsxs("div", {
|
|
157
|
+
arm.kind === 'control' || !editable && !draft.dirty ? /*#__PURE__*/ _jsxs("div", {
|
|
130
158
|
title: reason ?? undefined,
|
|
131
159
|
children: [
|
|
132
160
|
/*#__PURE__*/ _jsx("span", {
|
|
@@ -190,6 +218,7 @@ function Parameter({ test, surface, armIndex, paramKey, field }) {
|
|
|
190
218
|
}, option.value))
|
|
191
219
|
]
|
|
192
220
|
}) : control === 'number' ? /*#__PURE__*/ _jsx(NumberInput, {
|
|
221
|
+
...draftInput,
|
|
193
222
|
id: id,
|
|
194
223
|
label: field.label,
|
|
195
224
|
min: field.min,
|
|
@@ -201,15 +230,26 @@ function Parameter({ test, surface, armIndex, paramKey, field }) {
|
|
|
201
230
|
onChange: (event)=>editDraft(event.target.value)
|
|
202
231
|
}) : control === 'textarea' ? /*#__PURE__*/ _jsx(Textarea, {
|
|
203
232
|
...shared,
|
|
233
|
+
...draftInput,
|
|
204
234
|
error: issue ?? undefined,
|
|
205
235
|
value: text,
|
|
206
236
|
onChange: (event)=>editDraft(event.target.value)
|
|
207
237
|
}) : /*#__PURE__*/ _jsx(TextInput, {
|
|
208
238
|
...shared,
|
|
239
|
+
...draftInput,
|
|
209
240
|
error: issue ?? undefined,
|
|
210
241
|
value: text,
|
|
211
242
|
onChange: (event)=>editDraft(event.target.value)
|
|
212
243
|
}),
|
|
244
|
+
conflictId ? /*#__PURE__*/ _jsx(SavedValueChanged, {
|
|
245
|
+
id: conflictId,
|
|
246
|
+
value: saved,
|
|
247
|
+
reason: reason,
|
|
248
|
+
conflict: draft.conflict,
|
|
249
|
+
announce: announcement,
|
|
250
|
+
onKeep: editable && !test.stale ? ()=>commit(true) : undefined,
|
|
251
|
+
onDiscard: draft.discard
|
|
252
|
+
}) : null,
|
|
213
253
|
arm.kind === 'control' || !editable || control === 'segmented' ? inlineError : null
|
|
214
254
|
]
|
|
215
255
|
});
|
|
@@ -240,7 +280,7 @@ function VersionContent({ test, surface, armIndex }) {
|
|
|
240
280
|
armIndex: armIndex,
|
|
241
281
|
paramKey: key,
|
|
242
282
|
field: field
|
|
243
|
-
}, `${doc.id}:${point.id}:${arm.key}:${key}
|
|
283
|
+
}, `${doc.id}:${point.id}:${arm.key}:${key}`))
|
|
244
284
|
]
|
|
245
285
|
});
|
|
246
286
|
}
|
|
@@ -129,6 +129,7 @@ export function AdvancedSection({ test, surface }) {
|
|
|
129
129
|
numbers.map(([field, fallback, min])=>/*#__PURE__*/ _jsxs("div", {
|
|
130
130
|
children: [
|
|
131
131
|
/*#__PURE__*/ _jsx(TextEdit, {
|
|
132
|
+
test: test,
|
|
132
133
|
label: C[field].label,
|
|
133
134
|
value: doc.analysis?.[field] ?? fallback,
|
|
134
135
|
placeholder: field === 'attributionWindowHours' ? C.inheritedWindow : field === 'sequentialTuningParameter' ? C.automaticTuning : undefined,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DocId, ExperimentKind } from '../../../types/contracts.js';
|
|
2
|
+
export type DeleteOutcome = 'done' | 'already';
|
|
3
|
+
export declare const DELETE_IMPACT_TIMEOUT_MS = 15000;
|
|
4
|
+
/** Matches deleteExperiment's status guard; the server rechecks under its lock. */
|
|
5
|
+
export declare function DeleteTest({ test, canManage, apiRoute, contentLocale, onDeleted, onStatusChanged, onDialogChange }: {
|
|
6
|
+
test: {
|
|
7
|
+
id: DocId;
|
|
8
|
+
name: string;
|
|
9
|
+
status: string;
|
|
10
|
+
kind?: ExperimentKind;
|
|
11
|
+
updatedAt?: unknown;
|
|
12
|
+
};
|
|
13
|
+
canManage: boolean;
|
|
14
|
+
apiRoute: string;
|
|
15
|
+
contentLocale?: string;
|
|
16
|
+
onDeleted: (outcome: DeleteOutcome) => void;
|
|
17
|
+
onStatusChanged: () => void;
|
|
18
|
+
onDialogChange?: (open: boolean) => void;
|
|
19
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { placementLanguageSuffix } from '../../copy/languages.js';
|
|
4
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { createApi } from '../../api.js';
|
|
6
|
+
import { API_MESSAGES } from '../../copy/common.js';
|
|
7
|
+
import { DELETE_TEST as C, deleteStatusCopy } from '../../copy/testPage.js';
|
|
8
|
+
import { useOnTestReturn } from '../../useOnTestReturn.js';
|
|
9
|
+
import { Button } from '../../../ui/Button.js';
|
|
10
|
+
import { Dialog } from '../../../ui/Dialog.js';
|
|
11
|
+
const VISIBLE_PAGES = 5;
|
|
12
|
+
export const DELETE_IMPACT_TIMEOUT_MS = 15_000;
|
|
13
|
+
/** Matches deleteExperiment's status guard; the server rechecks under its lock. */ export function DeleteTest({ test, canManage, apiRoute, contentLocale, onDeleted, onStatusChanged, onDialogChange }) {
|
|
14
|
+
const [open, setOpen] = useState(false);
|
|
15
|
+
const [busy, setBusy] = useState(false);
|
|
16
|
+
const pending = useRef(false);
|
|
17
|
+
const actions = useRef(null);
|
|
18
|
+
const [error, setError] = useState();
|
|
19
|
+
const [checked, setChecked] = useState();
|
|
20
|
+
const [refusal, setRefusal] = useState();
|
|
21
|
+
const [checkAttempt, setCheckAttempt] = useState(0);
|
|
22
|
+
const checkKey = JSON.stringify([
|
|
23
|
+
test.id,
|
|
24
|
+
apiRoute,
|
|
25
|
+
contentLocale,
|
|
26
|
+
test.status,
|
|
27
|
+
typeof test.updatedAt === 'string' ? test.updatedAt : null,
|
|
28
|
+
checkAttempt
|
|
29
|
+
]);
|
|
30
|
+
const impact = refusal ?? (checked?.key === checkKey ? checked.impact : {
|
|
31
|
+
state: 'loading'
|
|
32
|
+
});
|
|
33
|
+
const deletable = test.status === 'draft' || test.status === 'archived';
|
|
34
|
+
const statusMessage = deletable ? undefined : deleteStatusCopy(test.status, test.kind);
|
|
35
|
+
const blocked = !canManage ? API_MESSAGES.forbidden : impact.state === 'blocked' ? impact.reason === 'invalid-status' ? statusMessage ?? impact.message : impact.message : statusMessage;
|
|
36
|
+
useOnTestReturn(useCallback(()=>{
|
|
37
|
+
if (!pending.current) setCheckAttempt((value)=>value + 1);
|
|
38
|
+
}, []), open && !blocked);
|
|
39
|
+
useEffect(()=>{
|
|
40
|
+
if (open && blocked && !busy) actions.current?.querySelector('[data-dialog-cancel]')?.focus();
|
|
41
|
+
}, [
|
|
42
|
+
open,
|
|
43
|
+
blocked,
|
|
44
|
+
busy
|
|
45
|
+
]);
|
|
46
|
+
useEffect(()=>{
|
|
47
|
+
if (!open || !deletable || !canManage || refusal) return;
|
|
48
|
+
let current = true;
|
|
49
|
+
const controller = new AbortController();
|
|
50
|
+
const record = (impact)=>setChecked({
|
|
51
|
+
key: checkKey,
|
|
52
|
+
impact
|
|
53
|
+
});
|
|
54
|
+
const timer = setTimeout(()=>{
|
|
55
|
+
if (!current) return;
|
|
56
|
+
current = false;
|
|
57
|
+
controller.abort();
|
|
58
|
+
record({
|
|
59
|
+
state: 'failed'
|
|
60
|
+
});
|
|
61
|
+
}, DELETE_IMPACT_TIMEOUT_MS);
|
|
62
|
+
void createApi(apiRoute, contentLocale).deleteImpact(test.id, controller.signal).then((result)=>{
|
|
63
|
+
if (!current) return;
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
if (result.ok) {
|
|
66
|
+
record(readableImpact(result.data) ? {
|
|
67
|
+
state: 'ready',
|
|
68
|
+
data: result.data
|
|
69
|
+
} : {
|
|
70
|
+
state: 'blocked',
|
|
71
|
+
message: API_MESSAGES.unreadable
|
|
72
|
+
});
|
|
73
|
+
} else if (result.status === 0 || result.status >= 500) record({
|
|
74
|
+
state: 'failed'
|
|
75
|
+
});
|
|
76
|
+
else if (result.status === 404) setRefusal({
|
|
77
|
+
state: 'blocked',
|
|
78
|
+
message: C.alreadyDeleted,
|
|
79
|
+
reason: 'already-deleted'
|
|
80
|
+
});
|
|
81
|
+
else if (result.status === 409 && result.code === 'invalid-status') {
|
|
82
|
+
setRefusal({
|
|
83
|
+
state: 'blocked',
|
|
84
|
+
message: result.message,
|
|
85
|
+
reason: 'invalid-status',
|
|
86
|
+
refusedStatus: test.status
|
|
87
|
+
});
|
|
88
|
+
} else setRefusal({
|
|
89
|
+
state: 'blocked',
|
|
90
|
+
message: result.message
|
|
91
|
+
});
|
|
92
|
+
if (!result.ok && !onDialogChange && [
|
|
93
|
+
401,
|
|
94
|
+
403,
|
|
95
|
+
404,
|
|
96
|
+
409
|
|
97
|
+
].includes(result.status)) onStatusChanged();
|
|
98
|
+
});
|
|
99
|
+
return ()=>{
|
|
100
|
+
current = false;
|
|
101
|
+
clearTimeout(timer);
|
|
102
|
+
controller.abort();
|
|
103
|
+
};
|
|
104
|
+
}, [
|
|
105
|
+
open,
|
|
106
|
+
deletable,
|
|
107
|
+
canManage,
|
|
108
|
+
refusal,
|
|
109
|
+
checkKey,
|
|
110
|
+
test.id,
|
|
111
|
+
apiRoute,
|
|
112
|
+
contentLocale
|
|
113
|
+
]);
|
|
114
|
+
if (!open && (!canManage || !deletable)) return null;
|
|
115
|
+
const checking = impact.state === 'loading';
|
|
116
|
+
function showDialog() {
|
|
117
|
+
setError(undefined);
|
|
118
|
+
setChecked(undefined);
|
|
119
|
+
setRefusal(undefined);
|
|
120
|
+
setOpen(true);
|
|
121
|
+
onDialogChange?.(true);
|
|
122
|
+
}
|
|
123
|
+
function close() {
|
|
124
|
+
setOpen(false);
|
|
125
|
+
onDialogChange?.(false);
|
|
126
|
+
// Keep the refusal visible until dismissed. Reloading can move the row to another group.
|
|
127
|
+
if (impact.state === 'blocked' && impact.reason === 'already-deleted') onDeleted('already');
|
|
128
|
+
if (onDialogChange && impact.state === 'blocked' && impact.reason === 'invalid-status') onStatusChanged();
|
|
129
|
+
}
|
|
130
|
+
async function remove() {
|
|
131
|
+
if (blocked || checking || pending.current) return;
|
|
132
|
+
pending.current = true;
|
|
133
|
+
setBusy(true);
|
|
134
|
+
setError(undefined);
|
|
135
|
+
const result = await createApi(apiRoute).deleteTest(test.id);
|
|
136
|
+
if (result.ok || result.status === 404) {
|
|
137
|
+
setOpen(false);
|
|
138
|
+
onDialogChange?.(false);
|
|
139
|
+
onDeleted(result.ok ? 'done' : 'already');
|
|
140
|
+
} else if (result.status === 409 && result.code === 'invalid-status') {
|
|
141
|
+
setRefusal({
|
|
142
|
+
state: 'blocked',
|
|
143
|
+
message: result.message,
|
|
144
|
+
reason: 'invalid-status',
|
|
145
|
+
refusedStatus: test.status
|
|
146
|
+
});
|
|
147
|
+
if (!onDialogChange) onStatusChanged();
|
|
148
|
+
} else if (result.status === 401 || result.status === 403) {
|
|
149
|
+
setRefusal({
|
|
150
|
+
state: 'blocked',
|
|
151
|
+
message: result.message
|
|
152
|
+
});
|
|
153
|
+
onStatusChanged();
|
|
154
|
+
} else {
|
|
155
|
+
setError(result.message);
|
|
156
|
+
if (result.status === 409) onStatusChanged();
|
|
157
|
+
}
|
|
158
|
+
pending.current = false;
|
|
159
|
+
setBusy(false);
|
|
160
|
+
}
|
|
161
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
162
|
+
children: [
|
|
163
|
+
canManage && deletable && (refusal?.reason !== 'invalid-status' || refusal.refusedStatus !== test.status) ? /*#__PURE__*/ _jsx(Button, {
|
|
164
|
+
variant: "quiet",
|
|
165
|
+
size: "sm",
|
|
166
|
+
onClick: showDialog,
|
|
167
|
+
children: C.action
|
|
168
|
+
}) : null,
|
|
169
|
+
/*#__PURE__*/ _jsxs(Dialog, {
|
|
170
|
+
open: open,
|
|
171
|
+
title: C.title(test.name),
|
|
172
|
+
initialFocus: "cancel",
|
|
173
|
+
dismissible: !busy,
|
|
174
|
+
onClose: close,
|
|
175
|
+
children: [
|
|
176
|
+
blocked ? /*#__PURE__*/ _jsx("p", {
|
|
177
|
+
role: "alert",
|
|
178
|
+
children: blocked
|
|
179
|
+
}) : /*#__PURE__*/ _jsxs(_Fragment, {
|
|
180
|
+
children: [
|
|
181
|
+
/*#__PURE__*/ _jsx("p", {
|
|
182
|
+
children: C.consequences
|
|
183
|
+
}),
|
|
184
|
+
/*#__PURE__*/ _jsx("p", {
|
|
185
|
+
children: C.content
|
|
186
|
+
}),
|
|
187
|
+
/*#__PURE__*/ _jsx("p", {
|
|
188
|
+
role: "status",
|
|
189
|
+
"aria-atomic": "true",
|
|
190
|
+
children: checking ? C.checking : impact.state === 'failed' ? C.checkFailed : impact.state === 'ready' ? impactSummary(impact.data) : ''
|
|
191
|
+
}),
|
|
192
|
+
impact.state === 'ready' ? /*#__PURE__*/ _jsx(ImpactDetails, {
|
|
193
|
+
impact: impact.data
|
|
194
|
+
}) : null,
|
|
195
|
+
error ? /*#__PURE__*/ _jsx("p", {
|
|
196
|
+
role: "alert",
|
|
197
|
+
children: error
|
|
198
|
+
}) : null
|
|
199
|
+
]
|
|
200
|
+
}),
|
|
201
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
202
|
+
ref: actions,
|
|
203
|
+
className: "xp-ui-button-group",
|
|
204
|
+
children: [
|
|
205
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
206
|
+
"data-dialog-cancel": true,
|
|
207
|
+
disabled: busy,
|
|
208
|
+
onClick: close,
|
|
209
|
+
children: blocked ? C.close : C.cancel
|
|
210
|
+
}),
|
|
211
|
+
!blocked ? /*#__PURE__*/ _jsx(Button, {
|
|
212
|
+
variant: "danger",
|
|
213
|
+
disabled: checking,
|
|
214
|
+
"aria-disabled": busy || checking || undefined,
|
|
215
|
+
"aria-busy": busy || undefined,
|
|
216
|
+
onClick: ()=>void remove(),
|
|
217
|
+
children: C.action
|
|
218
|
+
}) : null
|
|
219
|
+
]
|
|
220
|
+
})
|
|
221
|
+
]
|
|
222
|
+
})
|
|
223
|
+
]
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
function readableImpact(impact) {
|
|
227
|
+
if (impact?.effect === 'none') return true;
|
|
228
|
+
if (impact?.effect === 'page') return typeof impact.winnerPath === 'string' && Array.isArray(impact.addresses) && impact.addresses.every((path)=>typeof path === 'string') && (impact.afterPaths === undefined || impact.afterPaths !== null && typeof impact.afterPaths === 'object' && Object.values(impact.afterPaths).every((path)=>typeof path === 'string'));
|
|
229
|
+
return impact?.effect === 'block' && typeof impact.controlLabel === 'string' && Number.isInteger(impact.pageCount) && Number.isInteger(impact.unreadablePages) && Array.isArray(impact.placements) && impact.placements.every((place)=>typeof place?.title === 'string' && typeof place.before?.label === 'string' && typeof place.after?.label === 'string' && (place.path === null || typeof place.path === 'string') && (place.locales === undefined || Array.isArray(place.locales) && place.locales.every((locale)=>typeof locale === 'string')));
|
|
230
|
+
}
|
|
231
|
+
function impactSummary(impact) {
|
|
232
|
+
return impact.effect === 'none' ? C.noEffect : C.changedPages(impact.effect === 'block' ? impact.pageCount : impact.addresses.length);
|
|
233
|
+
}
|
|
234
|
+
function ImpactDetails({ impact }) {
|
|
235
|
+
if (impact.effect === 'none') return null;
|
|
236
|
+
const places = impact.effect === 'block' ? impact.placements.map((place)=>`${place.title}${place.path ? ` (${place.path})` : ''}${placementLanguageSuffix(place)}: ${C.versionChange(place.before.label, place.after.label)}`) : impact.addresses.map((path)=>`${path}: ${C.versionChange(impact.winnerPath, impact.afterPaths?.[path] ?? path)}`);
|
|
237
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
238
|
+
children: [
|
|
239
|
+
places.length ? /*#__PURE__*/ _jsxs(_Fragment, {
|
|
240
|
+
children: [
|
|
241
|
+
/*#__PURE__*/ _jsx("p", {
|
|
242
|
+
children: impact.effect === 'block' ? C.blockWinner(impact.controlLabel) : C.pageWinner
|
|
243
|
+
}),
|
|
244
|
+
/*#__PURE__*/ _jsx("p", {
|
|
245
|
+
children: C.currentSite
|
|
246
|
+
})
|
|
247
|
+
]
|
|
248
|
+
}) : null,
|
|
249
|
+
places.length ? /*#__PURE__*/ _jsx("ul", {
|
|
250
|
+
children: places.slice(0, VISIBLE_PAGES).map((place, index)=>/*#__PURE__*/ _jsx("li", {
|
|
251
|
+
children: place
|
|
252
|
+
}, index))
|
|
253
|
+
}) : null,
|
|
254
|
+
places.length > VISIBLE_PAGES ? /*#__PURE__*/ _jsx("p", {
|
|
255
|
+
children: C.morePages(places.length - VISIBLE_PAGES)
|
|
256
|
+
}) : null,
|
|
257
|
+
impact.effect === 'block' && impact.unreadablePages > 0 ? /*#__PURE__*/ _jsx("p", {
|
|
258
|
+
children: C.unreadablePages(impact.unreadablePages, impact.pageCount)
|
|
259
|
+
}) : null
|
|
260
|
+
]
|
|
261
|
+
});
|
|
262
|
+
}
|
|
@@ -7,8 +7,8 @@ import { Button } from '../../../ui/Button.js';
|
|
|
7
7
|
import { useEffect, useMemo, useState } from 'react';
|
|
8
8
|
import { surfaceUrls } from '../../surfaceUrls.js';
|
|
9
9
|
import { TEST_PAGE as C } from '../../copy/testPage.js';
|
|
10
|
-
import { METRIC_KIND_LABELS } from '../../copy/metrics.js';
|
|
11
|
-
import { isClickSource } from '../../../goals/key.js';
|
|
10
|
+
import { METRICS_COPY, METRIC_KIND_LABELS } from '../../copy/metrics.js';
|
|
11
|
+
import { isClickSource, validClickSource } from '../../../goals/key.js';
|
|
12
12
|
import { createApi } from '../../api.js';
|
|
13
13
|
import { sourceFor } from '../../metricSource.model.js';
|
|
14
14
|
import { reviewView } from '../../review/review.model.js';
|
|
@@ -209,7 +209,8 @@ export function GoalSection({ test, surface, embedded = false }) {
|
|
|
209
209
|
});
|
|
210
210
|
const display = (ids)=>ids.length ? ids.map((id)=>options.find((option)=>option.value === String(id))?.label ?? unknownGoal).join(', ') : C.noGoal;
|
|
211
211
|
const primary = metrics.find((metric)=>String(metric.id) === String(doc.metrics?.primary));
|
|
212
|
-
const
|
|
212
|
+
const primarySource = sourceFor(primary?.source, surface.metricSources);
|
|
213
|
+
const kind = primarySource?.kind;
|
|
213
214
|
const baseline = test.preflight?.baseline && String(test.preflight.baseline.metricId) === String(doc.metrics?.primary) ? reviewView(test.preflight, {
|
|
214
215
|
primaryMetricKind: kind
|
|
215
216
|
}).baseline : null;
|
|
@@ -266,6 +267,9 @@ export function GoalSection({ test, surface, embedded = false }) {
|
|
|
266
267
|
primary && isClickSource(primary.source) ? /*#__PURE__*/ _jsx("p", {
|
|
267
268
|
children: C.clickGoalHelp
|
|
268
269
|
}) : null,
|
|
270
|
+
validClickSource(primary?.source) || primarySource?.clientWritable && primarySource.kind !== 'revenue' ? /*#__PURE__*/ _jsx("p", {
|
|
271
|
+
children: METRICS_COPY.browserWritablePrimary
|
|
272
|
+
}) : null,
|
|
269
273
|
baseline ? /*#__PURE__*/ _jsxs("p", {
|
|
270
274
|
children: [
|
|
271
275
|
primary?.name ? `${primary.name}: ` : '',
|
|
@@ -30,6 +30,8 @@ export function LengthSection({ test, surface }) {
|
|
|
30
30
|
/*#__PURE__*/ _jsxs("div", {
|
|
31
31
|
children: [
|
|
32
32
|
/*#__PURE__*/ _jsx(TextEdit, {
|
|
33
|
+
test: test,
|
|
34
|
+
draftKey: "analysis.reachPerDay",
|
|
33
35
|
label: required ? `${C.reach} ${C.required}` : C.reach,
|
|
34
36
|
value: doc.analysis?.reachPerDay ?? '',
|
|
35
37
|
type: "number",
|
|
@@ -51,6 +53,7 @@ export function LengthSection({ test, surface }) {
|
|
|
51
53
|
/*#__PURE__*/ _jsxs("div", {
|
|
52
54
|
children: [
|
|
53
55
|
/*#__PURE__*/ _jsx(TextEdit, {
|
|
56
|
+
test: test,
|
|
54
57
|
label: C.duration,
|
|
55
58
|
value: doc.analysis?.plannedDurationDays ?? 28,
|
|
56
59
|
type: "number",
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
import { TEST_PAGE as C } from '../../copy/testPage.js';
|
|
4
4
|
import { ARMS_COPY } from '../../copy/arms.js';
|
|
5
5
|
import { addHoldoutArm, removeArm, splitEvenly } from '../../arms/arms.model.js';
|
|
6
|
-
import { balanceWeight } from './testPage.model.js';
|
|
6
|
+
import { balanceWeight, trafficSplit } from './testPage.model.js';
|
|
7
7
|
import { FieldErrors, reasonFor, save, TextEdit } from './fields.js';
|
|
8
8
|
import { Button } from '../../../ui/Button.js';
|
|
9
9
|
/** Whole-page holdouts have no page of their own; their controls live under Advanced. */ export function PageHoldout({ test }) {
|
|
@@ -16,6 +16,7 @@ import { Button } from '../../../ui/Button.js';
|
|
|
16
16
|
arm ? /*#__PURE__*/ _jsxs(_Fragment, {
|
|
17
17
|
children: [
|
|
18
18
|
/*#__PURE__*/ _jsx(TextEdit, {
|
|
19
|
+
test: test,
|
|
19
20
|
label: `${C.holdoutPrefix}${C.label}`,
|
|
20
21
|
value: arm.label,
|
|
21
22
|
reason: reason,
|
|
@@ -27,8 +28,10 @@ import { Button } from '../../../ui/Button.js';
|
|
|
27
28
|
}))
|
|
28
29
|
}),
|
|
29
30
|
/*#__PURE__*/ _jsx(TextEdit, {
|
|
31
|
+
test: test,
|
|
30
32
|
label: `${C.holdoutPrefix}${C.weight}`,
|
|
31
33
|
type: "number",
|
|
34
|
+
scope: trafficSplit(doc.arms),
|
|
32
35
|
min: 0,
|
|
33
36
|
max: 100,
|
|
34
37
|
value: arm.weight,
|
|
@@ -27,6 +27,6 @@ import { ReadinessContent } from '../readiness/Banner.js';
|
|
|
27
27
|
"aria-label": C.label,
|
|
28
28
|
children: props.test.doc ? /*#__PURE__*/ _jsx(ReadinessContent, {
|
|
29
29
|
...props
|
|
30
|
-
}, `${props.test.doc.id}/${props.test.doc.status}`) : null
|
|
30
|
+
}, `${props.test.doc.id}/${props.test.doc.status}/${props.test.doc.phase}`) : null
|
|
31
31
|
});
|
|
32
32
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { Button } from '../../../ui/Button.js';
|
|
4
4
|
import { useId, useState } from 'react';
|
|
5
5
|
import { ChipsInput } from '../../../ui/ChipsInput.js';
|
|
6
6
|
import { AUDIENCE_COPY } from '../../copy/audience.js';
|
|
7
7
|
import { coerceValue, emptyListHint, humaniseAttribute, opLabel, opsFor, readListValue, readTargetingRules, valueInput } from '../../targeting/targeting.model.js';
|
|
8
8
|
import { TEST_PAGE as C, NUMBER_COMPARISONS } from '../../copy/testPage.js';
|
|
9
|
-
import { CheckboxList, FieldErrors, reasonFor, save, SelectEdit, TextEdit } from './fields.js';
|
|
9
|
+
import { CheckboxList, FieldErrors, reasonFor, save, SavedValueChanged, SelectEdit, TextEdit, useDraftAnnouncement, useFieldDraft } from './fields.js';
|
|
10
10
|
import { Section } from './Section.js';
|
|
11
11
|
export function TargetingSection({ test, surface }) {
|
|
12
12
|
const id = useId();
|
|
@@ -59,12 +59,20 @@ export function TargetingSection({ test, surface }) {
|
|
|
59
59
|
...partial
|
|
60
60
|
} : row));
|
|
61
61
|
const hint = emptyListHint(rule.op, rule.value);
|
|
62
|
+
const draftKey = JSON.stringify([
|
|
63
|
+
'targeting',
|
|
64
|
+
rowsRevision,
|
|
65
|
+
index,
|
|
66
|
+
rule.attribute,
|
|
67
|
+
rule.op,
|
|
68
|
+
rules.length
|
|
69
|
+
]);
|
|
62
70
|
const changeValue = (raw)=>{
|
|
63
71
|
const current = test.doc.targeting?.[index];
|
|
64
72
|
const schema = current && surface.attributeKeys[current.attribute];
|
|
65
|
-
if (!current || !schema) return;
|
|
73
|
+
if (!current || !schema) return false;
|
|
66
74
|
const value = coerceValue(schema.type, current.op, raw);
|
|
67
|
-
|
|
75
|
+
return value !== null && setRule({
|
|
68
76
|
value
|
|
69
77
|
});
|
|
70
78
|
};
|
|
@@ -125,15 +133,15 @@ export function TargetingSection({ test, surface }) {
|
|
|
125
133
|
])
|
|
126
134
|
] : values.filter((saved)=>saved !== value));
|
|
127
135
|
}
|
|
128
|
-
}) : input.kind === 'chips' ? /*#__PURE__*/ _jsx(
|
|
136
|
+
}) : input.kind === 'chips' ? /*#__PURE__*/ _jsx(TargetingChips, {
|
|
137
|
+
draftKey: draftKey,
|
|
138
|
+
test: test,
|
|
129
139
|
id: `${id}-${index}-value`,
|
|
130
|
-
label: C.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
onChange: changeValue
|
|
136
|
-
}, `${rule.attribute}-${rule.op}`) : input.kind === 'select' ? /*#__PURE__*/ _jsx(SelectEdit, {
|
|
140
|
+
label: C.targetingValue(humaniseAttribute(rule.attribute)),
|
|
141
|
+
values: readListValue(rule.value),
|
|
142
|
+
reason: reason,
|
|
143
|
+
onCommit: changeValue
|
|
144
|
+
}, draftKey) : input.kind === 'select' ? /*#__PURE__*/ _jsx(SelectEdit, {
|
|
137
145
|
label: C.value,
|
|
138
146
|
reason: reason,
|
|
139
147
|
value: String(rule.value),
|
|
@@ -155,6 +163,8 @@ export function TargetingSection({ test, surface }) {
|
|
|
155
163
|
],
|
|
156
164
|
onCommit: changeValue
|
|
157
165
|
}) : /*#__PURE__*/ _jsx(TextEdit, {
|
|
166
|
+
test: test,
|
|
167
|
+
draftKey: draftKey,
|
|
158
168
|
label: C.value,
|
|
159
169
|
reason: reason,
|
|
160
170
|
value: Array.isArray(rule.value) ? rule.value.join(', ') : String(rule.value),
|
|
@@ -210,3 +220,58 @@ export function TargetingSection({ test, surface }) {
|
|
|
210
220
|
]
|
|
211
221
|
});
|
|
212
222
|
}
|
|
223
|
+
function TargetingChips({ test, draftKey, id, label, values, reason, onCommit }) {
|
|
224
|
+
const saved = values.join(', ');
|
|
225
|
+
const draft = useFieldDraft(test, draftKey, label, '', saved);
|
|
226
|
+
const [announcement, announce] = useDraftAnnouncement();
|
|
227
|
+
const choice = draft.dirty && !draft.saving && (draft.conflict || draft.retry || reason);
|
|
228
|
+
const locked = Boolean(reason || test.stale || draft.saving);
|
|
229
|
+
const commit = (text, confirmed = false)=>{
|
|
230
|
+
if (locked || choice && !confirmed) {
|
|
231
|
+
announce();
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const next = [
|
|
235
|
+
...new Set([
|
|
236
|
+
...values,
|
|
237
|
+
...text.split(',').map((value)=>value.trim()).filter(Boolean)
|
|
238
|
+
])
|
|
239
|
+
];
|
|
240
|
+
if (next.length === values.length) {
|
|
241
|
+
draft.discard();
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (text !== draft.value || !draft.dirty) draft.change(text);
|
|
245
|
+
draft.submit(()=>onCommit(next));
|
|
246
|
+
};
|
|
247
|
+
const choiceId = choice ? `${id}-new-value` : undefined;
|
|
248
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
249
|
+
children: [
|
|
250
|
+
/*#__PURE__*/ _jsx(ChipsInput, {
|
|
251
|
+
id: id,
|
|
252
|
+
label: C.value,
|
|
253
|
+
value: values,
|
|
254
|
+
disabled: locked,
|
|
255
|
+
description: reason ?? AUDIENCE_COPY.listDescription,
|
|
256
|
+
placeholder: AUDIENCE_COPY.listPlaceholder,
|
|
257
|
+
onChange: onCommit,
|
|
258
|
+
draft: {
|
|
259
|
+
value: draft.dirty ? draft.value : '',
|
|
260
|
+
change: draft.change,
|
|
261
|
+
submit: commit,
|
|
262
|
+
discard: draft.discard,
|
|
263
|
+
describedBy: choiceId
|
|
264
|
+
}
|
|
265
|
+
}),
|
|
266
|
+
choiceId ? /*#__PURE__*/ _jsx(SavedValueChanged, {
|
|
267
|
+
id: choiceId,
|
|
268
|
+
value: saved,
|
|
269
|
+
reason: reason,
|
|
270
|
+
conflict: draft.conflict,
|
|
271
|
+
announce: announcement,
|
|
272
|
+
onKeep: !locked ? ()=>commit(draft.value, true) : undefined,
|
|
273
|
+
onDiscard: draft.discard
|
|
274
|
+
}) : null
|
|
275
|
+
]
|
|
276
|
+
});
|
|
277
|
+
}
|