@delmaredigital/payload-experiments 0.4.0-rc.6 → 0.4.0-rc.7
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/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 +8 -4
- package/dist/admin/copy/blocks.d.ts +3 -2
- package/dist/admin/copy/blocks.js +7 -6
- package/dist/admin/surface/ResultsRoute.js +2 -1
- package/dist/admin/surface/TestsHome.d.ts +2 -1
- package/dist/admin/surface/TestsHome.js +91 -37
- 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 +1 -0
- package/dist/admin/surface/newTest/newTest.css +1 -1
- 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/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/db/appends.d.ts +13 -0
- package/dist/db/appends.js +49 -0
- package/dist/db/bulkPlacementRemoval.js +8 -4
- 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 +206 -0
- package/dist/endpoints/index.js +7 -0
- package/dist/endpoints/pages.js +7 -3
- package/dist/endpoints/placementStatus.js +6 -1
- package/dist/endpoints/preflight.d.ts +1 -1
- package/dist/endpoints/preflight.js +17 -2
- 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/goals/fairness.js +38 -31
- package/dist/hooks/blockRemovalRule.d.ts +2 -2
- package/dist/hooks/blockRemovalRule.js +16 -14
- package/dist/hooks/pageGuard.d.ts +3 -0
- package/dist/hooks/pageGuard.js +33 -23
- package/dist/hooks/puckNestedTests.d.ts +8 -0
- package/dist/hooks/puckNestedTests.js +36 -0
- 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 +5 -1
- package/dist/puck/ExperimentPicker.js +40 -37
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
- package/dist/puck/editor/ConfigureTestDrawer.js +4 -2
- package/dist/puck/editor/ExperimentSlotEditor.js +135 -104
- package/dist/puck/editor/LeftoverVersions.d.ts +1 -1
- package/dist/puck/editor/LeftoverVersions.js +40 -43
- package/dist/puck/editor/VersionBuilder.d.ts +18 -1
- package/dist/puck/editor/VersionBuilder.js +217 -39
- package/dist/puck/editor/blockClipboard.d.ts +16 -0
- package/dist/puck/editor/blockClipboard.js +20 -0
- package/dist/puck/editor/copy.d.ts +8 -1
- package/dist/puck/editor/copy.js +9 -1
- package/dist/puck/editor/editor.chrome.css +117 -3
- package/dist/puck/editor/editor.css +130 -8
- package/dist/puck/editor/editor.model.d.ts +2 -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 +18 -12
- package/dist/puck/editor/placementsCache.js +52 -47
- package/dist/puck/editor/usePlacementNotice.d.ts +1 -1
- package/dist/puck/editor/usePlacementNotice.js +4 -3
- 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/server/recordContentChange.js +34 -19
- package/dist/server/resolveExperimentData.js +2 -2
- package/dist/testSurface/PreviewLinks.js +6 -2
- package/dist/testSurface/api.d.ts +6 -3
- package/dist/testSurface/api.js +10 -6
- package/dist/testSurface/contentLocaleURL.d.ts +2 -0
- package/dist/testSurface/contentLocaleURL.js +3 -0
- package/dist/testSurface/copy/common.d.ts +4 -0
- package/dist/testSurface/copy/common.js +8 -4
- package/dist/testSurface/copy/languages.d.ts +11 -0
- package/dist/testSurface/copy/languages.js +7 -0
- package/dist/testSurface/copy/readiness.d.ts +1 -1
- package/dist/testSurface/copy/readiness.js +1 -1
- package/dist/testSurface/copy/testPage.d.ts +21 -0
- package/dist/testSurface/copy/testPage.js +21 -0
- 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/results/results.css +1 -1
- package/dist/testSurface/surface/contracts.d.ts +2 -0
- package/dist/testSurface/surface/editorPlacement.d.ts +5 -0
- package/dist/testSurface/surface/editorPlacement.js +18 -0
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +2 -1
- package/dist/testSurface/surface/pageBlock/parts.js +24 -6
- package/dist/testSurface/surface/readiness/readiness.model.js +9 -2
- package/dist/testSurface/surface/results/useResults.d.ts +4 -1
- package/dist/testSurface/surface/test/DeleteTest.d.ts +15 -0
- package/dist/testSurface/surface/test/DeleteTest.js +171 -0
- package/dist/testSurface/surface/test/TestSurface.js +29 -9
- package/dist/testSurface/surface/useTestDocument.d.ts +2 -1
- package/dist/testSurface/surface/useTestDocument.js +20 -4
- package/dist/testSurface/useApi.d.ts +4 -1
- package/dist/transitions/checkStart.d.ts +4 -1
- package/dist/transitions/checkStart.js +117 -14
- package/dist/transitions/contentFields.js +9 -5
- package/dist/transitions/makeContent.js +5 -4
- package/dist/transitions/nestedPlacementNames.d.ts +5 -0
- package/dist/transitions/nestedPlacementNames.js +33 -0
- package/dist/transitions/pageVersions.js +3 -1
- package/dist/transitions/placementInteractions.js +7 -4
- package/dist/transitions/placements.d.ts +26 -1
- package/dist/transitions/placements.js +219 -56
- package/dist/transitions/preflightData.d.ts +2 -1
- package/dist/transitions/preflightData.js +66 -3
- package/dist/transitions/start.js +4 -1
- package/dist/types/endpoints.d.ts +35 -1
- package/dist/types/endpoints.js +1 -1
- package/dist/types/surface.d.ts +2 -0
- package/dist/ui/Button.js +2 -2
- package/dist/ui/Inputs.d.ts +4 -3
- package/dist/ui/Inputs.js +9 -9
- package/dist/ui/SelectControl.d.ts +33 -0
- package/dist/ui/SelectControl.js +504 -0
- package/dist/ui/ui.css +13 -5
- package/package.json +3 -2
|
@@ -6,7 +6,7 @@ import { useEffect, useId, useRef, useState } from 'react';
|
|
|
6
6
|
import { copyOriginalIntoVersion, syncExperimentSlots, unwrapExperimentBlock } from '../../blocks/formState.js';
|
|
7
7
|
import { BLOCK_COPY, blockSyncNotice, blockUnwrapNotice, blockDeleteConfirmation, blockUnwrapConfirmation, blockRunningUnwrap, blockDecidedUnwrap, blockFinishedCopy } from '../../admin/copy/blocks.js';
|
|
8
8
|
import { API_MESSAGES } from '../../testSurface/copy/common.js';
|
|
9
|
-
import {
|
|
9
|
+
import { canUnwrapOriginal, liveStatus, slotLabel, statusSentence } from './model.js';
|
|
10
10
|
import { createApi } from '../../testSurface/api.js';
|
|
11
11
|
import { useBlockStatus, setBlockStatus } from './statusCache.js';
|
|
12
12
|
import { useBlockForm } from './useBlockForm.js';
|
|
@@ -65,7 +65,9 @@ export function BlockStatusField({ path }) {
|
|
|
65
65
|
const api = createApi(config.routes.api);
|
|
66
66
|
const found = await api.findTestIdBySlug(block.experiment);
|
|
67
67
|
if (!found.ok) throw new RefusalError(found.message);
|
|
68
|
-
const removed = await api.deleteTest(found.data
|
|
68
|
+
const removed = await api.deleteTest(found.data, {
|
|
69
|
+
draft: true
|
|
70
|
+
});
|
|
69
71
|
if (!removed.ok) throw new RefusalError(removed.message);
|
|
70
72
|
deleted = true;
|
|
71
73
|
setBlockStatus(config.routes.api, block.experiment, {
|
|
@@ -81,7 +83,7 @@ export function BlockStatusField({ path }) {
|
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
const sentence = statusSentence(status);
|
|
84
|
-
const linkedCopy = liveStatus(status) ? status.status === 'running' ? blockRunningUnwrap : status.status === 'decided' ? blockDecidedUnwrap : status.status === 'archived' && status.winnerArm ? blockFinishedCopy(slotLabel(status.winnerArm, status)) : undefined : undefined;
|
|
86
|
+
const linkedCopy = liveStatus(status) ? status.status === 'running' ? blockRunningUnwrap : status.status === 'decided' ? blockDecidedUnwrap : status.status === 'archived' && status.winnerArm && !status.discarded ? blockFinishedCopy(slotLabel(status.winnerArm, status), status.winnerArm === 'control', status.winnerArm !== 'control' && canUnwrapOriginal(status, block)) : undefined : undefined;
|
|
85
87
|
const href = formatAdminURL({
|
|
86
88
|
adminRoute: config.routes.admin,
|
|
87
89
|
path: `/experiments/by-slug/${encodeURIComponent(block?.experiment ?? '')}`
|
|
@@ -107,7 +109,7 @@ export function BlockStatusField({ path }) {
|
|
|
107
109
|
role: "status",
|
|
108
110
|
children: blockSyncNotice(Boolean(collection?.versions?.drafts))
|
|
109
111
|
}) : null,
|
|
110
|
-
|
|
112
|
+
canUnwrapOriginal(status, block) || draft || stopped ? /*#__PURE__*/ _jsx(Button, {
|
|
111
113
|
disabled: busy,
|
|
112
114
|
onClick: ()=>draft || stopped ? openModal(modalSlug) : void unwrap(),
|
|
113
115
|
children: draft ? BLOCK_COPY.removeAndUnwrap : BLOCK_COPY.unwrap
|
|
@@ -7,6 +7,7 @@ import { XP_TEST_BLOCK } from '../paths.js';
|
|
|
7
7
|
name: 'xpTestBlock',
|
|
8
8
|
type: 'ui',
|
|
9
9
|
admin: {
|
|
10
|
+
// Payload supplies the active locale's form data here; there is no raw adapter row.
|
|
10
11
|
condition: (data)=>{
|
|
11
12
|
try {
|
|
12
13
|
return registration.appliesTo ? registration.appliesTo(data) === true : true;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PlacementStatusResult } from '../../types/endpoints.js';
|
|
2
|
+
import { type HostBlock } from '../../blocks/model.js';
|
|
2
3
|
import type { RowsField } from './formApi.js';
|
|
3
4
|
export type BlockStatus = PlacementStatusResult['slugs'][string];
|
|
4
5
|
export type LiveBlockStatus = Extract<BlockStatus, {
|
|
@@ -7,10 +8,10 @@ export type LiveBlockStatus = Extract<BlockStatus, {
|
|
|
7
8
|
export declare function liveStatus(status: BlockStatus | null): status is LiveBlockStatus;
|
|
8
9
|
export declare function slotLabel(slot: string, status: BlockStatus | null): string;
|
|
9
10
|
export declare function statusSentence(status: BlockStatus): string;
|
|
10
|
-
export declare function
|
|
11
|
+
export declare function canUnwrapOriginal(status: BlockStatus, block?: HostBlock): boolean;
|
|
11
12
|
export declare function labelText(value: unknown): string | undefined;
|
|
12
13
|
export declare function blockChoices(value: unknown, field: RowsField, blockSlug: string): {
|
|
13
|
-
block:
|
|
14
|
+
block: HostBlock;
|
|
14
15
|
index: number;
|
|
15
16
|
label: string;
|
|
16
17
|
option: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hostBlocks } from '../../blocks/model.js';
|
|
1
|
+
import { hostBlocks, slotBlocks } from '../../blocks/model.js';
|
|
2
2
|
import { BLOCK_COPY, blockDecidedStatus, blockDraftStatus, blockFinishedStatus, blockPosition } from '../../admin/copy/blocks.js';
|
|
3
3
|
export function liveStatus(status) {
|
|
4
4
|
return !!status && 'status' in status;
|
|
@@ -20,11 +20,15 @@ export function statusSentence(status) {
|
|
|
20
20
|
case 'decided':
|
|
21
21
|
return blockDecidedStatus(winnerLabel, status.rollout);
|
|
22
22
|
case 'archived':
|
|
23
|
-
return status.winnerArm ? blockFinishedStatus(winnerLabel) : BLOCK_COPY.
|
|
23
|
+
return status.discarded ? BLOCK_COPY.discarded : status.winnerArm ? blockFinishedStatus(winnerLabel, status.winnerArm === 'control') : BLOCK_COPY.neverDecided;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
export function
|
|
27
|
-
|
|
26
|
+
export function canUnwrapOriginal(status, block) {
|
|
27
|
+
if (!liveStatus(status)) return true;
|
|
28
|
+
if (status.status !== 'archived') return false;
|
|
29
|
+
if (status.discarded || !status.winnerArm || status.winnerArm === 'control') return true;
|
|
30
|
+
const slot = status.arms.find((arm)=>arm.key === status.winnerArm)?.slot ?? status.winnerArm;
|
|
31
|
+
return !!block && slotBlocks(block, slot).length === 0;
|
|
28
32
|
}
|
|
29
33
|
export function labelText(value) {
|
|
30
34
|
return typeof value === 'string' ? value : value && typeof value === 'object' ? Object.values(value).find((item)=>typeof item === 'string') : undefined;
|
|
@@ -18,6 +18,7 @@ export declare const BLOCK_COPY: {
|
|
|
18
18
|
finishUnwrap: string;
|
|
19
19
|
deleted: string;
|
|
20
20
|
discarded: string;
|
|
21
|
+
neverDecided: string;
|
|
21
22
|
running: string;
|
|
22
23
|
stopped: string;
|
|
23
24
|
slotLabels: Record<string, string>;
|
|
@@ -34,8 +35,8 @@ export type BlockLinkedCopy = {
|
|
|
34
35
|
};
|
|
35
36
|
export declare const blockRunningUnwrap: BlockLinkedCopy;
|
|
36
37
|
export declare const blockDecidedUnwrap: BlockLinkedCopy;
|
|
37
|
-
export declare const blockFinishedCopy: (winner: string) => BlockLinkedCopy;
|
|
38
|
-
export declare const blockFinishedStatus: (winner: string) => string;
|
|
38
|
+
export declare const blockFinishedCopy: (winner: string, originalWon?: boolean, emptyWinner?: boolean) => BlockLinkedCopy;
|
|
39
|
+
export declare const blockFinishedStatus: (winner: string, originalWon?: boolean) => string;
|
|
39
40
|
export declare const blockDeleteConfirmation: (name: string) => string;
|
|
40
41
|
export declare const blockUnwrapConfirmation: (name: string) => string;
|
|
41
42
|
export declare const blockUnwrapNotice: (drafts: boolean, deleted: boolean) => string;
|
|
@@ -18,7 +18,8 @@ export const BLOCK_COPY = {
|
|
|
18
18
|
noLongerDraft: API_MESSAGES.testNoLongerDraft,
|
|
19
19
|
finishUnwrap: 'The test was removed; use Unwrap to finish.',
|
|
20
20
|
deleted: "This block's test was deleted; the page shows the Original.",
|
|
21
|
-
discarded: '
|
|
21
|
+
discarded: 'Winner discarded: this block shows the Original. Use Unwrap to replace it with the Original content.',
|
|
22
|
+
neverDecided: 'Archived without a winner: this block shows the Original. Use Unwrap to replace it with the Original content.',
|
|
22
23
|
running: "Running: visitors see different versions. Edit a version's tab to change it; the change is noted on the results.",
|
|
23
24
|
stopped: 'Stopped: visitors see the Original.',
|
|
24
25
|
slotLabels: {
|
|
@@ -49,13 +50,13 @@ export const blockDecidedUnwrap = {
|
|
|
49
50
|
link: 'the test',
|
|
50
51
|
after: '.'
|
|
51
52
|
};
|
|
52
|
-
export const blockFinishedCopy = (winner)=>({
|
|
53
|
-
before:
|
|
53
|
+
export const blockFinishedCopy = (winner, originalWon = false, emptyWinner = false)=>({
|
|
54
|
+
before: emptyWinner ? 'Archived: the winner has no content here, so visitors see the Original. Unwrap leaves the page as visitors see it now. View the results on ' : originalWon ? `Archived: the Original won. This block shows ${winner}. Use Unwrap to keep its content without the Experiment block. View the results on ` : `Archived: this block keeps serving ${winner}, with the Original as a fallback if it is empty. To replace it, copy the content into ordinary page blocks, then remove this Experiment block. View the results on `,
|
|
54
55
|
link: 'the test',
|
|
55
|
-
after: '
|
|
56
|
+
after: '.'
|
|
56
57
|
});
|
|
57
|
-
export const blockFinishedStatus = (winner)=>{
|
|
58
|
-
const copy = blockFinishedCopy(winner);
|
|
58
|
+
export const blockFinishedStatus = (winner, originalWon = false)=>{
|
|
59
|
+
const copy = blockFinishedCopy(winner, originalWon);
|
|
59
60
|
return copy.before + copy.link + copy.after;
|
|
60
61
|
};
|
|
61
62
|
export const blockDeleteConfirmation = (name)=>`Delete the draft test ${name} and put the Original back in its place? Deleting the test can't be undone.`;
|
|
@@ -22,7 +22,8 @@ export function ResultsRoute(props) {
|
|
|
22
22
|
}
|
|
23
23
|
function ManagedResults({ id, surface, onTitleChange }) {
|
|
24
24
|
const test = useTestDocument(id, {
|
|
25
|
-
apiRoute: surface.apiRoute
|
|
25
|
+
apiRoute: surface.apiRoute,
|
|
26
|
+
contentLocale: surface.contentLocale
|
|
26
27
|
});
|
|
27
28
|
useEffect(()=>{
|
|
28
29
|
if (test.doc?.name) onTitleChange?.(test.doc.name);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { SurfaceShellProps } from './SurfaceShell.js';
|
|
2
2
|
import type { ReadinessContext } from '../../testSurface/surface/readiness/readiness.model.js';
|
|
3
|
-
export declare function TestsHome({ adminRoute, apiRoute, canManage, crumbs, flagPoints }: {
|
|
3
|
+
export declare function TestsHome({ adminRoute, apiRoute, contentLocale, canManage, crumbs, flagPoints }: {
|
|
4
4
|
adminRoute: string;
|
|
5
5
|
apiRoute: string;
|
|
6
|
+
contentLocale?: string;
|
|
6
7
|
canManage?: boolean;
|
|
7
8
|
crumbs?: SurfaceShellProps['crumbs'];
|
|
8
9
|
flagPoints?: ReadinessContext['flagPoints'];
|
|
@@ -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 { DeleteTest } from '../../testSurface/surface/test/DeleteTest.js';
|
|
4
|
+
import { DELETE_TEST } from '../../testSurface/copy/testPage.js';
|
|
3
5
|
import { surfaceUrls } from '../../testSurface/surfaceUrls.js';
|
|
4
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
6
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
5
7
|
import { formatAdminURL } from 'payload/shared';
|
|
6
8
|
import { fetchAllDocs } from '../../lib/fetchAllDocs.js';
|
|
7
9
|
import { createApi } from '../../testSurface/api.js';
|
|
@@ -28,7 +30,7 @@ const HOME_FIELDS = [
|
|
|
28
30
|
const homeFieldsComplete = true;
|
|
29
31
|
void homeFieldsComplete;
|
|
30
32
|
const HOME_SELECT = HOME_FIELDS.map((field)=>`select[${field}]=true`).join('&');
|
|
31
|
-
export function TestsHome({ adminRoute, apiRoute, canManage = false, crumbs, flagPoints }) {
|
|
33
|
+
export function TestsHome({ adminRoute, apiRoute, contentLocale, canManage = false, crumbs, flagPoints }) {
|
|
32
34
|
const api = useMemo(()=>createApi(apiRoute), [
|
|
33
35
|
apiRoute
|
|
34
36
|
]);
|
|
@@ -37,6 +39,24 @@ export function TestsHome({ adminRoute, apiRoute, canManage = false, crumbs, fla
|
|
|
37
39
|
});
|
|
38
40
|
const [search, setSearch] = useState('');
|
|
39
41
|
const [attempt, setAttempt] = useState(0);
|
|
42
|
+
const [notice, setNotice] = useState();
|
|
43
|
+
const noticeRef = useRef(null);
|
|
44
|
+
useLayoutEffect(()=>{
|
|
45
|
+
if (notice) noticeRef.current?.focus();
|
|
46
|
+
}, [
|
|
47
|
+
notice
|
|
48
|
+
]);
|
|
49
|
+
useEffect(()=>{
|
|
50
|
+
const url = new URL(window.location.href);
|
|
51
|
+
const deleted = url.searchParams.get('deleted');
|
|
52
|
+
if (deleted === 'done' || deleted === 'already') setNotice({
|
|
53
|
+
outcome: deleted
|
|
54
|
+
});
|
|
55
|
+
if (url.searchParams.has('deleted')) {
|
|
56
|
+
url.searchParams.delete('deleted');
|
|
57
|
+
window.history.replaceState(window.history.state, '', `${url.pathname}${url.search}${url.hash}`);
|
|
58
|
+
}
|
|
59
|
+
}, []);
|
|
40
60
|
useEffect(()=>{
|
|
41
61
|
let active = true;
|
|
42
62
|
const controller = new AbortController();
|
|
@@ -120,7 +140,7 @@ export function TestsHome({ adminRoute, apiRoute, canManage = false, crumbs, fla
|
|
|
120
140
|
}),
|
|
121
141
|
children: SURFACE_COPY.newTest
|
|
122
142
|
});
|
|
123
|
-
return /*#__PURE__*/
|
|
143
|
+
return /*#__PURE__*/ _jsxs(SurfaceShell, {
|
|
124
144
|
adminRoute: adminRoute,
|
|
125
145
|
crumbs: crumbs,
|
|
126
146
|
actions: /*#__PURE__*/ _jsxs(_Fragment, {
|
|
@@ -161,37 +181,59 @@ export function TestsHome({ adminRoute, apiRoute, canManage = false, crumbs, fla
|
|
|
161
181
|
newTest
|
|
162
182
|
]
|
|
163
183
|
}),
|
|
164
|
-
children:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
184
|
+
children: [
|
|
185
|
+
/*#__PURE__*/ _jsx("p", {
|
|
186
|
+
ref: noticeRef,
|
|
187
|
+
role: "status",
|
|
188
|
+
"aria-atomic": "true",
|
|
189
|
+
tabIndex: -1,
|
|
190
|
+
"data-testid": "delete-notice",
|
|
191
|
+
children: notice ? notice.outcome === 'done' ? DELETE_TEST.deleted : DELETE_TEST.alreadyDeleted : ''
|
|
192
|
+
}),
|
|
193
|
+
state.loading ? /*#__PURE__*/ _jsx("p", {
|
|
194
|
+
role: "status",
|
|
195
|
+
children: SURFACE_COPY.loading
|
|
196
|
+
}) : state.error ? /*#__PURE__*/ _jsx(Banner, {
|
|
197
|
+
tone: "error",
|
|
198
|
+
action: retry,
|
|
199
|
+
children: SURFACE_COPY.loadError
|
|
200
|
+
}) : /*#__PURE__*/ _jsxs(_Fragment, {
|
|
201
|
+
children: [
|
|
202
|
+
state.summaryError ? /*#__PURE__*/ _jsx(Banner, {
|
|
203
|
+
tone: "error",
|
|
204
|
+
action: retry,
|
|
205
|
+
children: SURFACE_COPY.summaryError
|
|
206
|
+
}) : null,
|
|
207
|
+
state.tests.length === 0 ? /*#__PURE__*/ _jsx(EmptyState, {
|
|
208
|
+
action: newTest,
|
|
209
|
+
children: SURFACE_COPY.empty
|
|
210
|
+
}) : /*#__PURE__*/ _jsx(TestGroups, {
|
|
211
|
+
tests: state.tests,
|
|
212
|
+
summaries: state.summaries,
|
|
213
|
+
goalNames: state.goalNames,
|
|
214
|
+
adminRoute: adminRoute,
|
|
215
|
+
apiRoute: apiRoute,
|
|
216
|
+
contentLocale: contentLocale,
|
|
217
|
+
canManage: canManage,
|
|
218
|
+
onDeleted: (id, outcome)=>{
|
|
219
|
+
setNotice({
|
|
220
|
+
outcome
|
|
221
|
+
});
|
|
222
|
+
setState((current)=>!current.loading && !current.error ? {
|
|
223
|
+
...current,
|
|
224
|
+
tests: current.tests.filter((test)=>String(test.id) !== String(id))
|
|
225
|
+
} : current);
|
|
226
|
+
},
|
|
227
|
+
flagPoints: flagPoints,
|
|
228
|
+
search: search,
|
|
229
|
+
clear: ()=>setSearch('')
|
|
230
|
+
})
|
|
231
|
+
]
|
|
232
|
+
})
|
|
233
|
+
]
|
|
192
234
|
});
|
|
193
235
|
}
|
|
194
|
-
function TestGroups({ tests, summaries, goalNames, adminRoute, flagPoints, search, clear }) {
|
|
236
|
+
function TestGroups({ tests, summaries, goalNames, adminRoute, apiRoute, contentLocale, canManage, onDeleted, flagPoints, search, clear }) {
|
|
195
237
|
const groups = groupTests(tests, summaries, search);
|
|
196
238
|
if (!groups.some((group)=>group.tests.length)) return /*#__PURE__*/ _jsxs("div", {
|
|
197
239
|
className: "xp-tests-no-matches",
|
|
@@ -253,11 +295,23 @@ function TestGroups({ tests, summaries, goalNames, adminRoute, flagPoints, searc
|
|
|
253
295
|
})
|
|
254
296
|
]
|
|
255
297
|
}),
|
|
256
|
-
/*#__PURE__*/
|
|
257
|
-
className: "xp-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
298
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
299
|
+
className: "xp-ui-button-group",
|
|
300
|
+
children: [
|
|
301
|
+
/*#__PURE__*/ _jsx(DeleteTest, {
|
|
302
|
+
test: test,
|
|
303
|
+
canManage: canManage,
|
|
304
|
+
apiRoute: apiRoute,
|
|
305
|
+
contentLocale: contentLocale,
|
|
306
|
+
onDeleted: (outcome)=>onDeleted(test.id, outcome)
|
|
307
|
+
}),
|
|
308
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
309
|
+
className: "xp-tests-row-action",
|
|
310
|
+
size: "sm",
|
|
311
|
+
href: card.href,
|
|
312
|
+
children: card.action
|
|
313
|
+
})
|
|
314
|
+
]
|
|
261
315
|
})
|
|
262
316
|
]
|
|
263
317
|
}, test.id);
|
|
@@ -22,6 +22,8 @@ function SurfacePage(props) {
|
|
|
22
22
|
const surface = {
|
|
23
23
|
adminRoute: props.adminRoute,
|
|
24
24
|
apiRoute: props.apiRoute,
|
|
25
|
+
contentLocale: props.contentLocale,
|
|
26
|
+
contentLanguageLabels: props.contentLanguageLabels,
|
|
25
27
|
canManage: props.canManage,
|
|
26
28
|
canReadResults: props.canReadResults,
|
|
27
29
|
isAdmin: props.isAdmin,
|
|
@@ -48,6 +50,7 @@ function SurfacePage(props) {
|
|
|
48
50
|
if (props.route === 'home') return /*#__PURE__*/ _jsx(TestsHome, {
|
|
49
51
|
adminRoute: props.adminRoute,
|
|
50
52
|
apiRoute: props.apiRoute,
|
|
53
|
+
contentLocale: props.contentLocale,
|
|
51
54
|
canManage: props.canManage,
|
|
52
55
|
flagPoints: props.flagPoints,
|
|
53
56
|
crumbs: crumbs
|
|
@@ -24,6 +24,7 @@ import { useTransition } from '../../../testSurface/surface/readiness/useTransit
|
|
|
24
24
|
const [step, setStep] = useState(collections.length > 1 ? 'collection' : 'control');
|
|
25
25
|
const test = useTestDocument(id, {
|
|
26
26
|
apiRoute: surface.apiRoute,
|
|
27
|
+
contentLocale: surface.contentLocale,
|
|
27
28
|
refetchPreflightOnFocus: step === 'review'
|
|
28
29
|
});
|
|
29
30
|
const testUrl = formatAdminURL({
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useLocale } from '@payloadcms/ui';
|
|
4
|
+
import { TestsSurface as Surface } from '../surface/TestsSurface.js';
|
|
5
|
+
/** Payload context stays at the admin entry; the mountable surface stays neutral. */ export function TestsSurface(props) {
|
|
6
|
+
const locale = useLocale();
|
|
7
|
+
return /*#__PURE__*/ _jsx(Surface, {
|
|
8
|
+
...props,
|
|
9
|
+
contentLocale: locale?.code
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { placementLanguageNames } from '../../blocks/placementLanguages.js';
|
|
2
|
+
import { placementReader } from '../../blocks/placementLocale.js';
|
|
1
3
|
import { flattenTopLevelFields, formatAdminURL } from 'payload/shared';
|
|
2
4
|
import { serializeAttributeKeys, serializeFlagPoints, serializeMetricSources } from '../../collections/serialize.js';
|
|
3
5
|
import { serializePageCollections } from '../pageCollections.js';
|
|
4
6
|
import { collectionLabel as resolveLabel } from '../../collections/labels.js';
|
|
5
|
-
import {
|
|
7
|
+
import { puckCollections } from '../../options.js';
|
|
6
8
|
import { xpOptionsFromReq } from '../../options/fromReq.js';
|
|
7
9
|
import { routeAccess } from './access.model.js';
|
|
8
10
|
export async function buildSurfaceProps({ req, route, id, searchParams }) {
|
|
@@ -71,8 +73,10 @@ export async function buildSurfaceProps({ req, route, id, searchParams }) {
|
|
|
71
73
|
}
|
|
72
74
|
});
|
|
73
75
|
// The new-test list uses the latest draft's editing intent, as the "Test a block" field condition does (§4.1).
|
|
74
|
-
return result.docs.map((
|
|
75
|
-
const
|
|
76
|
+
return result.docs.map((row)=>{
|
|
77
|
+
const placement = placementReader(req, collection, options).read(row, req.locale === 'all' ? 'all-locales' : 'localized');
|
|
78
|
+
const doc = placement.doc;
|
|
79
|
+
const editor = placement.editor;
|
|
76
80
|
if (editor !== 'puck' && editor !== 'blocks') return null;
|
|
77
81
|
const id = doc.id;
|
|
78
82
|
const customUrl = options.admin?.editorUrl?.({
|
|
@@ -111,6 +115,9 @@ export async function buildSurfaceProps({ req, route, id, searchParams }) {
|
|
|
111
115
|
},
|
|
112
116
|
adminRoute,
|
|
113
117
|
apiRoute: req.payload.config.routes.api,
|
|
118
|
+
...req.payload.config.localization ? {
|
|
119
|
+
contentLanguageLabels: placementLanguageNames(req, req.payload.config.localization.localeCodes)
|
|
120
|
+
} : {},
|
|
114
121
|
canManage,
|
|
115
122
|
canReadResults,
|
|
116
123
|
isAdmin,
|
package/dist/blocks/bindings.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { puckExperimentSlug } from '../puck/experimentSlug.js';
|
|
1
2
|
import { walkVisiblePuck } from '../puck/visibility.js';
|
|
2
3
|
import { documentEditor, puckCollections } from '../options.js';
|
|
3
|
-
import { EXPERIMENT_BLOCK_SLUG, hostBlocks
|
|
4
|
+
import { EXPERIMENT_BLOCK_SLUG, hostBlocks } from './model.js';
|
|
4
5
|
/** Same document-kind rule as the scan; Payload blocks are top level, Puck is recursive. */ export function placementSlugs(options, collection, doc) {
|
|
5
6
|
if (!doc) return [];
|
|
6
7
|
const editor = documentEditor(options, collection, doc);
|
|
@@ -18,7 +19,7 @@ import { EXPERIMENT_BLOCK_SLUG, hostBlocks, isObject } from './model.js';
|
|
|
18
19
|
const found = new Set();
|
|
19
20
|
if (registration) walkVisiblePuck(doc[registration.field], (node, visibility)=>{
|
|
20
21
|
if (visibility.hidden || node.type !== 'ExperimentSlot') return;
|
|
21
|
-
const
|
|
22
|
+
const slug = puckExperimentSlug(node.props.experiment);
|
|
22
23
|
if (typeof slug === 'string') found.add(slug);
|
|
23
24
|
});
|
|
24
25
|
return [
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
/** One language naming rule for placement lists and visitor-impact details. */
|
|
3
|
+
export declare function placementLanguages(req: PayloadRequest, codes: readonly string[]): {
|
|
4
|
+
locales?: string[];
|
|
5
|
+
allLocales?: true;
|
|
6
|
+
};
|
|
7
|
+
export declare function placementLanguageNames(req: PayloadRequest, codes: readonly string[]): string[];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getTranslation } from '@payloadcms/translations';
|
|
2
|
+
/** One language naming rule for placement lists and visitor-impact details. */ export function placementLanguages(req, codes) {
|
|
3
|
+
const localization = req.payload.config.localization;
|
|
4
|
+
const unique = [
|
|
5
|
+
...new Set(codes.filter(Boolean))
|
|
6
|
+
];
|
|
7
|
+
if (localization && unique.length === localization.localeCodes.length) return {
|
|
8
|
+
allLocales: true
|
|
9
|
+
};
|
|
10
|
+
const locales = placementLanguageNames(req, unique);
|
|
11
|
+
return locales.length ? {
|
|
12
|
+
locales
|
|
13
|
+
} : {};
|
|
14
|
+
}
|
|
15
|
+
export function placementLanguageNames(req, codes) {
|
|
16
|
+
const localization = req.payload.config.localization;
|
|
17
|
+
const unique = [
|
|
18
|
+
...new Set(codes.filter(Boolean))
|
|
19
|
+
];
|
|
20
|
+
return unique.map((code)=>{
|
|
21
|
+
const label = localization && localization.locales.find((entry)=>entry.code === code)?.label;
|
|
22
|
+
return label ? getTranslation(label, req.i18n ?? {
|
|
23
|
+
language: 'en',
|
|
24
|
+
fallbackLanguage: 'en'
|
|
25
|
+
}) || code : code;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { type PayloadRequest } from 'payload';
|
|
2
|
-
import type { DocId } from '../types/contracts.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import type { DocId, ResolvedOptions } from '../types/contracts.js';
|
|
3
|
+
export type PlacementInput = 'all-locales' | 'localized';
|
|
4
|
+
export declare function placementLocaleContent(req: PayloadRequest, collection: string, doc: Record<string, unknown> | undefined, input: PlacementInput): Record<string, unknown> | undefined;
|
|
5
|
+
/** The single document → locale view → editor/placements boundary. Compiled schemas are shared per sanitized config.
|
|
6
|
+
* Local API and form documents explicitly bypass all-locale projection.
|
|
6
7
|
*/
|
|
7
|
-
export declare function
|
|
8
|
+
export declare function placementReader(req: PayloadRequest, collection: string, options?: Pick<ResolvedOptions, "puck" | "blocks">): {
|
|
9
|
+
views: PlacementLocaleView[];
|
|
10
|
+
documentViews: PlacementLocaleView[];
|
|
11
|
+
read(doc: Record<string, unknown> | null | undefined, input: PlacementInput, view?: PlacementLocaleView): {
|
|
12
|
+
view: PlacementLocaleView;
|
|
13
|
+
readonly doc: Record<string, unknown> | undefined;
|
|
14
|
+
readonly editor: "page" | "puck" | "blocks";
|
|
15
|
+
readonly slugs: string[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare function allPlacementSlugs(req: PayloadRequest, collection: string, doc: Record<string, unknown> | undefined, input: PlacementInput): string[];
|
|
8
19
|
export interface PlacementLocaleView {
|
|
9
20
|
locale: string;
|
|
10
21
|
fallbackLocale: import('payload').TypedFallbackLocale;
|
|
@@ -13,11 +24,14 @@ export declare const placementDocumentKey: (collection: string, id: DocId, view:
|
|
|
13
24
|
export type RemovedPlacementViews = Map<string, PlacementLocaleView[]>;
|
|
14
25
|
export declare function localeRequest(req: PayloadRequest, view: PlacementLocaleView): PayloadRequest;
|
|
15
26
|
/** Canonical views of registered content, without multiplying nonlocalized rows. */
|
|
16
|
-
export declare function placementLocaleViews(req: PayloadRequest, collection: string): PlacementLocaleView[];
|
|
27
|
+
export declare function placementLocaleViews(req: PayloadRequest, collection: string, options?: Pick<ResolvedOptions, "puck" | "blocks">): PlacementLocaleView[];
|
|
17
28
|
/** Compare every locale view: a localized edit can also change fallback
|
|
18
29
|
* content in another locale. Whole-row removals replace every view with absence.
|
|
19
30
|
* The incoming hook document is already flattened to the writing locale.
|
|
20
31
|
*/
|
|
21
|
-
export declare function removedPlacementViews(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>, removingPage: boolean): RemovedPlacementViews;
|
|
32
|
+
export declare function removedPlacementViews(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>, removingPage: boolean, input?: PlacementInput): RemovedPlacementViews;
|
|
22
33
|
/** Rebuild unchanged locale maps around a flattened hook write before reading each view. */
|
|
23
34
|
export declare function mergedPlacementLocales(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>): Record<string, unknown>;
|
|
35
|
+
/** Project host document adapters before they run. Callers own path normalization
|
|
36
|
+
* and use sortLockKeys for the existing experiment → page-path lock ordering. */
|
|
37
|
+
export declare function placementDocumentPaths(req: PayloadRequest, collection: string, docs: Array<Record<string, unknown> | undefined>, input: PlacementInput, pathOf: (doc: Record<string, unknown>) => string | null): string[];
|