@delmaredigital/payload-experiments 0.4.0-rc.5 → 0.4.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/copy/newTest.d.ts +1 -1
- package/dist/admin/copy/newTest.js +1 -1
- package/dist/admin/surface/newTest/NewTest.js +16 -18
- package/dist/admin/surface/newTest/newTest.css +3 -1
- 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.js +8 -6
- 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/CreateExperimentDrawer.d.ts +2 -1
- package/dist/puck/editor/CreateExperimentDrawer.js +24 -20
- package/dist/puck/editor/EditorControls.d.ts +1 -1
- package/dist/puck/editor/EditorControls.js +1 -1
- package/dist/puck/editor/ExperimentSlotEditor.js +354 -374
- package/dist/puck/editor/LeftoverVersions.d.ts +3 -1
- package/dist/puck/editor/LeftoverVersions.js +45 -63
- package/dist/puck/editor/QuickTestActions.js +2 -2
- package/dist/puck/editor/VersionBuilder.d.ts +24 -13
- package/dist/puck/editor/VersionBuilder.js +264 -205
- package/dist/puck/editor/armWrites.d.ts +9 -2
- package/dist/puck/editor/armWrites.js +40 -2
- package/dist/puck/editor/armsCache.d.ts +1 -1
- package/dist/puck/editor/armsCache.js +2 -1
- package/dist/puck/editor/copy.d.ts +19 -25
- package/dist/puck/editor/copy.js +19 -25
- package/dist/puck/editor/createTest.d.ts +3 -0
- package/dist/puck/editor/createTest.js +33 -0
- package/dist/puck/editor/editor.chrome.css +24 -17
- package/dist/puck/editor/editor.css +33 -21
- 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 +1 -1
- package/dist/puck/editor/localPlacements.d.ts +4 -2
- package/dist/puck/editor/localPlacements.js +20 -18
- package/dist/puck/editor/sidebar.d.ts +2 -6
- package/dist/puck/editor/sidebar.js +3 -6
- 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/copy/readiness.d.ts +1 -0
- package/dist/testSurface/copy/readiness.js +1 -0
- package/dist/testSurface/copy/testPage.d.ts +7 -6
- package/dist/testSurface/copy/testPage.js +7 -6
- package/dist/testSurface/results/results.css +1 -1
- package/dist/testSurface/results/results.model.d.ts +1 -1
- package/dist/testSurface/surface/readiness/ActionDialogs.js +28 -34
- package/dist/testSurface/surface/test/GoalSection.js +101 -74
- package/dist/testSurface/surface/test/fields.d.ts +1 -3
- package/dist/testSurface/surface/test/fields.js +5 -35
- package/dist/transitions/makeContent.js +24 -5
- package/dist/transitions/placements.js +23 -34
- package/dist/types/puck.d.ts +1 -0
- package/dist/ui/Inputs.js +8 -5
- package/dist/ui/Tabs.d.ts +0 -1
- package/dist/ui/Tabs.js +28 -40
- package/dist/ui/ui.css +9 -4
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { createUsePuck, useGetPuck } from '@puckeditor/core';
|
|
4
|
-
import { useEffect, useState, useSyncExternalStore
|
|
4
|
+
import { useEffect, useState, useSyncExternalStore } from 'react';
|
|
5
5
|
const usePuckSelector = createUsePuck();
|
|
6
6
|
// useGetPuck returns the store's stable getState function (Puck 0.24:7223–7228).
|
|
7
7
|
// A WeakMap keeps separate editors (including their iframes) isolated.
|
|
@@ -34,10 +34,8 @@ export function useSidebarTargets(id) {
|
|
|
34
34
|
};
|
|
35
35
|
}, ()=>entry.targets.get(id), ()=>undefined);
|
|
36
36
|
}
|
|
37
|
-
/** The custom field owns only its portal destinations
|
|
37
|
+
/** The custom field owns only its portal destinations never another data reader. */ export function TestSidebarField() {
|
|
38
38
|
const getPuck = useGetPuck();
|
|
39
|
-
const change = useRef(onChange);
|
|
40
|
-
change.current = onChange;
|
|
41
39
|
const id = usePuckSelector((state)=>state.selectedItem?.props.id);
|
|
42
40
|
const [test, setTest] = useState(null);
|
|
43
41
|
const [controls, setControls] = useState(null);
|
|
@@ -46,8 +44,7 @@ export function useSidebarTargets(id) {
|
|
|
46
44
|
const entry = bridge(getPuck);
|
|
47
45
|
const targets = {
|
|
48
46
|
test,
|
|
49
|
-
controls
|
|
50
|
-
onChange: (value)=>change.current(value)
|
|
47
|
+
controls
|
|
51
48
|
};
|
|
52
49
|
entry.targets.set(id, targets);
|
|
53
50
|
for (const notify of entry.listeners)notify();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** payload-puck's stored visibility contract. No runtime dependency on the host plugin. */
|
|
2
|
+
export declare const visibilitySizes: readonly ["phone", "tablet", "desktop"];
|
|
3
|
+
export type VisibilitySize = typeof visibilitySizes[number];
|
|
4
|
+
/** Read known sizes only; missing lists and malformed entries add no hiding. */
|
|
5
|
+
export declare function hiddenOnSizes(value: unknown): VisibilitySize[];
|
|
6
|
+
export declare function fullyHidden(value: unknown): boolean;
|
|
7
|
+
export type BlockVisibility = {
|
|
8
|
+
hidden: boolean;
|
|
9
|
+
hideOn: VisibilitySize[];
|
|
10
|
+
};
|
|
11
|
+
type PuckBlock = Record<string, unknown> & {
|
|
12
|
+
type: string;
|
|
13
|
+
props: Record<string, unknown>;
|
|
14
|
+
};
|
|
15
|
+
/** Visit blocks with their ancestors' visibility, including legacy owner-id:zone edges.
|
|
16
|
+
* Orphan zones retain their historical discovery behavior and count as shown.
|
|
17
|
+
*/
|
|
18
|
+
export declare function walkVisiblePuck(data: unknown, visit: (block: PuckBlock, visibility: BlockVisibility) => void): void;
|
|
19
|
+
/** Identity-keyed index shared by discovery and the public resolver. */
|
|
20
|
+
export declare function puckVisibility(data: unknown): Map<object, BlockVisibility>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** payload-puck's stored visibility contract. No runtime dependency on the host plugin. */ export const visibilitySizes = [
|
|
2
|
+
'phone',
|
|
3
|
+
'tablet',
|
|
4
|
+
'desktop'
|
|
5
|
+
];
|
|
6
|
+
const object = (value)=>!!value && typeof value === 'object' && !Array.isArray(value);
|
|
7
|
+
/** Read known sizes only; missing lists and malformed entries add no hiding. */ export function hiddenOnSizes(value) {
|
|
8
|
+
if (!object(value) || !Array.isArray(value.hideOn)) return [];
|
|
9
|
+
const sizes = value.hideOn;
|
|
10
|
+
return visibilitySizes.filter((size)=>sizes.includes(size));
|
|
11
|
+
}
|
|
12
|
+
export function fullyHidden(value) {
|
|
13
|
+
return object(value) && (value.hidden === true || hiddenOnSizes(value).length === visibilitySizes.length);
|
|
14
|
+
}
|
|
15
|
+
/** Visit blocks with their ancestors' visibility, including legacy owner-id:zone edges.
|
|
16
|
+
* Orphan zones retain their historical discovery behavior and count as shown.
|
|
17
|
+
*/ export function walkVisiblePuck(data, visit) {
|
|
18
|
+
const owners = new Set();
|
|
19
|
+
const zones = new Map();
|
|
20
|
+
const roots = [];
|
|
21
|
+
function index(value) {
|
|
22
|
+
if (Array.isArray(value)) {
|
|
23
|
+
value.forEach(index);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (!object(value)) return;
|
|
27
|
+
if (typeof value.type === 'string' && object(value.props) && typeof value.props.id === 'string') owners.add(value.props.id);
|
|
28
|
+
for (const [key, child] of Object.entries(value)){
|
|
29
|
+
if (value === data && key === 'zones' && object(child)) {
|
|
30
|
+
for (const [zone, content] of Object.entries(child)){
|
|
31
|
+
const owner = zone.slice(0, zone.lastIndexOf(':'));
|
|
32
|
+
zones.set(owner, [
|
|
33
|
+
...zones.get(owner) ?? [],
|
|
34
|
+
content
|
|
35
|
+
]);
|
|
36
|
+
roots.push({
|
|
37
|
+
owner,
|
|
38
|
+
content
|
|
39
|
+
});
|
|
40
|
+
index(content);
|
|
41
|
+
}
|
|
42
|
+
} else index(child);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
index(data);
|
|
46
|
+
const seen = new WeakSet();
|
|
47
|
+
function walk(value, inherited) {
|
|
48
|
+
if (Array.isArray(value)) {
|
|
49
|
+
value.forEach((child)=>walk(child, inherited));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (!object(value) || seen.has(value)) return;
|
|
53
|
+
seen.add(value);
|
|
54
|
+
let visibility = inherited;
|
|
55
|
+
const props = value.props;
|
|
56
|
+
if (typeof value.type === 'string' && object(props)) {
|
|
57
|
+
visibility = {
|
|
58
|
+
hidden: inherited.hidden || fullyHidden(props._visibility),
|
|
59
|
+
hideOn: visibilitySizes.filter((size)=>inherited.hideOn.includes(size) || hiddenOnSizes(props._visibility).includes(size))
|
|
60
|
+
};
|
|
61
|
+
visit(value, visibility);
|
|
62
|
+
if (typeof props.id === 'string') for (const content of zones.get(props.id) ?? [])walk(content, visibility);
|
|
63
|
+
}
|
|
64
|
+
for (const [key, child] of Object.entries(value))if (value !== data || key !== 'zones' || !object(child)) walk(child, visibility);
|
|
65
|
+
}
|
|
66
|
+
const shown = {
|
|
67
|
+
hidden: false,
|
|
68
|
+
hideOn: []
|
|
69
|
+
};
|
|
70
|
+
walk(data, shown);
|
|
71
|
+
for (const root of roots)if (!owners.has(root.owner)) walk(root.content, shown);
|
|
72
|
+
}
|
|
73
|
+
/** Identity-keyed index shared by discovery and the public resolver. */ export function puckVisibility(data) {
|
|
74
|
+
const result = new Map();
|
|
75
|
+
walkVisiblePuck(data, (block, visibility)=>result.set(block, visibility));
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { puckVisibility } from '../puck/visibility.js';
|
|
1
2
|
import { EXPERIMENT_BLOCK_SLUG, hostBlocks } from '../blocks/model.js';
|
|
2
3
|
import { safeError } from '../log.js';
|
|
3
4
|
import { isDeepStrictEqual } from 'node:util';
|
|
@@ -19,6 +20,7 @@ const slots = [
|
|
|
19
20
|
const object = (value)=>value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
20
21
|
function bindings(data, puck) {
|
|
21
22
|
const found = new Map();
|
|
23
|
+
const visibility = puck ? puckVisibility(data) : undefined;
|
|
22
24
|
function add(field, value, content) {
|
|
23
25
|
const key = field + ':' + value;
|
|
24
26
|
const binding = found.get(key) ?? {
|
|
@@ -34,7 +36,7 @@ function bindings(data, puck) {
|
|
|
34
36
|
value.forEach(walk);
|
|
35
37
|
return;
|
|
36
38
|
}
|
|
37
|
-
if (!object(value)) return;
|
|
39
|
+
if (!object(value) || visibility?.get(value)?.hidden) return;
|
|
38
40
|
if (puck && value.type === 'ExperimentSlot' && object(value.props)) {
|
|
39
41
|
const props = value.props;
|
|
40
42
|
const slug = typeof props.experiment === 'string' ? props.experiment : object(props.experiment) ? props.experiment.slug : undefined;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { puckVisibility } from '../puck/visibility.js';
|
|
1
2
|
import { manifestOf, suppressExposure } from './context.js';
|
|
2
3
|
export function resolveExperimentData(puckData, assignments) {
|
|
4
|
+
const visibility = puckVisibility(puckData);
|
|
3
5
|
const rendered = new Map();
|
|
4
6
|
const slots = [
|
|
5
7
|
'control',
|
|
@@ -9,8 +11,9 @@ export function resolveExperimentData(puckData, assignments) {
|
|
|
9
11
|
];
|
|
10
12
|
const manifest = manifestOf(assignments);
|
|
11
13
|
function walk(value) {
|
|
12
|
-
if (Array.isArray(value)) return value.map(walk);
|
|
14
|
+
if (Array.isArray(value)) return value.map(walk).filter((item)=>item !== undefined);
|
|
13
15
|
if (!value || typeof value !== 'object') return value;
|
|
16
|
+
if (visibility.get(value)?.hidden) return undefined;
|
|
14
17
|
const node = value;
|
|
15
18
|
if (node.type !== 'ExperimentSlot') return Object.fromEntries(Object.entries(node).map(([key, item])=>[
|
|
16
19
|
key,
|
|
@@ -81,6 +81,7 @@ export declare const stoppedCopy: (date: string | null) => string;
|
|
|
81
81
|
export declare const decidedCopy: (date: string | null, winner: string) => string;
|
|
82
82
|
export declare const runningCopy: (date: string | null, people: number | null, days: number | null) => string;
|
|
83
83
|
export declare const lastBlockPlacementCopy: (name: string, removingPage?: boolean) => string;
|
|
84
|
+
export declare const hiddenBlockPlacementCopy: (name: string) => string;
|
|
84
85
|
export declare const bulkBlockRemovalCopy: (name: string) => string;
|
|
85
86
|
export declare const pendingBlockRemovalCopy: (name: string) => string;
|
|
86
87
|
/** After archive the guard protects the winner and the Original; only the winner page is "the winner". */
|
|
@@ -82,6 +82,7 @@ export const runningCopy = (date, people, days)=>[
|
|
|
82
82
|
days === null ? null : `about ${days} days to go`
|
|
83
83
|
].filter(Boolean).join(' · ');
|
|
84
84
|
export const lastBlockPlacementCopy = (name, removingPage = false)=>removingPage ? `“${name}” is running and this page is the only published place it appears. Stop the test first.` : `“${name}” is running and this is the only published place it appears. Stop the test, or keep its block on this page.`;
|
|
85
|
+
export const hiddenBlockPlacementCopy = (name)=>`“${name}” is running and this is the only published place it appears. Stop the test first, or keep its block visible on this page.`;
|
|
85
86
|
export const bulkBlockRemovalCopy = (name)=>`“${name}” is running and the pages in this change are the only published places it appears. Stop the test first.`;
|
|
86
87
|
export const pendingBlockRemovalCopy = (name)=>`“${name}” is running and the pages in this change are the only published places it appears. Stop the test first, or change these pages one at a time.`;
|
|
87
88
|
/** After archive the guard protects the winner and the Original; only the winner page is "the winner". */ export const pageGuardCopy = (name, status, role = 'winner')=>status === 'archived' ? role === 'original' ? `This page's address now shows the winner of the finished test "${name}". To free it, open the test and choose "Release pages".` : `This page is shown at other addresses because the finished test "${name}" made it the winner. To free it, open the test and choose "Release pages".` : status === 'decided' ? `This page is part of the decided test "${name}". Choose "Make it the content" or "Discard winner" on the test before you delete, rename or unpublish it.` : `This page is part of the running test "${name}". Stop the test before you delete, rename or unpublish it.`;
|
|
@@ -2,7 +2,6 @@ export declare const TEST_PAGE: {
|
|
|
2
2
|
readonly noAudienceRules: "No audience choices are available here. Everyone eligible takes part; leave this section as it is.";
|
|
3
3
|
readonly editVersionsOnCanvas: "Edit version content on the canvas.";
|
|
4
4
|
readonly clickPageGroup: "On this test's page";
|
|
5
|
-
readonly clickGoalsNote: "Goals inside linked documents aren't shown. Goals added in code (data-xp-goal) work but aren't listed here.";
|
|
6
5
|
readonly clickGoalHelp: "A click shows interest, not the result you want.";
|
|
7
6
|
readonly staleEdit: "Someone else changed this test. Reload to see their changes.";
|
|
8
7
|
readonly reload: "Reload";
|
|
@@ -62,15 +61,17 @@ export declare const TEST_PAGE: {
|
|
|
62
61
|
readonly holdoutPrefix: "Holdout: ";
|
|
63
62
|
readonly allocation: "How many people take part";
|
|
64
63
|
readonly traffic: "How people are split";
|
|
64
|
+
readonly otherGoals: "Other goals (optional)";
|
|
65
|
+
readonly otherGoalsTitle: "Other goals";
|
|
66
|
+
readonly dontTrack: "Don't track";
|
|
67
|
+
readonly watch: "Watch";
|
|
68
|
+
readonly mustNotWorsen: "Must not get worse";
|
|
69
|
+
readonly otherGoalsHelp: "Watch: shown in results. Must not get worse: you're warned if a version makes it worse.";
|
|
65
70
|
readonly goal: "Goal";
|
|
66
|
-
readonly goalHelp: "The
|
|
71
|
+
readonly goalHelp: "The one thing you want more of. It decides the winner.";
|
|
67
72
|
readonly guardrailsShort: "Must not get worse";
|
|
68
|
-
readonly guardrails: "Must not get worse (optional)";
|
|
69
|
-
readonly guardrailHelp: "If a version makes one of these worse, you'll be warned.";
|
|
70
73
|
readonly secondaryShort: "Also keep an eye on";
|
|
71
|
-
readonly secondary: "Also keep an eye on (optional)";
|
|
72
74
|
readonly manageGoals: "Manage goals";
|
|
73
|
-
readonly searchGoals: "Search goals";
|
|
74
75
|
readonly chooseGoal: "Choose a goal";
|
|
75
76
|
readonly goalsError: "Couldn't load goals. Try again.";
|
|
76
77
|
readonly noGoal: "None selected";
|
|
@@ -4,7 +4,6 @@ export const TEST_PAGE = {
|
|
|
4
4
|
noAudienceRules: 'No audience choices are available here. Everyone eligible takes part; leave this section as it is.',
|
|
5
5
|
editVersionsOnCanvas: 'Edit version content on the canvas.',
|
|
6
6
|
clickPageGroup: "On this test's page",
|
|
7
|
-
clickGoalsNote: "Goals inside linked documents aren't shown. Goals added in code (data-xp-goal) work but aren't listed here.",
|
|
8
7
|
clickGoalHelp: 'A click shows interest, not the result you want.',
|
|
9
8
|
staleEdit: 'Someone else changed this test. Reload to see their changes.',
|
|
10
9
|
reload: 'Reload',
|
|
@@ -64,15 +63,17 @@ export const TEST_PAGE = {
|
|
|
64
63
|
holdoutPrefix: 'Holdout: ',
|
|
65
64
|
allocation: 'How many people take part',
|
|
66
65
|
traffic: 'How people are split',
|
|
66
|
+
otherGoals: 'Other goals (optional)',
|
|
67
|
+
otherGoalsTitle: 'Other goals',
|
|
68
|
+
dontTrack: "Don't track",
|
|
69
|
+
watch: 'Watch',
|
|
70
|
+
mustNotWorsen: 'Must not get worse',
|
|
71
|
+
otherGoalsHelp: "Watch: shown in results. Must not get worse: you're warned if a version makes it worse.",
|
|
67
72
|
goal: 'Goal',
|
|
68
|
-
goalHelp: 'The
|
|
73
|
+
goalHelp: 'The one thing you want more of. It decides the winner.',
|
|
69
74
|
guardrailsShort,
|
|
70
|
-
guardrails: `${guardrailsShort} (optional)`,
|
|
71
|
-
guardrailHelp: "If a version makes one of these worse, you'll be warned.",
|
|
72
75
|
secondaryShort,
|
|
73
|
-
secondary: `${secondaryShort} (optional)`,
|
|
74
76
|
manageGoals: 'Manage goals',
|
|
75
|
-
searchGoals: 'Search goals',
|
|
76
77
|
chooseGoal: 'Choose a goal',
|
|
77
78
|
goalsError: "Couldn't load goals. Try again.",
|
|
78
79
|
noGoal: 'None selected',
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
:where(.xp-test-surface) .xp-verdict-meta { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--xp-space-3); margin-top: var(--xp-space-5); padding-top: var(--xp-space-4); border-top: 1px solid var(--xp-border); color: var(--xp-text-3); font: var(--xp-text-small); }
|
|
7
7
|
:where(.xp-test-surface) .xp-round-meta { display: flex; align-items: center; flex-wrap: wrap; gap: var(--xp-space-2); min-width: 0; }
|
|
8
8
|
:where(.xp-test-surface) .xp-round-meta .xp-ui-field { display: flex; align-items: center; gap: var(--xp-space-2); margin: 0; min-width: 0; }
|
|
9
|
-
:where(.xp-test-surface) .xp-round-meta select { width: auto; max-width: 100%; }
|
|
9
|
+
:where(.xp-test-surface) .xp-round-meta .xp-ui-select-wrap { width: auto; max-width: 100%; }
|
|
10
10
|
:where(.xp-test-surface) .xp-results-chips { display: flex; flex-wrap: wrap; gap: var(--xp-space-2); list-style: none; padding: 0; margin-bottom: 0; }
|
|
11
11
|
:where(.xp-test-surface) .xp-stat-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--xp-border); border-radius: var(--xp-radius-card); background: var(--xp-surface); overflow: hidden; }
|
|
12
12
|
:where(.xp-test-surface) .xp-stat-tile { padding: 20px; min-width: 0; }
|
|
@@ -80,7 +80,7 @@ export declare function armRows({ snapshot, phase, metricId }: {
|
|
|
80
80
|
}): ArmRow[];
|
|
81
81
|
export declare function guardrailChips(snapshot: DisplaySnapshot): {
|
|
82
82
|
name: string;
|
|
83
|
-
status: "
|
|
83
|
+
status: "Watch" | "OK" | "Failing" | "Too little data";
|
|
84
84
|
}[];
|
|
85
85
|
interface RoundLineInput {
|
|
86
86
|
snapshot: DisplaySnapshot;
|
|
@@ -6,7 +6,7 @@ import { usePlacementLabels, placementDetailKey } from '../../placements/usePlac
|
|
|
6
6
|
import { placementUncheckedCopy } from '../../copy/readiness.js';
|
|
7
7
|
import { useEffect, useState } from 'react';
|
|
8
8
|
import { Button } from '../../../ui/Button.js';
|
|
9
|
-
import { TextInput } from '../../../ui/Inputs.js';
|
|
9
|
+
import { TextInput, Select } from '../../../ui/Inputs.js';
|
|
10
10
|
import { Dialog } from '../../../ui/Dialog.js';
|
|
11
11
|
import { MakeContentResult } from '../../actions/MakeContentResult.js';
|
|
12
12
|
import { expectedConfirm, matchesConfirm } from '../../../transitions/confirmPhrases.js';
|
|
@@ -273,44 +273,38 @@ import { useTransition } from './useTransition.js';
|
|
|
273
273
|
role: "status",
|
|
274
274
|
children: R.loadingMetrics
|
|
275
275
|
}) : null,
|
|
276
|
-
/*#__PURE__*/ _jsxs(
|
|
276
|
+
/*#__PURE__*/ _jsxs(Select, {
|
|
277
|
+
id: "xp-add-goal-role",
|
|
278
|
+
label: R.role,
|
|
279
|
+
value: role,
|
|
280
|
+
disabled: disabled,
|
|
281
|
+
onChange: (event)=>setRole(event.target.value),
|
|
277
282
|
children: [
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
value: "secondary",
|
|
286
|
-
children: R.supporting
|
|
287
|
-
}),
|
|
288
|
-
/*#__PURE__*/ _jsx("option", {
|
|
289
|
-
value: "guardrail",
|
|
290
|
-
children: R.guardrail
|
|
291
|
-
})
|
|
292
|
-
]
|
|
283
|
+
/*#__PURE__*/ _jsx("option", {
|
|
284
|
+
value: "secondary",
|
|
285
|
+
children: R.supporting
|
|
286
|
+
}),
|
|
287
|
+
/*#__PURE__*/ _jsx("option", {
|
|
288
|
+
value: "guardrail",
|
|
289
|
+
children: R.guardrail
|
|
293
290
|
})
|
|
294
291
|
]
|
|
295
292
|
}),
|
|
296
|
-
/*#__PURE__*/ _jsxs(
|
|
293
|
+
/*#__PURE__*/ _jsxs(Select, {
|
|
294
|
+
id: "xp-add-goal-metric",
|
|
295
|
+
label: R.metric,
|
|
296
|
+
value: metric,
|
|
297
|
+
disabled: disabled || loading,
|
|
298
|
+
onChange: (event)=>setMetric(event.target.value),
|
|
297
299
|
children: [
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
children: R.chooseMetric
|
|
307
|
-
}),
|
|
308
|
-
available.map((item)=>/*#__PURE__*/ _jsx("option", {
|
|
309
|
-
value: String(item.id),
|
|
310
|
-
children: item.name
|
|
311
|
-
}, item.id))
|
|
312
|
-
]
|
|
313
|
-
})
|
|
300
|
+
/*#__PURE__*/ _jsx("option", {
|
|
301
|
+
value: "",
|
|
302
|
+
children: R.chooseMetric
|
|
303
|
+
}),
|
|
304
|
+
available.map((item)=>/*#__PURE__*/ _jsx("option", {
|
|
305
|
+
value: String(item.id),
|
|
306
|
+
children: item.name
|
|
307
|
+
}, item.id))
|
|
314
308
|
]
|
|
315
309
|
}),
|
|
316
310
|
!loading && !loadError && !available.length ? /*#__PURE__*/ _jsx("p", {
|
|
@@ -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
|
});
|
|
@@ -232,19 +251,9 @@ export function GoalSection({ test, surface, embedded = false }) {
|
|
|
232
251
|
value: '',
|
|
233
252
|
label: C.chooseGoal
|
|
234
253
|
},
|
|
235
|
-
...
|
|
254
|
+
...visible
|
|
236
255
|
],
|
|
237
|
-
groups:
|
|
238
|
-
{
|
|
239
|
-
options: [
|
|
240
|
-
{
|
|
241
|
-
value: '',
|
|
242
|
-
label: C.chooseGoal
|
|
243
|
-
}
|
|
244
|
-
]
|
|
245
|
-
},
|
|
246
|
-
...roleGroups('primary')
|
|
247
|
-
] : undefined,
|
|
256
|
+
groups: goalGroups,
|
|
248
257
|
reason: reason,
|
|
249
258
|
readOnlyValue: display(doc.metrics?.primary == null ? [] : [
|
|
250
259
|
doc.metrics.primary
|
|
@@ -267,39 +276,57 @@ export function GoalSection({ test, surface, embedded = false }) {
|
|
|
267
276
|
test: test,
|
|
268
277
|
path: "metrics.primary"
|
|
269
278
|
}),
|
|
270
|
-
/*#__PURE__*/
|
|
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
|
-
|
|
302
|
-
|
|
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
|
+
]
|
|
303
330
|
}) : null,
|
|
304
331
|
test.errors.metrics ? /*#__PURE__*/ _jsx("p", {
|
|
305
332
|
role: "alert",
|
|
@@ -54,7 +54,7 @@ export declare function SelectEdit({ label, value, options, groups, reason, onCo
|
|
|
54
54
|
labelAction?: ReactNode;
|
|
55
55
|
groups?: readonly OptionGroup[];
|
|
56
56
|
}): import("react").JSX.Element;
|
|
57
|
-
export declare function CheckboxList({ label, value, options,
|
|
57
|
+
export declare function CheckboxList({ label, value, options, reason, onToggle, readOnlyValue }: {
|
|
58
58
|
label: string;
|
|
59
59
|
value: string[];
|
|
60
60
|
options: readonly {
|
|
@@ -64,8 +64,6 @@ export declare function CheckboxList({ label, value, options, groups, reason, on
|
|
|
64
64
|
reason?: string | null;
|
|
65
65
|
onToggle: (value: string, checked: boolean) => void;
|
|
66
66
|
readOnlyValue?: string;
|
|
67
|
-
searchable?: boolean;
|
|
68
|
-
groups?: readonly OptionGroup[];
|
|
69
67
|
}): import("react").JSX.Element;
|
|
70
68
|
export declare function TestName({ test }: SectionProps): import("react").JSX.Element;
|
|
71
69
|
export declare function Hypothesis({ test }: SectionProps): import("react").JSX.Element;
|