@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.
Files changed (135) hide show
  1. package/dist/admin/blocks/BlockPanel.js +6 -4
  2. package/dist/admin/blocks/inject.js +1 -0
  3. package/dist/admin/blocks/model.d.ts +3 -2
  4. package/dist/admin/blocks/model.js +8 -4
  5. package/dist/admin/copy/blocks.d.ts +3 -2
  6. package/dist/admin/copy/blocks.js +7 -6
  7. package/dist/admin/surface/ResultsRoute.js +2 -1
  8. package/dist/admin/surface/TestsHome.d.ts +2 -1
  9. package/dist/admin/surface/TestsHome.js +91 -37
  10. package/dist/admin/surface/TestsSurface.js +3 -0
  11. package/dist/admin/surface/home.model.d.ts +2 -0
  12. package/dist/admin/surface/newTest/PageWizard.js +1 -0
  13. package/dist/admin/surface/newTest/newTest.css +1 -1
  14. package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
  15. package/dist/admin/views/TestsSurfaceClient.js +11 -0
  16. package/dist/admin/views/buildSurfaceProps.js +10 -3
  17. package/dist/blocks/bindings.js +3 -2
  18. package/dist/blocks/placementLanguages.d.ts +7 -0
  19. package/dist/blocks/placementLanguages.js +27 -0
  20. package/dist/blocks/placementLocale.d.ts +21 -7
  21. package/dist/blocks/placementLocale.js +218 -67
  22. package/dist/db/appends.d.ts +13 -0
  23. package/dist/db/appends.js +49 -0
  24. package/dist/db/bulkPlacementRemoval.js +8 -4
  25. package/dist/endpoints/contentLocale.d.ts +6 -0
  26. package/dist/endpoints/contentLocale.js +15 -0
  27. package/dist/endpoints/deleteImpact.d.ts +6 -0
  28. package/dist/endpoints/deleteImpact.js +206 -0
  29. package/dist/endpoints/index.js +7 -0
  30. package/dist/endpoints/pages.js +7 -3
  31. package/dist/endpoints/placementStatus.js +6 -1
  32. package/dist/endpoints/preflight.d.ts +1 -1
  33. package/dist/endpoints/preflight.js +17 -2
  34. package/dist/exports/adminClient.d.ts +1 -1
  35. package/dist/exports/adminClient.js +1 -1
  36. package/dist/exports/index.d.ts +1 -1
  37. package/dist/goals/fairness.js +38 -31
  38. package/dist/hooks/blockRemovalRule.d.ts +2 -2
  39. package/dist/hooks/blockRemovalRule.js +16 -14
  40. package/dist/hooks/pageGuard.d.ts +3 -0
  41. package/dist/hooks/pageGuard.js +33 -23
  42. package/dist/hooks/puckNestedTests.d.ts +8 -0
  43. package/dist/hooks/puckNestedTests.js +36 -0
  44. package/dist/lib/placementPages.d.ts +2 -1
  45. package/dist/lib/placementPages.js +10 -2
  46. package/dist/manifest/compile.d.ts +2 -1
  47. package/dist/manifest/compile.js +5 -1
  48. package/dist/puck/ExperimentPicker.js +40 -37
  49. package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
  50. package/dist/puck/editor/ConfigureTestDrawer.js +4 -2
  51. package/dist/puck/editor/ExperimentSlotEditor.js +135 -104
  52. package/dist/puck/editor/LeftoverVersions.d.ts +1 -1
  53. package/dist/puck/editor/LeftoverVersions.js +40 -43
  54. package/dist/puck/editor/VersionBuilder.d.ts +18 -1
  55. package/dist/puck/editor/VersionBuilder.js +217 -39
  56. package/dist/puck/editor/blockClipboard.d.ts +16 -0
  57. package/dist/puck/editor/blockClipboard.js +20 -0
  58. package/dist/puck/editor/copy.d.ts +8 -1
  59. package/dist/puck/editor/copy.js +9 -1
  60. package/dist/puck/editor/editor.chrome.css +117 -3
  61. package/dist/puck/editor/editor.css +130 -8
  62. package/dist/puck/editor/editor.model.d.ts +2 -1
  63. package/dist/puck/editor/editor.model.js +2 -2
  64. package/dist/puck/editor/localPlacements.d.ts +1 -0
  65. package/dist/puck/editor/localPlacements.js +12 -0
  66. package/dist/puck/editor/placementsCache.d.ts +18 -12
  67. package/dist/puck/editor/placementsCache.js +52 -47
  68. package/dist/puck/editor/usePlacementNotice.d.ts +1 -1
  69. package/dist/puck/editor/usePlacementNotice.js +4 -3
  70. package/dist/puck/experimentSlug.d.ts +2 -0
  71. package/dist/puck/experimentSlug.js +3 -0
  72. package/dist/puck/nestedTestCopy.d.ts +8 -0
  73. package/dist/puck/nestedTestCopy.js +22 -0
  74. package/dist/puck/nestedTests.d.ts +17 -0
  75. package/dist/puck/nestedTests.js +30 -0
  76. package/dist/puck/slotConfig.d.ts +1 -1
  77. package/dist/puck/slotConfig.js +17 -4
  78. package/dist/puck/visibility.d.ts +2 -3
  79. package/dist/puck/visibility.js +11 -7
  80. package/dist/server/recordContentChange.js +34 -19
  81. package/dist/server/resolveExperimentData.js +2 -2
  82. package/dist/testSurface/PreviewLinks.js +6 -2
  83. package/dist/testSurface/api.d.ts +6 -3
  84. package/dist/testSurface/api.js +10 -6
  85. package/dist/testSurface/contentLocaleURL.d.ts +2 -0
  86. package/dist/testSurface/contentLocaleURL.js +3 -0
  87. package/dist/testSurface/copy/common.d.ts +4 -0
  88. package/dist/testSurface/copy/common.js +8 -4
  89. package/dist/testSurface/copy/languages.d.ts +11 -0
  90. package/dist/testSurface/copy/languages.js +7 -0
  91. package/dist/testSurface/copy/readiness.d.ts +1 -1
  92. package/dist/testSurface/copy/readiness.js +1 -1
  93. package/dist/testSurface/copy/testPage.d.ts +21 -0
  94. package/dist/testSurface/copy/testPage.js +21 -0
  95. package/dist/testSurface/placementLabel.d.ts +8 -0
  96. package/dist/testSurface/placementLabel.js +24 -0
  97. package/dist/testSurface/placements/placementLabels.d.ts +2 -0
  98. package/dist/testSurface/placements/placementLabels.js +2 -1
  99. package/dist/testSurface/results/results.css +1 -1
  100. package/dist/testSurface/surface/contracts.d.ts +2 -0
  101. package/dist/testSurface/surface/editorPlacement.d.ts +5 -0
  102. package/dist/testSurface/surface/editorPlacement.js +18 -0
  103. package/dist/testSurface/surface/pageBlock/pageBlock.model.js +2 -1
  104. package/dist/testSurface/surface/pageBlock/parts.js +24 -6
  105. package/dist/testSurface/surface/readiness/readiness.model.js +9 -2
  106. package/dist/testSurface/surface/results/useResults.d.ts +4 -1
  107. package/dist/testSurface/surface/test/DeleteTest.d.ts +15 -0
  108. package/dist/testSurface/surface/test/DeleteTest.js +171 -0
  109. package/dist/testSurface/surface/test/TestSurface.js +29 -9
  110. package/dist/testSurface/surface/useTestDocument.d.ts +2 -1
  111. package/dist/testSurface/surface/useTestDocument.js +20 -4
  112. package/dist/testSurface/useApi.d.ts +4 -1
  113. package/dist/transitions/checkStart.d.ts +4 -1
  114. package/dist/transitions/checkStart.js +117 -14
  115. package/dist/transitions/contentFields.js +9 -5
  116. package/dist/transitions/makeContent.js +5 -4
  117. package/dist/transitions/nestedPlacementNames.d.ts +5 -0
  118. package/dist/transitions/nestedPlacementNames.js +33 -0
  119. package/dist/transitions/pageVersions.js +3 -1
  120. package/dist/transitions/placementInteractions.js +7 -4
  121. package/dist/transitions/placements.d.ts +26 -1
  122. package/dist/transitions/placements.js +219 -56
  123. package/dist/transitions/preflightData.d.ts +2 -1
  124. package/dist/transitions/preflightData.js +66 -3
  125. package/dist/transitions/start.js +4 -1
  126. package/dist/types/endpoints.d.ts +35 -1
  127. package/dist/types/endpoints.js +1 -1
  128. package/dist/types/surface.d.ts +2 -0
  129. package/dist/ui/Button.js +2 -2
  130. package/dist/ui/Inputs.d.ts +4 -3
  131. package/dist/ui/Inputs.js +9 -9
  132. package/dist/ui/SelectControl.d.ts +33 -0
  133. package/dist/ui/SelectControl.js +504 -0
  134. package/dist/ui/ui.css +13 -5
  135. package/package.json +3 -2
