@qoretechnologies/reqraft 0.10.57-pr.127.ge03fd3a → 0.10.57
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/.claude/CLAUDE.md +1 -1
- package/README.md +1 -1
- package/design/TRACKING.md +82 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/tracking/ui/ExperimentCard.d.ts +55 -0
- package/dist/tracking/ui/ExperimentCard.d.ts.map +1 -0
- package/dist/tracking/ui/ExperimentCard.js +396 -0
- package/dist/tracking/ui/ExperimentCard.js.map +1 -0
- package/dist/tracking/ui/ExperimentsOverlay.d.ts +59 -0
- package/dist/tracking/ui/ExperimentsOverlay.d.ts.map +1 -0
- package/dist/tracking/ui/ExperimentsOverlay.js +359 -0
- package/dist/tracking/ui/ExperimentsOverlay.js.map +1 -0
- package/dist/tracking/ui/anchor.d.ts +107 -0
- package/dist/tracking/ui/anchor.d.ts.map +1 -0
- package/dist/tracking/ui/anchor.js +108 -0
- package/dist/tracking/ui/anchor.js.map +1 -0
- package/dist/tracking/ui/card.d.ts +121 -0
- package/dist/tracking/ui/card.d.ts.map +1 -0
- package/dist/tracking/ui/card.js +417 -0
- package/dist/tracking/ui/card.js.map +1 -0
- package/dist/tracking/ui/client.d.ts +42 -0
- package/dist/tracking/ui/client.d.ts.map +1 -0
- package/dist/tracking/ui/client.js +123 -0
- package/dist/tracking/ui/client.js.map +1 -0
- package/dist/tracking/ui/index.d.ts +20 -0
- package/dist/tracking/ui/index.d.ts.map +1 -0
- package/dist/tracking/ui/index.js +60 -0
- package/dist/tracking/ui/index.js.map +1 -0
- package/dist/tracking/ui/types.d.ts +120 -0
- package/dist/tracking/ui/types.d.ts.map +1 -0
- package/dist/tracking/ui/types.js +8 -0
- package/dist/tracking/ui/types.js.map +1 -0
- package/dist/tracking/ui/useExperimentsAdmin.d.ts +31 -0
- package/dist/tracking/ui/useExperimentsAdmin.d.ts.map +1 -0
- package/dist/tracking/ui/useExperimentsAdmin.js +136 -0
- package/dist/tracking/ui/useExperimentsAdmin.js.map +1 -0
- package/package.json +3 -3
- package/src/index.tsx +3 -1
- package/src/stories/tracking.tsx +206 -0
- package/src/tracking/ui/ExperimentCard.stories.tsx +296 -0
- package/src/tracking/ui/ExperimentCard.tsx +667 -0
- package/src/tracking/ui/ExperimentsOverlay.stories.tsx +155 -0
- package/src/tracking/ui/ExperimentsOverlay.tsx +437 -0
- package/src/tracking/ui/anchor.ts +180 -0
- package/src/tracking/ui/card.ts +464 -0
- package/src/tracking/ui/client.ts +117 -0
- package/src/tracking/ui/index.ts +77 -0
- package/src/tracking/ui/types.ts +110 -0
- package/src/tracking/ui/useExperimentsAdmin.ts +103 -0
- package/src/tracking/react/Experiment.stories.tsx +0 -174
|
@@ -0,0 +1,667 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ReqoreCallout,
|
|
3
|
+
ReqoreEntityRow,
|
|
4
|
+
ReqoreH4,
|
|
5
|
+
ReqoreModal,
|
|
6
|
+
ReqoreP,
|
|
7
|
+
ReqorePanel,
|
|
8
|
+
ReqoreProgress,
|
|
9
|
+
ReqoreVerticalSpacer,
|
|
10
|
+
useReqoreProperty,
|
|
11
|
+
useReqoreTheme,
|
|
12
|
+
} from '@qoretechnologies/reqore';
|
|
13
|
+
import type { TReqoreBadge } from '@qoretechnologies/reqore/dist/components/Button';
|
|
14
|
+
import type { IReqoreEntityRowAction } from '@qoretechnologies/reqore/dist/components/EntityRow';
|
|
15
|
+
import type { IReqorePanelBottomAction } from '@qoretechnologies/reqore/dist/components/Panel';
|
|
16
|
+
import type { IReqoreIconName } from '@qoretechnologies/reqore/dist/types/icons';
|
|
17
|
+
import { RADIUS_FROM_SIZE } from '@qoretechnologies/reqore/dist/constants/sizes';
|
|
18
|
+
import { getLuminance, rgba } from 'polished';
|
|
19
|
+
import {
|
|
20
|
+
useEffect,
|
|
21
|
+
useLayoutEffect,
|
|
22
|
+
useMemo,
|
|
23
|
+
useRef,
|
|
24
|
+
useState,
|
|
25
|
+
type KeyboardEvent as ReactKeyboardEvent,
|
|
26
|
+
} from 'react';
|
|
27
|
+
import styled from 'styled-components';
|
|
28
|
+
import { activatesRow } from './anchor';
|
|
29
|
+
import {
|
|
30
|
+
actionOutcome,
|
|
31
|
+
barValues,
|
|
32
|
+
canAccept,
|
|
33
|
+
canPause,
|
|
34
|
+
canRemove,
|
|
35
|
+
canStart,
|
|
36
|
+
canStop,
|
|
37
|
+
confirmCopy,
|
|
38
|
+
helpSections,
|
|
39
|
+
leadingVersion,
|
|
40
|
+
lifecycleCopy,
|
|
41
|
+
numbersLine,
|
|
42
|
+
phaseNote,
|
|
43
|
+
primaryMetric,
|
|
44
|
+
sortVersionRows,
|
|
45
|
+
statusTag,
|
|
46
|
+
verdictIntent,
|
|
47
|
+
verdictLine,
|
|
48
|
+
versionRows,
|
|
49
|
+
versionsMaxHeight,
|
|
50
|
+
} from './card';
|
|
51
|
+
import type { IExperimentEntry, TExperimentAction, TExperimentActionResult } from './types';
|
|
52
|
+
|
|
53
|
+
type TMaybeAsync<T = unknown> = T | Promise<T>;
|
|
54
|
+
|
|
55
|
+
export interface IExperimentCardProps {
|
|
56
|
+
/** The experiment key (`data-experiment` of `<Experiment>`). */
|
|
57
|
+
experimentKey: string;
|
|
58
|
+
/** The server's experiment and its results; absent while the test is not on the server. */
|
|
59
|
+
test?: IExperimentEntry | null;
|
|
60
|
+
/** The card's title. Default: the experiment's name, else its key. */
|
|
61
|
+
name?: string;
|
|
62
|
+
/** The version this page shows now: its row takes the info colour (and `aria-current`). */
|
|
63
|
+
shown?: string;
|
|
64
|
+
/** The versions the page's code renders (`data-variants`); a server version outside it cannot be shown. */
|
|
65
|
+
codeVariants?: string[];
|
|
66
|
+
/** The room the card has (px): the versions scroll inside when it is short. */
|
|
67
|
+
maxHeight?: number;
|
|
68
|
+
/** Why the list could not be loaded (the analytics service cannot be reached). */
|
|
69
|
+
loadError?: string | null;
|
|
70
|
+
/** An "Open in …" link at the start of the footer (a new tab). */
|
|
71
|
+
detailsUrl?: string | null;
|
|
72
|
+
/** The link's label. Default `Open in admin portal`. */
|
|
73
|
+
detailsLabel?: string;
|
|
74
|
+
/** One version's analytics (a new tab): a "Show analytics" action on each row; none without it. */
|
|
75
|
+
versionDetailsUrl?: (variant: string) => string | null | undefined;
|
|
76
|
+
/** Where the full analytics live, in the help's words. Default `the admin portal`. */
|
|
77
|
+
analyticsLabel?: string;
|
|
78
|
+
/** Best first (conversion on the primary metric, then visitors). Default true. */
|
|
79
|
+
sort?: boolean;
|
|
80
|
+
/** The words for a test that is in the page's code but not set up in the analytics service yet. */
|
|
81
|
+
notSetUpText?: string;
|
|
82
|
+
/** Who removed a version, in words, by the history's `actor` (`{ 'landing-editor': 'in the editor' }`). */
|
|
83
|
+
actorLabels?: Record<string, string>;
|
|
84
|
+
/** Asks before Accept, Remove, Start, Pause and Stop (Reqore's confirm dialog). Default true. */
|
|
85
|
+
confirm?: boolean;
|
|
86
|
+
/** A notification after each action (what happened, or the server's error). Default true. */
|
|
87
|
+
notify?: boolean;
|
|
88
|
+
/** A click (or Enter / Space) on a version's row: show that version on this page. Rows are not clickable without it. */
|
|
89
|
+
onShow?: (variant: string) => void;
|
|
90
|
+
/** Each action appears only when its callback is given; a returned promise shows the button busy until it settles. */
|
|
91
|
+
onAccept?: (variant: string) => TMaybeAsync<TExperimentActionResult | unknown>;
|
|
92
|
+
onRemove?: (variant: string) => TMaybeAsync<TExperimentActionResult | unknown>;
|
|
93
|
+
onStart?: () => TMaybeAsync;
|
|
94
|
+
onPause?: () => TMaybeAsync;
|
|
95
|
+
onStop?: () => TMaybeAsync;
|
|
96
|
+
/** The ✕ in the header. */
|
|
97
|
+
onClose?: () => void;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
type TTagIntent = 'success' | 'warning' | 'danger' | 'muted' | 'info';
|
|
101
|
+
|
|
102
|
+
// Soft tags: an outlined pill over a wash of its colour, readable on dark and light themes.
|
|
103
|
+
const soft = (intent: TTagIntent) => ({ intent, appearance: 'soft' as const });
|
|
104
|
+
|
|
105
|
+
type THighlight = 'winner' | 'leading' | undefined;
|
|
106
|
+
|
|
107
|
+
const ROW_GAP = 6;
|
|
108
|
+
/** Below this width (the versions list, px) the footer's link drops its words for its icon. */
|
|
109
|
+
const NARROW_CARD = 400;
|
|
110
|
+
/** Room around the rows for the leader's glow, taken from the card's own padding. */
|
|
111
|
+
const GLOW_ROOM = 6;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* How a version's row stands out, drawn around and over the row without taking the pointer:
|
|
115
|
+
*
|
|
116
|
+
* - the version this page shows: an inset ring and a flat wash in the info colour (the row itself
|
|
117
|
+
* keeps no intent, so its actions stay neutral);
|
|
118
|
+
* - the leading version: a ring and a soft glow in the success colour, and a wash from the left;
|
|
119
|
+
* - the winner (a likely-winner verdict or an ended test's winner): the same, clearly stronger.
|
|
120
|
+
*
|
|
121
|
+
* Static (nothing animates, so there is nothing for reduced motion to stop), and in the theme's
|
|
122
|
+
* own intent colours, so it reads on dark and light.
|
|
123
|
+
*/
|
|
124
|
+
const StyledVersion = styled.div<{
|
|
125
|
+
$highlight: THighlight;
|
|
126
|
+
$shown: boolean;
|
|
127
|
+
$success: string;
|
|
128
|
+
$info: string;
|
|
129
|
+
$radius: number;
|
|
130
|
+
}>`
|
|
131
|
+
position: relative;
|
|
132
|
+
border-radius: ${({ $radius }) => $radius}px;
|
|
133
|
+
box-shadow: ${({ $highlight, $success }) =>
|
|
134
|
+
[
|
|
135
|
+
$highlight === 'winner' ?
|
|
136
|
+
`0 0 0 1px ${rgba($success, 0.95)}, 0 0 18px ${rgba($success, 0.4)}`
|
|
137
|
+
: null,
|
|
138
|
+
$highlight === 'leading' ?
|
|
139
|
+
`0 0 0 1px ${rgba($success, 0.5)}, 0 0 10px ${rgba($success, 0.18)}`
|
|
140
|
+
: null,
|
|
141
|
+
]
|
|
142
|
+
.filter(Boolean)
|
|
143
|
+
.join(', ') || 'none'};
|
|
144
|
+
|
|
145
|
+
&::after {
|
|
146
|
+
content: '';
|
|
147
|
+
position: absolute;
|
|
148
|
+
inset: 0;
|
|
149
|
+
border-radius: inherit;
|
|
150
|
+
pointer-events: none;
|
|
151
|
+
/* The shown version's ring sits over the row (an inset shadow on the wrapper would be
|
|
152
|
+
painted under the row's own background). */
|
|
153
|
+
box-shadow: ${({ $shown, $info }) => ($shown ? `inset 0 0 0 1px ${rgba($info, 0.85)}` : 'none')};
|
|
154
|
+
background: ${({ $highlight, $shown, $success, $info }) =>
|
|
155
|
+
[
|
|
156
|
+
$highlight ?
|
|
157
|
+
`linear-gradient(100deg, ${rgba($success, $highlight === 'winner' ? 0.26 : 0.13)} 0%, ${rgba(
|
|
158
|
+
$success,
|
|
159
|
+
$highlight === 'winner' ? 0.08 : 0.04
|
|
160
|
+
)} 45%, ${rgba($success, 0)} 75%)`
|
|
161
|
+
: null,
|
|
162
|
+
$shown ? `linear-gradient(${rgba($info, 0.1)}, ${rgba($info, 0.1)})` : null,
|
|
163
|
+
]
|
|
164
|
+
.filter(Boolean)
|
|
165
|
+
.join(', ') || 'none'};
|
|
166
|
+
}
|
|
167
|
+
`;
|
|
168
|
+
|
|
169
|
+
// Layout only: the versions scroll inside the card past three and a half rows.
|
|
170
|
+
const StyledVersions = styled.div<{ $max: number | null }>`
|
|
171
|
+
display: flex;
|
|
172
|
+
flex-direction: column;
|
|
173
|
+
gap: ${ROW_GAP}px;
|
|
174
|
+
max-height: ${({ $max }) => ($max ? `${$max}px` : 'none')};
|
|
175
|
+
overflow-y: ${({ $max }) => ($max ? 'auto' : 'visible')};
|
|
176
|
+
overflow-x: hidden;
|
|
177
|
+
overscroll-behavior: contain;
|
|
178
|
+
min-width: 0;
|
|
179
|
+
/* Room for the leader's glow, taken back from the card's padding so the rows keep their width. */
|
|
180
|
+
margin: 0 -${GLOW_ROOM}px;
|
|
181
|
+
padding: ${GLOW_ROOM}px;
|
|
182
|
+
|
|
183
|
+
/* The rows take the card's width, never their content's, padding included: a host page
|
|
184
|
+
without a global border-box reset would otherwise push each row past the card's edge. */
|
|
185
|
+
> * {
|
|
186
|
+
min-width: 0;
|
|
187
|
+
}
|
|
188
|
+
*,
|
|
189
|
+
*::before,
|
|
190
|
+
*::after {
|
|
191
|
+
box-sizing: border-box;
|
|
192
|
+
}
|
|
193
|
+
`;
|
|
194
|
+
|
|
195
|
+
/** Header, verdict and footer take about this much of `maxHeight`; the versions get the rest. */
|
|
196
|
+
const CHROME_HEIGHT = 230;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* One A/B test: its name and status, the verdict in plain words, one row per version (visitors,
|
|
200
|
+
* conversion, chance to beat the original, a bar; click a row to show that version; Accept, and
|
|
201
|
+
* Remove at the far end), and the test's own controls (Start / Resume, Pause, Stop) with an
|
|
202
|
+
* optional link to its details. Driven only by props: no requests of its own.
|
|
203
|
+
*/
|
|
204
|
+
export const ExperimentCard = ({
|
|
205
|
+
experimentKey,
|
|
206
|
+
test,
|
|
207
|
+
name,
|
|
208
|
+
shown,
|
|
209
|
+
codeVariants = [],
|
|
210
|
+
maxHeight,
|
|
211
|
+
loadError,
|
|
212
|
+
detailsUrl,
|
|
213
|
+
detailsLabel = 'Open in admin portal',
|
|
214
|
+
versionDetailsUrl,
|
|
215
|
+
analyticsLabel = 'the admin portal',
|
|
216
|
+
sort = true,
|
|
217
|
+
notSetUpText,
|
|
218
|
+
actorLabels,
|
|
219
|
+
confirm = true,
|
|
220
|
+
notify = true,
|
|
221
|
+
onShow,
|
|
222
|
+
onAccept,
|
|
223
|
+
onRemove,
|
|
224
|
+
onStart,
|
|
225
|
+
onPause,
|
|
226
|
+
onStop,
|
|
227
|
+
onClose,
|
|
228
|
+
}: IExperimentCardProps) => {
|
|
229
|
+
const entry = test ?? undefined;
|
|
230
|
+
const confirmAction = useReqoreProperty('confirmAction');
|
|
231
|
+
const addNotification = useReqoreProperty('addNotification');
|
|
232
|
+
const theme = useReqoreTheme();
|
|
233
|
+
// The card's own width, not the window's: it lives in a narrow overlay on a wide page.
|
|
234
|
+
const [narrow, setNarrow] = useState(false);
|
|
235
|
+
const versionsList = useRef<HTMLDivElement>(null);
|
|
236
|
+
useEffect(() => {
|
|
237
|
+
const el = versionsList.current;
|
|
238
|
+
if (!el || typeof ResizeObserver === 'undefined') return undefined;
|
|
239
|
+
const ro = new ResizeObserver(() => setNarrow(el.offsetWidth < NARROW_CARD));
|
|
240
|
+
ro.observe(el);
|
|
241
|
+
return () => ro.disconnect();
|
|
242
|
+
}, []);
|
|
243
|
+
const light = (() => {
|
|
244
|
+
try {
|
|
245
|
+
return getLuminance(theme.main) > 0.5;
|
|
246
|
+
} catch {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
})();
|
|
250
|
+
const [busy, setBusy] = useState<string | null>(null);
|
|
251
|
+
const [helpOpen, setHelpOpen] = useState(false);
|
|
252
|
+
const [rowHeight, setRowHeight] = useState(0);
|
|
253
|
+
const firstRow = useRef<HTMLDivElement>(null);
|
|
254
|
+
const mounted = useRef(true);
|
|
255
|
+
useEffect(
|
|
256
|
+
() => () => {
|
|
257
|
+
mounted.current = false;
|
|
258
|
+
},
|
|
259
|
+
[]
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
const unreachable = !entry && !!loadError;
|
|
263
|
+
const codeKey = codeVariants.join(',');
|
|
264
|
+
// The order is decided when the data arrives (a refresh), never while the user works in the card.
|
|
265
|
+
const order = useMemo(() => {
|
|
266
|
+
const all = versionRows(entry, codeVariants);
|
|
267
|
+
return (sort ? sortVersionRows(all) : all).map((r) => r.key);
|
|
268
|
+
// `codeVariants` is followed by its keys, not its identity.
|
|
269
|
+
}, [entry, codeKey, sort]);
|
|
270
|
+
const unsorted = versionRows(entry, codeVariants);
|
|
271
|
+
const rows = order
|
|
272
|
+
.map((key) => unsorted.find((r) => r.key === key))
|
|
273
|
+
.filter(Boolean)
|
|
274
|
+
.concat(unsorted.filter((r) => !order.includes(r.key)));
|
|
275
|
+
const leader = leadingVersion(entry, rows);
|
|
276
|
+
const bars = barValues(rows);
|
|
277
|
+
const metric = primaryMetric(entry?.results);
|
|
278
|
+
const status = entry?.experiment.status;
|
|
279
|
+
const title = name || entry?.experiment.name || experimentKey;
|
|
280
|
+
const tag = statusTag(entry, unreachable);
|
|
281
|
+
const note = phaseNote(entry, actorLabels);
|
|
282
|
+
const busyOn = (action: string, variant = '') => busy === `${action}:${variant}`;
|
|
283
|
+
|
|
284
|
+
useLayoutEffect(() => {
|
|
285
|
+
const h = firstRow.current?.offsetHeight ?? 0;
|
|
286
|
+
if (h && h !== rowHeight) setRowHeight(h);
|
|
287
|
+
});
|
|
288
|
+
// A row's height changes with the card's width (a phone, a resized window): measure it again.
|
|
289
|
+
useEffect(() => {
|
|
290
|
+
const el = firstRow.current;
|
|
291
|
+
if (!el || typeof ResizeObserver === 'undefined') return undefined;
|
|
292
|
+
const ro = new ResizeObserver(() => setRowHeight(el.offsetHeight));
|
|
293
|
+
ro.observe(el);
|
|
294
|
+
return () => ro.disconnect();
|
|
295
|
+
}, []);
|
|
296
|
+
|
|
297
|
+
// Minimal buttons tint their text from the intent, too pale on a light theme: a deeper shade there.
|
|
298
|
+
const quiet = (intent?: 'success' | 'warning' | 'danger' | 'info') => ({
|
|
299
|
+
minimal: true,
|
|
300
|
+
...(light && intent ?
|
|
301
|
+
{
|
|
302
|
+
effect: { color: `${intent}:darken:2` as const, weight: 'thick' as const },
|
|
303
|
+
iconColor: `${intent}:darken:2` as const,
|
|
304
|
+
}
|
|
305
|
+
: {}),
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
const act = (action: TExperimentAction, variant?: string) => {
|
|
309
|
+
if (!entry) return;
|
|
310
|
+
const callbacks = {
|
|
311
|
+
accept: onAccept,
|
|
312
|
+
remove: onRemove,
|
|
313
|
+
start: onStart,
|
|
314
|
+
pause: onPause,
|
|
315
|
+
stop: onStop,
|
|
316
|
+
};
|
|
317
|
+
const callback = callbacks[action];
|
|
318
|
+
if (!callback) return;
|
|
319
|
+
const isVersion = action === 'accept' || action === 'remove';
|
|
320
|
+
const copy = isVersion ? confirmCopy(action, entry, variant) : lifecycleCopy(action, entry);
|
|
321
|
+
const titles: Record<TExperimentAction, [string, string]> = {
|
|
322
|
+
accept: ['Winner accepted', 'Could not accept'],
|
|
323
|
+
remove: ['Version removed', 'Could not remove'],
|
|
324
|
+
start: [status === 'paused' ? 'Test resumed' : 'Test started', 'Could not start'],
|
|
325
|
+
pause: ['Test paused', 'Could not pause'],
|
|
326
|
+
stop: ['Test stopped', 'Could not stop'],
|
|
327
|
+
};
|
|
328
|
+
const run = async () => {
|
|
329
|
+
setBusy(`${action}:${variant ?? ''}`);
|
|
330
|
+
try {
|
|
331
|
+
const result = await (callback as (v?: string) => TMaybeAsync)(variant);
|
|
332
|
+
if (notify) {
|
|
333
|
+
const content =
|
|
334
|
+
isVersion ?
|
|
335
|
+
actionOutcome(action, result as TExperimentActionResult, variant)
|
|
336
|
+
: `“${title}” is ${
|
|
337
|
+
action === 'start' ? 'running'
|
|
338
|
+
: action === 'pause' ? 'paused'
|
|
339
|
+
: 'stopped'
|
|
340
|
+
}.`;
|
|
341
|
+
addNotification?.({
|
|
342
|
+
intent: 'success',
|
|
343
|
+
title: titles[action][0],
|
|
344
|
+
content,
|
|
345
|
+
duration: 8000,
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
} catch (err) {
|
|
349
|
+
if (notify) {
|
|
350
|
+
addNotification?.({
|
|
351
|
+
intent: 'danger',
|
|
352
|
+
title: titles[action][1],
|
|
353
|
+
content: (err as Error)?.message ?? String(err),
|
|
354
|
+
duration: 10000,
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
} finally {
|
|
358
|
+
if (mounted.current) setBusy(null);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
if (confirm && confirmAction) {
|
|
362
|
+
confirmAction({
|
|
363
|
+
title: copy.title,
|
|
364
|
+
description: copy.description,
|
|
365
|
+
confirmLabel: copy.confirmLabel,
|
|
366
|
+
confirmButtonIntent:
|
|
367
|
+
action === 'accept' || action === 'start' ? 'success'
|
|
368
|
+
: action === 'pause' ? 'warning'
|
|
369
|
+
: 'danger',
|
|
370
|
+
onConfirm: () => void run(),
|
|
371
|
+
});
|
|
372
|
+
} else {
|
|
373
|
+
void run();
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
const footer: IReqorePanelBottomAction[] = [];
|
|
378
|
+
// A test the analytics service does not know has no analytics to open.
|
|
379
|
+
if (detailsUrl && entry) {
|
|
380
|
+
footer.push({
|
|
381
|
+
position: 'left',
|
|
382
|
+
icon: 'ExternalLinkLine',
|
|
383
|
+
// In a narrow card it is the icon alone (with its tooltip and name), so the footer fits one row.
|
|
384
|
+
label: narrow ? undefined : detailsLabel,
|
|
385
|
+
'aria-label': detailsLabel,
|
|
386
|
+
responsive: false,
|
|
387
|
+
...quiet(),
|
|
388
|
+
tooltip: 'This test’s details (a new tab)',
|
|
389
|
+
onClick: () => window.open(detailsUrl, '_blank', 'noopener'),
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
if (entry && status) {
|
|
393
|
+
// Every button in the card is minimal, except Start test / Resume: the one primary action.
|
|
394
|
+
if (onStart && canStart(status)) {
|
|
395
|
+
footer.push({
|
|
396
|
+
position: 'right',
|
|
397
|
+
icon: 'PlayLine',
|
|
398
|
+
intent: 'success',
|
|
399
|
+
label: status === 'paused' ? 'Resume' : 'Start test',
|
|
400
|
+
responsive: false,
|
|
401
|
+
disabled: !!busy,
|
|
402
|
+
loading: busyOn('start'),
|
|
403
|
+
tooltip:
|
|
404
|
+
status === 'paused' ?
|
|
405
|
+
'Split visitors between the versions again'
|
|
406
|
+
: 'Start splitting visitors between the versions and counting',
|
|
407
|
+
onClick: () => act('start'),
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
if (onPause && canPause(status)) {
|
|
411
|
+
footer.push({
|
|
412
|
+
position: 'right',
|
|
413
|
+
icon: 'PauseLine',
|
|
414
|
+
intent: 'warning',
|
|
415
|
+
label: 'Pause',
|
|
416
|
+
responsive: false,
|
|
417
|
+
...quiet('warning'),
|
|
418
|
+
disabled: !!busy,
|
|
419
|
+
loading: busyOn('pause'),
|
|
420
|
+
tooltip: 'Everybody sees the original until you resume',
|
|
421
|
+
onClick: () => act('pause'),
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
if (onStop && canStop(status)) {
|
|
425
|
+
footer.push({
|
|
426
|
+
position: 'right',
|
|
427
|
+
icon: 'StopLine',
|
|
428
|
+
intent: 'danger',
|
|
429
|
+
label: 'Stop',
|
|
430
|
+
responsive: false,
|
|
431
|
+
...quiet('danger'),
|
|
432
|
+
disabled: !!busy,
|
|
433
|
+
loading: busyOn('stop'),
|
|
434
|
+
tooltip: 'End the test without a winner',
|
|
435
|
+
onClick: () => act('stop'),
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const accept = status ? canAccept(status) : false;
|
|
441
|
+
const remove = status ? canRemove(status, rows.length) : false;
|
|
442
|
+
const listMax = versionsMaxHeight({
|
|
443
|
+
rows: rows.length,
|
|
444
|
+
rowHeight,
|
|
445
|
+
gap: ROW_GAP,
|
|
446
|
+
available: maxHeight ? Math.max(rowHeight, maxHeight - CHROME_HEIGHT) : undefined,
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
return (
|
|
450
|
+
<ReqorePanel
|
|
451
|
+
className='reqraft-experiment-card'
|
|
452
|
+
label={title}
|
|
453
|
+
showLabelTooltip
|
|
454
|
+
labelMaxLines={1}
|
|
455
|
+
icon='FlaskLine'
|
|
456
|
+
badge={{ label: tag.label, icon: tag.icon as IReqoreIconName, ...soft(tag.intent) }}
|
|
457
|
+
size='small'
|
|
458
|
+
rounded
|
|
459
|
+
flat={false}
|
|
460
|
+
padded
|
|
461
|
+
collapsible={false}
|
|
462
|
+
onClose={onClose}
|
|
463
|
+
closeTooltip='Close (Esc)'
|
|
464
|
+
closeButtonProps={{ 'aria-label': 'Close the test card', minimal: true } as never}
|
|
465
|
+
actions={[
|
|
466
|
+
{
|
|
467
|
+
icon: 'QuestionLine',
|
|
468
|
+
minimal: true,
|
|
469
|
+
flat: true,
|
|
470
|
+
tooltip: 'How A/B tests work',
|
|
471
|
+
'aria-label': 'How A/B tests work',
|
|
472
|
+
onClick: () => setHelpOpen(true),
|
|
473
|
+
} as never,
|
|
474
|
+
]}
|
|
475
|
+
bottomActions={footer.length ? footer : undefined}
|
|
476
|
+
>
|
|
477
|
+
<ReqoreCallout
|
|
478
|
+
size='small'
|
|
479
|
+
flat
|
|
480
|
+
icon='LineChartLine'
|
|
481
|
+
intent={unreachable ? 'warning' : verdictIntent(entry)}
|
|
482
|
+
effect={{ weight: 500 }}
|
|
483
|
+
>
|
|
484
|
+
{verdictLine(entry, { unreachable, notSetUpText })}
|
|
485
|
+
</ReqoreCallout>
|
|
486
|
+
{note && (
|
|
487
|
+
<>
|
|
488
|
+
<ReqoreVerticalSpacer height={6} />
|
|
489
|
+
<ReqoreP size='small' effect={{ opacity: 0.7 }}>
|
|
490
|
+
{note}
|
|
491
|
+
</ReqoreP>
|
|
492
|
+
</>
|
|
493
|
+
)}
|
|
494
|
+
<ReqoreVerticalSpacer height={10} />
|
|
495
|
+
<ReqoreP size='small' effect={{ opacity: 0.75, weight: 500 }}>
|
|
496
|
+
{`${rows.length} versions${metric?.name ? ` · goal: “${metric.name}”` : ''}`}
|
|
497
|
+
</ReqoreP>
|
|
498
|
+
<ReqoreVerticalSpacer height={6} />
|
|
499
|
+
<StyledVersions
|
|
500
|
+
ref={versionsList}
|
|
501
|
+
$max={listMax}
|
|
502
|
+
role='list'
|
|
503
|
+
aria-label='Versions'
|
|
504
|
+
className='reqraft-experiment-versions'
|
|
505
|
+
>
|
|
506
|
+
{rows.map((r, i) => {
|
|
507
|
+
const isShown = r.key === shown;
|
|
508
|
+
const highlight: THighlight = leader?.key === r.key ? leader.kind : undefined;
|
|
509
|
+
const badges: TReqoreBadge[] = [];
|
|
510
|
+
if (leader?.key === r.key) {
|
|
511
|
+
badges.push(
|
|
512
|
+
leader.kind === 'winner' ?
|
|
513
|
+
{ label: 'Winner', icon: 'TrophyLine', ...soft('success') }
|
|
514
|
+
: { label: 'Leading', icon: 'ArrowUpLine', ...soft('success') }
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
if (r.control) badges.push({ label: 'Original', icon: 'HomeLine', ...soft('muted') });
|
|
518
|
+
if (!r.inCode)
|
|
519
|
+
badges.push({ label: 'Not in the code', icon: 'AlertLine', ...soft('warning') });
|
|
520
|
+
// The whole row shows its version; Accept and Remove stop the click (Reqore's row actions do).
|
|
521
|
+
const showable = !!onShow && r.inCode && !isShown;
|
|
522
|
+
const actions: IReqoreEntityRowAction[] = [];
|
|
523
|
+
const analytics = entry ? versionDetailsUrl?.(r.key) : null;
|
|
524
|
+
if (analytics) {
|
|
525
|
+
actions.push({
|
|
526
|
+
size: 'small',
|
|
527
|
+
icon: 'BarChartBoxLine',
|
|
528
|
+
label: 'Show analytics',
|
|
529
|
+
...quiet(),
|
|
530
|
+
tooltip: `Show analytics for “${r.name}” (a new tab)`,
|
|
531
|
+
'aria-label': `Show analytics for ${r.name}`,
|
|
532
|
+
onClick: () => window.open(analytics, '_blank', 'noopener'),
|
|
533
|
+
} as IReqoreEntityRowAction);
|
|
534
|
+
}
|
|
535
|
+
if (entry && onAccept) {
|
|
536
|
+
actions.push({
|
|
537
|
+
size: 'small',
|
|
538
|
+
icon: 'TrophyLine',
|
|
539
|
+
intent: 'success',
|
|
540
|
+
label: 'Accept',
|
|
541
|
+
...quiet('success'),
|
|
542
|
+
disabled: !accept || !!busy,
|
|
543
|
+
loading: busyOn('accept', r.key),
|
|
544
|
+
tooltip:
|
|
545
|
+
accept ?
|
|
546
|
+
`End the test: every visitor sees “${r.name}”`
|
|
547
|
+
: 'Only a started test can be accepted',
|
|
548
|
+
onClick: () => act('accept', r.key),
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
if (entry && onRemove) {
|
|
552
|
+
actions.push({
|
|
553
|
+
size: 'small',
|
|
554
|
+
icon: 'DeleteBinLine',
|
|
555
|
+
intent: 'danger',
|
|
556
|
+
...quiet('danger'),
|
|
557
|
+
'aria-label': `Remove version ${r.name}`,
|
|
558
|
+
// At the far end of the row, away from Accept, so it is not clicked by accident.
|
|
559
|
+
style: { marginLeft: 'auto' },
|
|
560
|
+
disabled: !remove || !!busy,
|
|
561
|
+
loading: busyOn('remove', r.key),
|
|
562
|
+
tooltip:
|
|
563
|
+
remove ?
|
|
564
|
+
`Remove version: drop “${r.name}” from the test`
|
|
565
|
+
: 'This version cannot be removed now',
|
|
566
|
+
onClick: () => act('remove', r.key),
|
|
567
|
+
} as IReqoreEntityRowAction);
|
|
568
|
+
}
|
|
569
|
+
return (
|
|
570
|
+
<StyledVersion
|
|
571
|
+
role='listitem'
|
|
572
|
+
key={r.key}
|
|
573
|
+
ref={i === 0 ? firstRow : undefined}
|
|
574
|
+
data-version={r.key}
|
|
575
|
+
data-highlight={highlight}
|
|
576
|
+
aria-current={isShown || undefined}
|
|
577
|
+
$highlight={highlight}
|
|
578
|
+
$shown={isShown}
|
|
579
|
+
$success={theme.intents?.success}
|
|
580
|
+
$info={theme.intents?.info}
|
|
581
|
+
$radius={RADIUS_FROM_SIZE.small}
|
|
582
|
+
>
|
|
583
|
+
<ReqoreEntityRow
|
|
584
|
+
size='small'
|
|
585
|
+
rounded
|
|
586
|
+
flat
|
|
587
|
+
label={r.name}
|
|
588
|
+
badge={badges}
|
|
589
|
+
description={numbersLine(r, metric?.name, status)}
|
|
590
|
+
metadata={
|
|
591
|
+
r.visitors ?
|
|
592
|
+
<ReqoreProgress
|
|
593
|
+
value={bars[i]}
|
|
594
|
+
size='tiny'
|
|
595
|
+
rounded
|
|
596
|
+
flat
|
|
597
|
+
style={{ width: '100%', minWidth: 160 }}
|
|
598
|
+
intent={
|
|
599
|
+
isShown ? 'info'
|
|
600
|
+
: r.control ?
|
|
601
|
+
'muted'
|
|
602
|
+
: 'success'
|
|
603
|
+
}
|
|
604
|
+
aria-label={`${r.name}: conversion compared with the best version`}
|
|
605
|
+
/>
|
|
606
|
+
: undefined
|
|
607
|
+
}
|
|
608
|
+
iconHasBackground={false}
|
|
609
|
+
showIcon={false}
|
|
610
|
+
actions={actions.length ? actions : undefined}
|
|
611
|
+
{...(showable ?
|
|
612
|
+
{
|
|
613
|
+
role: 'button',
|
|
614
|
+
tabIndex: 0,
|
|
615
|
+
'aria-label': `Show “${r.name}” on this page`,
|
|
616
|
+
tooltip: `Show “${r.name}” on this page (only here, never counted)`,
|
|
617
|
+
onClick: () => onShow(r.key),
|
|
618
|
+
onKeyDown: (e: ReactKeyboardEvent<HTMLDivElement>) => {
|
|
619
|
+
if (!activatesRow(e.key, e.target === e.currentTarget)) return;
|
|
620
|
+
e.preventDefault();
|
|
621
|
+
onShow(r.key);
|
|
622
|
+
},
|
|
623
|
+
}
|
|
624
|
+
: {})}
|
|
625
|
+
/>
|
|
626
|
+
</StyledVersion>
|
|
627
|
+
);
|
|
628
|
+
})}
|
|
629
|
+
</StyledVersions>
|
|
630
|
+
{!entry && (
|
|
631
|
+
<>
|
|
632
|
+
<ReqoreVerticalSpacer height={8} />
|
|
633
|
+
<ReqoreP size='small' effect={{ opacity: 0.7 }}>
|
|
634
|
+
{unreachable ?
|
|
635
|
+
'Start, Accept and Remove come back once the analytics service answers.'
|
|
636
|
+
: 'Start, Accept and Remove appear once the test is set up.'}
|
|
637
|
+
</ReqoreP>
|
|
638
|
+
</>
|
|
639
|
+
)}
|
|
640
|
+
<ReqoreModal
|
|
641
|
+
isOpen={helpOpen}
|
|
642
|
+
onClose={() => setHelpOpen(false)}
|
|
643
|
+
label='How A/B tests work'
|
|
644
|
+
icon='QuestionLine'
|
|
645
|
+
width='640px'
|
|
646
|
+
blur={2}
|
|
647
|
+
className='reqraft-experiment-help'
|
|
648
|
+
>
|
|
649
|
+
{helpSections(entry, analyticsLabel).map((section) => (
|
|
650
|
+
<div key={section.title}>
|
|
651
|
+
<ReqoreH4>{section.title}</ReqoreH4>
|
|
652
|
+
<ReqoreVerticalSpacer height={4} />
|
|
653
|
+
{section.paragraphs.map((text) => (
|
|
654
|
+
<div key={text}>
|
|
655
|
+
<ReqoreP size='small' effect={{ weight: 500 }}>
|
|
656
|
+
{text}
|
|
657
|
+
</ReqoreP>
|
|
658
|
+
<ReqoreVerticalSpacer height={6} />
|
|
659
|
+
</div>
|
|
660
|
+
))}
|
|
661
|
+
<ReqoreVerticalSpacer height={14} />
|
|
662
|
+
</div>
|
|
663
|
+
))}
|
|
664
|
+
</ReqoreModal>
|
|
665
|
+
</ReqorePanel>
|
|
666
|
+
);
|
|
667
|
+
};
|