@delmaredigital/payload-experiments 0.4.0-rc.4 → 0.4.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/copy/newTest.d.ts +1 -1
- package/dist/admin/copy/newTest.js +1 -1
- package/dist/admin/surface/ResultsRoute.js +2 -10
- package/dist/admin/surface/newTest/NewTest.js +16 -18
- package/dist/admin/surface/newTest/PageWizard.js +10 -12
- package/dist/admin/surface/newTest/newTest.css +3 -1
- package/dist/admin/surface/results/ResultsHeader.js +15 -8
- package/dist/blocks/bindings.js +6 -13
- package/dist/blocks/placementLocale.d.ts +2 -0
- package/dist/blocks/placementLocale.js +16 -12
- package/dist/goals/fairness.d.ts +1 -1
- package/dist/goals/fairness.js +9 -7
- package/dist/hooks/blockRemovalRule.d.ts +2 -1
- package/dist/hooks/blockRemovalRule.js +27 -5
- package/dist/hooks/pageGuard.js +2 -2
- package/dist/puck/ExperimentPicker.d.ts +2 -1
- package/dist/puck/ExperimentPicker.js +34 -30
- package/dist/puck/ExperimentSlot.js +3 -1
- package/dist/puck/copy.d.ts +1 -0
- package/dist/puck/copy.js +1 -0
- package/dist/puck/editor/ConfigureTestDrawer.js +2 -2
- package/dist/puck/editor/CreateExperimentDrawer.d.ts +2 -1
- package/dist/puck/editor/CreateExperimentDrawer.js +24 -16
- package/dist/puck/editor/EditorControls.d.ts +1 -1
- package/dist/puck/editor/EditorControls.js +1 -1
- package/dist/puck/editor/ExperimentSlotEditor.js +624 -299
- package/dist/puck/editor/LeftoverVersions.d.ts +15 -0
- package/dist/puck/editor/LeftoverVersions.js +97 -0
- package/dist/puck/editor/PlacementNotice.d.ts +8 -0
- package/dist/puck/editor/PlacementNotice.js +22 -0
- package/dist/puck/editor/QuickTestActions.d.ts +3 -0
- package/dist/puck/editor/QuickTestActions.js +50 -0
- package/dist/puck/editor/ResultsReadout.js +5 -0
- package/dist/puck/editor/VersionBuilder.d.ts +37 -12
- package/dist/puck/editor/VersionBuilder.js +273 -184
- package/dist/puck/editor/armWrites.d.ts +11 -2
- package/dist/puck/editor/armWrites.js +42 -3
- package/dist/puck/editor/armsCache.d.ts +1 -1
- package/dist/puck/editor/armsCache.js +2 -1
- package/dist/puck/editor/cloneSlot.d.ts +2 -0
- package/dist/puck/editor/cloneSlot.js +7 -0
- package/dist/puck/editor/copy.d.ts +35 -20
- package/dist/puck/editor/copy.js +35 -20
- package/dist/puck/editor/createTest.d.ts +3 -0
- package/dist/puck/editor/createTest.js +33 -0
- package/dist/puck/editor/editor.chrome.css +32 -14
- package/dist/puck/editor/editor.css +58 -17
- package/dist/puck/editor/editor.model.d.ts +1 -1
- package/dist/puck/editor/editor.model.js +2 -2
- package/dist/puck/editor/experimentOutlinePlugin.js +96 -28
- package/dist/puck/editor/localPlacements.d.ts +4 -2
- package/dist/puck/editor/localPlacements.js +20 -18
- package/dist/puck/editor/outlineVersion.d.ts +5 -0
- package/dist/puck/editor/outlineVersion.js +36 -0
- package/dist/puck/editor/placementsCache.d.ts +33 -2
- package/dist/puck/editor/placementsCache.js +208 -33
- package/dist/puck/editor/sidebar.d.ts +8 -0
- package/dist/puck/editor/sidebar.js +74 -0
- package/dist/puck/editor/usePlacementNotice.d.ts +3 -0
- package/dist/puck/editor/usePlacementNotice.js +14 -0
- package/dist/puck/visibility.d.ts +21 -0
- package/dist/puck/visibility.js +77 -0
- package/dist/server/recordContentChange.js +3 -1
- package/dist/server/resolveExperimentData.js +4 -1
- package/dist/testSurface/api.js +1 -1
- package/dist/testSurface/copy/common.d.ts +1 -1
- package/dist/testSurface/copy/common.js +3 -1
- package/dist/testSurface/copy/readiness.d.ts +18 -1
- package/dist/testSurface/copy/readiness.js +23 -1
- package/dist/testSurface/copy/testPage.d.ts +8 -6
- package/dist/testSurface/copy/testPage.js +8 -6
- package/dist/testSurface/readPreflight.d.ts +9 -0
- package/dist/testSurface/readPreflight.js +38 -0
- package/dist/testSurface/readinessRead.d.ts +50 -0
- package/dist/testSurface/readinessRead.js +46 -0
- package/dist/testSurface/results/results.css +1 -1
- package/dist/testSurface/results/results.model.d.ts +1 -1
- package/dist/testSurface/surface/contracts.d.ts +6 -2
- package/dist/testSurface/surface/editorPlacement.d.ts +21 -0
- package/dist/testSurface/surface/editorPlacement.js +60 -0
- package/dist/testSurface/surface/pageBlock/parts.js +13 -3
- package/dist/testSurface/surface/readiness/ActionDialogs.js +65 -41
- package/dist/testSurface/surface/readiness/Banner.d.ts +1 -4
- package/dist/testSurface/surface/readiness/Banner.js +106 -68
- package/dist/testSurface/surface/readiness/BlockerList.d.ts +11 -0
- package/dist/testSurface/surface/readiness/BlockerList.js +31 -0
- package/dist/testSurface/surface/readiness/SaveStatus.d.ts +6 -2
- package/dist/testSurface/surface/readiness/SaveStatus.js +35 -22
- package/dist/testSurface/surface/readiness/parts.js +0 -2
- package/dist/testSurface/surface/readiness/readiness.model.d.ts +13 -0
- package/dist/testSurface/surface/readiness/readiness.model.js +51 -36
- package/dist/testSurface/surface/readiness/useTransition.d.ts +5 -2
- package/dist/testSurface/surface/readiness/useTransition.js +69 -7
- package/dist/testSurface/surface/test/AdvancedSection.js +1 -0
- package/dist/testSurface/surface/test/GoalSection.js +102 -74
- package/dist/testSurface/surface/test/LengthSection.d.ts +1 -1
- package/dist/testSurface/surface/test/LengthSection.js +2 -1
- package/dist/testSurface/surface/test/Rail.js +7 -4
- package/dist/testSurface/surface/test/ReadinessBar.js +1 -2
- package/dist/testSurface/surface/test/Section.d.ts +3 -1
- package/dist/testSurface/surface/test/Section.js +38 -6
- package/dist/testSurface/surface/test/TargetingSection.js +5 -0
- package/dist/testSurface/surface/test/TestSurface.d.ts +2 -1
- package/dist/testSurface/surface/test/TestSurface.js +68 -7
- package/dist/testSurface/surface/test/VersionsSection.js +1 -0
- package/dist/testSurface/surface/test/fields.d.ts +1 -3
- package/dist/testSurface/surface/test/fields.js +5 -35
- package/dist/testSurface/surface/test/testPage.css +12 -0
- package/dist/testSurface/surface/useTestDocument.d.ts +5 -2
- package/dist/testSurface/surface/useTestDocument.js +61 -46
- package/dist/testSurface/useReadinessPolling.d.ts +3 -0
- package/dist/testSurface/useReadinessPolling.js +24 -0
- package/dist/transitions/makeContent.js +24 -5
- package/dist/transitions/placements.js +23 -34
- package/dist/transitions/preflightData.js +1 -1
- package/dist/types/puck.d.ts +1 -0
- package/dist/ui/Card.d.ts +2 -1
- package/dist/ui/Card.js +4 -4
- package/dist/ui/Inputs.js +8 -5
- package/dist/ui/Tabs.d.ts +2 -2
- package/dist/ui/Tabs.js +33 -32
- package/dist/ui/ui.css +26 -3
- package/package.json +1 -1
|
@@ -1,12 +1,13 @@
|
|
|
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 { readinessRead } from '../../readinessRead.js';
|
|
3
4
|
import { useRef, useState } from 'react';
|
|
4
5
|
import { Button } from '../../../ui/Button.js';
|
|
5
6
|
import { READINESS_COPY as C } from '../../copy/readiness.js';
|
|
6
7
|
export function saveStatusMessage(test) {
|
|
7
|
-
return test.saving === 'saving' ? C.saving : test.saving === 'saved' || test.saving === 'idle' ? C.saved : test.saving === 'error' && !test.stale ? C.saveError : null;
|
|
8
|
+
return test.saving === 'saving' ? C.saving : test.saving === 'saved' || test.saving === 'idle' ? C.saved : test.saving === 'error' && !test.stale ? test.errors._section ? C.saveGeneralError : C.saveError : null;
|
|
8
9
|
}
|
|
9
|
-
export function
|
|
10
|
+
export function ReadinessReadStatus({ test, messageInBlockerList = false }) {
|
|
10
11
|
const inFlight = useRef(false);
|
|
11
12
|
const [retrying, setRetrying] = useState(false);
|
|
12
13
|
async function retry() {
|
|
@@ -20,6 +21,33 @@ export function SaveStatus({ test }) {
|
|
|
20
21
|
setRetrying(false);
|
|
21
22
|
}
|
|
22
23
|
}
|
|
24
|
+
const read = test.preflightRead ?? (test.preflightError ? readinessRead(test) : undefined);
|
|
25
|
+
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
26
|
+
children: read?.message ? /*#__PURE__*/ _jsxs("div", {
|
|
27
|
+
children: [
|
|
28
|
+
!messageInBlockerList ? /*#__PURE__*/ _jsx("span", {
|
|
29
|
+
role: "alert",
|
|
30
|
+
children: read.message
|
|
31
|
+
}) : null,
|
|
32
|
+
' ',
|
|
33
|
+
test.hasUnsaved || test.saving === 'saving' ? /*#__PURE__*/ _jsx("p", {
|
|
34
|
+
children: test.stale ? C.reloadFirst : C.saveFirst
|
|
35
|
+
}) : null,
|
|
36
|
+
read.retry ? /*#__PURE__*/ _jsx("span", {
|
|
37
|
+
title: test.stale ? C.reloadFirst : test.hasUnsaved || test.saving === 'saving' ? C.saveFirst : undefined,
|
|
38
|
+
children: /*#__PURE__*/ _jsx(Button, {
|
|
39
|
+
disabled: retrying || test.preflightPending || test.hasUnsaved || test.saving === 'saving',
|
|
40
|
+
onClick: ()=>{
|
|
41
|
+
void retry();
|
|
42
|
+
},
|
|
43
|
+
children: C.retry
|
|
44
|
+
})
|
|
45
|
+
}) : null
|
|
46
|
+
]
|
|
47
|
+
}) : null
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export function SaveStatus({ test, messageInBlockerList }) {
|
|
23
51
|
const message = saveStatusMessage(test);
|
|
24
52
|
return /*#__PURE__*/ _jsxs("div", {
|
|
25
53
|
className: "xp-save-status",
|
|
@@ -29,25 +57,10 @@ export function SaveStatus({ test }) {
|
|
|
29
57
|
role: test.saving === 'error' ? 'alert' : 'status',
|
|
30
58
|
children: message
|
|
31
59
|
}) : null,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
children: test.preflightError
|
|
37
|
-
}),
|
|
38
|
-
' ',
|
|
39
|
-
/*#__PURE__*/ _jsx("span", {
|
|
40
|
-
title: test.hasUnsaved || test.saving === 'saving' ? C.saveFirst : undefined,
|
|
41
|
-
children: /*#__PURE__*/ _jsx(Button, {
|
|
42
|
-
disabled: retrying || test.preflightPending || test.hasUnsaved || test.saving === 'saving',
|
|
43
|
-
onClick: ()=>{
|
|
44
|
-
void retry();
|
|
45
|
-
},
|
|
46
|
-
children: C.retry
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
]
|
|
50
|
-
}) : null
|
|
60
|
+
/*#__PURE__*/ _jsx(ReadinessReadStatus, {
|
|
61
|
+
test: test,
|
|
62
|
+
messageInBlockerList: messageInBlockerList
|
|
63
|
+
})
|
|
51
64
|
]
|
|
52
65
|
});
|
|
53
66
|
}
|
|
@@ -4,6 +4,7 @@ import type { TestDocument } from '../testDocument.model.js';
|
|
|
4
4
|
import type { SurfaceProps } from '../contracts.js';
|
|
5
5
|
import { type SectionId } from '../contracts.js';
|
|
6
6
|
export type ReadinessContext = Pick<TestDocument, 'arms' | 'unitType' | 'flagPoint'> & {
|
|
7
|
+
editorPlacementMessage?: string;
|
|
7
8
|
collectionLabel?: string;
|
|
8
9
|
pagePlacements?: PreflightResult['pagePlacements'];
|
|
9
10
|
flagPoints?: readonly Pick<SerializedFlagPoint, 'id' | 'params'>[];
|
|
@@ -14,6 +15,12 @@ export declare const READINESS: Record<ReadinessCode, {
|
|
|
14
15
|
next(detail: unknown, ctx: ReadinessContext): string | null;
|
|
15
16
|
nextStep?: string | ((detail: unknown, ctx: ReadinessContext) => string);
|
|
16
17
|
}>;
|
|
18
|
+
export declare function blockingSteps(preflight: PreflightResult | null, ctx: ReadinessContext): {
|
|
19
|
+
arm?: import("../../../types/contracts.js").ArmKey | undefined;
|
|
20
|
+
section: "header" | SectionId;
|
|
21
|
+
sentence: string;
|
|
22
|
+
code: ReadinessCode;
|
|
23
|
+
}[];
|
|
17
24
|
export declare function nextStep(preflight: PreflightResult | null, ctx: ReadinessContext): {
|
|
18
25
|
nextStep?: string | undefined;
|
|
19
26
|
arm?: import("../../../types/contracts.js").ArmKey | undefined;
|
|
@@ -21,8 +28,14 @@ export declare function nextStep(preflight: PreflightResult | null, ctx: Readine
|
|
|
21
28
|
sentence: string;
|
|
22
29
|
code: ReadinessCode;
|
|
23
30
|
} | null;
|
|
31
|
+
export declare function errorSection(path: string): SectionId | undefined;
|
|
32
|
+
export declare function sectionBlocked(test: {
|
|
33
|
+
preflight: PreflightResult | null;
|
|
34
|
+
errors?: Record<string, string>;
|
|
35
|
+
}, section: SectionId): boolean;
|
|
24
36
|
export declare function sectionDone(test: {
|
|
25
37
|
preflight: PreflightResult | null;
|
|
38
|
+
doc?: Pick<TestDocument, 'targeting'> | null;
|
|
26
39
|
}): Record<SectionId, boolean>;
|
|
27
40
|
export declare function displayDate(value: unknown): string | null;
|
|
28
41
|
export declare function daysRemaining(doc: TestDocument, now: number): number | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SURFACE_COPY } from '../../copy/surface.js';
|
|
2
2
|
import { formatDate } from '../../format/date.js';
|
|
3
3
|
import { actionGroupLabel } from '../../actions/actions.model.js';
|
|
4
|
-
import { asymmetricGoalsCopy, placementUncheckedCopy, interactingTestsCopy, sameAddressCopy, identicalVersionCopy, unsupportedContentCopy, versionPageUnavailableCopy, versionPageUncheckedCopy, placementFailureCopy, pageInUseCopy, unpublishedPageCopy, READINESS_COPY as C, attributeNext, contentNext, goalPeopleNext, parameterNext, placementNext, ruleNext, versionsNext } from '../../copy/readiness.js';
|
|
4
|
+
import { unpublishedPlacementsCopy, asymmetricGoalsCopy, placementUncheckedCopy, interactingTestsCopy, sameAddressCopy, identicalVersionCopy, unsupportedContentCopy, versionPageUnavailableCopy, versionPageUncheckedCopy, placementFailureCopy, pageInUseCopy, unpublishedPageCopy, READINESS_COPY as C, attributeNext, contentNext, goalPeopleNext, parameterNext, placementNext, ruleNext, versionsNext } from '../../copy/readiness.js';
|
|
5
5
|
import { normalisePath } from '../../../runtime/normalisePath.js';
|
|
6
6
|
import { testPageCollection } from '../pagePicker/pagePicker.model.js';
|
|
7
7
|
import { SECTION_ORDER } from '../contracts.js';
|
|
@@ -29,12 +29,10 @@ const versions = row('versions', (detail)=>versionsNext(detailText(detail, C.ver
|
|
|
29
29
|
nextStep: (detail)=>`Open ${text(object(detail).title ?? object(detail).path, 'the page')}`
|
|
30
30
|
},
|
|
31
31
|
'invalid-status': row('header', ()=>null),
|
|
32
|
-
'no-placements': row('what', (detail)=>detail === undefined ? C.noPlacements : placementFailureCopy(detail)),
|
|
32
|
+
'no-placements': row('what', (detail, ctx)=>ctx.editorPlacementMessage ?? (detail === undefined ? C.noPlacements : placementFailureCopy(detail))),
|
|
33
33
|
'placement-removed': row('what', ()=>C.placementRemoved),
|
|
34
34
|
'placement-unpublished': {
|
|
35
|
-
...row('versions',
|
|
36
|
-
detail
|
|
37
|
-
]).map((placement)=>`The block you're testing is only on a draft of ${text(object(placement).title, 'this page')}. Publish the page before you start.`).join('\n')),
|
|
35
|
+
...row('versions', unpublishedPlacementsCopy),
|
|
38
36
|
nextStep: 'Publish the page'
|
|
39
37
|
},
|
|
40
38
|
'duplicate-version-row': {
|
|
@@ -136,44 +134,60 @@ const versions = row('versions', (detail)=>versionsNext(detailText(detail, C.ver
|
|
|
136
134
|
'slot-required': versions,
|
|
137
135
|
'duplicate-slot': versions
|
|
138
136
|
};
|
|
139
|
-
export function
|
|
140
|
-
|
|
137
|
+
export function blockingSteps(preflight, ctx) {
|
|
138
|
+
return [
|
|
141
139
|
'header',
|
|
142
140
|
...SECTION_ORDER
|
|
143
|
-
]){
|
|
144
|
-
|
|
145
|
-
if (
|
|
146
|
-
|
|
147
|
-
section,
|
|
148
|
-
sentence: SURFACE_COPY.next,
|
|
149
|
-
code: check.code
|
|
150
|
-
};
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
const mapping = READINESS[check.code];
|
|
154
|
-
if (check.ok || mapping.section !== section) continue;
|
|
155
|
-
const sentence = mapping.next(check.detail, ctx);
|
|
156
|
-
const nextStep = typeof mapping.nextStep === 'function' ? mapping.nextStep(check.detail, ctx) : mapping.nextStep;
|
|
141
|
+
].flatMap((section)=>(preflight?.checks ?? []).flatMap((check)=>{
|
|
142
|
+
const mapping = Object.hasOwn(READINESS, check.code) ? READINESS[check.code] : undefined;
|
|
143
|
+
if (check.ok || (mapping?.section ?? 'what') !== section) return [];
|
|
144
|
+
const sentence = mapping ? mapping.next(check.detail, ctx) : SURFACE_COPY.next;
|
|
157
145
|
const arm = readinessArm(check.code, check.detail, ctx);
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
arm
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
146
|
+
return sentence ? [
|
|
147
|
+
{
|
|
148
|
+
section,
|
|
149
|
+
sentence,
|
|
150
|
+
code: check.code,
|
|
151
|
+
...arm ? {
|
|
152
|
+
arm
|
|
153
|
+
} : {}
|
|
154
|
+
}
|
|
155
|
+
] : [];
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
export function nextStep(preflight, ctx) {
|
|
159
|
+
const next = blockingSteps(preflight, ctx)[0];
|
|
160
|
+
if (!next) return null;
|
|
161
|
+
const mapping = READINESS[next.code];
|
|
162
|
+
const detail = preflight?.checks.find((check)=>!check.ok && check.code === next.code)?.detail;
|
|
163
|
+
const action = mapping && (typeof mapping.nextStep === 'function' ? mapping.nextStep(detail, ctx) : mapping.nextStep);
|
|
164
|
+
return {
|
|
165
|
+
...next,
|
|
166
|
+
...action ? {
|
|
167
|
+
nextStep: action
|
|
168
|
+
} : {}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
export function errorSection(path) {
|
|
172
|
+
if ([
|
|
173
|
+
'name',
|
|
174
|
+
'hypothesis',
|
|
175
|
+
'flagPoint'
|
|
176
|
+
].some((field)=>path === field || path.startsWith(`${field}.`))) return 'what';
|
|
177
|
+
if (/^(arms|pageCollection|allocation)(\.|$)/.test(path)) return 'versions';
|
|
178
|
+
if (/^metrics(\.|$)/.test(path)) return 'win';
|
|
179
|
+
if (/^(targeting)(\.|$)/.test(path)) return 'who';
|
|
180
|
+
if (/^analysis\.(plannedDurationDays|reachPerDay)(\.|$)/.test(path)) return 'length';
|
|
181
|
+
if (/^(analysis|exposurePolicy|layer)(\.|$)/.test(path)) return 'advanced';
|
|
182
|
+
}
|
|
183
|
+
export function sectionBlocked(test, section) {
|
|
184
|
+
if (Object.keys(test.errors ?? {}).some((path)=>errorSection(path) === section)) return true;
|
|
185
|
+
return !!test.preflight?.checks.some((check)=>!check.ok && (Object.hasOwn(READINESS, check.code) ? READINESS[check.code].section : 'what') === section);
|
|
172
186
|
}
|
|
173
187
|
export function sectionDone(test) {
|
|
174
188
|
return Object.fromEntries(SECTION_ORDER.map((section)=>[
|
|
175
189
|
section,
|
|
176
|
-
test.preflight ? !test.preflight.checks.some((check)=>!check.ok && (Object.hasOwn(READINESS, check.code) ? READINESS[check.code].section : SECTION_ORDER[0]) === section) : section === '
|
|
190
|
+
section === 'who' && test.doc && !test.doc.targeting?.length ? false : test.preflight ? !test.preflight.checks.some((check)=>!check.ok && (Object.hasOwn(READINESS, check.code) ? READINESS[check.code].section : SECTION_ORDER[0]) === section) : section === 'advanced'
|
|
177
191
|
]));
|
|
178
192
|
}
|
|
179
193
|
export function displayDate(value) {
|
|
@@ -191,6 +205,7 @@ function pageArm(path, ctx) {
|
|
|
191
205
|
export function pageReadinessContext(doc, preflight, surface) {
|
|
192
206
|
return {
|
|
193
207
|
...doc,
|
|
208
|
+
editorPlacementMessage: surface.editorPlacementMessage,
|
|
194
209
|
flagPoints: surface.flagPoints,
|
|
195
210
|
pagePlacements: preflight?.pagePlacements,
|
|
196
211
|
collectionLabel: testPageCollection(surface.pageCollections, doc, preflight?.pagePlacements)?.label
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { ApiResult } from '../../api.js';
|
|
2
2
|
import type { TestDocApi } from '../contracts.js';
|
|
3
|
+
import type { SurfaceProps } from '../contracts.js';
|
|
4
|
+
import type { ActionId } from '../../actions/actions.model.js';
|
|
3
5
|
/** The ref closes the gap before React renders the disabled button. */
|
|
4
|
-
export declare function useTransition(test: TestDocApi, onSuccess?: () => void): {
|
|
6
|
+
export declare function useTransition(test: TestDocApi, onSuccess?: () => void, surface?: SurfaceProps): {
|
|
5
7
|
busy: boolean;
|
|
8
|
+
checking: boolean;
|
|
6
9
|
error: string | null;
|
|
7
|
-
run: (request: () => Promise<ApiResult<unknown>>, { reloadOnSuccess }?: {
|
|
10
|
+
run: (kind: ActionId | "restart", request: () => Promise<ApiResult<unknown>>, { reloadOnSuccess }?: {
|
|
8
11
|
reloadOnSuccess?: boolean | undefined;
|
|
9
12
|
}) => Promise<void>;
|
|
10
13
|
clearError: () => void;
|
|
@@ -1,15 +1,58 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { useRef, useState } from 'react';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { blockingSteps, pageReadinessContext } from './readiness.model.js';
|
|
3
4
|
import { API_MESSAGES } from '../../copy/common.js';
|
|
4
|
-
/** The ref closes the gap before React renders the disabled button. */ export function useTransition(test, onSuccess) {
|
|
5
|
+
/** The ref closes the gap before React renders the disabled button. */ export function useTransition(test, onSuccess, surface) {
|
|
5
6
|
const inFlight = useRef(false);
|
|
6
7
|
const [busy, setBusy] = useState(false);
|
|
8
|
+
const [checking, setChecking] = useState(false);
|
|
7
9
|
const [error, setError] = useState(null);
|
|
8
|
-
|
|
10
|
+
const refusal = useRef(null);
|
|
11
|
+
const answer = test.preflightRead?.answer ?? test.preflight;
|
|
12
|
+
const latestAnswer = useRef(answer);
|
|
13
|
+
latestAnswer.current = answer;
|
|
14
|
+
// Dismissal mutates the lifetime once; a later ready answer cannot revive it.
|
|
15
|
+
useEffect(()=>{
|
|
16
|
+
if (!refusal.current) return;
|
|
17
|
+
if (refusal.current.status !== test.doc?.status) {
|
|
18
|
+
clearError();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (refusal.current.kind !== 'start' && refusal.current.kind !== 'restart') return;
|
|
22
|
+
const successful = !!answer && !test.preflightError;
|
|
23
|
+
const explained = successful && !test.preflightRead?.failed && test.doc && [
|
|
24
|
+
'draft',
|
|
25
|
+
'stopped'
|
|
26
|
+
].includes(test.doc.status) && blockingSteps(answer, surface ? pageReadinessContext(test.doc, answer, surface) : test.doc).length > 0;
|
|
27
|
+
if (refusal.current.phase === 'rereading') {
|
|
28
|
+
// Observe the answer even if another shared read has already begun.
|
|
29
|
+
if (!checking || successful && answer !== refusal.current.answer) {
|
|
30
|
+
refusal.current = {
|
|
31
|
+
...refusal.current,
|
|
32
|
+
phase: 'waiting',
|
|
33
|
+
answer
|
|
34
|
+
};
|
|
35
|
+
if (explained) clearError();
|
|
36
|
+
}
|
|
37
|
+
} else if (explained && answer !== refusal.current.answer) clearError();
|
|
38
|
+
}, [
|
|
39
|
+
answer,
|
|
40
|
+
checking,
|
|
41
|
+
error,
|
|
42
|
+
test.preflightPending,
|
|
43
|
+
test.preflightError,
|
|
44
|
+
test.doc?.status
|
|
45
|
+
]);
|
|
46
|
+
function clearError() {
|
|
47
|
+
refusal.current = null;
|
|
48
|
+
setError(null);
|
|
49
|
+
}
|
|
50
|
+
async function run(kind, request, { reloadOnSuccess = true } = {}) {
|
|
9
51
|
if (inFlight.current || test.hasUnsaved || test.saving === 'saving') return;
|
|
52
|
+
clearError();
|
|
10
53
|
inFlight.current = true;
|
|
11
54
|
setBusy(true);
|
|
12
|
-
|
|
55
|
+
let refused = false;
|
|
13
56
|
try {
|
|
14
57
|
const result = await request();
|
|
15
58
|
if (result.ok) {
|
|
@@ -20,17 +63,36 @@ import { API_MESSAGES } from '../../copy/common.js';
|
|
|
20
63
|
// Keep the successful action locked until the reloaded document replaces this view.
|
|
21
64
|
return;
|
|
22
65
|
}
|
|
23
|
-
} else
|
|
66
|
+
} else {
|
|
67
|
+
refused = true;
|
|
68
|
+
setError(result.message);
|
|
69
|
+
}
|
|
24
70
|
} catch {
|
|
71
|
+
refused = true;
|
|
25
72
|
setError(API_MESSAGES.network);
|
|
26
73
|
}
|
|
27
|
-
inFlight.current = false;
|
|
28
74
|
setBusy(false);
|
|
75
|
+
try {
|
|
76
|
+
if (refused) {
|
|
77
|
+
refusal.current = {
|
|
78
|
+
kind,
|
|
79
|
+
status: test.doc?.status,
|
|
80
|
+
phase: 'rereading',
|
|
81
|
+
answer: latestAnswer.current
|
|
82
|
+
};
|
|
83
|
+
setChecking(true);
|
|
84
|
+
await test.refreshPreflight(true);
|
|
85
|
+
}
|
|
86
|
+
} finally{
|
|
87
|
+
inFlight.current = false;
|
|
88
|
+
setChecking(false);
|
|
89
|
+
}
|
|
29
90
|
}
|
|
30
91
|
return {
|
|
31
92
|
busy,
|
|
93
|
+
checking,
|
|
32
94
|
error,
|
|
33
95
|
run,
|
|
34
|
-
clearError
|
|
96
|
+
clearError
|
|
35
97
|
};
|
|
36
98
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { fetchAllDocs } from '../../../lib/fetchAllDocs.js';
|
|
4
|
+
import { Select } from '../../../ui/Inputs.js';
|
|
5
|
+
import { useId } from 'react';
|
|
4
6
|
import { Button } from '../../../ui/Button.js';
|
|
5
7
|
import { useEffect, useMemo, useState } from 'react';
|
|
6
8
|
import { surfaceUrls } from '../../surfaceUrls.js';
|
|
@@ -10,7 +12,7 @@ import { isClickSource } from '../../../goals/key.js';
|
|
|
10
12
|
import { createApi } from '../../api.js';
|
|
11
13
|
import { sourceFor } from '../../metricSource.model.js';
|
|
12
14
|
import { reviewView } from '../../review/review.model.js';
|
|
13
|
-
import {
|
|
15
|
+
import { FieldErrors, reasonFor, save, SelectEdit } from './fields.js';
|
|
14
16
|
import { Section } from './Section.js';
|
|
15
17
|
export function GoalSection({ test, surface, embedded = false }) {
|
|
16
18
|
const api = useMemo(()=>createApi(surface.apiRoute), [
|
|
@@ -137,28 +139,38 @@ export function GoalSection({ test, surface, embedded = false }) {
|
|
|
137
139
|
value: id,
|
|
138
140
|
label: unknownGoal
|
|
139
141
|
});
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
142
|
+
const otherGoals = visible.filter((option)=>option.value !== String(doc.metrics?.primary ?? ''));
|
|
143
|
+
const otherCount = new Set([
|
|
144
|
+
...doc.metrics?.guardrails ?? [],
|
|
145
|
+
...doc.metrics?.secondary ?? []
|
|
146
|
+
].map(String).filter((id)=>id !== String(doc.metrics?.primary ?? ''))).size;
|
|
147
|
+
const [otherOpen, setOtherOpen] = useState(otherCount > 0);
|
|
148
|
+
const [previousCount, setPreviousCount] = useState(otherCount);
|
|
149
|
+
if (previousCount !== otherCount) {
|
|
150
|
+
setPreviousCount(otherCount);
|
|
151
|
+
if (previousCount === 0 && otherCount > 0) setOtherOpen(true);
|
|
152
|
+
}
|
|
153
|
+
const roleId = useId();
|
|
154
|
+
const goalGroups = onPage.size ? [
|
|
155
|
+
{
|
|
156
|
+
options: [
|
|
157
|
+
{
|
|
158
|
+
value: '',
|
|
159
|
+
label: C.chooseGoal
|
|
160
|
+
}
|
|
161
|
+
]
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
label: C.clickPageGroup,
|
|
165
|
+
options: visible.filter((option)=>onPage.has(option.value)).map((option)=>({
|
|
166
|
+
...option,
|
|
167
|
+
label: onPage.get(option.value)
|
|
168
|
+
}))
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
options: visible.filter((option)=>!onPage.has(option.value))
|
|
172
|
+
}
|
|
173
|
+
] : undefined;
|
|
162
174
|
const originalId = (value)=>metrics.find((metric)=>String(metric.id) === value)?.id ?? [
|
|
163
175
|
test.doc.metrics?.primary,
|
|
164
176
|
...test.doc.metrics?.guardrails ?? [],
|
|
@@ -170,21 +182,28 @@ export function GoalSection({ test, surface, embedded = false }) {
|
|
|
170
182
|
save(test, 'metrics', ()=>({
|
|
171
183
|
metrics: {
|
|
172
184
|
...test.doc.metrics,
|
|
173
|
-
primary: id
|
|
185
|
+
primary: id,
|
|
186
|
+
guardrails: test.doc.metrics?.guardrails?.filter((saved)=>String(saved) !== value),
|
|
187
|
+
secondary: test.doc.metrics?.secondary?.filter((saved)=>String(saved) !== value)
|
|
174
188
|
}
|
|
175
189
|
}));
|
|
176
190
|
};
|
|
177
|
-
const
|
|
191
|
+
const setRole = (value, role)=>save(test, 'metrics', ()=>{
|
|
178
192
|
const current = test.doc.metrics;
|
|
179
|
-
const ids = current?.[role] ?? [];
|
|
180
193
|
const id = originalId(value);
|
|
194
|
+
const guardrails = (current?.guardrails ?? []).filter((saved)=>String(saved) !== value);
|
|
195
|
+
const secondary = (current?.secondary ?? []).filter((saved)=>String(saved) !== value);
|
|
181
196
|
return {
|
|
182
197
|
metrics: {
|
|
183
198
|
...current,
|
|
184
|
-
|
|
185
|
-
...
|
|
199
|
+
guardrails: role === 'guardrails' && id != null ? [
|
|
200
|
+
...guardrails,
|
|
186
201
|
id
|
|
187
|
-
] :
|
|
202
|
+
] : guardrails,
|
|
203
|
+
secondary: role === 'secondary' && id != null ? [
|
|
204
|
+
...secondary,
|
|
205
|
+
id
|
|
206
|
+
] : secondary
|
|
188
207
|
}
|
|
189
208
|
};
|
|
190
209
|
});
|
|
@@ -195,6 +214,7 @@ export function GoalSection({ test, surface, embedded = false }) {
|
|
|
195
214
|
primaryMetricKind: kind
|
|
196
215
|
}).baseline : null;
|
|
197
216
|
return /*#__PURE__*/ _jsxs(Section, {
|
|
217
|
+
surface: surface,
|
|
198
218
|
test: test,
|
|
199
219
|
sectionId: "win",
|
|
200
220
|
children: [
|
|
@@ -231,19 +251,9 @@ export function GoalSection({ test, surface, embedded = false }) {
|
|
|
231
251
|
value: '',
|
|
232
252
|
label: C.chooseGoal
|
|
233
253
|
},
|
|
234
|
-
...
|
|
254
|
+
...visible
|
|
235
255
|
],
|
|
236
|
-
groups:
|
|
237
|
-
{
|
|
238
|
-
options: [
|
|
239
|
-
{
|
|
240
|
-
value: '',
|
|
241
|
-
label: C.chooseGoal
|
|
242
|
-
}
|
|
243
|
-
]
|
|
244
|
-
},
|
|
245
|
-
...roleGroups('primary')
|
|
246
|
-
] : undefined,
|
|
256
|
+
groups: goalGroups,
|
|
247
257
|
reason: reason,
|
|
248
258
|
readOnlyValue: display(doc.metrics?.primary == null ? [] : [
|
|
249
259
|
doc.metrics.primary
|
|
@@ -266,39 +276,57 @@ export function GoalSection({ test, surface, embedded = false }) {
|
|
|
266
276
|
test: test,
|
|
267
277
|
path: "metrics.primary"
|
|
268
278
|
}),
|
|
269
|
-
/*#__PURE__*/
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
279
|
+
otherGoals.length ? /*#__PURE__*/ _jsxs("details", {
|
|
280
|
+
className: "xp-other-goals",
|
|
281
|
+
open: otherOpen,
|
|
282
|
+
onToggle: (event)=>setOtherOpen(event.currentTarget.open),
|
|
283
|
+
children: [
|
|
284
|
+
/*#__PURE__*/ _jsx("summary", {
|
|
285
|
+
children: otherCount ? `${C.otherGoalsTitle} · ${otherCount}` : C.otherGoals
|
|
286
|
+
}),
|
|
287
|
+
/*#__PURE__*/ _jsx("div", {
|
|
288
|
+
className: "xp-other-goal-list",
|
|
289
|
+
children: otherGoals.map((option, index)=>{
|
|
290
|
+
const role = doc.metrics?.guardrails?.some((id)=>String(id) === option.value) ? 'guardrails' : doc.metrics?.secondary?.some((id)=>String(id) === option.value) ? 'secondary' : '';
|
|
291
|
+
return /*#__PURE__*/ _jsxs(Select, {
|
|
292
|
+
id: `${roleId}-${index}`,
|
|
293
|
+
label: onPage.get(option.value) ?? option.label,
|
|
294
|
+
value: role,
|
|
295
|
+
disabled: Boolean(reason),
|
|
296
|
+
onChange: (event)=>setRole(option.value, event.target.value),
|
|
297
|
+
children: [
|
|
298
|
+
/*#__PURE__*/ _jsx("option", {
|
|
299
|
+
value: "",
|
|
300
|
+
children: C.dontTrack
|
|
301
|
+
}),
|
|
302
|
+
/*#__PURE__*/ _jsx("option", {
|
|
303
|
+
value: "secondary",
|
|
304
|
+
children: C.watch
|
|
305
|
+
}),
|
|
306
|
+
/*#__PURE__*/ _jsx("option", {
|
|
307
|
+
value: "guardrails",
|
|
308
|
+
children: C.mustNotWorsen
|
|
309
|
+
})
|
|
310
|
+
]
|
|
311
|
+
}, option.value);
|
|
312
|
+
})
|
|
313
|
+
}),
|
|
314
|
+
/*#__PURE__*/ _jsx("p", {
|
|
315
|
+
children: C.otherGoalsHelp
|
|
316
|
+
}),
|
|
317
|
+
reason ? /*#__PURE__*/ _jsx("p", {
|
|
318
|
+
className: "xp-ui-help",
|
|
319
|
+
children: reason
|
|
320
|
+
}) : null,
|
|
321
|
+
/*#__PURE__*/ _jsx(FieldErrors, {
|
|
322
|
+
test: test,
|
|
323
|
+
path: "metrics.guardrails"
|
|
324
|
+
}),
|
|
325
|
+
/*#__PURE__*/ _jsx(FieldErrors, {
|
|
326
|
+
test: test,
|
|
327
|
+
path: "metrics.secondary"
|
|
328
|
+
})
|
|
329
|
+
]
|
|
302
330
|
}) : null,
|
|
303
331
|
test.errors.metrics ? /*#__PURE__*/ _jsx("p", {
|
|
304
332
|
role: "alert",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { SectionProps } from '../contracts.js';
|
|
2
|
-
export declare function LengthSection({ test }: SectionProps): import("react").JSX.Element;
|
|
2
|
+
export declare function LengthSection({ test, surface }: SectionProps): import("react").JSX.Element;
|
|
@@ -5,7 +5,7 @@ import { TEST_PAGE as C, suggestedWeeks, weeksHint } from '../../copy/testPage.j
|
|
|
5
5
|
import { durationSuggestion } from './testPage.model.js';
|
|
6
6
|
import { FieldErrors, positiveInteger, reasonFor, save, TextEdit } from './fields.js';
|
|
7
7
|
import { Section } from './Section.js';
|
|
8
|
-
export function LengthSection({ test }) {
|
|
8
|
+
export function LengthSection({ test, surface }) {
|
|
9
9
|
const doc = test.doc;
|
|
10
10
|
const reason = reasonFor(test, 'analysis');
|
|
11
11
|
const suggestion = durationSuggestion(test.preflight, doc.analysis?.plannedDurationDays);
|
|
@@ -20,6 +20,7 @@ export function LengthSection({ test }) {
|
|
|
20
20
|
}
|
|
21
21
|
}));
|
|
22
22
|
return /*#__PURE__*/ _jsxs(Section, {
|
|
23
|
+
surface: surface,
|
|
23
24
|
test: test,
|
|
24
25
|
sectionId: "length",
|
|
25
26
|
children: [
|