@delmaredigital/payload-experiments 0.4.0-rc.6 → 0.4.0-rc.9
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/README.md +12 -12
- 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 +9 -5
- package/dist/admin/copy/blocks.d.ts +3 -2
- package/dist/admin/copy/blocks.js +8 -7
- package/dist/admin/surface/ResultsRoute.js +18 -11
- package/dist/admin/surface/TestsHome.d.ts +2 -1
- package/dist/admin/surface/TestsHome.js +131 -44
- 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 +9 -2
- package/dist/admin/surface/newTest/newTest.css +1 -1
- package/dist/admin/surface/results/ResultsHeader.js +11 -6
- package/dist/admin/surface/test/TestPage.js +3 -3
- 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/formState.js +1 -1
- 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/collections/experiments/config.js +8 -3
- package/dist/collections/experiments/deleteGuard.js +2 -2
- package/dist/collections/experiments/lockHook.js +21 -2
- package/dist/collections/experiments/pickSlug.js +2 -0
- package/dist/collections/metricsGuards.js +2 -0
- package/dist/collections/serialize.js +5 -4
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/db/adapter.d.ts +9 -1
- package/dist/db/adapter.js +77 -1
- package/dist/db/appends.d.ts +13 -0
- package/dist/db/appends.js +49 -0
- package/dist/db/bulkPlacementRemoval.js +8 -4
- package/dist/db/delete.d.ts +1 -1
- package/dist/db/delete.js +2 -4
- package/dist/db/events.d.ts +9 -0
- package/dist/db/events.js +42 -8
- package/dist/db/executor.d.ts +7 -1
- package/dist/db/executor.js +7 -3
- package/dist/db/results.d.ts +5 -1
- package/dist/db/results.js +21 -5
- package/dist/db/snapshots.d.ts +1 -0
- 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 +207 -0
- package/dist/endpoints/events.js +103 -39
- package/dist/endpoints/index.js +9 -8
- package/dist/endpoints/pages.js +7 -3
- package/dist/endpoints/placementStatus.js +13 -5
- package/dist/endpoints/preflight.d.ts +1 -1
- package/dist/endpoints/preflight.js +17 -2
- package/dist/endpoints/results.d.ts +1 -1
- package/dist/endpoints/results.js +6 -2
- package/dist/endpoints/routeId.d.ts +2 -2
- package/dist/endpoints/routeId.js +11 -5
- package/dist/endpoints/summary.js +46 -12
- package/dist/endpoints/transitions.js +37 -24
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +6 -0
- package/dist/events/request.d.ts +6 -2
- package/dist/events/request.js +35 -8
- package/dist/events/rows.d.ts +1 -1
- package/dist/events/rows.js +24 -8
- package/dist/events/writable.d.ts +9 -0
- package/dist/events/writable.js +13 -0
- 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/exports/rsc.d.ts +1 -0
- package/dist/exports/rsc.js +1 -0
- 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/hostHook.js +6 -2
- package/dist/hooks/pageGuard.d.ts +3 -0
- package/dist/hooks/pageGuard.js +37 -23
- package/dist/hooks/puckNestedTests.d.ts +8 -0
- package/dist/hooks/puckNestedTests.js +36 -0
- package/dist/lib/fetchAllDocs.d.ts +1 -1
- 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 +13 -6
- package/dist/onInit.js +14 -0
- package/dist/options.js +5 -0
- package/dist/proxy/pageNavigation.d.ts +4 -0
- package/dist/proxy/pageNavigation.js +28 -0
- package/dist/proxy/resolve.js +52 -25
- package/dist/puck/ExperimentPicker.js +40 -37
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
- package/dist/puck/editor/ConfigureTestDrawer.js +5 -2
- package/dist/puck/editor/ExperimentSlotEditor.js +313 -158
- package/dist/puck/editor/LeftoverVersions.d.ts +1 -1
- package/dist/puck/editor/LeftoverVersions.js +40 -43
- package/dist/puck/editor/QuickTestActions.d.ts +5 -2
- package/dist/puck/editor/QuickTestActions.js +16 -4
- package/dist/puck/editor/ResultsReadout.d.ts +2 -1
- package/dist/puck/editor/ResultsReadout.js +2 -1
- package/dist/puck/editor/VersionBuilder.d.ts +31 -3
- package/dist/puck/editor/VersionBuilder.js +336 -74
- package/dist/puck/editor/armWrites.js +1 -1
- package/dist/puck/editor/armsCache.js +1 -3
- package/dist/puck/editor/blockClipboard.d.ts +16 -0
- package/dist/puck/editor/blockClipboard.js +20 -0
- package/dist/puck/editor/copy.d.ts +12 -2
- package/dist/puck/editor/copy.js +13 -2
- package/dist/puck/editor/editor.chrome.css +118 -3
- package/dist/puck/editor/editor.css +131 -8
- package/dist/puck/editor/editor.model.d.ts +3 -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 +22 -12
- package/dist/puck/editor/placementsCache.js +62 -49
- package/dist/puck/editor/usePageSaveReadiness.d.ts +9 -0
- package/dist/puck/editor/usePageSaveReadiness.js +34 -0
- package/dist/puck/editor/usePlacementNotice.d.ts +2 -2
- package/dist/puck/editor/usePlacementNotice.js +6 -4
- 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/results/aggregate.d.ts +6 -3
- package/dist/results/aggregate.js +9 -9
- package/dist/results/health.d.ts +8 -0
- package/dist/results/health.js +28 -0
- package/dist/results/identityCredit.d.ts +1 -0
- package/dist/results/identityCredit.js +4 -1
- package/dist/results/verdict.js +2 -1
- package/dist/runtime/cookie.d.ts +10 -2
- package/dist/runtime/cookie.js +38 -6
- package/dist/runtime/cookieOptions.d.ts +6 -0
- package/dist/runtime/cookieOptions.js +14 -0
- package/dist/runtime/proxyRuntime.d.ts +1 -0
- package/dist/runtime/proxyRuntime.js +18 -8
- package/dist/runtime/signing.d.ts +1 -0
- package/dist/runtime/signing.js +5 -0
- package/dist/sanitizeReadinessDetail.d.ts +2 -2
- package/dist/sanitizeReadinessDetail.js +20 -2
- package/dist/server/getAssignments.js +11 -10
- package/dist/server/recordContentChange.d.ts +1 -1
- package/dist/server/recordContentChange.js +45 -21
- package/dist/server/resolveExperimentBlocks.js +2 -4
- package/dist/server/resolveExperimentData.js +4 -7
- package/dist/server/runResults.js +52 -14
- package/dist/server/startExperiment.d.ts +20 -0
- package/dist/server/startExperiment.js +70 -0
- package/dist/server/trackConversion.js +10 -13
- package/dist/testSurface/PreviewLinks.js +6 -2
- package/dist/testSurface/actions/DecideDialog.d.ts +4 -1
- package/dist/testSurface/actions/DecideDialog.js +32 -14
- package/dist/testSurface/actions/MakeContentResult.d.ts +4 -3
- package/dist/testSurface/actions/MakeContentResult.js +9 -1
- package/dist/testSurface/api.d.ts +11 -8
- package/dist/testSurface/api.js +27 -11
- package/dist/testSurface/contentLocaleURL.d.ts +2 -0
- package/dist/testSurface/contentLocaleURL.js +3 -0
- package/dist/testSurface/copy/actions.d.ts +1 -0
- package/dist/testSurface/copy/actions.js +1 -0
- package/dist/testSurface/copy/common.d.ts +6 -0
- package/dist/testSurface/copy/common.js +11 -5
- package/dist/testSurface/copy/languages.d.ts +12 -0
- package/dist/testSurface/copy/languages.js +8 -0
- package/dist/testSurface/copy/metrics.d.ts +1 -0
- package/dist/testSurface/copy/metrics.js +1 -0
- package/dist/testSurface/copy/readiness.d.ts +13 -2
- package/dist/testSurface/copy/readiness.js +19 -2
- package/dist/testSurface/copy/results.d.ts +5 -2
- package/dist/testSurface/copy/results.js +5 -2
- package/dist/testSurface/copy/testPage.d.ts +40 -1
- package/dist/testSurface/copy/testPage.js +53 -1
- 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/readPreflight.d.ts +5 -0
- package/dist/testSurface/readPreflight.js +7 -0
- package/dist/testSurface/readinessRead.d.ts +3 -0
- package/dist/testSurface/readinessRead.js +4 -0
- package/dist/testSurface/results/VerdictHero.d.ts +2 -1
- package/dist/testSurface/results/VerdictHero.js +5 -1
- package/dist/testSurface/results/results.css +1 -1
- package/dist/testSurface/results/results.model.d.ts +1 -1
- package/dist/testSurface/results/results.model.js +6 -2
- package/dist/testSurface/surface/contracts.d.ts +10 -1
- package/dist/testSurface/surface/editorPlacement.d.ts +7 -2
- package/dist/testSurface/surface/editorPlacement.js +19 -1
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +4 -3
- package/dist/testSurface/surface/pageBlock/parts.js +24 -6
- package/dist/testSurface/surface/pagePicker/PageCombobox.js +20 -6
- package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +4 -2
- package/dist/testSurface/surface/readiness/ActionDialogs.js +39 -34
- package/dist/testSurface/surface/readiness/Banner.js +23 -12
- package/dist/testSurface/surface/readiness/SaveStatus.d.ts +4 -3
- package/dist/testSurface/surface/readiness/SaveStatus.js +15 -15
- package/dist/testSurface/surface/readiness/readiness.model.d.ts +6 -1
- package/dist/testSurface/surface/readiness/readiness.model.js +116 -12
- package/dist/testSurface/surface/readiness/useTransition.d.ts +4 -4
- package/dist/testSurface/surface/readiness/useTransition.js +12 -10
- package/dist/testSurface/surface/results/ReleasePages.d.ts +4 -2
- package/dist/testSurface/surface/results/ReleasePages.js +5 -4
- package/dist/testSurface/surface/results/ResultsBody.d.ts +4 -2
- package/dist/testSurface/surface/results/ResultsBody.js +86 -43
- package/dist/testSurface/surface/results/useResults.d.ts +11 -7
- package/dist/testSurface/surface/results/useResults.js +3 -2
- package/dist/testSurface/surface/setting/parts.js +58 -18
- package/dist/testSurface/surface/test/AdvancedSection.js +1 -0
- package/dist/testSurface/surface/test/DeleteTest.d.ts +19 -0
- package/dist/testSurface/surface/test/DeleteTest.js +262 -0
- package/dist/testSurface/surface/test/GoalSection.js +7 -3
- package/dist/testSurface/surface/test/LengthSection.js +3 -0
- package/dist/testSurface/surface/test/PageHoldout.js +4 -1
- package/dist/testSurface/surface/test/ReadinessBar.js +1 -1
- package/dist/testSurface/surface/test/TargetingSection.js +77 -12
- package/dist/testSurface/surface/test/TestSurface.js +97 -15
- package/dist/testSurface/surface/test/VersionsSection.js +56 -29
- package/dist/testSurface/surface/test/fields.d.ts +29 -4
- package/dist/testSurface/surface/test/fields.js +159 -39
- package/dist/testSurface/surface/test/pageParts.js +14 -5
- package/dist/testSurface/surface/test/testPage.model.d.ts +1 -0
- package/dist/testSurface/surface/test/testPage.model.js +6 -0
- package/dist/testSurface/surface/testDocument.model.d.ts +3 -0
- package/dist/testSurface/surface/testDocument.model.js +4 -1
- package/dist/testSurface/surface/useTestDocument.d.ts +23 -4
- package/dist/testSurface/surface/useTestDocument.js +425 -162
- package/dist/testSurface/useApi.d.ts +9 -6
- package/dist/testSurface/useOnTestReturn.d.ts +2 -0
- package/dist/testSurface/useOnTestReturn.js +27 -0
- package/dist/testSurface/useReadinessPolling.js +3 -1
- package/dist/transitions/addMetric.d.ts +1 -4
- package/dist/transitions/allocate.d.ts +2 -2
- package/dist/transitions/allocate.js +3 -1
- package/dist/transitions/archive.d.ts +1 -1
- package/dist/transitions/archive.js +3 -2
- package/dist/transitions/checkStart.d.ts +5 -1
- package/dist/transitions/checkStart.js +130 -16
- package/dist/transitions/contentFields.js +9 -5
- package/dist/transitions/decide.d.ts +1 -1
- package/dist/transitions/decide.js +5 -3
- package/dist/transitions/deleteExperiment.d.ts +2 -2
- package/dist/transitions/deleteExperiment.js +17 -7
- package/dist/transitions/kernel.d.ts +2 -0
- package/dist/transitions/kernel.js +9 -4
- package/dist/transitions/makeContent.d.ts +2 -1
- package/dist/transitions/makeContent.js +17 -12
- package/dist/transitions/nestedPlacementNames.d.ts +5 -0
- package/dist/transitions/nestedPlacementNames.js +32 -0
- package/dist/transitions/pageVersions.js +3 -1
- package/dist/transitions/phaseRecord.d.ts +2 -0
- package/dist/transitions/phaseRecord.js +5 -0
- package/dist/transitions/placementInteractions.d.ts +3 -3
- package/dist/transitions/placementInteractions.js +15 -11
- package/dist/transitions/placements.d.ts +28 -1
- package/dist/transitions/placements.js +223 -60
- package/dist/transitions/preflightData.d.ts +5 -3
- package/dist/transitions/preflightData.js +126 -37
- package/dist/transitions/releaseHoldout.d.ts +2 -1
- package/dist/transitions/releaseHoldout.js +3 -1
- package/dist/transitions/releasePages.d.ts +2 -1
- package/dist/transitions/releasePages.js +3 -1
- package/dist/transitions/resolveCaps.d.ts +2 -4
- package/dist/transitions/start.d.ts +6 -8
- package/dist/transitions/start.js +70 -34
- package/dist/transitions/startReads.d.ts +7 -0
- package/dist/transitions/startReads.js +28 -0
- package/dist/transitions/stop.d.ts +2 -1
- package/dist/transitions/stop.js +3 -2
- package/dist/types/contracts.d.ts +6 -3
- package/dist/types/endpoints.d.ts +86 -9
- package/dist/types/endpoints.js +1 -1
- package/dist/types/runtime.d.ts +15 -9
- package/dist/types/snapshot.d.ts +2 -0
- package/dist/types/surface.d.ts +2 -0
- package/dist/ui/Button.js +2 -2
- package/dist/ui/ChipsInput.d.ts +8 -1
- package/dist/ui/ChipsInput.js +17 -4
- 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
package/README.md
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
A/B testing for Payload CMS and Next.js, from the content you already manage. Test a block on a page, a whole page against another page, or a setting your developer makes testable. Pick a goal, including click goals you name and attach to buttons and links, then compare the Original with your new versions. Results appear in the admin: they count only people who actually saw the content, warn when traffic looks wrong, and check guardrail goals (goals you don't want to hurt). You pick a winner and can make it permanent. Your data stays in your own Postgres database. There is no vendor.
|
|
4
4
|
|
|
5
|
-
> ⚠️ Upgrading
|
|
5
|
+
> ⚠️ Upgrading from 0.4.0-rc.8 to rc.9? Set `events.rateLimit` and `rateLimitUnit`, or explicitly use `false` for requests you limit upstream. Use signing keys of at least 32 characters, including previous rotation keys. Serve events on the page's origin, preserve `Sec-Fetch-Site`, `Origin`, and `Referer`, and configure the public origin in `events.origin` or Payload's `serverURL`. If you use a reverse proxy, forward the browser-facing host and protocol. Set `skipProxyUrlNormalize: true` and keep full prefetch off experiment routes. Use matching cookie settings in the proxy and event handler and cap `cookie.maxAgeDays` at 400. Deploy proxies and event handlers together because an older proxy can reissue IDs. Pre-rc.9 IDs expire on January 7, 2028 at 00:00 UTC by default. Drain older `trackConversion` writers before upgraded writers use the same event table. Update exhaustive TypeScript switches and records over `SnapshotHealth` and `RefusalCode`. See the [rc.9 upgrade steps](https://plugins.delmaredigital.com/docs/experiments/upgrading#from-040-rc7-or-rc8-to-rc9).
|
|
6
|
+
|
|
7
|
+
> ⚠️ Upgrading from 0.4.0-rc.7? Apply the rc.9 runtime steps above and set the Postgres adapter's `transactionOptions.isolationLevel` to `'read committed'` or remove the override if the database has a supported default. PostgreSQL treats `READ UNCOMMITTED` as `READ COMMITTED`, so both are supported. The app refuses to start with other levels. If your client expects HTTP `403` when a manager deletes a running, stopped, or decided test by ID, handle HTTP `409` with code `invalid-status` and ask the manager to archive the test first. See the [rc.8 release notes](https://github.com/delmaredigital/payload-experiments/blob/main/CHANGELOG.md#040-rc8---2026-12-01).
|
|
8
|
+
|
|
9
|
+
> ⚠️ Upgrading to 0.4 from 0.3? Run `payload migrate:create` for four nullable plugin columns (`xp_experiments.page_collection`, `_xp_experiments_v.version_page_collection`, `xp_phases.placement_docs`, and `xp_state.retired_slugs`), plus the Experiment block and `xpGoal` changes if you adopt them. Apply the migration and run `payload generate:importmap`. Use PostgreSQL `READ COMMITTED` for default and guarded host transactions. PostgreSQL's `READ UNCOMMITTED` is equivalent. Update clients that expect HTTP `403` when a manager deletes a running, stopped, or decided test by ID. Handle HTTP `409` with code `invalid-status` and ask the manager to archive first. Registered page and block saves can be refused with `page-busy` or `interacting-tests`. Publish draft-only placements before starting a test, and publish the Original and winning pages before deciding a stopped whole-page test. Reserve `click:` for click goals and update `admin.editorUrl` for its required `editor` argument. Apply the runtime requirements in the rc.9 callout above. See the [full 0.4 upgrade steps](https://plugins.delmaredigital.com/docs/experiments/upgrading#to-04).
|
|
6
10
|
|
|
7
11
|
## Install
|
|
8
12
|
|
|
@@ -12,7 +16,7 @@ pnpm add @delmaredigital/payload-experiments
|
|
|
12
16
|
|
|
13
17
|
### Requirements
|
|
14
18
|
|
|
15
|
-
Use Node.js `>=22.23.4`, the Next.js App Router, and Postgres through `@payloadcms/db-postgres` with transactions enabled. Puck is optional. Install the peers your application uses:
|
|
19
|
+
Use Node.js `>=22.23.4`, the Next.js App Router, and Postgres through `@payloadcms/db-postgres` with transactions enabled and `READ COMMITTED` (or its PostgreSQL equivalent, `READ UNCOMMITTED`) as the default isolation level. Puck is optional. Install the peers your application uses:
|
|
16
20
|
|
|
17
21
|
| Peer | Version |
|
|
18
22
|
| --- | --- |
|
|
@@ -28,23 +32,20 @@ These examples use your existing Payload app and Pages collection. Imports start
|
|
|
28
32
|
|
|
29
33
|
### 1. Set a secret and create the runtimes
|
|
30
34
|
|
|
31
|
-
Set a private `XP_SECRET` in your server environment.
|
|
35
|
+
Set a private `XP_SECRET` of at least 32 characters in your server environment. Use the shared Postgres pool from the [rate limiter example](https://plugins.delmaredigital.com/docs/experiments/installation#rate-limit-browser-traffic).
|
|
32
36
|
|
|
33
37
|
```ts
|
|
34
38
|
// src/experiments/proxyRuntime.ts
|
|
35
|
-
import { Pool } from 'pg'
|
|
36
39
|
import {
|
|
37
40
|
defineExperimentsProxyRuntime,
|
|
38
41
|
createPostgresManifestLoader,
|
|
39
42
|
} from '@delmaredigital/payload-experiments/runtime/proxy'
|
|
43
|
+
import { allowNewVisitor, pool } from '@/experiments/rateLimit'
|
|
40
44
|
|
|
41
|
-
const pool = new Pool({
|
|
42
|
-
connectionString: process.env.DATABASE_URI,
|
|
43
|
-
connectionTimeoutMillis: 5_000,
|
|
44
|
-
})
|
|
45
45
|
export const proxyRuntime = defineExperimentsProxyRuntime({
|
|
46
46
|
secret: process.env.XP_SECRET!,
|
|
47
47
|
apiRoute: '/api', // match Payload's routes.api
|
|
48
|
+
rateLimitUnit: allowNewVisitor,
|
|
48
49
|
loadManifest: createPostgresManifestLoader({ pool }),
|
|
49
50
|
})
|
|
50
51
|
```
|
|
@@ -74,17 +75,16 @@ Add this to your existing `payload.config.ts` plugins array. Your permission che
|
|
|
74
75
|
import { createExperimentsPlugin } from '@delmaredigital/payload-experiments'
|
|
75
76
|
import { serverRuntime } from '@/experiments/serverRuntime'
|
|
76
77
|
import { canManageTests } from '@/access/tests'
|
|
77
|
-
import {
|
|
78
|
+
import { allowExperimentEvents } from '@/experiments/rateLimit'
|
|
78
79
|
|
|
79
80
|
createExperimentsPlugin({
|
|
80
81
|
runtime: serverRuntime,
|
|
81
82
|
access: { manage: canManageTests },
|
|
82
|
-
events: { rateLimit:
|
|
83
|
+
events: { rateLimit: allowExperimentEvents },
|
|
83
84
|
})
|
|
84
85
|
```
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
`{ req, unitId }` and returns `true` to permit or `false` to drop a request.
|
|
87
|
+
Use shared rate limiters keyed by a trusted client address. `events.rateLimit` receives `{ req, unitId }`, with `unitId` available as context only. `rateLimitUnit` receives the `NextRequest` before a new visitor cookie is issued. Each adapter returns `true` to allow the operation. Set either option to `false` only when a firewall or equivalent upstream control limits the corresponding events or page requests, since doing so disables the plugin's rate limit for that traffic. Serve the browser events route on the same origin as your pages and set `events.origin` or Payload's `serverURL` to that public origin. See the [shared rate limiter example](https://plugins.delmaredigital.com/docs/experiments/installation#rate-limit-browser-traffic).
|
|
88
88
|
Keep identifying attributes out of `events.dimensions`. Use the proxy runtime's `cookie.consent` to enrol only after consent (`ExperimentsProxyRuntimeOptions`); `eraseUser(payload, { userId })` from `/rsc` handles privacy erasure (typed by that exported function).
|
|
89
89
|
|
|
90
90
|
### 3. Run migrations and generate the import map
|
|
@@ -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,10 +1,10 @@
|
|
|
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;
|
|
5
5
|
}
|
|
6
6
|
export function slotLabel(slot, status) {
|
|
7
|
-
return (liveStatus(status) ? status.arms.find((arm)=>arm.key !== 'holdout' &&
|
|
7
|
+
return (liveStatus(status) ? status.arms.find((arm)=>arm.key !== 'holdout' && arm.key === slot)?.label : undefined) || BLOCK_COPY.slotLabels[slot] || slot;
|
|
8
8
|
}
|
|
9
9
|
export function statusSentence(status) {
|
|
10
10
|
if (!liveStatus(status)) return BLOCK_COPY.deleted;
|
|
@@ -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.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;
|
|
@@ -10,7 +10,7 @@ export const BLOCK_COPY = {
|
|
|
10
10
|
saveFirst: 'Save your changes, then try again.',
|
|
11
11
|
setup: 'Set up the test',
|
|
12
12
|
copy: 'Copy the Original into this version',
|
|
13
|
-
confirmCopy:
|
|
13
|
+
confirmCopy: "Replace this version's content with a copy of the Original? Edits you made to this version will be lost.",
|
|
14
14
|
unwrap: 'Unwrap',
|
|
15
15
|
removeAndUnwrap: 'Remove the test and unwrap',
|
|
16
16
|
deleteAndUnwrap: 'Delete and unwrap',
|
|
@@ -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,10 @@ 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,
|
|
27
|
+
refetchDocumentOnFocus: true,
|
|
28
|
+
refetchPreflightOnFocus: true
|
|
26
29
|
});
|
|
27
30
|
useEffect(()=>{
|
|
28
31
|
if (test.doc?.name) onTitleChange?.(test.doc.name);
|
|
@@ -38,12 +41,17 @@ function ManagedResults({ id, surface, onTitleChange }) {
|
|
|
38
41
|
test.doc.allocation,
|
|
39
42
|
test.doc.metrics
|
|
40
43
|
]) : 'loading';
|
|
41
|
-
// ResultsBody's Decide is the shared DecideDialog, which reloads the page; Recompute keeps status.
|
|
42
44
|
if (test.loadState === 'ready' && test.doc) return /*#__PURE__*/ _jsx(ResultsBody, {
|
|
45
|
+
documentVersion: bodyKey,
|
|
46
|
+
liveDocument: test.doc,
|
|
47
|
+
statusReadPending: test.statusReadPending,
|
|
43
48
|
id: id,
|
|
44
49
|
surface: surface,
|
|
45
50
|
onRecomputed: ()=>setResultsVersion((value)=>value + 1),
|
|
46
|
-
|
|
51
|
+
onChanged: (doc)=>{
|
|
52
|
+
test.acceptTransition?.({
|
|
53
|
+
doc
|
|
54
|
+
});
|
|
47
55
|
void test.reload();
|
|
48
56
|
},
|
|
49
57
|
renderPage: (parts)=>/*#__PURE__*/ _jsx(ResultsHeader, {
|
|
@@ -51,8 +59,8 @@ function ManagedResults({ id, surface, onTitleChange }) {
|
|
|
51
59
|
surface: surface,
|
|
52
60
|
resultsVersion: resultsVersion,
|
|
53
61
|
...parts
|
|
54
|
-
}, `${test.doc.id}/${test.doc.status}`)
|
|
55
|
-
}
|
|
62
|
+
}, `${test.doc.id}/${test.doc.status}/${test.doc.phase}`)
|
|
63
|
+
});
|
|
56
64
|
return /*#__PURE__*/ _jsx(ReaderResultsShell, {
|
|
57
65
|
surface: surface,
|
|
58
66
|
children: /*#__PURE__*/ _jsxs("div", {
|
|
@@ -66,14 +74,13 @@ function ManagedResults({ id, surface, onTitleChange }) {
|
|
|
66
74
|
onClick: ()=>void test.reload(),
|
|
67
75
|
children: C.retry
|
|
68
76
|
}) : null,
|
|
69
|
-
test.loadState
|
|
77
|
+
test.loadState === 'error' ? /*#__PURE__*/ _jsx(ResultsBody, {
|
|
70
78
|
id: id,
|
|
71
|
-
surface:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
void test.reload();
|
|
79
|
+
surface: {
|
|
80
|
+
...surface,
|
|
81
|
+
canManage: false
|
|
75
82
|
}
|
|
76
|
-
}
|
|
83
|
+
}) : null
|
|
77
84
|
]
|
|
78
85
|
})
|
|
79
86
|
});
|
|
@@ -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,10 +1,13 @@
|
|
|
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 { useCallback, 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';
|
|
10
|
+
import { useOnTestReturn } from '../../testSurface/useOnTestReturn.js';
|
|
8
11
|
import { noMatchesLine, SURFACE_COPY } from '../../testSurface/copy/surface.js';
|
|
9
12
|
import { Banner, EmptyState, StatusChip } from '../../ui/Feedback.js';
|
|
10
13
|
import { Button } from '../../ui/Button.js';
|
|
@@ -28,7 +31,7 @@ const HOME_FIELDS = [
|
|
|
28
31
|
const homeFieldsComplete = true;
|
|
29
32
|
void homeFieldsComplete;
|
|
30
33
|
const HOME_SELECT = HOME_FIELDS.map((field)=>`select[${field}]=true`).join('&');
|
|
31
|
-
export function TestsHome({ adminRoute, apiRoute, canManage = false, crumbs, flagPoints }) {
|
|
34
|
+
export function TestsHome({ adminRoute, apiRoute, contentLocale, canManage = false, crumbs, flagPoints }) {
|
|
32
35
|
const api = useMemo(()=>createApi(apiRoute), [
|
|
33
36
|
apiRoute
|
|
34
37
|
]);
|
|
@@ -37,16 +40,51 @@ export function TestsHome({ adminRoute, apiRoute, canManage = false, crumbs, fla
|
|
|
37
40
|
});
|
|
38
41
|
const [search, setSearch] = useState('');
|
|
39
42
|
const [attempt, setAttempt] = useState(0);
|
|
43
|
+
const reload = useCallback(()=>setAttempt((value)=>value + 1), []);
|
|
44
|
+
const [notice, setNotice] = useState();
|
|
45
|
+
const noticeRef = useRef(null);
|
|
46
|
+
const deletedIds = useRef(new Set());
|
|
47
|
+
const openDeleteId = useRef(undefined);
|
|
48
|
+
const [dialogTest, setDialogTest] = useState();
|
|
49
|
+
const refreshDeferred = useRef(false);
|
|
50
|
+
useLayoutEffect(()=>{
|
|
51
|
+
if (notice) noticeRef.current?.focus();
|
|
52
|
+
}, [
|
|
53
|
+
notice
|
|
54
|
+
]);
|
|
55
|
+
useEffect(()=>{
|
|
56
|
+
const url = new URL(window.location.href);
|
|
57
|
+
const deleted = url.searchParams.get('deleted');
|
|
58
|
+
if (deleted === 'done' || deleted === 'already') setNotice({
|
|
59
|
+
outcome: deleted
|
|
60
|
+
});
|
|
61
|
+
if (url.searchParams.has('deleted')) {
|
|
62
|
+
url.searchParams.delete('deleted');
|
|
63
|
+
window.history.replaceState(window.history.state, '', `${url.pathname}${url.search}${url.hash}`);
|
|
64
|
+
}
|
|
65
|
+
}, []);
|
|
66
|
+
useOnTestReturn(reload);
|
|
40
67
|
useEffect(()=>{
|
|
41
68
|
let active = true;
|
|
42
69
|
const controller = new AbortController();
|
|
43
|
-
setState({
|
|
44
|
-
|
|
45
|
-
|
|
70
|
+
setState((current)=>current.loading || current.error ? {
|
|
71
|
+
loading: true
|
|
72
|
+
} : current);
|
|
73
|
+
function settle(next) {
|
|
74
|
+
if (!active) return;
|
|
75
|
+
// A new group can remount a row. Let its open dialog finish before replacing the list.
|
|
76
|
+
if (openDeleteId.current === undefined) {
|
|
77
|
+
setState(next);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
refreshDeferred.current = true;
|
|
81
|
+
if (!next.loading && !next.error) setDialogTest(next.tests.find((test)=>String(test.id) === openDeleteId.current));
|
|
82
|
+
}
|
|
46
83
|
async function load() {
|
|
47
84
|
try {
|
|
48
85
|
const response = await fetchAllDocs(`${apiRoute.replace(/\/$/, '')}/xp-experiments?depth=0&sort=id&${HOME_SELECT}`, {
|
|
49
86
|
credentials: 'include',
|
|
87
|
+
cache: 'no-store',
|
|
50
88
|
signal: controller.signal
|
|
51
89
|
});
|
|
52
90
|
if (!response.ok) throw new Error('list');
|
|
@@ -81,16 +119,16 @@ export function TestsHome({ adminRoute, apiRoute, canManage = false, crumbs, fla
|
|
|
81
119
|
for (const goal of body?.docs ?? [])if (typeof goal.name === 'string' && goal.name.trim() && ids.includes(String(goal.id))) goalNames[String(goal.id)] = goal.name;
|
|
82
120
|
} catch {}
|
|
83
121
|
}
|
|
84
|
-
|
|
122
|
+
settle({
|
|
85
123
|
loading: false,
|
|
86
124
|
error: false,
|
|
87
|
-
tests: docs,
|
|
125
|
+
tests: docs.filter((doc)=>!deletedIds.current.has(String(doc.id))),
|
|
88
126
|
goalNames,
|
|
89
127
|
summaries,
|
|
90
128
|
summaryError: !summary.ok
|
|
91
129
|
});
|
|
92
130
|
} catch {
|
|
93
|
-
|
|
131
|
+
settle({
|
|
94
132
|
loading: false,
|
|
95
133
|
error: true
|
|
96
134
|
});
|
|
@@ -107,9 +145,27 @@ export function TestsHome({ adminRoute, apiRoute, canManage = false, crumbs, fla
|
|
|
107
145
|
attempt,
|
|
108
146
|
canManage
|
|
109
147
|
]);
|
|
148
|
+
function handleDialogChange(id, open) {
|
|
149
|
+
openDeleteId.current = open ? String(id) : undefined;
|
|
150
|
+
setDialogTest(undefined);
|
|
151
|
+
if (!open && refreshDeferred.current) {
|
|
152
|
+
refreshDeferred.current = false;
|
|
153
|
+
reload();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function handleDeleted(id, outcome) {
|
|
157
|
+
deletedIds.current.add(String(id));
|
|
158
|
+
setNotice({
|
|
159
|
+
outcome
|
|
160
|
+
});
|
|
161
|
+
setState((current)=>!current.loading && !current.error ? {
|
|
162
|
+
...current,
|
|
163
|
+
tests: current.tests.filter((test)=>String(test.id) !== String(id))
|
|
164
|
+
} : current);
|
|
165
|
+
}
|
|
110
166
|
const retry = /*#__PURE__*/ _jsx(Button, {
|
|
111
167
|
size: "sm",
|
|
112
|
-
onClick:
|
|
168
|
+
onClick: reload,
|
|
113
169
|
children: SURFACE_COPY.retry
|
|
114
170
|
});
|
|
115
171
|
const newTest = /*#__PURE__*/ _jsx(Button, {
|
|
@@ -120,7 +176,7 @@ export function TestsHome({ adminRoute, apiRoute, canManage = false, crumbs, fla
|
|
|
120
176
|
}),
|
|
121
177
|
children: SURFACE_COPY.newTest
|
|
122
178
|
});
|
|
123
|
-
return /*#__PURE__*/
|
|
179
|
+
return /*#__PURE__*/ _jsxs(SurfaceShell, {
|
|
124
180
|
adminRoute: adminRoute,
|
|
125
181
|
crumbs: crumbs,
|
|
126
182
|
actions: /*#__PURE__*/ _jsxs(_Fragment, {
|
|
@@ -161,37 +217,54 @@ export function TestsHome({ adminRoute, apiRoute, canManage = false, crumbs, fla
|
|
|
161
217
|
newTest
|
|
162
218
|
]
|
|
163
219
|
}),
|
|
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
|
-
|
|
220
|
+
children: [
|
|
221
|
+
/*#__PURE__*/ _jsx("p", {
|
|
222
|
+
ref: noticeRef,
|
|
223
|
+
role: "status",
|
|
224
|
+
"aria-atomic": "true",
|
|
225
|
+
tabIndex: -1,
|
|
226
|
+
"data-testid": "delete-notice",
|
|
227
|
+
children: notice ? notice.outcome === 'done' ? DELETE_TEST.deleted : DELETE_TEST.alreadyDeleted : ''
|
|
228
|
+
}),
|
|
229
|
+
state.loading ? /*#__PURE__*/ _jsx("p", {
|
|
230
|
+
role: "status",
|
|
231
|
+
children: SURFACE_COPY.loading
|
|
232
|
+
}) : state.error ? /*#__PURE__*/ _jsx(Banner, {
|
|
233
|
+
tone: "error",
|
|
234
|
+
action: retry,
|
|
235
|
+
children: SURFACE_COPY.loadError
|
|
236
|
+
}) : /*#__PURE__*/ _jsxs(_Fragment, {
|
|
237
|
+
children: [
|
|
238
|
+
state.summaryError ? /*#__PURE__*/ _jsx(Banner, {
|
|
239
|
+
tone: "error",
|
|
240
|
+
action: retry,
|
|
241
|
+
children: SURFACE_COPY.summaryError
|
|
242
|
+
}) : null,
|
|
243
|
+
state.tests.length === 0 ? /*#__PURE__*/ _jsx(EmptyState, {
|
|
244
|
+
action: newTest,
|
|
245
|
+
children: SURFACE_COPY.empty
|
|
246
|
+
}) : /*#__PURE__*/ _jsx(TestGroups, {
|
|
247
|
+
tests: state.tests,
|
|
248
|
+
dialogTest: dialogTest,
|
|
249
|
+
summaries: state.summaries,
|
|
250
|
+
goalNames: state.goalNames,
|
|
251
|
+
adminRoute: adminRoute,
|
|
252
|
+
apiRoute: apiRoute,
|
|
253
|
+
contentLocale: contentLocale,
|
|
254
|
+
canManage: canManage,
|
|
255
|
+
onDeleted: handleDeleted,
|
|
256
|
+
onDialogChange: handleDialogChange,
|
|
257
|
+
onStatusChanged: reload,
|
|
258
|
+
flagPoints: flagPoints,
|
|
259
|
+
search: search,
|
|
260
|
+
clear: ()=>setSearch('')
|
|
261
|
+
})
|
|
262
|
+
]
|
|
263
|
+
})
|
|
264
|
+
]
|
|
192
265
|
});
|
|
193
266
|
}
|
|
194
|
-
function TestGroups({ tests, summaries, goalNames, adminRoute, flagPoints, search, clear }) {
|
|
267
|
+
function TestGroups({ tests, dialogTest, summaries, goalNames, adminRoute, apiRoute, contentLocale, canManage, onDeleted, onDialogChange, onStatusChanged, flagPoints, search, clear }) {
|
|
195
268
|
const groups = groupTests(tests, summaries, search);
|
|
196
269
|
if (!groups.some((group)=>group.tests.length)) return /*#__PURE__*/ _jsxs("div", {
|
|
197
270
|
className: "xp-tests-no-matches",
|
|
@@ -253,11 +326,25 @@ function TestGroups({ tests, summaries, goalNames, adminRoute, flagPoints, searc
|
|
|
253
326
|
})
|
|
254
327
|
]
|
|
255
328
|
}),
|
|
256
|
-
/*#__PURE__*/
|
|
257
|
-
className: "xp-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
329
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
330
|
+
className: "xp-ui-button-group",
|
|
331
|
+
children: [
|
|
332
|
+
/*#__PURE__*/ _jsx(DeleteTest, {
|
|
333
|
+
test: dialogTest?.id === test.id ? dialogTest : test,
|
|
334
|
+
canManage: canManage,
|
|
335
|
+
apiRoute: apiRoute,
|
|
336
|
+
contentLocale: contentLocale,
|
|
337
|
+
onDeleted: (outcome)=>onDeleted(test.id, outcome),
|
|
338
|
+
onDialogChange: (open)=>onDialogChange(test.id, open),
|
|
339
|
+
onStatusChanged: onStatusChanged
|
|
340
|
+
}),
|
|
341
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
342
|
+
className: "xp-tests-row-action",
|
|
343
|
+
size: "sm",
|
|
344
|
+
href: card.href,
|
|
345
|
+
children: card.action
|
|
346
|
+
})
|
|
347
|
+
]
|
|
261
348
|
})
|
|
262
349
|
]
|
|
263
350
|
}, 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
|