@delmaredigital/payload-experiments 0.4.0-rc.5 → 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 (164) 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/copy/newTest.d.ts +1 -1
  8. package/dist/admin/copy/newTest.js +1 -1
  9. package/dist/admin/surface/ResultsRoute.js +2 -1
  10. package/dist/admin/surface/TestsHome.d.ts +2 -1
  11. package/dist/admin/surface/TestsHome.js +91 -37
  12. package/dist/admin/surface/TestsSurface.js +3 -0
  13. package/dist/admin/surface/home.model.d.ts +2 -0
  14. package/dist/admin/surface/newTest/NewTest.js +16 -18
  15. package/dist/admin/surface/newTest/PageWizard.js +1 -0
  16. package/dist/admin/surface/newTest/newTest.css +3 -1
  17. package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
  18. package/dist/admin/views/TestsSurfaceClient.js +11 -0
  19. package/dist/admin/views/buildSurfaceProps.js +10 -3
  20. package/dist/blocks/bindings.js +8 -14
  21. package/dist/blocks/placementLanguages.d.ts +7 -0
  22. package/dist/blocks/placementLanguages.js +27 -0
  23. package/dist/blocks/placementLocale.d.ts +23 -7
  24. package/dist/blocks/placementLocale.js +221 -66
  25. package/dist/db/appends.d.ts +13 -0
  26. package/dist/db/appends.js +49 -0
  27. package/dist/db/bulkPlacementRemoval.js +8 -4
  28. package/dist/endpoints/contentLocale.d.ts +6 -0
  29. package/dist/endpoints/contentLocale.js +15 -0
  30. package/dist/endpoints/deleteImpact.d.ts +6 -0
  31. package/dist/endpoints/deleteImpact.js +206 -0
  32. package/dist/endpoints/index.js +7 -0
  33. package/dist/endpoints/pages.js +7 -3
  34. package/dist/endpoints/placementStatus.js +6 -1
  35. package/dist/endpoints/preflight.d.ts +1 -1
  36. package/dist/endpoints/preflight.js +17 -2
  37. package/dist/exports/adminClient.d.ts +1 -1
  38. package/dist/exports/adminClient.js +1 -1
  39. package/dist/exports/index.d.ts +1 -1
  40. package/dist/goals/fairness.js +43 -34
  41. package/dist/hooks/blockRemovalRule.d.ts +4 -3
  42. package/dist/hooks/blockRemovalRule.js +33 -9
  43. package/dist/hooks/pageGuard.d.ts +3 -0
  44. package/dist/hooks/pageGuard.js +34 -24
  45. package/dist/hooks/puckNestedTests.d.ts +8 -0
  46. package/dist/hooks/puckNestedTests.js +36 -0
  47. package/dist/lib/placementPages.d.ts +2 -1
  48. package/dist/lib/placementPages.js +10 -2
  49. package/dist/manifest/compile.d.ts +2 -1
  50. package/dist/manifest/compile.js +5 -1
  51. package/dist/puck/ExperimentPicker.d.ts +2 -1
  52. package/dist/puck/ExperimentPicker.js +37 -30
  53. package/dist/puck/ExperimentSlot.js +3 -1
  54. package/dist/puck/copy.d.ts +1 -0
  55. package/dist/puck/copy.js +1 -0
  56. package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
  57. package/dist/puck/editor/ConfigureTestDrawer.js +4 -2
  58. package/dist/puck/editor/CreateExperimentDrawer.d.ts +2 -1
  59. package/dist/puck/editor/CreateExperimentDrawer.js +24 -20
  60. package/dist/puck/editor/EditorControls.d.ts +1 -1
  61. package/dist/puck/editor/EditorControls.js +1 -1
  62. package/dist/puck/editor/ExperimentSlotEditor.js +405 -394
  63. package/dist/puck/editor/LeftoverVersions.d.ts +4 -2
  64. package/dist/puck/editor/LeftoverVersions.js +23 -44
  65. package/dist/puck/editor/QuickTestActions.js +2 -2
  66. package/dist/puck/editor/VersionBuilder.d.ts +41 -13
  67. package/dist/puck/editor/VersionBuilder.js +461 -224
  68. package/dist/puck/editor/armWrites.d.ts +9 -2
  69. package/dist/puck/editor/armWrites.js +40 -2
  70. package/dist/puck/editor/armsCache.d.ts +1 -1
  71. package/dist/puck/editor/armsCache.js +2 -1
  72. package/dist/puck/editor/blockClipboard.d.ts +16 -0
  73. package/dist/puck/editor/blockClipboard.js +20 -0
  74. package/dist/puck/editor/copy.d.ts +27 -26
  75. package/dist/puck/editor/copy.js +28 -26
  76. package/dist/puck/editor/createTest.d.ts +3 -0
  77. package/dist/puck/editor/createTest.js +33 -0
  78. package/dist/puck/editor/editor.chrome.css +138 -17
  79. package/dist/puck/editor/editor.css +156 -22
  80. package/dist/puck/editor/editor.model.d.ts +2 -1
  81. package/dist/puck/editor/editor.model.js +3 -3
  82. package/dist/puck/editor/experimentOutlinePlugin.js +1 -1
  83. package/dist/puck/editor/localPlacements.d.ts +5 -2
  84. package/dist/puck/editor/localPlacements.js +32 -18
  85. package/dist/puck/editor/placementsCache.d.ts +18 -12
  86. package/dist/puck/editor/placementsCache.js +52 -47
  87. package/dist/puck/editor/sidebar.d.ts +2 -6
  88. package/dist/puck/editor/sidebar.js +3 -6
  89. package/dist/puck/editor/usePlacementNotice.d.ts +1 -1
  90. package/dist/puck/editor/usePlacementNotice.js +4 -3
  91. package/dist/puck/experimentSlug.d.ts +2 -0
  92. package/dist/puck/experimentSlug.js +3 -0
  93. package/dist/puck/nestedTestCopy.d.ts +8 -0
  94. package/dist/puck/nestedTestCopy.js +22 -0
  95. package/dist/puck/nestedTests.d.ts +17 -0
  96. package/dist/puck/nestedTests.js +30 -0
  97. package/dist/puck/slotConfig.d.ts +1 -1
  98. package/dist/puck/slotConfig.js +17 -4
  99. package/dist/puck/visibility.d.ts +20 -0
  100. package/dist/puck/visibility.js +81 -0
  101. package/dist/server/recordContentChange.js +37 -20
  102. package/dist/server/resolveExperimentData.js +6 -3
  103. package/dist/testSurface/PreviewLinks.js +6 -2
  104. package/dist/testSurface/api.d.ts +6 -3
  105. package/dist/testSurface/api.js +10 -6
  106. package/dist/testSurface/contentLocaleURL.d.ts +2 -0
  107. package/dist/testSurface/contentLocaleURL.js +3 -0
  108. package/dist/testSurface/copy/common.d.ts +4 -0
  109. package/dist/testSurface/copy/common.js +8 -4
  110. package/dist/testSurface/copy/languages.d.ts +11 -0
  111. package/dist/testSurface/copy/languages.js +7 -0
  112. package/dist/testSurface/copy/readiness.d.ts +2 -1
  113. package/dist/testSurface/copy/readiness.js +2 -1
  114. package/dist/testSurface/copy/testPage.d.ts +28 -6
  115. package/dist/testSurface/copy/testPage.js +28 -6
  116. package/dist/testSurface/placementLabel.d.ts +8 -0
  117. package/dist/testSurface/placementLabel.js +24 -0
  118. package/dist/testSurface/placements/placementLabels.d.ts +2 -0
  119. package/dist/testSurface/placements/placementLabels.js +2 -1
  120. package/dist/testSurface/results/results.css +1 -1
  121. package/dist/testSurface/results/results.model.d.ts +1 -1
  122. package/dist/testSurface/surface/contracts.d.ts +2 -0
  123. package/dist/testSurface/surface/editorPlacement.d.ts +5 -0
  124. package/dist/testSurface/surface/editorPlacement.js +18 -0
  125. package/dist/testSurface/surface/pageBlock/pageBlock.model.js +2 -1
  126. package/dist/testSurface/surface/pageBlock/parts.js +24 -6
  127. package/dist/testSurface/surface/readiness/ActionDialogs.js +28 -34
  128. package/dist/testSurface/surface/readiness/readiness.model.js +9 -2
  129. package/dist/testSurface/surface/results/useResults.d.ts +4 -1
  130. package/dist/testSurface/surface/test/DeleteTest.d.ts +15 -0
  131. package/dist/testSurface/surface/test/DeleteTest.js +171 -0
  132. package/dist/testSurface/surface/test/GoalSection.js +101 -74
  133. package/dist/testSurface/surface/test/TestSurface.js +29 -9
  134. package/dist/testSurface/surface/test/fields.d.ts +1 -3
  135. package/dist/testSurface/surface/test/fields.js +5 -35
  136. package/dist/testSurface/surface/useTestDocument.d.ts +2 -1
  137. package/dist/testSurface/surface/useTestDocument.js +20 -4
  138. package/dist/testSurface/useApi.d.ts +4 -1
  139. package/dist/transitions/checkStart.d.ts +4 -1
  140. package/dist/transitions/checkStart.js +117 -14
  141. package/dist/transitions/contentFields.js +9 -5
  142. package/dist/transitions/makeContent.js +29 -9
  143. package/dist/transitions/nestedPlacementNames.d.ts +5 -0
  144. package/dist/transitions/nestedPlacementNames.js +33 -0
  145. package/dist/transitions/pageVersions.js +3 -1
  146. package/dist/transitions/placementInteractions.js +7 -4
  147. package/dist/transitions/placements.d.ts +26 -1
  148. package/dist/transitions/placements.js +239 -87
  149. package/dist/transitions/preflightData.d.ts +2 -1
  150. package/dist/transitions/preflightData.js +66 -3
  151. package/dist/transitions/start.js +4 -1
  152. package/dist/types/endpoints.d.ts +35 -1
  153. package/dist/types/endpoints.js +1 -1
  154. package/dist/types/puck.d.ts +1 -0
  155. package/dist/types/surface.d.ts +2 -0
  156. package/dist/ui/Button.js +2 -2
  157. package/dist/ui/Inputs.d.ts +4 -3
  158. package/dist/ui/Inputs.js +7 -4
  159. package/dist/ui/SelectControl.d.ts +33 -0
  160. package/dist/ui/SelectControl.js +504 -0
  161. package/dist/ui/Tabs.d.ts +0 -1
  162. package/dist/ui/Tabs.js +28 -40
  163. package/dist/ui/ui.css +18 -5
  164. package/package.json +3 -2
