@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
|
@@ -1,9 +1,11 @@
|
|
|
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
|
+
import { DeleteTest } from './DeleteTest.js';
|
|
4
|
+
import { surfaceUrls } from '../../surfaceUrls.js';
|
|
3
5
|
import { useEffect, useState, useRef } from 'react';
|
|
4
6
|
import { useTestDocument } from '../useTestDocument.js';
|
|
5
7
|
import { API_MESSAGES } from '../../copy/common.js';
|
|
6
|
-
import { TEST_PAGE as C } from '../../copy/testPage.js';
|
|
8
|
+
import { DELETE_TEST, TEST_PAGE as C } from '../../copy/testPage.js';
|
|
7
9
|
import { pageBlockParts } from '../pageBlock/parts.js';
|
|
8
10
|
import { settingParts } from '../setting/parts.js';
|
|
9
11
|
import { pageParts } from './pageParts.js';
|
|
@@ -28,7 +30,9 @@ export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded
|
|
|
28
30
|
const [barHeight, setBarHeight] = useState();
|
|
29
31
|
const documentState = useTestDocument(id, {
|
|
30
32
|
apiRoute: surface.apiRoute,
|
|
33
|
+
contentLocale: surface.contentLocale,
|
|
31
34
|
refetchPreflightOnFocus: true,
|
|
35
|
+
refetchDocumentOnFocus: true,
|
|
32
36
|
...!surface.canManage ? {
|
|
33
37
|
enabled: false
|
|
34
38
|
} : {},
|
|
@@ -45,27 +49,39 @@ export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded
|
|
|
45
49
|
const [placementRead, setPlacementRead] = useState();
|
|
46
50
|
const placementKey = JSON.stringify([
|
|
47
51
|
surface.apiRoute,
|
|
48
|
-
String(id)
|
|
52
|
+
String(id),
|
|
53
|
+
...surface.contentLocale ? [
|
|
54
|
+
surface.contentLocale
|
|
55
|
+
] : []
|
|
49
56
|
]);
|
|
50
57
|
const watching = embedded && surface.canManage && documentState.loadState === 'ready';
|
|
51
58
|
useEffect(()=>{
|
|
52
59
|
if (!embedded || !surface.canManage) return;
|
|
53
60
|
return subscribePlacements(surface.apiRoute, id, ()=>setPlacementRead({
|
|
54
61
|
key: placementKey,
|
|
55
|
-
preflight: cachedPreflight(surface.apiRoute, id),
|
|
56
|
-
read: cachedReadinessRead(surface.apiRoute, id),
|
|
57
|
-
pending: placementsPending(surface.apiRoute, id),
|
|
58
|
-
blocking: placementsBlocking(surface.apiRoute, id),
|
|
59
|
-
error: placementReadError(surface.apiRoute, id)
|
|
60
|
-
}));
|
|
62
|
+
preflight: cachedPreflight(surface.apiRoute, id, surface.contentLocale),
|
|
63
|
+
read: cachedReadinessRead(surface.apiRoute, id, surface.contentLocale),
|
|
64
|
+
pending: placementsPending(surface.apiRoute, id, surface.contentLocale),
|
|
65
|
+
blocking: placementsBlocking(surface.apiRoute, id, surface.contentLocale),
|
|
66
|
+
error: placementReadError(surface.apiRoute, id, surface.contentLocale)
|
|
67
|
+
}), surface.contentLocale);
|
|
61
68
|
}, [
|
|
62
69
|
surface.apiRoute,
|
|
63
70
|
id,
|
|
64
71
|
embedded,
|
|
65
72
|
surface.canManage,
|
|
66
|
-
placementKey
|
|
73
|
+
placementKey,
|
|
74
|
+
surface.contentLocale
|
|
67
75
|
]);
|
|
68
76
|
const currentRead = documentState.loadState === 'ready' && placementRead?.key === placementKey ? placementRead : undefined;
|
|
77
|
+
const answer = currentRead?.pending ? undefined : currentRead?.read;
|
|
78
|
+
const { syncDocument } = documentState;
|
|
79
|
+
useEffect(()=>{
|
|
80
|
+
syncDocument?.(answer);
|
|
81
|
+
}, [
|
|
82
|
+
answer,
|
|
83
|
+
syncDocument
|
|
84
|
+
]);
|
|
69
85
|
const preflight = currentRead ? currentRead.preflight ?? (currentRead.pending && !currentRead.error ? documentState.preflight : null) : documentState.preflight;
|
|
70
86
|
const sharedDocument = currentRead ? {
|
|
71
87
|
...documentState,
|
|
@@ -88,7 +104,7 @@ export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded
|
|
|
88
104
|
editorPage,
|
|
89
105
|
editorPlacementMessage: message
|
|
90
106
|
};
|
|
91
|
-
usePlacementNotice(surface.apiRoute, id, watching ? sharedDocument.preflightError ?? (placementFailed ? placementReadError(surface.apiRoute, id) : message) : undefined);
|
|
107
|
+
usePlacementNotice(surface.apiRoute, id, watching ? sharedDocument.preflightError ?? (placementFailed ? placementReadError(surface.apiRoute, id, surface.contentLocale) : message) : undefined, surface.contentLocale, watching);
|
|
92
108
|
const setup = documentState.doc?.status === 'draft' || documentState.doc?.status === 'stopped';
|
|
93
109
|
const test = setup ? {
|
|
94
110
|
...sharedDocument,
|
|
@@ -110,6 +126,23 @@ export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded
|
|
|
110
126
|
children
|
|
111
127
|
}) : children;
|
|
112
128
|
};
|
|
129
|
+
const detachedEdits = (test.detachedDrafts ?? []).map((key)=>{
|
|
130
|
+
const draft = test.fieldDrafts?.[key];
|
|
131
|
+
return draft && !draft.saving ? /*#__PURE__*/ _jsxs(Banner, {
|
|
132
|
+
tone: "warning",
|
|
133
|
+
action: /*#__PURE__*/ _jsx(Button, {
|
|
134
|
+
onClick: ()=>test.trackDraft(key, null),
|
|
135
|
+
children: C.discardEdit
|
|
136
|
+
}),
|
|
137
|
+
children: [
|
|
138
|
+
C.detachedEdit(draft.label),
|
|
139
|
+
" ",
|
|
140
|
+
/*#__PURE__*/ _jsx("strong", {
|
|
141
|
+
children: draft.value || C.emptyValue
|
|
142
|
+
})
|
|
143
|
+
]
|
|
144
|
+
}, key) : null;
|
|
145
|
+
});
|
|
113
146
|
// Results readers have no permission to load the manager-only test/preflight.
|
|
114
147
|
if (!surface.canManage) return frame(/*#__PURE__*/ _jsx(ResultsBody, {
|
|
115
148
|
id: id,
|
|
@@ -119,6 +152,20 @@ export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded
|
|
|
119
152
|
className: "xp-test-page",
|
|
120
153
|
role: test.loadState === 'error' ? 'alert' : 'status',
|
|
121
154
|
children: [
|
|
155
|
+
Object.entries(test.fieldDrafts ?? {}).map(([key, draft])=>/*#__PURE__*/ _jsxs(Banner, {
|
|
156
|
+
tone: "warning",
|
|
157
|
+
action: /*#__PURE__*/ _jsx(Button, {
|
|
158
|
+
onClick: ()=>test.trackDraft(key, null),
|
|
159
|
+
children: C.discardEdit
|
|
160
|
+
}),
|
|
161
|
+
children: [
|
|
162
|
+
C.detachedEdit(draft.label),
|
|
163
|
+
" ",
|
|
164
|
+
/*#__PURE__*/ _jsx("strong", {
|
|
165
|
+
children: draft.value || C.emptyValue
|
|
166
|
+
})
|
|
167
|
+
]
|
|
168
|
+
}, key)),
|
|
122
169
|
/*#__PURE__*/ _jsx("p", {
|
|
123
170
|
children: test.preflightRead?.kind === 'signed-out' ? API_MESSAGES.unauthenticated : test.loadState === 'forbidden' ? C.forbidden : test.loadState === 'missing' ? C.missing : test.loadState === 'error' ? C.error : C.loading
|
|
124
171
|
}),
|
|
@@ -148,14 +195,25 @@ export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded
|
|
|
148
195
|
/*#__PURE__*/ _jsxs("div", {
|
|
149
196
|
className: "xp-test-content",
|
|
150
197
|
children: [
|
|
151
|
-
test.errors._section ? /*#__PURE__*/
|
|
198
|
+
test.errors._section ? /*#__PURE__*/ _jsxs(Banner, {
|
|
152
199
|
tone: "error",
|
|
153
200
|
action: /*#__PURE__*/ _jsx(Button, {
|
|
154
|
-
onClick: ()=>void test.reload(
|
|
201
|
+
onClick: ()=>void test.reload({
|
|
202
|
+
discardDrafts: true
|
|
203
|
+
}),
|
|
155
204
|
children: C.reload
|
|
156
205
|
}),
|
|
157
|
-
children:
|
|
206
|
+
children: [
|
|
207
|
+
test.errors._section,
|
|
208
|
+
test.stale ? null : /*#__PURE__*/ _jsxs(_Fragment, {
|
|
209
|
+
children: [
|
|
210
|
+
" ",
|
|
211
|
+
C.reloadAfterError
|
|
212
|
+
]
|
|
213
|
+
})
|
|
214
|
+
]
|
|
158
215
|
}) : null,
|
|
216
|
+
detachedEdits,
|
|
159
217
|
/*#__PURE__*/ _jsxs(Section, {
|
|
160
218
|
surface: surface,
|
|
161
219
|
test: test,
|
|
@@ -190,7 +248,31 @@ export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded
|
|
|
190
248
|
/*#__PURE__*/ _jsx(AdvancedSection, {
|
|
191
249
|
...props
|
|
192
250
|
}),
|
|
251
|
+
!embedded ? /*#__PURE__*/ _jsxs("div", {
|
|
252
|
+
children: [
|
|
253
|
+
/*#__PURE__*/ _jsx(DeleteTest, {
|
|
254
|
+
test: test.doc,
|
|
255
|
+
canManage: surface.canManage && !test.statusReadPending,
|
|
256
|
+
apiRoute: surface.apiRoute,
|
|
257
|
+
contentLocale: surface.contentLocale,
|
|
258
|
+
onStatusChanged: ()=>{
|
|
259
|
+
void test.reload();
|
|
260
|
+
},
|
|
261
|
+
onDeleted: (outcome)=>{
|
|
262
|
+
window.location.assign(surfaceUrls.home(surface.adminRoute, {
|
|
263
|
+
deleted: outcome
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
266
|
+
}, test.doc.id),
|
|
267
|
+
!test.statusReadPending && (test.doc.status === 'stopped' || test.doc.status === 'decided') ? /*#__PURE__*/ _jsx("p", {
|
|
268
|
+
children: DELETE_TEST.archiveFirst
|
|
269
|
+
}) : null
|
|
270
|
+
]
|
|
271
|
+
}) : null,
|
|
193
272
|
embedded && surface.canReadResults && test.doc.status !== 'draft' ? /*#__PURE__*/ _jsx(ResultsBody, {
|
|
273
|
+
documentVersion: `${test.doc.phase}/${test.doc.status}`,
|
|
274
|
+
liveDocument: test.doc,
|
|
275
|
+
statusReadPending: test.statusReadPending,
|
|
194
276
|
id: id,
|
|
195
277
|
surface: surface,
|
|
196
278
|
onChanged: (doc)=>{
|
|
@@ -199,7 +281,7 @@ export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded
|
|
|
199
281
|
});
|
|
200
282
|
void test.reload();
|
|
201
283
|
}
|
|
202
|
-
}
|
|
284
|
+
}) : null
|
|
203
285
|
]
|
|
204
286
|
})
|
|
205
287
|
]
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useId } from 'react';
|
|
3
|
+
import { useId, useState } from 'react';
|
|
4
4
|
import { Button } from '../../../ui/Button.js';
|
|
5
5
|
import { Range } from '../../../ui/Inputs.js';
|
|
6
|
-
import { useEffect, useRef, useState } from 'react';
|
|
7
6
|
import { TEST_PAGE as C } from '../../copy/testPage.js';
|
|
8
7
|
import { ARMS_COPY, GROUP_LABELS, issueMessage } from '../../copy/arms.js';
|
|
9
8
|
import { addHoldoutArm, addVariant, issuesByRow, removeArm, splitEvenly, totalWeight, withSlotsFor } from '../../arms/arms.model.js';
|
|
10
9
|
import { allocationSentence } from '../../allocation.model.js';
|
|
11
|
-
import { balanceWeight, orderedVersions, trafficShares } from './testPage.model.js';
|
|
12
|
-
import { FieldErrors, ReadOnly, reasonFor, save, TextEdit } from './fields.js';
|
|
10
|
+
import { balanceWeight, orderedVersions, trafficShares, trafficSplit } from './testPage.model.js';
|
|
11
|
+
import { FieldErrors, ReadOnly, reasonFor, save, SavedValueChanged, TextEdit, useDraftAnnouncement, useFieldDraft } from './fields.js';
|
|
13
12
|
import { PAGE_COPY } from '../../copy/pages.js';
|
|
14
13
|
import { testPageCollection } from '../pagePicker/pagePicker.model.js';
|
|
15
14
|
import { Section } from './Section.js';
|
|
@@ -24,28 +23,31 @@ export function VersionsSection({ test, surface, parts, contentOnCanvas = false
|
|
|
24
23
|
const id = useId();
|
|
25
24
|
const doc = test.doc;
|
|
26
25
|
const [weightEdit, setWeightEdit] = useState(null);
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
]);
|
|
26
|
+
const split = trafficSplit(doc.arms);
|
|
27
|
+
const allocationEdit = useFieldDraft(test, 'allocation', C.allocation, String(doc.allocation));
|
|
28
|
+
const [announcement, announce] = useDraftAnnouncement();
|
|
29
|
+
const allocation = Number(allocationEdit.value);
|
|
30
|
+
const allocationReason = reasonFor(test, 'allocation');
|
|
31
|
+
const allocationConflict = allocationEdit.dirty && !allocationEdit.saving && (allocationEdit.conflict || allocationEdit.retry || allocationReason) ? `${id}-new-value` : undefined;
|
|
32
|
+
if (weightEdit && (weightEdit.split !== split || test.mountDraft && !test.fieldDrafts?.[`share:${weightEdit.key}`])) setWeightEdit(null);
|
|
35
33
|
const reason = reasonFor(test, 'arms');
|
|
36
|
-
const live = weightEdit ? balanceWeight(doc.arms, weightEdit.key, weightEdit.weight) : doc.arms;
|
|
34
|
+
const live = weightEdit && !reason ? balanceWeight(doc.arms, weightEdit.key, weightEdit.weight) : doc.arms;
|
|
37
35
|
const ordered = orderedVersions(live);
|
|
38
36
|
const shares = trafficShares(ordered.map((row)=>row.arm));
|
|
39
|
-
const issues = issuesByRow(live, doc.kind);
|
|
37
|
+
const issues = issuesByRow(doc.kind === 'block' ? withSlotsFor(live, 'block') : live, doc.kind);
|
|
40
38
|
const update = (transform)=>save(test, 'arms', ()=>({
|
|
41
39
|
arms: withSlotsFor(transform(test.doc.arms), test.doc.kind)
|
|
42
40
|
}));
|
|
43
|
-
const commitAllocation = ()=>{
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
const commitAllocation = (confirmed = false)=>{
|
|
42
|
+
if (!allocationEdit.dirty || allocationEdit.saving) return;
|
|
43
|
+
if (allocationReason || test.stale || allocationConflict && !confirmed) {
|
|
44
|
+
announce();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (allocation === doc.allocation) allocationEdit.discard();
|
|
48
|
+
else allocationEdit.submit(()=>save(test, 'allocation', ()=>({
|
|
49
|
+
allocation
|
|
50
|
+
})));
|
|
49
51
|
};
|
|
50
52
|
return /*#__PURE__*/ _jsxs(Section, {
|
|
51
53
|
surface: surface,
|
|
@@ -87,6 +89,7 @@ export function VersionsSection({ test, surface, parts, contentOnCanvas = false
|
|
|
87
89
|
contentOnCanvas ? /*#__PURE__*/ _jsx("span", {
|
|
88
90
|
children: arm.label
|
|
89
91
|
}) : /*#__PURE__*/ _jsx(TextEdit, {
|
|
92
|
+
test: test,
|
|
90
93
|
label: `${GROUP_LABELS[arm.key]}: ${C.label}`,
|
|
91
94
|
value: arm.label,
|
|
92
95
|
reason: reason,
|
|
@@ -98,17 +101,22 @@ export function VersionsSection({ test, surface, parts, contentOnCanvas = false
|
|
|
98
101
|
} : current))
|
|
99
102
|
}),
|
|
100
103
|
/*#__PURE__*/ _jsx(TextEdit, {
|
|
104
|
+
test: test,
|
|
105
|
+
draftKey: `share:${arm.key}`,
|
|
101
106
|
label: `${GROUP_LABELS[arm.key]}: ${C.weight}`,
|
|
102
107
|
type: "number",
|
|
103
108
|
min: 0,
|
|
104
109
|
max: 100,
|
|
105
110
|
value: doc.arms[index].weight,
|
|
111
|
+
preview: weightEdit?.key !== arm.key ? arm.weight : undefined,
|
|
112
|
+
scope: split,
|
|
106
113
|
reason: reason,
|
|
107
114
|
hideLabel: true,
|
|
108
115
|
disabled: Boolean(reason),
|
|
109
116
|
isValid: (raw)=>raw.trim() !== '' && Number.isInteger(Number(raw)) && Number(raw) >= 0 && Number(raw) <= 100,
|
|
110
117
|
invalidMessage: C.invalidShare,
|
|
111
|
-
onDraft: (value)=>setWeightEdit({
|
|
118
|
+
onDraft: (value)=>setWeightEdit(value === null ? null : {
|
|
119
|
+
split,
|
|
112
120
|
key: arm.key,
|
|
113
121
|
weight: Number(value)
|
|
114
122
|
}),
|
|
@@ -207,10 +215,10 @@ export function VersionsSection({ test, surface, parts, contentOnCanvas = false
|
|
|
207
215
|
className: "xp-ui-help",
|
|
208
216
|
children: ARMS_COPY.holdout
|
|
209
217
|
}) : null,
|
|
210
|
-
|
|
218
|
+
allocationReason && !allocationEdit.dirty ? /*#__PURE__*/ _jsx(ReadOnly, {
|
|
211
219
|
label: C.allocation,
|
|
212
220
|
value: `${doc.allocation}%`,
|
|
213
|
-
reason:
|
|
221
|
+
reason: allocationReason
|
|
214
222
|
}) : /*#__PURE__*/ _jsx(Range, {
|
|
215
223
|
id: id,
|
|
216
224
|
label: C.allocation,
|
|
@@ -218,11 +226,21 @@ export function VersionsSection({ test, surface, parts, contentOnCanvas = false
|
|
|
218
226
|
min: 1,
|
|
219
227
|
max: 100,
|
|
220
228
|
value: allocation,
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
229
|
+
"aria-describedby": allocationConflict,
|
|
230
|
+
disabled: Boolean(allocationReason || test.stale || allocationEdit.saving),
|
|
231
|
+
onChange: (e)=>allocationEdit.change(e.target.value),
|
|
232
|
+
onPointerUp: ()=>commitAllocation(),
|
|
233
|
+
onKeyDown: (e)=>{
|
|
234
|
+
if (e.key === 'Enter' && allocationConflict) {
|
|
235
|
+
e.preventDefault();
|
|
236
|
+
announce();
|
|
237
|
+
}
|
|
238
|
+
if (e.key === 'Escape' && allocationEdit.dirty && !allocationEdit.saving) {
|
|
239
|
+
e.preventDefault();
|
|
240
|
+
e.stopPropagation();
|
|
241
|
+
allocationEdit.discard();
|
|
242
|
+
}
|
|
224
243
|
},
|
|
225
|
-
onPointerUp: commitAllocation,
|
|
226
244
|
onKeyUp: (e)=>{
|
|
227
245
|
if ([
|
|
228
246
|
'ArrowLeft',
|
|
@@ -235,11 +253,20 @@ export function VersionsSection({ test, surface, parts, contentOnCanvas = false
|
|
|
235
253
|
'PageDown'
|
|
236
254
|
].includes(e.key)) commitAllocation();
|
|
237
255
|
},
|
|
238
|
-
onBlur: commitAllocation
|
|
256
|
+
onBlur: ()=>commitAllocation()
|
|
239
257
|
}),
|
|
258
|
+
allocationConflict ? /*#__PURE__*/ _jsx(SavedValueChanged, {
|
|
259
|
+
id: allocationConflict,
|
|
260
|
+
value: `${doc.allocation}%`,
|
|
261
|
+
reason: allocationReason,
|
|
262
|
+
conflict: allocationEdit.conflict,
|
|
263
|
+
announce: announcement,
|
|
264
|
+
onKeep: !allocationReason && !test.stale ? ()=>commitAllocation(true) : undefined,
|
|
265
|
+
onDiscard: allocationEdit.discard
|
|
266
|
+
}) : null,
|
|
240
267
|
/*#__PURE__*/ _jsx("p", {
|
|
241
268
|
children: allocationSentence({
|
|
242
|
-
allocation:
|
|
269
|
+
allocation: allocationReason ? doc.allocation : allocation,
|
|
243
270
|
unitType: doc.unitType,
|
|
244
271
|
arms: live,
|
|
245
272
|
status: doc.status
|
|
@@ -3,7 +3,7 @@ import type { SectionProps, TestDocApi } from '../contracts.js';
|
|
|
3
3
|
import type { EditableField } from '../../../types/admin.js';
|
|
4
4
|
import type { TestDocumentPatch } from '../testDocument.model.js';
|
|
5
5
|
export declare function reasonFor(test: TestDocApi, field: string): string | null;
|
|
6
|
-
export declare function save(test: TestDocApi, field: EditableField, patch: () => TestDocumentPatch):
|
|
6
|
+
export declare function save(test: TestDocApi, field: EditableField, patch: () => TestDocumentPatch): boolean;
|
|
7
7
|
export declare function FieldErrors({ test, path }: {
|
|
8
8
|
test: TestDocApi;
|
|
9
9
|
path: string;
|
|
@@ -14,13 +14,38 @@ export declare function ReadOnly({ label, value, reason, labelAction }: {
|
|
|
14
14
|
reason: string | null;
|
|
15
15
|
labelAction?: ReactNode;
|
|
16
16
|
}): import("react").JSX.Element;
|
|
17
|
+
export declare function useFieldDraft(test: TestDocApi, key: string, label: string, saved: string, scope?: string): {
|
|
18
|
+
value: string;
|
|
19
|
+
dirty: boolean;
|
|
20
|
+
saving: boolean;
|
|
21
|
+
retry: boolean;
|
|
22
|
+
conflict: boolean;
|
|
23
|
+
change(value: string): void;
|
|
24
|
+
submit(save: () => boolean | void): void;
|
|
25
|
+
discard(): void;
|
|
26
|
+
};
|
|
27
|
+
export declare function SavedValueChanged({ id, value, reason, conflict, announce, onKeep, onDiscard }: {
|
|
28
|
+
id: string;
|
|
29
|
+
value: string;
|
|
30
|
+
reason?: string | null;
|
|
31
|
+
conflict: boolean;
|
|
32
|
+
announce: number;
|
|
33
|
+
onKeep?: () => void;
|
|
34
|
+
onDiscard: () => void;
|
|
35
|
+
}): import("react").JSX.Element;
|
|
36
|
+
/** Announce the existing choices again when blur or Enter cannot commit. */
|
|
37
|
+
export declare function useDraftAnnouncement(): readonly [number, () => void];
|
|
17
38
|
/** Local typing is intentionally separate from staging: build the current group on commit. */
|
|
18
|
-
export declare function TextEdit({ label, value, onCommit, reason, multiline, placeholder, type, min, max, required, onDraft, isValid, invalidMessage, hideLabel, disabled, help }: {
|
|
39
|
+
export declare function TextEdit({ test, label, draftKey, value, preview, onCommit, reason, multiline, placeholder, type, min, max, required, onDraft, scope, isValid, invalidMessage, hideLabel, disabled, help }: {
|
|
40
|
+
test: TestDocApi;
|
|
19
41
|
label: string;
|
|
42
|
+
draftKey?: string;
|
|
20
43
|
value: string | number;
|
|
21
|
-
onCommit: (value: string) => void;
|
|
44
|
+
onCommit: (value: string) => boolean | void;
|
|
22
45
|
reason?: string | null;
|
|
23
|
-
onDraft?: (value: string) => void;
|
|
46
|
+
onDraft?: (value: string | null) => void;
|
|
47
|
+
scope?: string;
|
|
48
|
+
preview?: number;
|
|
24
49
|
multiline?: boolean;
|
|
25
50
|
placeholder?: string;
|
|
26
51
|
type?: 'text' | 'number';
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { useId, useLayoutEffect, useState } from 'react';
|
|
4
4
|
import { TextInput, NumberInput, Textarea, Select, CheckboxList as UICheckboxList } from '../../../ui/Inputs.js';
|
|
5
|
+
import { Button } from '../../../ui/Button.js';
|
|
6
|
+
import { Banner } from '../../../ui/Feedback.js';
|
|
5
7
|
import { TEST_PAGE as C } from '../../copy/testPage.js';
|
|
6
8
|
import { EDITABLE_BY_STATUS } from '../../../collections/experiments/editability.js';
|
|
7
9
|
import { lockedReason } from '../../lockedNotice.model.js';
|
|
@@ -9,9 +11,9 @@ export function reasonFor(test, field) {
|
|
|
9
11
|
return test.doc ? lockedReason(test.doc.status, field, EDITABLE_BY_STATUS) : null;
|
|
10
12
|
}
|
|
11
13
|
export function save(test, field, patch) {
|
|
12
|
-
if (!test.doc || reasonFor(test, field)) return;
|
|
13
|
-
test.stage(patch());
|
|
14
|
+
if (!test.doc || reasonFor(test, field) || !test.stage(patch())) return false;
|
|
14
15
|
void test.commit();
|
|
16
|
+
return true;
|
|
15
17
|
}
|
|
16
18
|
export function FieldErrors({ test, path }) {
|
|
17
19
|
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
@@ -45,55 +47,171 @@ export function ReadOnly({ label, value, reason, labelAction }) {
|
|
|
45
47
|
]
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
|
-
|
|
50
|
+
export function useFieldDraft(test, key, label, saved, scope) {
|
|
51
|
+
const { mountDraft, submitDraft, trackDraft } = test;
|
|
52
|
+
const [localEdit, setLocalEdit] = useState(null);
|
|
53
|
+
const edit = mountDraft ? test.fieldDrafts?.[key] : localEdit;
|
|
54
|
+
const conflict = Boolean(edit && !edit.saving && (edit.scope !== scope || edit.base !== saved && edit.value !== saved));
|
|
55
|
+
useLayoutEffect(()=>mountDraft?.(key), [
|
|
56
|
+
key,
|
|
57
|
+
mountDraft
|
|
58
|
+
]);
|
|
59
|
+
const update = (draft)=>mountDraft ? trackDraft(key, draft) : setLocalEdit(draft);
|
|
60
|
+
return {
|
|
61
|
+
value: edit?.value ?? saved,
|
|
62
|
+
dirty: Boolean(edit),
|
|
63
|
+
saving: Boolean(edit?.saving),
|
|
64
|
+
retry: Boolean(edit?.retry),
|
|
65
|
+
conflict,
|
|
66
|
+
change (value) {
|
|
67
|
+
update(value === saved && !conflict ? null : {
|
|
68
|
+
label,
|
|
69
|
+
base: edit?.base ?? saved,
|
|
70
|
+
scope: edit ? edit.scope : scope,
|
|
71
|
+
value
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
submit (save) {
|
|
75
|
+
if (submitDraft) submitDraft(key, save);
|
|
76
|
+
else if (save() !== false) update(null);
|
|
77
|
+
},
|
|
78
|
+
discard () {
|
|
79
|
+
update(null);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export function SavedValueChanged({ id, value, reason, conflict, announce, onKeep, onDiscard }) {
|
|
84
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
85
|
+
id: id,
|
|
86
|
+
className: "xp-field-draft-notice",
|
|
87
|
+
children: /*#__PURE__*/ _jsx(Banner, {
|
|
88
|
+
tone: "error",
|
|
89
|
+
action: /*#__PURE__*/ _jsxs("div", {
|
|
90
|
+
className: "xp-ui-button-group",
|
|
91
|
+
children: [
|
|
92
|
+
onKeep ? /*#__PURE__*/ _jsx(Button, {
|
|
93
|
+
size: "sm",
|
|
94
|
+
onClick: onKeep,
|
|
95
|
+
children: conflict ? C.keepEdit : C.retryEdit
|
|
96
|
+
}) : null,
|
|
97
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
98
|
+
size: "sm",
|
|
99
|
+
variant: "quiet",
|
|
100
|
+
onClick: onDiscard,
|
|
101
|
+
children: C.useSavedValue
|
|
102
|
+
})
|
|
103
|
+
]
|
|
104
|
+
}),
|
|
105
|
+
children: /*#__PURE__*/ _jsxs("span", {
|
|
106
|
+
children: [
|
|
107
|
+
reason ?? (conflict ? C.savedValueChanged : null),
|
|
108
|
+
' ',
|
|
109
|
+
onKeep && conflict ? C.conflictChoice : C.draftNotSaved,
|
|
110
|
+
' ',
|
|
111
|
+
C.savedValue,
|
|
112
|
+
" ",
|
|
113
|
+
/*#__PURE__*/ _jsx("strong", {
|
|
114
|
+
children: value || C.emptyValue
|
|
115
|
+
})
|
|
116
|
+
]
|
|
117
|
+
}, announce)
|
|
118
|
+
})
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/** Announce the existing choices again when blur or Enter cannot commit. */ export function useDraftAnnouncement() {
|
|
122
|
+
const [announcement, setAnnouncement] = useState(0);
|
|
123
|
+
return [
|
|
124
|
+
announcement,
|
|
125
|
+
()=>setAnnouncement((count)=>count + 1)
|
|
126
|
+
];
|
|
127
|
+
}
|
|
128
|
+
/** Local typing is intentionally separate from staging: build the current group on commit. */ export function TextEdit({ test, label, draftKey = label, value, preview, onCommit, reason, multiline, placeholder, type = 'text', min, max, required, onDraft, scope, isValid, invalidMessage, hideLabel = false, disabled = false, help }) {
|
|
49
129
|
const id = useId();
|
|
50
|
-
const
|
|
130
|
+
const edit = useFieldDraft(test, draftKey, label, String(value), scope);
|
|
131
|
+
const [announcement, announce] = useDraftAnnouncement();
|
|
51
132
|
const [error, setError] = useState(null);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
133
|
+
if (error && !edit.dirty) setError(null);
|
|
134
|
+
const discard = ()=>{
|
|
135
|
+
edit.discard();
|
|
136
|
+
onDraft?.(null);
|
|
137
|
+
setError(null);
|
|
138
|
+
};
|
|
139
|
+
const locked = Boolean(reason || disabled);
|
|
140
|
+
const choice = edit.dirty && !edit.saving && (edit.conflict || edit.retry || locked || Boolean(error));
|
|
141
|
+
const choiceId = choice ? `${id}-new-value` : undefined;
|
|
142
|
+
const commit = (confirmed = false)=>{
|
|
143
|
+
if (!edit.dirty || edit.saving) return;
|
|
144
|
+
if (locked || test.stale || choice && !confirmed) {
|
|
145
|
+
announce();
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const draft = edit.value;
|
|
149
|
+
if (draft === String(value)) {
|
|
150
|
+
discard();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
58
153
|
if (isValid && !isValid(draft)) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
onDraft?.(String(value));
|
|
154
|
+
onDraft?.(null);
|
|
155
|
+
setError(invalidMessage ?? C.editInvalid);
|
|
62
156
|
return;
|
|
63
157
|
}
|
|
64
|
-
onCommit(draft);
|
|
158
|
+
edit.submit(()=>onCommit(draft));
|
|
159
|
+
onDraft?.(null);
|
|
65
160
|
};
|
|
66
|
-
if (reason && !disabled) return /*#__PURE__*/ _jsx(ReadOnly, {
|
|
161
|
+
if (reason && !disabled && !edit.dirty) return /*#__PURE__*/ _jsx(ReadOnly, {
|
|
67
162
|
label: label,
|
|
68
163
|
value: value === '' && placeholder ? placeholder : value,
|
|
69
164
|
reason: reason
|
|
70
165
|
});
|
|
71
166
|
const Input = multiline ? Textarea : type === 'number' ? NumberInput : TextInput;
|
|
72
|
-
return /*#__PURE__*/
|
|
167
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
73
168
|
className: hideLabel ? 'xp-grid-field' : undefined,
|
|
74
169
|
title: reason ?? undefined,
|
|
75
|
-
children:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
170
|
+
children: [
|
|
171
|
+
/*#__PURE__*/ _jsx(Input, {
|
|
172
|
+
id: id,
|
|
173
|
+
label: label,
|
|
174
|
+
"aria-label": label,
|
|
175
|
+
value: edit.dirty ? edit.value : preview ?? edit.value,
|
|
176
|
+
disabled: disabled && !edit.dirty,
|
|
177
|
+
readOnly: locked || test.stale || edit.saving,
|
|
178
|
+
"aria-describedby": choiceId,
|
|
179
|
+
placeholder: placeholder,
|
|
180
|
+
min: min,
|
|
181
|
+
max: max,
|
|
182
|
+
required: required,
|
|
183
|
+
help: help,
|
|
184
|
+
error: error ?? undefined,
|
|
185
|
+
onChange: (e)=>{
|
|
186
|
+
if (locked || test.stale || edit.saving) return;
|
|
187
|
+
const draft = e.target.value;
|
|
188
|
+
setError(null);
|
|
189
|
+
edit.change(draft);
|
|
190
|
+
onDraft?.(draft === String(value) || edit.conflict ? null : draft);
|
|
191
|
+
},
|
|
192
|
+
onBlur: ()=>commit(),
|
|
193
|
+
onKeyDown: (e)=>{
|
|
194
|
+
if (e.key === 'Escape' && edit.dirty && !edit.saving) {
|
|
195
|
+
e.preventDefault();
|
|
196
|
+
e.stopPropagation();
|
|
197
|
+
discard();
|
|
198
|
+
}
|
|
199
|
+
if (e.key === 'Enter' && !e.nativeEvent.isComposing && (choice || !multiline)) {
|
|
200
|
+
e.preventDefault();
|
|
201
|
+
commit();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}),
|
|
205
|
+
choiceId ? /*#__PURE__*/ _jsx(SavedValueChanged, {
|
|
206
|
+
id: choiceId,
|
|
207
|
+
value: String(value),
|
|
208
|
+
reason: reason,
|
|
209
|
+
conflict: edit.conflict,
|
|
210
|
+
announce: announcement,
|
|
211
|
+
onKeep: !locked && !test.stale && !error ? ()=>commit(true) : undefined,
|
|
212
|
+
onDiscard: discard
|
|
213
|
+
}) : null
|
|
214
|
+
]
|
|
97
215
|
});
|
|
98
216
|
}
|
|
99
217
|
export const positiveInteger = (raw)=>raw.trim() !== '' && Number.isInteger(Number(raw)) && Number(raw) > 0;
|
|
@@ -150,6 +268,7 @@ export function TestName({ test }) {
|
|
|
150
268
|
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
151
269
|
children: [
|
|
152
270
|
/*#__PURE__*/ _jsx(TextEdit, {
|
|
271
|
+
test: test,
|
|
153
272
|
label: C.name,
|
|
154
273
|
value: test.doc?.name ?? '',
|
|
155
274
|
reason: reasonFor(test, 'name'),
|
|
@@ -168,6 +287,7 @@ export function Hypothesis({ test }) {
|
|
|
168
287
|
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
169
288
|
children: [
|
|
170
289
|
/*#__PURE__*/ _jsx(TextEdit, {
|
|
290
|
+
test: test,
|
|
171
291
|
label: C.hypothesis,
|
|
172
292
|
value: test.doc?.hypothesis ?? '',
|
|
173
293
|
multiline: true,
|