@delmaredigital/payload-experiments 0.4.0-rc.7 → 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/model.js +2 -2
- package/dist/admin/copy/blocks.js +1 -1
- package/dist/admin/surface/ResultsRoute.js +17 -11
- package/dist/admin/surface/TestsHome.js +53 -20
- package/dist/admin/surface/newTest/PageWizard.js +8 -2
- package/dist/admin/surface/results/ResultsHeader.js +11 -6
- package/dist/admin/surface/test/TestPage.js +3 -3
- package/dist/blocks/formState.js +1 -1
- 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/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/deleteImpact.js +2 -1
- package/dist/endpoints/events.js +103 -39
- package/dist/endpoints/index.js +2 -8
- package/dist/endpoints/placementStatus.js +7 -4
- 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/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 +2 -2
- package/dist/hooks/hostHook.js +6 -2
- package/dist/hooks/pageGuard.js +4 -0
- package/dist/lib/fetchAllDocs.d.ts +1 -1
- package/dist/manifest/compile.js +8 -5
- 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/editor/ConfigureTestDrawer.js +5 -4
- package/dist/puck/editor/ExperimentSlotEditor.js +182 -58
- 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 +13 -2
- package/dist/puck/editor/VersionBuilder.js +133 -49
- package/dist/puck/editor/armWrites.js +1 -1
- package/dist/puck/editor/armsCache.js +1 -3
- package/dist/puck/editor/copy.d.ts +4 -1
- package/dist/puck/editor/copy.js +4 -1
- package/dist/puck/editor/editor.chrome.css +1 -0
- package/dist/puck/editor/editor.css +1 -0
- package/dist/puck/editor/editor.model.d.ts +1 -0
- package/dist/puck/editor/placementsCache.d.ts +5 -1
- package/dist/puck/editor/placementsCache.js +17 -9
- 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 +5 -4
- 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 +11 -2
- package/dist/server/resolveExperimentBlocks.js +2 -4
- package/dist/server/resolveExperimentData.js +2 -5
- 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/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 +5 -5
- package/dist/testSurface/api.js +21 -9
- package/dist/testSurface/copy/actions.d.ts +1 -0
- package/dist/testSurface/copy/actions.js +1 -0
- package/dist/testSurface/copy/common.d.ts +3 -1
- package/dist/testSurface/copy/common.js +4 -2
- package/dist/testSurface/copy/languages.d.ts +1 -0
- package/dist/testSurface/copy/languages.js +1 -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 +12 -1
- package/dist/testSurface/copy/readiness.js +18 -1
- package/dist/testSurface/copy/results.d.ts +5 -2
- package/dist/testSurface/copy/results.js +5 -2
- package/dist/testSurface/copy/testPage.d.ts +20 -2
- package/dist/testSurface/copy/testPage.js +34 -3
- 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.model.d.ts +1 -1
- package/dist/testSurface/results/results.model.js +6 -2
- package/dist/testSurface/surface/contracts.d.ts +8 -1
- package/dist/testSurface/surface/editorPlacement.d.ts +2 -2
- package/dist/testSurface/surface/editorPlacement.js +1 -1
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +2 -2
- 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 +108 -11
- 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 +7 -6
- 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 +6 -2
- package/dist/testSurface/surface/test/DeleteTest.js +145 -54
- 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 +81 -19
- 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 +22 -4
- package/dist/testSurface/surface/useTestDocument.js +407 -160
- package/dist/testSurface/useApi.d.ts +5 -5
- 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 +1 -0
- package/dist/transitions/checkStart.js +17 -6
- 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 +12 -8
- package/dist/transitions/nestedPlacementNames.d.ts +2 -2
- package/dist/transitions/nestedPlacementNames.js +4 -5
- 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 +8 -7
- package/dist/transitions/placements.d.ts +2 -0
- package/dist/transitions/placements.js +5 -5
- package/dist/transitions/preflightData.d.ts +3 -2
- package/dist/transitions/preflightData.js +67 -41
- 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 +67 -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 +52 -9
- package/dist/types/runtime.d.ts +15 -9
- package/dist/types/snapshot.d.ts +2 -0
- package/dist/ui/ChipsInput.d.ts +8 -1
- package/dist/ui/ChipsInput.js +17 -4
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, useContext, useEffect, useId, useRef, useState } from 'react';
|
|
4
4
|
import { balanceWeight, splitEvenly, totalWeight, withSlotsFor } from '../../arms/model.js';
|
|
5
5
|
import { checkArms } from '../../collections/experiments/armInvariants.js';
|
|
@@ -9,6 +9,7 @@ import { Dialog } from '../../ui/Dialog.js';
|
|
|
9
9
|
import { NumberInput, TextInput } from '../../ui/Inputs.js';
|
|
10
10
|
import { addVersionArms, ArmWriteError, removeVersionArms, renameVersionArms, setVersionTraffic, writeArms } from './armWrites.js';
|
|
11
11
|
import { editorCopy as C } from './copy.js';
|
|
12
|
+
import { SavedValueChanged, useDraftAnnouncement } from '../../testSurface/surface/test/fields.js';
|
|
12
13
|
const VersionLockContext = /*#__PURE__*/ createContext(undefined);
|
|
13
14
|
/** A pointer shortcut supplements the explicit, keyboard-accessible open marker. */ export function VersionCard({ label, openLabel = label, active, dragging, interactive = true, onSelect, children }) {
|
|
14
15
|
return /*#__PURE__*/ _jsx("div", {
|
|
@@ -282,21 +283,19 @@ export function AddVariant({ experiment, writes, onSelect }) {
|
|
|
282
283
|
children: C.add
|
|
283
284
|
});
|
|
284
285
|
}
|
|
285
|
-
|
|
286
|
+
export function VersionName({ arm, writes, editable, draftState }) {
|
|
286
287
|
const id = useId();
|
|
287
288
|
const lockId = useContext(VersionLockContext);
|
|
288
|
-
const
|
|
289
|
-
const
|
|
289
|
+
const localDraft = useState(null);
|
|
290
|
+
const [edit, setEdit] = draftState ?? localDraft;
|
|
290
291
|
const pending = useRef(null);
|
|
291
292
|
const [error, setError] = useState();
|
|
292
293
|
const [invalid, setInvalid] = useState(false);
|
|
293
294
|
const [saved, setSaved] = useState(false);
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
arm.label
|
|
299
|
-
]);
|
|
295
|
+
const [announcement, announce] = useDraftAnnouncement();
|
|
296
|
+
const changed = edit !== null && edit.base !== arm.label;
|
|
297
|
+
const name = changed && edit.submitted ? arm.label : edit?.draft ?? arm.label;
|
|
298
|
+
const conflict = changed && !edit.submitted && name !== arm.label;
|
|
300
299
|
useEffect(()=>{
|
|
301
300
|
if (!saved) return;
|
|
302
301
|
const timer = setTimeout(()=>setSaved(false), 2000);
|
|
@@ -304,13 +303,33 @@ export function AddVariant({ experiment, writes, onSelect }) {
|
|
|
304
303
|
}, [
|
|
305
304
|
saved
|
|
306
305
|
]);
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
306
|
+
const unfinished = edit !== null && !edit.submitted;
|
|
307
|
+
const choice = unfinished && (conflict || !editable);
|
|
308
|
+
const choiceId = choice ? `${id}-new-value` : undefined;
|
|
309
|
+
const discard = ()=>{
|
|
310
|
+
if (pending.current?.started) return;
|
|
311
|
+
if (pending.current) pending.current.cancelled = true;
|
|
312
|
+
setEdit(null);
|
|
313
|
+
setInvalid(false);
|
|
314
|
+
setError(undefined);
|
|
315
|
+
setSaved(false);
|
|
316
|
+
};
|
|
317
|
+
async function commit(confirmed = false) {
|
|
318
|
+
if (pending.current || !edit || edit.submitted) return;
|
|
319
|
+
if (!editable || choice && !confirmed) {
|
|
320
|
+
announce();
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (name === arm.label) {
|
|
324
|
+
discard();
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
if (!name.trim()) {
|
|
310
328
|
setInvalid(true);
|
|
311
329
|
return;
|
|
312
330
|
}
|
|
313
|
-
const label =
|
|
331
|
+
const label = name.trim();
|
|
332
|
+
const base = confirmed ? arm.label : edit.base;
|
|
314
333
|
const attempt = {
|
|
315
334
|
started: false,
|
|
316
335
|
cancelled: false
|
|
@@ -319,7 +338,10 @@ export function AddVariant({ experiment, writes, onSelect }) {
|
|
|
319
338
|
setError(undefined);
|
|
320
339
|
setSaved(false);
|
|
321
340
|
try {
|
|
322
|
-
const result = await writes.write((arms)=>
|
|
341
|
+
const result = await writes.write((arms)=>{
|
|
342
|
+
if (arms.find((current)=>current.key === arm.key)?.label !== base) throw new ArmWriteError(C.nameChanged);
|
|
343
|
+
return renameVersionArms(arms, arm.key, label);
|
|
344
|
+
}, {
|
|
323
345
|
onError: setError,
|
|
324
346
|
queue: true,
|
|
325
347
|
cancelled: ()=>attempt.cancelled,
|
|
@@ -327,12 +349,18 @@ export function AddVariant({ experiment, writes, onSelect }) {
|
|
|
327
349
|
attempt.started = true;
|
|
328
350
|
}
|
|
329
351
|
});
|
|
330
|
-
if (result)
|
|
352
|
+
if (result) {
|
|
353
|
+
setEdit(draftState ? null : {
|
|
354
|
+
...edit,
|
|
355
|
+
submitted: true
|
|
356
|
+
});
|
|
357
|
+
setSaved(true);
|
|
358
|
+
}
|
|
331
359
|
} finally{
|
|
332
360
|
pending.current = null;
|
|
333
361
|
}
|
|
334
362
|
}
|
|
335
|
-
const message = invalid ? C.emptyLabel : error;
|
|
363
|
+
const message = !choice ? invalid ? C.emptyLabel : error : undefined;
|
|
336
364
|
return /*#__PURE__*/ _jsxs("div", {
|
|
337
365
|
className: "xp-slot-version-name",
|
|
338
366
|
children: [
|
|
@@ -345,33 +373,32 @@ export function AddVariant({ experiment, writes, onSelect }) {
|
|
|
345
373
|
"aria-disabled": !editable || writes.busy || undefined,
|
|
346
374
|
"aria-describedby": [
|
|
347
375
|
lockId,
|
|
376
|
+
choiceId,
|
|
348
377
|
saved ? `${id}-saved` : undefined
|
|
349
378
|
].filter(Boolean).join(' ') || undefined,
|
|
350
379
|
"aria-errormessage": message ? `${id}-error` : undefined,
|
|
351
380
|
error: message,
|
|
352
381
|
onChange: (event)=>{
|
|
353
382
|
if (!editable || writes.busy) return;
|
|
354
|
-
draft
|
|
355
|
-
|
|
383
|
+
const draft = event.target.value;
|
|
384
|
+
setEdit(draft === arm.label ? null : {
|
|
385
|
+
base: edit && !edit.submitted ? edit.base : arm.label,
|
|
386
|
+
draft,
|
|
387
|
+
submitted: false
|
|
388
|
+
});
|
|
356
389
|
setInvalid(false);
|
|
357
390
|
setError(undefined);
|
|
358
391
|
setSaved(false);
|
|
359
392
|
},
|
|
360
393
|
onBlur: ()=>void commit(),
|
|
361
394
|
onKeyDown: (event)=>{
|
|
362
|
-
if (event.key === 'Enter') {
|
|
395
|
+
if (event.key === 'Enter' && !event.nativeEvent.isComposing) {
|
|
363
396
|
event.preventDefault();
|
|
364
397
|
void commit();
|
|
365
398
|
}
|
|
366
399
|
if (event.key === 'Escape') {
|
|
367
400
|
event.preventDefault();
|
|
368
|
-
|
|
369
|
-
if (pending.current) pending.current.cancelled = true;
|
|
370
|
-
draft.current = arm.label;
|
|
371
|
-
setName(arm.label);
|
|
372
|
-
setInvalid(false);
|
|
373
|
-
setError(undefined);
|
|
374
|
-
setSaved(false);
|
|
401
|
+
discard();
|
|
375
402
|
}
|
|
376
403
|
}
|
|
377
404
|
}),
|
|
@@ -380,7 +407,18 @@ export function AddVariant({ experiment, writes, onSelect }) {
|
|
|
380
407
|
role: "status",
|
|
381
408
|
className: "xp-ui-help xp-slot-version-saved",
|
|
382
409
|
children: saved ? C.saved : ''
|
|
383
|
-
})
|
|
410
|
+
}),
|
|
411
|
+
choiceId && !writes.busy ? /*#__PURE__*/ _jsx(SavedValueChanged, {
|
|
412
|
+
id: choiceId,
|
|
413
|
+
value: arm.label,
|
|
414
|
+
reason: conflict ? C.nameChanged : error,
|
|
415
|
+
conflict: conflict,
|
|
416
|
+
announce: announcement,
|
|
417
|
+
onDiscard: discard,
|
|
418
|
+
onKeep: editable && !writes.busy ? ()=>{
|
|
419
|
+
void commit(true);
|
|
420
|
+
} : undefined
|
|
421
|
+
}) : null
|
|
384
422
|
]
|
|
385
423
|
});
|
|
386
424
|
}
|
|
@@ -445,11 +483,14 @@ export function RemoveVersion({ arm, writes, count, shared, onRemove, onClose })
|
|
|
445
483
|
})
|
|
446
484
|
});
|
|
447
485
|
}
|
|
486
|
+
const shareBase = (arms)=>arms.map((arm)=>`${arm.key}:${arm.weight}`).join(',');
|
|
448
487
|
export function VersionWeights({ experiment, writes, edits, setEdits, groupId, splitIntent, editable = true, showSplit = editable, beforeSplit, beforeActions, renderRow }) {
|
|
449
488
|
const id = useId();
|
|
450
489
|
const lockId = useContext(VersionLockContext);
|
|
451
490
|
const [errors, setErrors] = useState({});
|
|
452
491
|
const armKeys = experiment.arms.map((arm)=>arm.key).join(',');
|
|
492
|
+
const base = shareBase(experiment.arms);
|
|
493
|
+
const [announcement, announce] = useDraftAnnouncement();
|
|
453
494
|
useEffect(()=>{
|
|
454
495
|
const keys = new Set(armKeys.split(','));
|
|
455
496
|
setErrors((current)=>Object.fromEntries(Object.entries(current).filter(([key])=>keys.has(key))));
|
|
@@ -457,18 +498,27 @@ export function VersionWeights({ experiment, writes, edits, setEdits, groupId, s
|
|
|
457
498
|
armKeys
|
|
458
499
|
]);
|
|
459
500
|
const clearErrors = (keys)=>setErrors((current)=>Object.fromEntries(Object.entries(current).filter(([key])=>!keys.includes(key))));
|
|
460
|
-
const invalidKeys = new Set(Object.entries(edits).filter(([,
|
|
461
|
-
const apply = (arms, key)=>balanceWeight(arms, key, Number(edits[key]));
|
|
501
|
+
const invalidKeys = new Set(Object.entries(edits).filter(([, edit])=>edit.value.trim() === '' || !Number.isInteger(Number(edit.value)) || Number(edit.value) < 0 || Number(edit.value) > 100).map(([key])=>key));
|
|
502
|
+
const apply = (arms, key)=>balanceWeight(arms, key, Number(edits[key]?.value));
|
|
462
503
|
const keys = Object.keys(edits);
|
|
463
504
|
const clearDraft = (key)=>setEdits((current)=>Object.fromEntries(Object.entries(current).filter(([candidate])=>candidate !== key)));
|
|
464
|
-
const live = withSlotsFor(keys.length === 1 && !invalidKeys.has(keys[0]) && !errors[keys[0]] ? apply(experiment.arms, keys[0]) : experiment.arms, 'block');
|
|
505
|
+
const live = withSlotsFor(keys.length === 1 && !invalidKeys.has(keys[0]) && !errors[keys[0]] && edits[keys[0]]?.base === base && editable ? apply(experiment.arms, keys[0]) : experiment.arms, 'block');
|
|
465
506
|
const issues = checkArms(live, 'block');
|
|
466
|
-
async function commit(key) {
|
|
467
|
-
|
|
507
|
+
async function commit(key, confirmed = false) {
|
|
508
|
+
const edit = edits[key];
|
|
509
|
+
if (writes.busy || !edit || invalidKeys.has(key)) return;
|
|
510
|
+
if (!editable || !confirmed && edit.base !== base) {
|
|
511
|
+
announce();
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
468
514
|
clearErrors([
|
|
469
515
|
key
|
|
470
516
|
]);
|
|
471
|
-
const
|
|
517
|
+
const expected = confirmed ? base : edit.base;
|
|
518
|
+
const saved = await writes.write((arms)=>{
|
|
519
|
+
if (shareBase(arms) !== expected) throw new ArmWriteError(C.shareChanged);
|
|
520
|
+
return setVersionTraffic(arms, key, Number(edit.value));
|
|
521
|
+
}, {
|
|
472
522
|
onError: (message)=>setErrors((current)=>({
|
|
473
523
|
...current,
|
|
474
524
|
[key]: message
|
|
@@ -482,6 +532,11 @@ export function VersionWeights({ experiment, writes, edits, setEdits, groupId, s
|
|
|
482
532
|
/*#__PURE__*/ _jsx("div", {
|
|
483
533
|
className: "xp-slot-weight-inputs",
|
|
484
534
|
children: experiment.arms.map((arm)=>{
|
|
535
|
+
const edit = edits[arm.key];
|
|
536
|
+
const conflict = !!edit && edit.base !== base;
|
|
537
|
+
const choiceId = edit && (conflict || !editable) ? `${id}-${arm.key}-new-value` : undefined;
|
|
538
|
+
const error = !choiceId ? invalidKeys.has(arm.key) ? C.invalidShare : errors[arm.key] : undefined;
|
|
539
|
+
const errorId = error ? `${id}-${arm.key}-error` : undefined;
|
|
485
540
|
const input = /*#__PURE__*/ _jsx(NumberInput, {
|
|
486
541
|
id: `${id}-${arm.key}`,
|
|
487
542
|
label: C.traffic,
|
|
@@ -489,21 +544,29 @@ export function VersionWeights({ experiment, writes, edits, setEdits, groupId, s
|
|
|
489
544
|
min: 0,
|
|
490
545
|
max: 100,
|
|
491
546
|
step: 1,
|
|
492
|
-
value:
|
|
547
|
+
value: edit?.value ?? live.find((current)=>current.key === arm.key)?.weight ?? '',
|
|
493
548
|
readOnly: !editable || writes.busy,
|
|
494
549
|
"aria-disabled": !editable || writes.busy || undefined,
|
|
495
|
-
"aria-describedby":
|
|
496
|
-
|
|
497
|
-
|
|
550
|
+
"aria-describedby": [
|
|
551
|
+
lockId,
|
|
552
|
+
choiceId
|
|
553
|
+
].filter(Boolean).join(' ') || undefined,
|
|
554
|
+
"aria-errormessage": errorId,
|
|
555
|
+
error: error,
|
|
498
556
|
onChange: (event)=>{
|
|
499
557
|
if (!editable || writes.busy) return;
|
|
500
558
|
clearErrors([
|
|
501
559
|
arm.key
|
|
502
560
|
]);
|
|
503
561
|
const value = event.target.value;
|
|
504
|
-
|
|
562
|
+
if (!conflict && value === String(arm.weight)) clearDraft(arm.key);
|
|
563
|
+
else setEdits((current)=>({
|
|
505
564
|
...current,
|
|
506
|
-
[arm.key]:
|
|
565
|
+
[arm.key]: {
|
|
566
|
+
value,
|
|
567
|
+
base: current[arm.key]?.base ?? base,
|
|
568
|
+
label: C.weight(arm.label)
|
|
569
|
+
}
|
|
507
570
|
}));
|
|
508
571
|
},
|
|
509
572
|
onBlur: (event)=>{
|
|
@@ -524,23 +587,44 @@ export function VersionWeights({ experiment, writes, edits, setEdits, groupId, s
|
|
|
524
587
|
}
|
|
525
588
|
}
|
|
526
589
|
});
|
|
590
|
+
const notice = choiceId && !writes.busy ? /*#__PURE__*/ _jsx(SavedValueChanged, {
|
|
591
|
+
id: choiceId,
|
|
592
|
+
value: `${arm.weight}%`,
|
|
593
|
+
reason: conflict ? C.shareChanged : errors[arm.key],
|
|
594
|
+
conflict: conflict,
|
|
595
|
+
announce: announcement,
|
|
596
|
+
onDiscard: ()=>clearDraft(arm.key),
|
|
597
|
+
onKeep: editable && !invalidKeys.has(arm.key) ? ()=>{
|
|
598
|
+
void commit(arm.key, true);
|
|
599
|
+
} : undefined
|
|
600
|
+
}) : null;
|
|
527
601
|
return /*#__PURE__*/ _jsx("div", {
|
|
528
602
|
className: "xp-slot-version-item",
|
|
529
|
-
children: renderRow ? renderRow(arm, /*#__PURE__*/ _jsxs(
|
|
530
|
-
|
|
603
|
+
children: renderRow ? renderRow(arm, /*#__PURE__*/ _jsxs(_Fragment, {
|
|
604
|
+
children: [
|
|
605
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
606
|
+
className: "xp-slot-version-traffic",
|
|
607
|
+
children: [
|
|
608
|
+
input,
|
|
609
|
+
/*#__PURE__*/ _jsx("span", {
|
|
610
|
+
className: "xp-slot-percent",
|
|
611
|
+
"aria-hidden": "true",
|
|
612
|
+
children: C.percent
|
|
613
|
+
})
|
|
614
|
+
]
|
|
615
|
+
}),
|
|
616
|
+
notice
|
|
617
|
+
]
|
|
618
|
+
})) : /*#__PURE__*/ _jsxs(_Fragment, {
|
|
531
619
|
children: [
|
|
532
620
|
input,
|
|
533
|
-
|
|
534
|
-
className: "xp-slot-percent",
|
|
535
|
-
"aria-hidden": "true",
|
|
536
|
-
children: C.percent
|
|
537
|
-
})
|
|
621
|
+
notice
|
|
538
622
|
]
|
|
539
|
-
})
|
|
623
|
+
})
|
|
540
624
|
}, arm.key);
|
|
541
625
|
})
|
|
542
626
|
}),
|
|
543
|
-
|
|
627
|
+
keys.length && !invalidKeys.size ? issues.map((issue, i)=>/*#__PURE__*/ _jsx("p", {
|
|
544
628
|
role: "alert",
|
|
545
629
|
className: "xp-ui-error",
|
|
546
630
|
children: issueMessage(issue, totalWeight(live))
|
|
@@ -94,7 +94,7 @@ export async function readExperiment(url, signal) {
|
|
|
94
94
|
if (!response.ok) {
|
|
95
95
|
const codes = Array.isArray(body?.errors) ? body.errors : [];
|
|
96
96
|
const stale = response.status === 409 && codes.some((error)=>error?.code === 'stale-edit');
|
|
97
|
-
if (
|
|
97
|
+
if (response.status === 409 || response.status === 403) {
|
|
98
98
|
try {
|
|
99
99
|
publish(await readExperiment(`${url}?depth=0`));
|
|
100
100
|
} catch {}
|
|
@@ -33,11 +33,9 @@ const mounted = new Map();
|
|
|
33
33
|
const revision = revisions.get(key) ?? 0;
|
|
34
34
|
entry.promise = load(controller.signal).then((doc)=>{
|
|
35
35
|
if ((revisions.get(key) ?? 0) !== revision) return cache.get(key)?.doc ?? doc;
|
|
36
|
-
|
|
37
|
-
return doc;
|
|
36
|
+
return controller.signal.aborted ? doc : publishExperiment(testId, doc);
|
|
38
37
|
}, (error)=>{
|
|
39
38
|
if ((revisions.get(key) ?? 0) !== revision && cache.get(key)?.doc) return cache.get(key).doc;
|
|
40
|
-
if (!controller.signal.aborted && (revisions.get(key) ?? 0) === revision) setArms(testId, undefined);
|
|
41
39
|
throw error;
|
|
42
40
|
}).finally(()=>{
|
|
43
41
|
if (pending.get(key) === entry) pending.delete(key);
|
|
@@ -86,7 +86,10 @@ export declare const editorCopy: {
|
|
|
86
86
|
readonly decided: "This test has a decision, so its versions can't change. View the results on the test page.";
|
|
87
87
|
readonly archived: "This test is archived, so its versions can't change. View the results on the test page.";
|
|
88
88
|
};
|
|
89
|
-
readonly staleEdit: "
|
|
89
|
+
readonly staleEdit: "This test changed. Check the saved settings and try again.";
|
|
90
|
+
readonly nameChanged: "This version name changed while you were editing.";
|
|
91
|
+
readonly versionName: (label: string) => string;
|
|
92
|
+
readonly shareChanged: "The saved shares changed while you were editing.";
|
|
90
93
|
readonly writeError: "Couldn't complete this change. Try again.";
|
|
91
94
|
readonly writeNetwork: "Couldn't reach the server. Check your connection and try again.";
|
|
92
95
|
readonly writeUnreadable: "Couldn't read the server's response. Reload and try again.";
|
package/dist/puck/editor/copy.js
CHANGED
|
@@ -82,7 +82,10 @@ export const editorCopy = {
|
|
|
82
82
|
decided: "This test has a decision, so its versions can't change. View the results on the test page.",
|
|
83
83
|
archived: "This test is archived, so its versions can't change. View the results on the test page."
|
|
84
84
|
},
|
|
85
|
-
staleEdit: '
|
|
85
|
+
staleEdit: 'This test changed. Check the saved settings and try again.',
|
|
86
|
+
nameChanged: 'This version name changed while you were editing.',
|
|
87
|
+
versionName: (label)=>`${label} version name`,
|
|
88
|
+
shareChanged: 'The saved shares changed while you were editing.',
|
|
86
89
|
writeError: "Couldn't complete this change. Try again.",
|
|
87
90
|
writeNetwork: "Couldn't reach the server. Check your connection and try again.",
|
|
88
91
|
writeUnreadable: "Couldn't read the server's response. Reload and try again.",
|
|
@@ -247,6 +247,7 @@
|
|
|
247
247
|
.xp-slot-version-name .xp-ui-input { grid-area: 1 / 2; min-width: 0; font-weight: 600; }
|
|
248
248
|
.xp-slot-version-traffic .xp-ui-input { grid-area: 1 / 3; min-width: 0; }
|
|
249
249
|
.xp-slot-version-label { grid-area: 1 / 2 / auto / -1; align-self: center; min-width: 0; overflow-wrap: anywhere; }
|
|
250
|
+
.xp-slot-version-row .xp-field-draft-notice,
|
|
250
251
|
.xp-slot-version-row .xp-ui-error { grid-column: 1 / -1; margin: 0; }
|
|
251
252
|
/* Reserve one feedback line. Visibility preserves geometry between saves. */
|
|
252
253
|
.xp-slot-version-saved { grid-column: 1 / -1; min-height: 16px; margin: 0; font: var(--xp-text-small); }
|
|
@@ -641,6 +641,7 @@
|
|
|
641
641
|
.xp-slot-version-name .xp-ui-input { grid-area: 1 / 2; min-width: 0; font-weight: 600; }
|
|
642
642
|
.xp-slot-version-traffic .xp-ui-input { grid-area: 1 / 3; min-width: 0; }
|
|
643
643
|
.xp-slot-version-label { grid-area: 1 / 2 / auto / -1; align-self: center; min-width: 0; overflow-wrap: anywhere; }
|
|
644
|
+
.xp-slot-version-row .xp-field-draft-notice,
|
|
644
645
|
.xp-slot-version-row .xp-ui-error { grid-column: 1 / -1; margin: 0; }
|
|
645
646
|
/* Reserve one feedback line. Visibility preserves geometry between saves. */
|
|
646
647
|
.xp-slot-version-saved { grid-column: 1 / -1; min-height: 16px; margin: 0; font: var(--xp-text-small); }
|
|
@@ -3,6 +3,7 @@ import type { ArmSlot } from '../../types/puck.js';
|
|
|
3
3
|
import type { PreflightResult } from '../../types/endpoints.js';
|
|
4
4
|
export type EditorExperiment = {
|
|
5
5
|
name: string;
|
|
6
|
+
phase?: number;
|
|
6
7
|
updatedAt?: string;
|
|
7
8
|
status: Status;
|
|
8
9
|
arms: Array<Pick<Arm, 'key' | 'kind' | 'label'> & Partial<Arm>>;
|
|
@@ -8,10 +8,12 @@ export declare function refreshPlacements(api: string, id: DocId, contentLocale?
|
|
|
8
8
|
title: string;
|
|
9
9
|
locales?: string[];
|
|
10
10
|
allLocales?: true;
|
|
11
|
+
localeCodes?: string[];
|
|
11
12
|
slotCount?: number;
|
|
12
13
|
url?: string;
|
|
13
14
|
editorUrl?: string;
|
|
14
15
|
slots?: Record<import("../../types/puck.js").ArmSlot, number>;
|
|
16
|
+
partlyFilledSlots?: import("../../types/puck.js").ArmSlot[];
|
|
15
17
|
ok: boolean;
|
|
16
18
|
detail?: string;
|
|
17
19
|
}[] | undefined>;
|
|
@@ -22,10 +24,12 @@ export declare function focusPlacements(api: string, id: DocId, contentLocale?:
|
|
|
22
24
|
title: string;
|
|
23
25
|
locales?: string[];
|
|
24
26
|
allLocales?: true;
|
|
27
|
+
localeCodes?: string[];
|
|
25
28
|
slotCount?: number;
|
|
26
29
|
url?: string;
|
|
27
30
|
editorUrl?: string;
|
|
28
31
|
slots?: Record<import("../../types/puck.js").ArmSlot, number>;
|
|
32
|
+
partlyFilledSlots?: import("../../types/puck.js").ArmSlot[];
|
|
29
33
|
ok: boolean;
|
|
30
34
|
detail?: string;
|
|
31
35
|
}[] | undefined>;
|
|
@@ -52,5 +56,5 @@ export declare function cachedReadinessRead(api: string, id: DocId, contentLocal
|
|
|
52
56
|
pollDelay: number | null;
|
|
53
57
|
} | undefined;
|
|
54
58
|
export declare function placementReadError(api: string, id: DocId, contentLocale?: string): string | undefined;
|
|
55
|
-
export declare function watchPlacementNotice(api: string, id: DocId, doc: Document, contentLocale?: string): () => void;
|
|
59
|
+
export declare function watchPlacementNotice(api: string, id: DocId, doc: Document, contentLocale?: string, showingNotice?: boolean): () => void;
|
|
56
60
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { contentLocaleURL } from '../../testSurface/contentLocaleURL.js';
|
|
2
|
-
import { isPreflightResult, readPreflight } from '../../testSurface/readPreflight.js';
|
|
2
|
+
import { isPreflightResult, readPreflight, READINESS_REFRESH_MS } from '../../testSurface/readPreflight.js';
|
|
3
3
|
import { classifyReadinessRead } from '../../testSurface/readinessRead.js';
|
|
4
4
|
const cache = new Map();
|
|
5
5
|
const latest = new Map();
|
|
@@ -180,8 +180,12 @@ export function placementReadError(api, id, contentLocale) {
|
|
|
180
180
|
return cachedReadinessRead(api, id, contentLocale)?.message;
|
|
181
181
|
}
|
|
182
182
|
const notices = new WeakMap();
|
|
183
|
-
const noticeDelay = (api, id, contentLocale
|
|
184
|
-
|
|
183
|
+
const noticeDelay = ({ api, id, contentLocale, noticeSubscribers })=>{
|
|
184
|
+
const read = cachedReadinessRead(api, id, contentLocale);
|
|
185
|
+
if (read?.pollDelay && (read.failed || noticeSubscribers)) return read.pollDelay;
|
|
186
|
+
return read?.answer?.document ? READINESS_REFRESH_MS : null;
|
|
187
|
+
};
|
|
188
|
+
export function watchPlacementNotice(api, id, doc, contentLocale, showingNotice = true) {
|
|
185
189
|
let session = notices.get(doc);
|
|
186
190
|
if (!session) {
|
|
187
191
|
const requests = new Map();
|
|
@@ -200,7 +204,7 @@ export function watchPlacementNotice(api, id, doc, contentLocale) {
|
|
|
200
204
|
}
|
|
201
205
|
const eligible = [
|
|
202
206
|
...created.requests.values()
|
|
203
|
-
].filter((request)=>!request.pending && noticeDelay(request
|
|
207
|
+
].filter((request)=>!request.pending && noticeDelay(request) !== null);
|
|
204
208
|
if (doc.visibilityState !== 'visible' || !eligible.length) return;
|
|
205
209
|
created.timer = setTimeout(()=>{
|
|
206
210
|
created.timer = undefined;
|
|
@@ -210,7 +214,7 @@ export function watchPlacementNotice(api, id, doc, contentLocale) {
|
|
|
210
214
|
request.pending = true;
|
|
211
215
|
void refreshPlacements(request.api, request.id, request.contentLocale).then(()=>{
|
|
212
216
|
request.pending = false;
|
|
213
|
-
request.nextAt = Date.now() + (noticeDelay(request
|
|
217
|
+
request.nextAt = Date.now() + (noticeDelay(request) ?? 0);
|
|
214
218
|
if (notices.get(doc) === created) created.schedule();
|
|
215
219
|
});
|
|
216
220
|
}
|
|
@@ -218,7 +222,7 @@ export function watchPlacementNotice(api, id, doc, contentLocale) {
|
|
|
218
222
|
}, Math.max(0, Math.min(...eligible.map((request)=>request.nextAt)) - Date.now()));
|
|
219
223
|
};
|
|
220
224
|
created.visibility = ()=>{
|
|
221
|
-
for (const request of created.requests.values())request.nextAt = Date.now() + (noticeDelay(request
|
|
225
|
+
for (const request of created.requests.values())request.nextAt = Date.now() + (noticeDelay(request) ?? 0);
|
|
222
226
|
created.schedule();
|
|
223
227
|
};
|
|
224
228
|
session = created;
|
|
@@ -233,23 +237,27 @@ export function watchPlacementNotice(api, id, doc, contentLocale) {
|
|
|
233
237
|
id,
|
|
234
238
|
contentLocale,
|
|
235
239
|
subscribers: 0,
|
|
236
|
-
|
|
240
|
+
noticeSubscribers: 0,
|
|
241
|
+
nextAt: 0,
|
|
237
242
|
pending: false,
|
|
238
243
|
release: ()=>{}
|
|
239
244
|
};
|
|
240
245
|
request.subscribers++;
|
|
246
|
+
if (showingNotice) request.noticeSubscribers++;
|
|
247
|
+
if (!existing || request.noticeSubscribers === 1 && showingNotice) request.nextAt = Date.now() + (noticeDelay(request) ?? 0);
|
|
241
248
|
current.requests.set(key, request);
|
|
242
249
|
if (!existing) request.release = subscribePlacements(api, id, ()=>{
|
|
243
250
|
if (placementsPending(api, id, contentLocale)) return;
|
|
244
251
|
// Manual/focus retries also reset the backoff after recovery.
|
|
245
|
-
request.nextAt = Date.now() + (noticeDelay(
|
|
252
|
+
request.nextAt = Date.now() + (noticeDelay(request) ?? 0);
|
|
246
253
|
current.schedule();
|
|
247
254
|
}, contentLocale);
|
|
248
|
-
|
|
255
|
+
current.schedule();
|
|
249
256
|
let active = true;
|
|
250
257
|
return ()=>{
|
|
251
258
|
if (!active) return;
|
|
252
259
|
active = false;
|
|
260
|
+
if (showingNotice && --request.noticeSubscribers === 0) request.nextAt = Date.now() + (noticeDelay(request) ?? 0);
|
|
253
261
|
if (--request.subscribers === 0) {
|
|
254
262
|
current.removeRequest(key);
|
|
255
263
|
request.release();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DocId } from '../../types/contracts.js';
|
|
2
|
+
/** Payload Puck's built-in editor exposes no save callback through integrations.
|
|
3
|
+
* Observe its completed same-origin page request. Custom editors and browsers
|
|
4
|
+
* without Resource Timing still use the placement watcher.
|
|
5
|
+
*/
|
|
6
|
+
export declare function usePageSaveReadiness(api: string, id: DocId | undefined, page: {
|
|
7
|
+
collection: string;
|
|
8
|
+
id: string;
|
|
9
|
+
} | undefined, contentLocale?: string): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { invalidatePlacements } from './placementsCache.js';
|
|
4
|
+
/** Payload Puck's built-in editor exposes no save callback through integrations.
|
|
5
|
+
* Observe its completed same-origin page request. Custom editors and browsers
|
|
6
|
+
* without Resource Timing still use the placement watcher.
|
|
7
|
+
*/ export function usePageSaveReadiness(api, id, page, contentLocale) {
|
|
8
|
+
const collection = page?.collection;
|
|
9
|
+
const pageId = page?.id;
|
|
10
|
+
useEffect(()=>{
|
|
11
|
+
if (id === undefined || !collection || !pageId || !globalThis.PerformanceObserver?.supportedEntryTypes?.includes('resource')) return;
|
|
12
|
+
const endpoint = new URL(`/api/puck/${encodeURIComponent(collection)}/${encodeURIComponent(pageId)}`, window.location.origin);
|
|
13
|
+
const observer = new PerformanceObserver((entries)=>{
|
|
14
|
+
const completed = entries.getEntriesByType('resource').some((entry)=>{
|
|
15
|
+
const response = entry;
|
|
16
|
+
const status = response.responseStatus;
|
|
17
|
+
if (response.initiatorType !== 'fetch' || status && (status < 200 || status >= 300)) return false;
|
|
18
|
+
const url = new URL(response.name);
|
|
19
|
+
return url.origin === endpoint.origin && url.pathname === endpoint.pathname;
|
|
20
|
+
});
|
|
21
|
+
if (completed) invalidatePlacements(api, id, contentLocale);
|
|
22
|
+
});
|
|
23
|
+
observer.observe({
|
|
24
|
+
type: 'resource'
|
|
25
|
+
});
|
|
26
|
+
return ()=>observer.disconnect();
|
|
27
|
+
}, [
|
|
28
|
+
api,
|
|
29
|
+
id,
|
|
30
|
+
collection,
|
|
31
|
+
pageId,
|
|
32
|
+
contentLocale
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { DocId } from '../../types/contracts.js';
|
|
2
|
-
/**
|
|
3
|
-
export declare function usePlacementNotice(api: string, id: DocId | undefined, message: string | undefined, contentLocale?: string): void;
|
|
2
|
+
/** Visible guidance refreshes sooner than idle status. */
|
|
3
|
+
export declare function usePlacementNotice(api: string, id: DocId | undefined, message: string | undefined, contentLocale?: string, watchStatus?: boolean): void;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useEffect } from 'react';
|
|
3
3
|
import { watchPlacementNotice } from './placementsCache.js';
|
|
4
|
-
/**
|
|
4
|
+
/** Visible guidance refreshes sooner than idle status. */ export function usePlacementNotice(api, id, message, contentLocale, watchStatus = false) {
|
|
5
5
|
const showing = message !== undefined && id !== undefined;
|
|
6
6
|
useEffect(()=>{
|
|
7
|
-
if (id === undefined || !showing) return;
|
|
8
|
-
return watchPlacementNotice(api, id, document, contentLocale);
|
|
7
|
+
if (id === undefined || !showing && !watchStatus) return;
|
|
8
|
+
return watchPlacementNotice(api, id, document, contentLocale, showing);
|
|
9
9
|
}, [
|
|
10
10
|
api,
|
|
11
11
|
id,
|
|
12
12
|
showing,
|
|
13
|
-
contentLocale
|
|
13
|
+
contentLocale,
|
|
14
|
+
watchStatus
|
|
14
15
|
]);
|
|
15
16
|
}
|
|
@@ -2,11 +2,13 @@ export type Timestamp = Date | string | number;
|
|
|
2
2
|
export interface ExposedUnit {
|
|
3
3
|
arm: string;
|
|
4
4
|
firstTs: Timestamp;
|
|
5
|
+
unitAgeMs?: number;
|
|
5
6
|
}
|
|
6
7
|
export interface MetricEvent {
|
|
7
8
|
unitId: string;
|
|
8
9
|
value: number;
|
|
9
10
|
ts: Timestamp;
|
|
11
|
+
unitAgeMs?: number;
|
|
10
12
|
}
|
|
11
13
|
/** Accept Date, timestamp text, or epoch milliseconds; reject invalid dates. */
|
|
12
14
|
export declare function timestampMs(ts: Timestamp): number;
|
|
@@ -17,18 +19,19 @@ export declare function firstExposures(rows: readonly {
|
|
|
17
19
|
unitId: string;
|
|
18
20
|
arm: string;
|
|
19
21
|
ts: Timestamp;
|
|
22
|
+
unitAgeMs?: number;
|
|
20
23
|
}[], { endedAt }?: {
|
|
21
24
|
endedAt?: Timestamp;
|
|
22
25
|
}): {
|
|
23
|
-
units: Map<string, {
|
|
24
|
-
arm: string;
|
|
26
|
+
units: Map<string, ExposedUnit & {
|
|
25
27
|
firstTs: Date;
|
|
26
28
|
}>;
|
|
27
29
|
excludedMultiArm: number;
|
|
28
30
|
};
|
|
29
31
|
/** Spec §7.6/§8.2: zero-filled outcomes over each exposed unit's half-open window. */
|
|
30
|
-
export declare function perUnitValues(units: ReadonlyMap<string, ExposedUnit>, events: readonly MetricEvent[], { kind, windowHours, endedAt }: {
|
|
32
|
+
export declare function perUnitValues(units: ReadonlyMap<string, ExposedUnit>, events: readonly MetricEvent[], { kind, windowHours, endedAt, onAttributed }: {
|
|
31
33
|
kind: 'binomial' | 'count' | 'revenue';
|
|
32
34
|
windowHours: number;
|
|
33
35
|
endedAt?: Timestamp;
|
|
36
|
+
onAttributed?: (event: MetricEvent, ts: number) => void;
|
|
34
37
|
}): Map<string, number>;
|