@@ -5,8 +5,10 @@ import { Button } from '../../../ui/Button.js';
5
5
  import { placementPages } from '../../../lib/placementPages.js';
6
6
  import { TEST_PAGE as C, placementCount } from '../../copy/testPage.js';
7
7
  import { placementLine, slotReady } from './pageBlock.model.js';
8
+ import { placementLabel, placementGroupLabel } from '../../placementLabel.js';
8
9
  function Binding({ test, surface }) {
9
10
  const placements = test.preflight?.placements ?? [];
11
+ const pages = placementPages(placements);
10
12
  return /*#__PURE__*/ _jsx("div", {
11
13
  className: "xp-page-binding",
12
14
  children: surface.editorPlacementMessage ? test.doc?.status === 'running' ? /*#__PURE__*/ _jsxs(Banner, {
@@ -20,7 +22,7 @@ function Binding({ test, surface }) {
20
22
  ]
21
23
  }) : null : placements.length ? /*#__PURE__*/ _jsxs(_Fragment, {
22
24
  children: [
23
- placementPages(placements).map((placement)=>/*#__PURE__*/ _jsxs("p", {
25
+ pages.map((placement)=>/*#__PURE__*/ _jsxs("p", {
24
26
  className: "xp-ui-button-group",
25
27
  children: [
26
28
  placementLine(placement),
@@ -30,6 +32,7 @@ function Binding({ test, surface }) {
30
32
  variant: "link",
31
33
  size: "sm",
32
34
  href: placement.editorUrl,
35
+ "aria-label": pages.length > 1 ? `${C.openPage}: ${placementLabel(placement, true)}` : undefined,
33
36
  children: C.openPage
34
37
  }) : null
35
38
  ]
@@ -43,7 +46,7 @@ function Binding({ test, surface }) {
43
46
  })
44
47
  });
45
48
  }
46
- function VersionContent({ test, armIndex, summary }) {
49
+ function VersionContent({ test, surface, armIndex, summary }) {
47
50
  const arm = test.doc?.arms[armIndex];
48
51
  if (!arm) return null;
49
52
  if (arm.kind === 'holdout') return /*#__PURE__*/ _jsx("span", {
@@ -52,6 +55,15 @@ function VersionContent({ test, armIndex, summary }) {
52
55
  });
53
56
  const placements = test.preflight?.placements ?? [];
54
57
  const pages = placementPages(placements);
58
+ const localized = pages.some((page)=>page.allLocales || page.locales?.length);
59
+ const editPages = new Map();
60
+ for (const page of pages){
61
+ if (!page.editorUrl) continue;
62
+ const key = localized ? page.editorUrl : page.key;
63
+ const group = editPages.get(key) ?? [];
64
+ group.push(page);
65
+ editPages.set(key, group);
66
+ }
55
67
  const ready = placements.length > 0 && placements.every((placement)=>slotReady(placement, arm));
56
68
  return /*#__PURE__*/ _jsxs("div", {
57
69
  className: "xp-version-content",
@@ -62,13 +74,19 @@ function VersionContent({ test, armIndex, summary }) {
62
74
  }),
63
75
  /*#__PURE__*/ _jsx("div", {
64
76
  className: "xp-ui-button-group",
65
- children: !summary ? pages.filter((page)=>page.editorUrl).map((page)=>/*#__PURE__*/ _jsx(Button, {
77
+ children: !summary ? [
78
+ ...editPages.values()
79
+ ].map((group)=>{
80
+ const page = group[0];
81
+ const label = localized ? `${C.editOnPage}: ${placementGroupLabel(group, surface.contentLanguageLabels)}` : C.editOnPage;
82
+ return /*#__PURE__*/ _jsx(Button, {
66
83
  variant: "link",
67
84
  size: "sm",
68
85
  href: page.editorUrl,
69
- "aria-label": pages.length > 1 ? `${C.editOnPage}: ${page.title}` : undefined,
70
- children: C.editOnPage
71
- }, page.key)) : null
86
+ "aria-label": localized ? label : pages.length > 1 ? `${C.editOnPage}: ${page.title}` : undefined,
87
+ children: label
88
+ }, page.key);
89
+ }) : null
72
90
  })
73
91
  ]
74
92
  });
@@ -1,3 +1,4 @@
1
+ import { nestedTestCopy } from '../../../puck/nestedTestCopy.js';
1
2
  import { SURFACE_COPY } from '../../copy/surface.js';
2
3
  import { formatDate } from '../../format/date.js';
3
4
  import { actionGroupLabel } from '../../actions/actions.model.js';
@@ -13,6 +14,10 @@ const group = (key, ctx)=>{
13
14
  const found = ctx.arms.find((item)=>item.key === key);
14
15
  return found ? actionGroupLabel(found.key, found.label) : C.groupFallback;
15
16
  };
17
+ const hasLanguages = (value)=>object(value).allLocales === true || Array.isArray(object(value).locales);
18
+ const detailRows = (detail)=>Array.isArray(detail) && detail.length && detail.some(hasLanguages) ? detail : [
19
+ first(detail)
20
+ ];
16
21
  const row = (section, next)=>({
17
22
  section,
18
23
  next
@@ -36,15 +41,17 @@ const versions = row('versions', (detail)=>versionsNext(detailText(detail, C.ver
36
41
  nextStep: 'Publish the page'
37
42
  },
38
43
  'duplicate-version-row': {
39
- ...row('versions', (detail)=>`The Experiment block on ${text(first(detail).title, 'this page')} has the same version twice. Remove one of them, then save.`),
40
- nextStep: (detail)=>`Edit ${text(first(detail).title, 'this page')}`
44
+ ...row('versions', (detail)=>detailRows(detail).map((value)=>`The Experiment block on ${text(object(value).title, 'this page')} has the same version twice. Remove one of them, then save.`).join('\n')),
45
+ nextStep: (detail)=>detailRows(detail).map((value)=>`Edit ${text(object(value).title, 'this page')}`).join('\n')
41
46
  },
47
+ 'nested-tests': row('versions', (detail)=>nestedTestCopy.readiness(detail)),
42
48
  'interacting-tests': {
43
49
  ...row('versions', (detail)=>interactingTestsCopy(text(first(detail).path, 'this page'), text(first(detail).status, 'running'), text(first(detail).name, 'another test'), first(detail).version === true)),
44
50
  nextStep: (detail)=>`Open ${text(first(detail).name, 'the test')}${first(detail).version === true ? `\nEdit ${text(first(detail).path, 'this page')}` : ''}`
45
51
  },
46
52
  'empty-slot': row('versions', (detail, ctx)=>{
47
53
  const placements = Array.isArray(detail) ? detail : [];
54
+ if (placements.some(hasLanguages)) return placements.flatMap((placement)=>ctx.arms.filter((arm)=>arm.kind !== 'holdout' && (!arm.slot || !(Number(object(object(placement).slots)[arm.slot]) > 0))).map((arm)=>contentNext(group(arm.key, ctx), text(object(placement).title, 'the page')))).join('\n');
48
55
  const missing = ctx.arms.find((item)=>item.kind !== 'holdout' && placements.some((placement)=>{
49
56
  const slots = object(object(placement).slots);
50
57
  return !item.slot || !(typeof slots[item.slot] === 'number' && Number(slots[item.slot]) > 0);
@@ -35,7 +35,9 @@ export declare function useResults(id: DocId, { apiRoute, canReadResults, canMan
35
35
  ok: true;
36
36
  data: DocId;
37
37
  }>;
38
- deleteTest: (id: DocId) => Promise<ApiResult<unknown>>;
38
+ deleteTest: (id: DocId, { draft }?: {
39
+ draft?: boolean;
40
+ }) => Promise<ApiResult<unknown>>;
39
41
  wrapBlock: (body: import("../../../types/endpoints.js").WrapBlockBody) => Promise<ApiResult<Record<string, unknown>>>;
40
42
  pages: (query: {
41
43
  collection: string;
@@ -66,6 +68,7 @@ export declare function useResults(id: DocId, { apiRoute, canReadResults, canMan
66
68
  restoreContentEntry: (id: DocId, body: import("../../../types/endpoints.js").RestoreContentEntryBody) => Promise<ApiResult<import("../../../types/endpoints.js").RestoreContentEntryResult>>;
67
69
  archive: (id: DocId, body: import("../../../types/endpoints.js").ArchiveBody) => Promise<ApiResult<import("../../../types/endpoints.js").TransitionSuccess>>;
68
70
  clickKeys: (id: DocId) => Promise<ApiResult<import("../../../types/endpoints.js").ClickKeysResult>>;
71
+ deleteImpact: (id: DocId, signal?: AbortSignal) => Promise<ApiResult<import("../../../types/endpoints.js").DeleteImpactResult>>;
69
72
  preflight: (id: DocId) => Promise<ApiResult<import("../../../types/endpoints.js").PreflightResult>>;
70
73
  previewToken: (id: DocId, arm: string) => Promise<ApiResult<import("../../../types/endpoints.js").PreviewTokenResult>>;
71
74
  results: (id: DocId, options?: {
@@ -0,0 +1,15 @@
1
+ import type { DocId } from '../../../types/contracts.js';
2
+ export type DeleteOutcome = 'done' | 'already';
3
+ export declare const DELETE_IMPACT_TIMEOUT_MS = 15000;
4
+ /** Matches deleteExperiment's status guard; the server rechecks under its lock. */
5
+ export declare function DeleteTest({ test, canManage, apiRoute, contentLocale, onDeleted }: {
6
+ test: {
7
+ id: DocId;
8
+ name: string;
9
+ status: string;
10
+ };
11
+ canManage: boolean;
12
+ apiRoute: string;
13
+ contentLocale?: string;
14
+ onDeleted: (outcome: DeleteOutcome) => void;
15
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,171 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { placementLanguageSuffix } from '../../copy/languages.js';
4
+ import { useEffect, useRef, useState } from 'react';
5
+ import { createApi } from '../../api.js';
6
+ import { DELETE_TEST as C } from '../../copy/testPage.js';
7
+ import { Button } from '../../../ui/Button.js';
8
+ import { Dialog } from '../../../ui/Dialog.js';
9
+ const VISIBLE_PAGES = 5;
10
+ export const DELETE_IMPACT_TIMEOUT_MS = 15_000;
11
+ /** Matches deleteExperiment's status guard; the server rechecks under its lock. */ export function DeleteTest({ test, canManage, apiRoute, contentLocale, onDeleted }) {
12
+ const [open, setOpen] = useState(false);
13
+ const [busy, setBusy] = useState(false);
14
+ const pending = useRef(false);
15
+ const [error, setError] = useState();
16
+ const [impact, setImpact] = useState({
17
+ state: 'loading'
18
+ });
19
+ useEffect(()=>{
20
+ if (!open) return;
21
+ let current = true;
22
+ const controller = new AbortController();
23
+ const timer = setTimeout(()=>{
24
+ if (!current) return;
25
+ current = false;
26
+ controller.abort();
27
+ setImpact({
28
+ state: 'failed'
29
+ });
30
+ }, DELETE_IMPACT_TIMEOUT_MS);
31
+ setImpact({
32
+ state: 'loading'
33
+ });
34
+ void createApi(apiRoute, contentLocale).deleteImpact(test.id, controller.signal).then((result)=>{
35
+ if (!current) return;
36
+ clearTimeout(timer);
37
+ setImpact(result.ok && result.data && [
38
+ 'none',
39
+ 'block',
40
+ 'page'
41
+ ].includes(result.data.effect) ? {
42
+ state: 'ready',
43
+ data: result.data
44
+ } : {
45
+ state: 'failed'
46
+ });
47
+ });
48
+ return ()=>{
49
+ current = false;
50
+ clearTimeout(timer);
51
+ controller.abort();
52
+ };
53
+ }, [
54
+ open,
55
+ test.id,
56
+ apiRoute,
57
+ contentLocale
58
+ ]);
59
+ if (!canManage || ![
60
+ 'draft',
61
+ 'archived'
62
+ ].includes(test.status)) return null;
63
+ const checking = impact.state === 'loading';
64
+ async function remove() {
65
+ if (checking || pending.current) return;
66
+ pending.current = true;
67
+ setBusy(true);
68
+ setError(undefined);
69
+ const result = await createApi(apiRoute).deleteTest(test.id);
70
+ if (result.ok || result.status === 404) {
71
+ setOpen(false);
72
+ onDeleted(result.ok ? 'done' : 'already');
73
+ } else setError(result.message);
74
+ pending.current = false;
75
+ setBusy(false);
76
+ }
77
+ return /*#__PURE__*/ _jsxs(_Fragment, {
78
+ children: [
79
+ /*#__PURE__*/ _jsx(Button, {
80
+ variant: "quiet",
81
+ size: "sm",
82
+ onClick: ()=>{
83
+ setError(undefined);
84
+ setImpact({
85
+ state: 'loading'
86
+ });
87
+ setOpen(true);
88
+ },
89
+ children: C.action
90
+ }),
91
+ /*#__PURE__*/ _jsxs(Dialog, {
92
+ open: open,
93
+ title: C.title(test.name),
94
+ initialFocus: "cancel",
95
+ dismissible: !busy,
96
+ onClose: ()=>setOpen(false),
97
+ children: [
98
+ /*#__PURE__*/ _jsx("p", {
99
+ children: C.consequences
100
+ }),
101
+ /*#__PURE__*/ _jsx("p", {
102
+ children: C.content
103
+ }),
104
+ /*#__PURE__*/ _jsx("p", {
105
+ role: "status",
106
+ "aria-atomic": "true",
107
+ children: checking ? C.checking : impact.state === 'failed' ? C.checkFailed : impact.state === 'ready' ? impactSummary(impact.data) : ''
108
+ }),
109
+ impact.state === 'ready' ? /*#__PURE__*/ _jsx(ImpactDetails, {
110
+ impact: impact.data
111
+ }) : null,
112
+ error ? /*#__PURE__*/ _jsx("p", {
113
+ role: "alert",
114
+ children: error
115
+ }) : null,
116
+ /*#__PURE__*/ _jsxs("div", {
117
+ className: "xp-ui-button-group",
118
+ children: [
119
+ /*#__PURE__*/ _jsx(Button, {
120
+ "data-dialog-cancel": true,
121
+ disabled: busy,
122
+ onClick: ()=>setOpen(false),
123
+ children: C.cancel
124
+ }),
125
+ /*#__PURE__*/ _jsx(Button, {
126
+ variant: "danger",
127
+ disabled: checking,
128
+ "aria-disabled": busy || checking || undefined,
129
+ "aria-busy": busy || undefined,
130
+ onClick: ()=>void remove(),
131
+ children: C.action
132
+ })
133
+ ]
134
+ })
135
+ ]
136
+ })
137
+ ]
138
+ });
139
+ }
140
+ function impactSummary(impact) {
141
+ return impact.effect === 'none' ? C.noEffect : C.changedPages(impact.effect === 'block' ? impact.pageCount : impact.addresses.length);
142
+ }
143
+ function ImpactDetails({ impact }) {
144
+ if (impact.effect === 'none') return null;
145
+ const places = impact.effect === 'block' ? impact.placements.map((place)=>`${place.title}${place.path ? ` (${place.path})` : ''}${placementLanguageSuffix(place)}: ${C.versionChange(place.before.label, place.after.label)}`) : impact.addresses.map((path)=>`${path}: ${C.versionChange(impact.winnerPath, impact.afterPaths?.[path] ?? path)}`);
146
+ return /*#__PURE__*/ _jsxs(_Fragment, {
147
+ children: [
148
+ places.length ? /*#__PURE__*/ _jsxs(_Fragment, {
149
+ children: [
150
+ /*#__PURE__*/ _jsx("p", {
151
+ children: impact.effect === 'block' ? C.blockWinner(impact.controlLabel) : C.pageWinner
152
+ }),
153
+ /*#__PURE__*/ _jsx("p", {
154
+ children: C.currentSite
155
+ })
156
+ ]
157
+ }) : null,
158
+ places.length ? /*#__PURE__*/ _jsx("ul", {
159
+ children: places.slice(0, VISIBLE_PAGES).map((place, index)=>/*#__PURE__*/ _jsx("li", {
160
+ children: place
161
+ }, index))
162
+ }) : null,
163
+ places.length > VISIBLE_PAGES ? /*#__PURE__*/ _jsx("p", {
164
+ children: C.morePages(places.length - VISIBLE_PAGES)
165
+ }) : null,
166
+ impact.effect === 'block' && impact.unreadablePages > 0 ? /*#__PURE__*/ _jsx("p", {
167
+ children: C.unreadablePages(impact.unreadablePages, impact.pageCount)
168
+ }) : null
169
+ ]
170
+ });
171
+ }
@@ -1,5 +1,7 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { DeleteTest } from './DeleteTest.js';
4
+ import { surfaceUrls } from '../../surfaceUrls.js';
3
5
  import { useEffect, useState, useRef } from 'react';
4
6
  import { useTestDocument } from '../useTestDocument.js';
5
7
  import { API_MESSAGES } from '../../copy/common.js';
@@ -28,6 +30,7 @@ export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded
28
30
  const [barHeight, setBarHeight] = useState();
29
31
  const documentState = useTestDocument(id, {
30
32
  apiRoute: surface.apiRoute,
33
+ contentLocale: surface.contentLocale,
31
34
  refetchPreflightOnFocus: true,
32
35
  ...!surface.canManage ? {
33
36
  enabled: false
@@ -45,25 +48,29 @@ export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded
45
48
  const [placementRead, setPlacementRead] = useState();
46
49
  const placementKey = JSON.stringify([
47
50
  surface.apiRoute,
48
- String(id)
51
+ String(id),
52
+ ...surface.contentLocale ? [
53
+ surface.contentLocale
54
+ ] : []
49
55
  ]);
50
56
  const watching = embedded && surface.canManage && documentState.loadState === 'ready';
51
57
  useEffect(()=>{
52
58
  if (!embedded || !surface.canManage) return;
53
59
  return subscribePlacements(surface.apiRoute, id, ()=>setPlacementRead({
54
60
  key: placementKey,
55
- preflight: cachedPreflight(surface.apiRoute, id),
56
- read: cachedReadinessRead(surface.apiRoute, id),
57
- pending: placementsPending(surface.apiRoute, id),
58
- blocking: placementsBlocking(surface.apiRoute, id),
59
- error: placementReadError(surface.apiRoute, id)
60
- }));
61
+ preflight: cachedPreflight(surface.apiRoute, id, surface.contentLocale),
62
+ read: cachedReadinessRead(surface.apiRoute, id, surface.contentLocale),
63
+ pending: placementsPending(surface.apiRoute, id, surface.contentLocale),
64
+ blocking: placementsBlocking(surface.apiRoute, id, surface.contentLocale),
65
+ error: placementReadError(surface.apiRoute, id, surface.contentLocale)
66
+ }), surface.contentLocale);
61
67
  }, [
62
68
  surface.apiRoute,
63
69
  id,
64
70
  embedded,
65
71
  surface.canManage,
66
- placementKey
72
+ placementKey,
73
+ surface.contentLocale
67
74
  ]);
68
75
  const currentRead = documentState.loadState === 'ready' && placementRead?.key === placementKey ? placementRead : undefined;
69
76
  const preflight = currentRead ? currentRead.preflight ?? (currentRead.pending && !currentRead.error ? documentState.preflight : null) : documentState.preflight;
@@ -88,7 +95,7 @@ export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded
88
95
  editorPage,
89
96
  editorPlacementMessage: message
90
97
  };
91
- usePlacementNotice(surface.apiRoute, id, watching ? sharedDocument.preflightError ?? (placementFailed ? placementReadError(surface.apiRoute, id) : message) : undefined);
98
+ usePlacementNotice(surface.apiRoute, id, watching ? sharedDocument.preflightError ?? (placementFailed ? placementReadError(surface.apiRoute, id, surface.contentLocale) : message) : undefined, surface.contentLocale);
92
99
  const setup = documentState.doc?.status === 'draft' || documentState.doc?.status === 'stopped';
93
100
  const test = setup ? {
94
101
  ...sharedDocument,
@@ -190,6 +197,19 @@ export function TestSurface({ id, surface, onTitleChange, renderFrame, embedded
190
197
  /*#__PURE__*/ _jsx(AdvancedSection, {
191
198
  ...props
192
199
  }),
200
+ !embedded ? /*#__PURE__*/ _jsx("div", {
201
+ children: /*#__PURE__*/ _jsx(DeleteTest, {
202
+ test: test.doc,
203
+ canManage: surface.canManage,
204
+ apiRoute: surface.apiRoute,
205
+ contentLocale: surface.contentLocale,
206
+ onDeleted: (outcome)=>{
207
+ window.location.assign(surfaceUrls.home(surface.adminRoute, {
208
+ deleted: outcome
209
+ }));
210
+ }
211
+ })
212
+ }) : null,
193
213
  embedded && surface.canReadResults && test.doc.status !== 'draft' ? /*#__PURE__*/ _jsx(ResultsBody, {
194
214
  id: id,
195
215
  surface: surface,
@@ -3,8 +3,9 @@ import type { PreflightResult } from '../../types/endpoints.js';
3
3
  import { type ReadinessRead } from '../readinessRead.js';
4
4
  import type { TestDocument, TestDocumentPatch } from './testDocument.model.js';
5
5
  /** Section data only: staging never saves. Call commit on blur or a section action. */
6
- export declare function useTestDocument(id: DocId, { apiRoute, refetchPreflightOnFocus, enabled, onDocument, onPreflight, requestPreflight }: {
6
+ export declare function useTestDocument(id: DocId, { apiRoute, contentLocale, refetchPreflightOnFocus, enabled, onDocument, onPreflight, requestPreflight }: {
7
7
  apiRoute: string;
8
+ contentLocale?: string;
8
9
  refetchPreflightOnFocus?: boolean;
9
10
  enabled?: boolean;
10
11
  onDocument?: (doc: TestDocument) => void;
@@ -1,4 +1,5 @@
1
1
  'use client';
2
+ import { contentLocaleURL } from '../contentLocaleURL.js';
2
3
  import { useCallback, useEffect, useRef, useState } from 'react';
3
4
  import { API_MESSAGES } from '../copy/common.js';
4
5
  import { readPreflight } from '../readPreflight.js';
@@ -68,16 +69,18 @@ function stage(session, partial) {
68
69
  if (!session.queue.length) session.view.saving = 'idle';
69
70
  session.publish();
70
71
  }
71
- /** Section data only: staging never saves. Call commit on blur or a section action. */ export function useTestDocument(id, { apiRoute, refetchPreflightOnFocus = false, enabled = true, onDocument, onPreflight, requestPreflight }) {
72
+ /** Section data only: staging never saves. Call commit on blur or a section action. */ export function useTestDocument(id, { apiRoute, contentLocale, refetchPreflightOnFocus = false, enabled = true, onDocument, onPreflight, requestPreflight }) {
72
73
  const observers = useRef({
73
74
  onDocument,
74
75
  onPreflight,
75
- requestPreflight
76
+ requestPreflight,
77
+ contentLocale
76
78
  });
77
79
  observers.current = {
78
80
  onDocument,
79
81
  onPreflight,
80
- requestPreflight
82
+ requestPreflight,
83
+ contentLocale
81
84
  };
82
85
  const base = apiRoute.replace(/\/$/, '');
83
86
  const documentId = String(id);
@@ -129,13 +132,14 @@ function stage(session, partial) {
129
132
  async function refreshPreflight(initial = false, supersede = false) {
130
133
  if (controller.signal.aborted) return;
131
134
  const revision = ++preflightRevision;
135
+ const requestedLocale = observers.current.contentLocale;
132
136
  session.preflightLoading = true;
133
137
  session.publish();
134
138
  // createApi has no signal option; this read must abort without cancelling submitted PATCHes.
135
139
  let body;
136
140
  let status = 0;
137
141
  try {
138
- const { response, body: answerBody } = await readPreflight((signal)=>observers.current.requestPreflight?.(signal, supersede || initial && reloadCount > 0) ?? fetch(`${base}/xp/experiments/${encodeURIComponent(documentId)}/preflight`, {
142
+ const { response, body: answerBody } = await readPreflight((signal)=>observers.current.requestPreflight?.(signal, supersede || initial && reloadCount > 0) ?? fetch(contentLocaleURL(`${base}/xp/experiments/${encodeURIComponent(documentId)}/preflight`, requestedLocale), {
139
143
  method: 'GET',
140
144
  credentials: 'include',
141
145
  cache: 'no-store',
@@ -146,6 +150,7 @@ function stage(session, partial) {
146
150
  } catch {}
147
151
  if (controller.signal.aborted) return;
148
152
  if (revision !== preflightRevision) return;
153
+ if (requestedLocale !== observers.current.contentLocale) return refreshPreflight(initial, supersede);
149
154
  session.preflightLoading = false;
150
155
  session.view.preflightRead = classifyReadinessRead(status, body, session.preflightFailures + 1);
151
156
  session.preflightFailures = session.view.preflightRead.failed ? session.preflightFailures + 1 : 0;
@@ -362,6 +367,17 @@ function stage(session, partial) {
362
367
  reloadCount,
363
368
  enabled
364
369
  ]);
370
+ const previousLocale = useRef(contentLocale);
371
+ useEffect(()=>{
372
+ if (previousLocale.current === contentLocale) return;
373
+ previousLocale.current = contentLocale;
374
+ const entry = commitRef.current;
375
+ if (enabled && entry?.session.key === key && entry.session.view.loadState === 'ready') void entry.refreshPreflight();
376
+ }, [
377
+ contentLocale,
378
+ enabled,
379
+ key
380
+ ]);
365
381
  const stagePartial = useCallback((partial)=>{
366
382
  const session = current.current;
367
383
  if (session?.key === key) stage(session, partial);
@@ -5,7 +5,9 @@ export declare function useApi(apiRoute: string): {
5
5
  ok: true;
6
6
  data: import("../types/contracts.js").DocId;
7
7
  }>;
8
- deleteTest: (id: import("../types/contracts.js").DocId) => Promise<import("./api.js").ApiResult<unknown>>;
8
+ deleteTest: (id: import("../types/contracts.js").DocId, { draft }?: {
9
+ draft?: boolean;
10
+ }) => Promise<import("./api.js").ApiResult<unknown>>;
9
11
  wrapBlock: (body: import("../types/endpoints.js").WrapBlockBody) => Promise<import("./api.js").ApiResult<Record<string, unknown>>>;
10
12
  pages: (query: {
11
13
  collection: string;
@@ -36,6 +38,7 @@ export declare function useApi(apiRoute: string): {
36
38
  restoreContentEntry: (id: import("../types/contracts.js").DocId, body: import("../types/endpoints.js").RestoreContentEntryBody) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").RestoreContentEntryResult>>;
37
39
  archive: (id: import("../types/contracts.js").DocId, body: import("../types/endpoints.js").ArchiveBody) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").TransitionSuccess>>;
38
40
  clickKeys: (id: import("../types/contracts.js").DocId) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").ClickKeysResult>>;
41
+ deleteImpact: (id: import("../types/contracts.js").DocId, signal?: AbortSignal) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").DeleteImpactResult>>;
39
42
  preflight: (id: import("../types/contracts.js").DocId) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").PreflightResult>>;
40
43
  previewToken: (id: import("../types/contracts.js").DocId, arm: string) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").PreviewTokenResult>>;
41
44
  results: (id: import("../types/contracts.js").DocId, options?: {
@@ -2,7 +2,7 @@ import { type GoalContent } from '../goals/fairness.js';
2
2
  import type { Arm, DocId, ExperimentKind, ExposurePolicy, FlagPoint, MetricSource, ResolvedOptions, Status, TargetingRule, UnitType } from '../types/contracts.js';
3
3
  import type { ArmIssueCode, PreflightResult } from '../types/endpoints.js';
4
4
  import type { BlockPlacement, FlagPlacement } from './placements.js';
5
- export type ReadinessCode = ArmIssueCode | 'goal-in-some-versions' | 'placement-unchecked' | 'invalid-status' | 'no-planned-duration' | 'no-primary-metric' | 'no-reach-per-day' | 'placement-unpublished' | 'duplicate-version-row' | 'interacting-tests' | 'version-identical' | 'version-same-address' | 'unknown-collection' | 'page-no-targets' | 'page-in-use' | 'page-target-unpublished' | 'page-targets-unchecked' | 'version-page-unavailable' | 'version-page-unchecked' | 'page-user-unit' | 'flag-no-point' | 'flag-params-invalid' | 'flag-point-busy' | 'flag-placement-missing' | 'no-placements' | 'placement-removed' | 'empty-slot' | 'make-content-unsupported' | 'layer-unit-mismatch' | 'layer-full' | 'unknown-metric-source' | 'unit-source-mismatch' | 'block-path-rule' | 'undeclared-targeting-key' | 'invalid-targeting-rule';
5
+ export type ReadinessCode = ArmIssueCode | 'nested-tests' | 'goal-in-some-versions' | 'placement-unchecked' | 'invalid-status' | 'no-planned-duration' | 'no-primary-metric' | 'no-reach-per-day' | 'placement-unpublished' | 'duplicate-version-row' | 'interacting-tests' | 'version-identical' | 'version-same-address' | 'unknown-collection' | 'page-no-targets' | 'page-in-use' | 'page-target-unpublished' | 'page-targets-unchecked' | 'version-page-unavailable' | 'version-page-unchecked' | 'page-user-unit' | 'flag-no-point' | 'flag-params-invalid' | 'flag-point-busy' | 'flag-placement-missing' | 'no-placements' | 'placement-removed' | 'empty-slot' | 'make-content-unsupported' | 'layer-unit-mismatch' | 'layer-full' | 'unknown-metric-source' | 'unit-source-mismatch' | 'block-path-rule' | 'undeclared-targeting-key' | 'invalid-targeting-rule';
6
6
  export interface StartExperiment {
7
7
  id: DocId;
8
8
  slug: string;
@@ -50,6 +50,9 @@ export interface CheckStartInput {
50
50
  flagPoints?: FlagPoint[];
51
51
  placements?: BlockPlacement[];
52
52
  flagPlacements?: FlagPlacement[];
53
+ placementLocaleCodes?: readonly string[];
54
+ placementLocale?: string;
55
+ placementDefaultLocale?: string;
53
56
  placementError?: PlacementFailure;
54
57
  flagPlacementError?: PlacementFailure;
55
58
  flagPointBusy?: boolean;