@@ -1,6 +1,7 @@
1
1
  import { TEST_PAGE as C } from '../../copy/testPage.js';
2
+ import { placementLabel } from '../../placementLabel.js';
2
3
  export function placementLine(placement) {
3
- return `${C.onPage} ${placement.title} (${placement.detail === 'Published' ? 'Published' : 'Draft'})`;
4
+ return `${C.onPage} ${placementLabel(placement, true)}`;
4
5
  }
5
6
  export function slotReady(placement, arm) {
6
7
  const slot = arm.kind === 'holdout' ? 'control' : arm.slot;
@@ -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
  });
@@ -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("label", {
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
- R.role,
279
- /*#__PURE__*/ _jsxs("select", {
280
- value: role,
281
- disabled: disabled,
282
- onChange: (event)=>setRole(event.target.value),
283
- children: [
284
- /*#__PURE__*/ _jsx("option", {
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("label", {
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
- R.metric,
299
- /*#__PURE__*/ _jsxs("select", {
300
- value: metric,
301
- disabled: disabled || loading,
302
- onChange: (event)=>setMetric(event.target.value),
303
- children: [
304
- /*#__PURE__*/ _jsx("option", {
305
- value: "",
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,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,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 { CheckboxList, FieldErrors, reasonFor, save, SelectEdit } from './fields.js';
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 roleOptions = (role)=>{
141
- const blocked = new Set([
142
- ...role !== 'primary' && doc.metrics?.primary != null ? [
143
- doc.metrics.primary
144
- ] : [],
145
- ...role !== 'guardrails' ? doc.metrics?.guardrails ?? [] : [],
146
- ...role !== 'secondary' ? doc.metrics?.secondary ?? [] : []
147
- ].map(String));
148
- return visible.filter((option)=>!blocked.has(option.value));
149
- };
150
- const roleGroups = (role)=>onPage.size ? [
151
- {
152
- label: C.clickPageGroup,
153
- options: roleOptions(role).filter((option)=>onPage.has(option.value)).map((option)=>({
154
- ...option,
155
- label: onPage.get(option.value)
156
- }))
157
- },
158
- {
159
- options: roleOptions(role).filter((option)=>!onPage.has(option.value))
160
- }
161
- ] : undefined;
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 toggle = (role, value, checked)=>save(test, 'metrics', ()=>{
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
- [role]: checked && id != null ? ids.some((saved)=>String(saved) === value) ? ids : [
185
- ...ids,
199
+ guardrails: role === 'guardrails' && id != null ? [
200
+ ...guardrails,
186
201
  id
187
- ] : ids.filter((saved)=>String(saved) !== value)
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
- ...roleOptions('primary')
254
+ ...visible
236
255
  ],
237
- groups: onPage.size ? [
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__*/ _jsx(CheckboxList, {
271
- searchable: metrics.length > 8,
272
- label: C.guardrails,
273
- value: (doc.metrics?.guardrails ?? []).map(String),
274
- options: roleOptions('guardrails'),
275
- groups: roleGroups('guardrails'),
276
- reason: reason,
277
- readOnlyValue: display(doc.metrics?.guardrails ?? []),
278
- onToggle: (value, checked)=>toggle('guardrails', value, checked)
279
- }),
280
- /*#__PURE__*/ _jsx("p", {
281
- children: C.guardrailHelp
282
- }),
283
- /*#__PURE__*/ _jsx(FieldErrors, {
284
- test: test,
285
- path: "metrics.guardrails"
286
- }),
287
- /*#__PURE__*/ _jsx(CheckboxList, {
288
- searchable: metrics.length > 8,
289
- label: C.secondary,
290
- value: (doc.metrics?.secondary ?? []).map(String),
291
- options: roleOptions('secondary'),
292
- groups: roleGroups('secondary'),
293
- reason: reason,
294
- readOnlyValue: display(doc.metrics?.secondary ?? []),
295
- onToggle: (value, checked)=>toggle('secondary', value, checked)
296
- }),
297
- /*#__PURE__*/ _jsx(FieldErrors, {
298
- test: test,
299
- path: "metrics.secondary"
300
- }),
301
- metrics.some((metric)=>isClickSource(metric.source)) ? /*#__PURE__*/ _jsx("p", {
302
- children: C.clickGoalsNote
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",