@uniformdev/context-ui 17.7.1-alpha.140 → 17.7.1-alpha.167
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/dist/index.esm.js +1493 -19
- package/dist/index.js +1541 -19
- package/dist/index.mjs +1493 -19
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,4 +1,74 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
|
|
27
|
+
// src/index.ts
|
|
28
|
+
var src_exports = {};
|
|
29
|
+
__export(src_exports, {
|
|
30
|
+
ContextData: () => ContextData,
|
|
31
|
+
CriteriaMatchMenu: () => CriteriaMatchMenu,
|
|
32
|
+
CriteriaOperatorMenu: () => CriteriaOperatorMenu,
|
|
33
|
+
DimensionMenu: () => DimensionMenu,
|
|
34
|
+
DimensionValue: () => DimensionValue,
|
|
35
|
+
EditLink: () => EditLink,
|
|
36
|
+
EnrichmentTag: () => EnrichmentTag,
|
|
37
|
+
PersonalizationCriteria: () => PersonalizationCriteria,
|
|
38
|
+
PersonalizationCriteriaStatic: () => PersonalizationCriteriaStatic,
|
|
39
|
+
ProjectUIVersion: () => ProjectUIVersion,
|
|
40
|
+
addEnrichmentLink: () => addEnrichmentLink,
|
|
41
|
+
contextCriteriaMenuOperators: () => contextCriteriaMenuOperators,
|
|
42
|
+
convertErrorsToObj: () => convertErrorsToObj,
|
|
43
|
+
isEnrichmentTagData: () => isEnrichmentTagData,
|
|
44
|
+
isPersonalizationCriteriaData: () => isPersonalizationCriteriaData,
|
|
45
|
+
opHasRhs: () => opHasRhs,
|
|
46
|
+
useContextConfig: () => useContextConfig,
|
|
47
|
+
useContextData: () => useContextData,
|
|
48
|
+
useDimensions: () => useDimensions,
|
|
49
|
+
useDimensionsDataContext: () => useDimensionsDataContext,
|
|
50
|
+
useManifest: () => useManifest,
|
|
51
|
+
useValidateContextConfig: () => useValidateContextConfig,
|
|
52
|
+
validateContextConfig: () => validateContextConfig
|
|
53
|
+
});
|
|
54
|
+
module.exports = __toCommonJS(src_exports);
|
|
55
|
+
|
|
56
|
+
// ../../scripts/emotion-jsx-shim.js
|
|
57
|
+
var import_react = require("@emotion/react");
|
|
58
|
+
var React = __toESM(require("react"));
|
|
59
|
+
|
|
60
|
+
// src/components/CriteriaOperatorMenu/CriteriaOperatorMenu.tsx
|
|
61
|
+
var import_design_system = require("@uniformdev/design-system");
|
|
62
|
+
|
|
63
|
+
// src/components/CriteriaOperatorMenu/OperatorBubble.tsx
|
|
64
|
+
var import_react2 = require("@emotion/react");
|
|
65
|
+
var import_jsx_runtime = require("@emotion/react/jsx-runtime");
|
|
66
|
+
function OperatorBubble({ op }) {
|
|
67
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
68
|
+
"div",
|
|
69
|
+
{
|
|
70
|
+
className: "operation-bubble",
|
|
71
|
+
css: import_react2.css`
|
|
2
72
|
align-items: center;
|
|
3
73
|
background: var(--gray-700);
|
|
4
74
|
border-radius: var(--rounded-full);
|
|
@@ -8,12 +78,661 @@
|
|
|
8
78
|
height: 30px;
|
|
9
79
|
justify-content: center;
|
|
10
80
|
font-size: var(--fs-base);
|
|
11
|
-
`,
|
|
81
|
+
`,
|
|
82
|
+
children: op
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/components/CriteriaOperatorMenu/CriteriaOperatorOption.tsx
|
|
88
|
+
var import_jsx_runtime2 = require("@emotion/react/jsx-runtime");
|
|
89
|
+
var CriteriaOperatorOption = (props) => {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
const { data, getStyles, isDisabled, innerRef, innerProps } = props;
|
|
92
|
+
const [name, description] = (_b = (_a = data.label) == null ? void 0 : _a.split(":")) != null ? _b : [];
|
|
93
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
94
|
+
"div",
|
|
95
|
+
{
|
|
96
|
+
css: {
|
|
97
|
+
...getStyles("option", props),
|
|
98
|
+
display: "flex",
|
|
99
|
+
alignItems: "center",
|
|
100
|
+
gap: "var(--spacing-sm)"
|
|
101
|
+
},
|
|
102
|
+
ref: innerRef,
|
|
103
|
+
"aria-disabled": isDisabled,
|
|
104
|
+
...innerProps,
|
|
105
|
+
children: [
|
|
106
|
+
description ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OperatorBubble, { op: name }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
107
|
+
"div",
|
|
108
|
+
{
|
|
109
|
+
css: {
|
|
110
|
+
width: "20px",
|
|
111
|
+
height: "20px"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
),
|
|
115
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: description != null ? description : name })
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// src/components/CriteriaOperatorMenu/CriteriaOperatorSingleValue.tsx
|
|
122
|
+
var import_jsx_runtime3 = require("@emotion/react/jsx-runtime");
|
|
123
|
+
var CriteriaOperatorSingleValue = (props) => {
|
|
124
|
+
const { data, getStyles } = props;
|
|
125
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
126
|
+
"div",
|
|
127
|
+
{
|
|
128
|
+
css: {
|
|
129
|
+
...getStyles("singleValue", props),
|
|
130
|
+
width: "max-content"
|
|
131
|
+
},
|
|
132
|
+
children: data.label.length === 1 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(OperatorBubble, { op: data.label }) : data.label
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// src/components/CriteriaOperatorMenu/CriteriaOperatorMenu.tsx
|
|
138
|
+
var import_jsx_runtime4 = require("@emotion/react/jsx-runtime");
|
|
139
|
+
var contextCriteriaMenuOperators = [
|
|
140
|
+
{
|
|
141
|
+
name: "=",
|
|
142
|
+
description: "equals",
|
|
143
|
+
value: "="
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
name: "\u2260",
|
|
147
|
+
description: "not equal",
|
|
148
|
+
value: "!="
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: ">",
|
|
152
|
+
description: "is greater than",
|
|
153
|
+
value: ">"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: "\u2265",
|
|
157
|
+
description: "is greater than or equal to",
|
|
158
|
+
value: ">="
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
name: "<",
|
|
162
|
+
description: "is less than",
|
|
163
|
+
value: "<"
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
name: "\u2264",
|
|
167
|
+
description: "is less than or equal to",
|
|
168
|
+
value: "<="
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
name: "has the strongest score",
|
|
172
|
+
value: "+"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
name: "has the weakest score",
|
|
176
|
+
value: "-"
|
|
177
|
+
}
|
|
178
|
+
];
|
|
179
|
+
function CriteriaOperatorMenu({ onChange, value, ...props }) {
|
|
180
|
+
var _a, _b;
|
|
181
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
182
|
+
import_design_system.InputComboBox,
|
|
183
|
+
{
|
|
184
|
+
...props,
|
|
185
|
+
value: {
|
|
186
|
+
label: (_b = (_a = contextCriteriaMenuOperators.find((e) => e.value === value)) == null ? void 0 : _a.name) != null ? _b : value,
|
|
187
|
+
value
|
|
188
|
+
},
|
|
189
|
+
options: contextCriteriaMenuOperators.map((option) => ({
|
|
190
|
+
label: option.description ? `${option.name}:${option.description}` : option.name,
|
|
191
|
+
value: option.value
|
|
192
|
+
})),
|
|
193
|
+
styles: {
|
|
194
|
+
...props.styles,
|
|
195
|
+
valueContainer: (provided, state) => {
|
|
196
|
+
var _a2, _b2;
|
|
197
|
+
return {
|
|
198
|
+
...provided,
|
|
199
|
+
padding: "var(--spacing-sm)",
|
|
200
|
+
...(_b2 = (_a2 = props.styles) == null ? void 0 : _a2.valueContainer) == null ? void 0 : _b2.call(_a2, provided, state)
|
|
201
|
+
};
|
|
202
|
+
},
|
|
203
|
+
menu: (provided, state) => {
|
|
204
|
+
var _a2, _b2;
|
|
205
|
+
return {
|
|
206
|
+
...provided,
|
|
207
|
+
width: "max-content",
|
|
208
|
+
...(_b2 = (_a2 = props.styles) == null ? void 0 : _a2.menu) == null ? void 0 : _b2.call(_a2, provided, state)
|
|
209
|
+
};
|
|
210
|
+
},
|
|
211
|
+
control: (provided, state) => {
|
|
212
|
+
var _a2, _b2;
|
|
213
|
+
return {
|
|
214
|
+
...provided,
|
|
215
|
+
border: 0,
|
|
216
|
+
...(_b2 = (_a2 = props.styles) == null ? void 0 : _a2.control) == null ? void 0 : _b2.call(_a2, provided, state)
|
|
217
|
+
};
|
|
218
|
+
},
|
|
219
|
+
indicatorSeparator: (provided, state) => {
|
|
220
|
+
var _a2, _b2;
|
|
221
|
+
return {
|
|
222
|
+
...provided,
|
|
223
|
+
display: "none",
|
|
224
|
+
...(_b2 = (_a2 = props.styles) == null ? void 0 : _a2.indicatorSeparator) == null ? void 0 : _b2.call(_a2, provided, state)
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
onChange: (e) => {
|
|
229
|
+
if (e) {
|
|
230
|
+
onChange(e.value);
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
components: {
|
|
234
|
+
SingleValue: CriteriaOperatorSingleValue,
|
|
235
|
+
Option: CriteriaOperatorOption,
|
|
236
|
+
...props.components
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// src/components/DataContext/DataContext.tsx
|
|
243
|
+
var import_design_system2 = require("@uniformdev/design-system");
|
|
244
|
+
var import_react5 = require("react");
|
|
245
|
+
|
|
246
|
+
// src/hooks/useContextData.ts
|
|
247
|
+
var import_api = require("@uniformdev/context/api");
|
|
248
|
+
var import_react3 = require("react");
|
|
249
|
+
function useContextData({ apiHost, apiKey, projectId }) {
|
|
250
|
+
const [state, setState] = (0, import_react3.useState)({
|
|
251
|
+
loading: false,
|
|
252
|
+
notConfigured: false,
|
|
253
|
+
error: null,
|
|
254
|
+
result: null
|
|
255
|
+
});
|
|
256
|
+
(0, import_react3.useEffect)(() => {
|
|
257
|
+
if (!projectId || !apiKey || !apiHost) {
|
|
258
|
+
setState({ notConfigured: true, loading: false, error: null, result: null });
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const runEffect = async () => {
|
|
262
|
+
setState({ notConfigured: false, loading: true, error: null, result: null });
|
|
263
|
+
try {
|
|
264
|
+
const client = new import_api.CachedManifestClient({
|
|
265
|
+
projectId,
|
|
266
|
+
apiKey,
|
|
267
|
+
apiHost
|
|
268
|
+
});
|
|
269
|
+
const result = await client.get({ preview: true });
|
|
270
|
+
setState({ notConfigured: false, loading: false, error: null, result });
|
|
271
|
+
} catch (e) {
|
|
272
|
+
let message;
|
|
273
|
+
if (e instanceof import_api.ApiClientError) {
|
|
274
|
+
if (e.statusCode === 403) {
|
|
275
|
+
message = `The API key ${apiKey} did not have permissions to fetch the manifest. Ensure Context > Read Drafts permissions are granted.`;
|
|
276
|
+
}
|
|
277
|
+
message = e.message;
|
|
278
|
+
} else {
|
|
279
|
+
message = e.toString();
|
|
280
|
+
}
|
|
281
|
+
setState({ notConfigured: false, loading: false, error: message, result: null });
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
runEffect();
|
|
286
|
+
}, [apiHost, apiKey, projectId]);
|
|
287
|
+
return {
|
|
288
|
+
result: state.result,
|
|
289
|
+
error: state.error,
|
|
290
|
+
loading: state.loading,
|
|
291
|
+
notConfigured: state.notConfigured
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// src/hooks/useDimensions.ts
|
|
296
|
+
var import_api2 = require("@uniformdev/context/api");
|
|
297
|
+
var import_react4 = require("react");
|
|
298
|
+
|
|
299
|
+
// src/utils/objectify.ts
|
|
300
|
+
function objectify(array2, keySelector, valueSelector) {
|
|
301
|
+
return array2.reduce((prev, current) => {
|
|
302
|
+
const key = keySelector(current);
|
|
303
|
+
if (typeof key === "undefined" || key === null) {
|
|
304
|
+
throw new Error(`Objectify key selector returned undefined or null.`);
|
|
305
|
+
}
|
|
306
|
+
prev[keySelector(current)] = valueSelector ? valueSelector(current) : current;
|
|
307
|
+
return prev;
|
|
308
|
+
}, {});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// src/hooks/useDimensions.ts
|
|
312
|
+
function useDimensions({ apiHost, apiKey, projectId }) {
|
|
313
|
+
const [state, setState] = (0, import_react4.useState)({
|
|
314
|
+
loading: false,
|
|
315
|
+
notConfigured: false,
|
|
316
|
+
error: null,
|
|
317
|
+
result: null
|
|
318
|
+
});
|
|
319
|
+
(0, import_react4.useEffect)(() => {
|
|
320
|
+
if (!projectId || !apiKey || !apiHost) {
|
|
321
|
+
setState({ notConfigured: true, loading: false, error: null, result: null });
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const runEffect = async () => {
|
|
325
|
+
setState({ notConfigured: false, loading: true, error: null, result: null });
|
|
326
|
+
try {
|
|
327
|
+
const client = new import_api2.CachedDimensionClient({
|
|
328
|
+
projectId,
|
|
329
|
+
apiKey,
|
|
330
|
+
apiHost
|
|
331
|
+
});
|
|
332
|
+
const dimensions = (await client.get()).dimensions.map((dim) => ({
|
|
333
|
+
...dim,
|
|
334
|
+
displayName: (0, import_api2.computeDimensionDisplayName)(dim)
|
|
335
|
+
}));
|
|
336
|
+
const result = {
|
|
337
|
+
dimensions,
|
|
338
|
+
dimIndex: objectify(
|
|
339
|
+
dimensions,
|
|
340
|
+
(k) => k.dim,
|
|
341
|
+
(v) => v
|
|
342
|
+
)
|
|
343
|
+
};
|
|
344
|
+
setState({ notConfigured: false, loading: false, error: null, result });
|
|
345
|
+
} catch (e) {
|
|
346
|
+
let message;
|
|
347
|
+
if (e instanceof import_api2.ApiClientError) {
|
|
348
|
+
message = e.message;
|
|
349
|
+
} else {
|
|
350
|
+
message = e.toString();
|
|
351
|
+
}
|
|
352
|
+
setState({ notConfigured: false, loading: false, error: message, result: null });
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
runEffect();
|
|
357
|
+
}, [apiHost, apiKey, projectId]);
|
|
358
|
+
return {
|
|
359
|
+
result: state.result,
|
|
360
|
+
error: state.error,
|
|
361
|
+
loading: state.loading,
|
|
362
|
+
notConfigured: state.notConfigured
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/components/DataContext/DataContext.tsx
|
|
367
|
+
var import_jsx_runtime5 = require("@emotion/react/jsx-runtime");
|
|
368
|
+
var ContextDataContext = (0, import_react5.createContext)(null);
|
|
369
|
+
var ContextData = ({
|
|
370
|
+
loadingComponent: LoadingComponent,
|
|
371
|
+
errorComponent: ErrorComponent,
|
|
372
|
+
contextConfig,
|
|
373
|
+
children
|
|
374
|
+
}) => {
|
|
375
|
+
const contextData = useContextData(contextConfig);
|
|
376
|
+
const dimensionsData = useDimensions(contextConfig);
|
|
377
|
+
if (contextData.error || contextData.notConfigured) {
|
|
378
|
+
if (ErrorComponent)
|
|
379
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorComponent, { contextConfig, result: contextData });
|
|
380
|
+
else
|
|
381
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: "ErrorComponent is not configured" });
|
|
382
|
+
}
|
|
383
|
+
if (dimensionsData.error || dimensionsData.notConfigured) {
|
|
384
|
+
if (ErrorComponent)
|
|
385
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorComponent, { contextConfig, result: dimensionsData });
|
|
386
|
+
else
|
|
387
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: "ErrorComponent is not configured" });
|
|
388
|
+
}
|
|
389
|
+
if (contextData.loading || dimensionsData.loading) {
|
|
390
|
+
if (LoadingComponent)
|
|
391
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(LoadingComponent, {});
|
|
392
|
+
else
|
|
393
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_design_system2.LoadingIndicator, {});
|
|
394
|
+
}
|
|
395
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
396
|
+
ContextDataContext.Provider,
|
|
397
|
+
{
|
|
398
|
+
value: { manifest: contextData.result, dimensions: dimensionsData.result, contextConfig },
|
|
399
|
+
children
|
|
400
|
+
}
|
|
401
|
+
);
|
|
402
|
+
};
|
|
403
|
+
function useContextConfig() {
|
|
404
|
+
const context = (0, import_react5.useContext)(ContextDataContext);
|
|
405
|
+
if (!(context == null ? void 0 : context.contextConfig)) {
|
|
406
|
+
throw new Error("Not within DataContext! Configuration data is not exist.");
|
|
407
|
+
}
|
|
408
|
+
return context.contextConfig;
|
|
409
|
+
}
|
|
410
|
+
function useManifest() {
|
|
411
|
+
const context = (0, import_react5.useContext)(ContextDataContext);
|
|
412
|
+
if (!(context == null ? void 0 : context.manifest)) {
|
|
413
|
+
throw new Error("Not within DataContext! Manifest data is not exist.");
|
|
414
|
+
}
|
|
415
|
+
return context.manifest;
|
|
416
|
+
}
|
|
417
|
+
function useDimensionsDataContext() {
|
|
418
|
+
const context = (0, import_react5.useContext)(ContextDataContext);
|
|
419
|
+
if (!(context == null ? void 0 : context.dimensions)) {
|
|
420
|
+
throw new Error("Not within DataContext! Dimensions data is not exist.");
|
|
421
|
+
}
|
|
422
|
+
return context.dimensions;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// src/components/DimensionMenu/CriteriaMatchMenu.tsx
|
|
426
|
+
var import_design_system5 = require("@uniformdev/design-system");
|
|
427
|
+
var import_react7 = require("react");
|
|
428
|
+
|
|
429
|
+
// src/components/DimensionMenu/DimensionGroupHeading.tsx
|
|
430
|
+
var import_design_system3 = require("@uniformdev/design-system");
|
|
431
|
+
|
|
432
|
+
// src/components/DimensionMenu/utils.ts
|
|
433
|
+
function dimensionToMenuOption(dimension) {
|
|
434
|
+
return {
|
|
435
|
+
label: dimension.displayName,
|
|
436
|
+
value: dimension.dim,
|
|
437
|
+
isDisabled: false
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
function dimensionIcon(displayName) {
|
|
441
|
+
if (!displayName) {
|
|
442
|
+
return "unavailable";
|
|
443
|
+
}
|
|
444
|
+
const [type] = displayName.split(":");
|
|
445
|
+
switch (type.toLowerCase()) {
|
|
446
|
+
case "signal":
|
|
447
|
+
return "data";
|
|
448
|
+
case "intent":
|
|
449
|
+
return "assign";
|
|
450
|
+
case "audience":
|
|
451
|
+
return "boy";
|
|
452
|
+
default:
|
|
453
|
+
return "user-list";
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
function groupDimensions(dimensions) {
|
|
457
|
+
const result = [];
|
|
458
|
+
let lastType = "";
|
|
459
|
+
for (const dim of dimensions) {
|
|
460
|
+
const [type] = dim.displayName.split(":");
|
|
461
|
+
if (lastType !== type) {
|
|
462
|
+
result.push({ label: type, options: [] });
|
|
463
|
+
lastType = type;
|
|
464
|
+
}
|
|
465
|
+
result[result.length - 1].options.push(dimensionToMenuOption(dim));
|
|
466
|
+
}
|
|
467
|
+
return result;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// src/components/DimensionMenu/DimensionGroupHeading.tsx
|
|
471
|
+
var import_jsx_runtime6 = require("@emotion/react/jsx-runtime");
|
|
472
|
+
var DimensionGroupHeading = (props) => {
|
|
473
|
+
var _a;
|
|
474
|
+
const { data, getStyles, className } = props;
|
|
475
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
476
|
+
"div",
|
|
477
|
+
{
|
|
478
|
+
css: {
|
|
479
|
+
...getStyles("groupHeading", props),
|
|
480
|
+
textTransform: "none",
|
|
481
|
+
fontSize: "var(--font-size-sm)"
|
|
482
|
+
},
|
|
483
|
+
className,
|
|
484
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
485
|
+
"small",
|
|
486
|
+
{
|
|
487
|
+
css: { color: "var(--gray-500)", display: "flex", alignItems: "center", gap: "var(--spacing-xs)" },
|
|
488
|
+
children: [
|
|
489
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_design_system3.Icon, { icon: dimensionIcon((_a = data.label) != null ? _a : ""), iconColor: "currentColor", size: 16 }),
|
|
490
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: data.label })
|
|
491
|
+
]
|
|
492
|
+
}
|
|
493
|
+
)
|
|
494
|
+
}
|
|
495
|
+
);
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
// src/components/DimensionMenu/DimensionMenuErrorMessage.tsx
|
|
499
|
+
var import_react6 = require("@emotion/react");
|
|
500
|
+
var import_jsx_runtime7 = require("@emotion/react/jsx-runtime");
|
|
501
|
+
function DimensionMenuErrorMessage({ message }) {
|
|
502
|
+
if (!message)
|
|
503
|
+
return null;
|
|
504
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
505
|
+
"div",
|
|
506
|
+
{
|
|
507
|
+
css: import_react6.css`
|
|
12
508
|
color: var(--brand-primary-2);
|
|
13
509
|
font-size: var(--fs-xs);
|
|
14
510
|
position: absolute;
|
|
15
511
|
bottom: calc((var(--spacing-base) * -1) + -2px);
|
|
16
|
-
`,
|
|
512
|
+
`,
|
|
513
|
+
children: message
|
|
514
|
+
}
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// src/components/DimensionMenu/DimensionOption.tsx
|
|
519
|
+
var import_jsx_runtime8 = require("@emotion/react/jsx-runtime");
|
|
520
|
+
var DimensionOption = (props) => {
|
|
521
|
+
var _a, _b;
|
|
522
|
+
const { data, getStyles, cx, isDisabled, isFocused, isSelected, className, innerRef, innerProps } = props;
|
|
523
|
+
const [, value] = (_b = (_a = data.label) == null ? void 0 : _a.split(":")) != null ? _b : [];
|
|
524
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
525
|
+
"div",
|
|
526
|
+
{
|
|
527
|
+
css: getStyles("option", props),
|
|
528
|
+
className: cx(
|
|
529
|
+
{
|
|
530
|
+
option: true,
|
|
531
|
+
"option--is-disabled": isDisabled,
|
|
532
|
+
"option--is-focused": isFocused,
|
|
533
|
+
"option--is-selected": isSelected
|
|
534
|
+
},
|
|
535
|
+
className
|
|
536
|
+
),
|
|
537
|
+
ref: innerRef,
|
|
538
|
+
"aria-disabled": isDisabled,
|
|
539
|
+
...innerProps,
|
|
540
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { css: { color: "var(--gray-700)" }, children: value != null ? value : data.label })
|
|
541
|
+
}
|
|
542
|
+
);
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
// src/components/DimensionMenu/DimensionValue.tsx
|
|
546
|
+
var import_design_system4 = require("@uniformdev/design-system");
|
|
547
|
+
var import_jsx_runtime9 = require("@emotion/react/jsx-runtime");
|
|
548
|
+
function DimensionValue({ displayName }) {
|
|
549
|
+
const [type, name] = displayName.split(":");
|
|
550
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
551
|
+
"div",
|
|
552
|
+
{
|
|
553
|
+
css: {
|
|
554
|
+
whiteSpace: "normal",
|
|
555
|
+
overflow: "hidden"
|
|
556
|
+
},
|
|
557
|
+
children: [
|
|
558
|
+
name ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
559
|
+
"small",
|
|
560
|
+
{
|
|
561
|
+
css: { color: "var(--gray-500)", display: "flex", alignItems: "center", gap: "var(--spacing-xs)" },
|
|
562
|
+
children: [
|
|
563
|
+
type ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_design_system4.Icon, { icon: dimensionIcon(type), iconColor: "currentColor", size: 16 }) : null,
|
|
564
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { "data-test-id": "dimension-name", children: type })
|
|
565
|
+
]
|
|
566
|
+
}
|
|
567
|
+
) : null,
|
|
568
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { css: { color: "var(--gray-700)" }, "data-test-id": "dimension-value", children: name != null ? name : type })
|
|
569
|
+
]
|
|
570
|
+
}
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// src/components/DimensionMenu/DimensionSingleValue.tsx
|
|
575
|
+
var import_jsx_runtime10 = require("@emotion/react/jsx-runtime");
|
|
576
|
+
var DimensionSingleValue = (props) => {
|
|
577
|
+
const { data, getStyles } = props;
|
|
578
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { css: getStyles("singleValue", props), children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(DimensionValue, { displayName: data.label }) });
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
// src/components/DimensionMenu/CriteriaMatchMenu.tsx
|
|
582
|
+
var import_jsx_runtime11 = require("@emotion/react/jsx-runtime");
|
|
583
|
+
function CriteriaMatchMenu({
|
|
584
|
+
onChange,
|
|
585
|
+
criteriaMatch,
|
|
586
|
+
dimensions,
|
|
587
|
+
errorMessage,
|
|
588
|
+
...props
|
|
589
|
+
}) {
|
|
590
|
+
var _a, _b;
|
|
591
|
+
const [inputValue, setInputValue] = (0, import_react7.useState)(
|
|
592
|
+
typeof criteriaMatch.r !== "undefined" && isInt(criteriaMatch.r) !== null ? criteriaMatch.r.toString(10) : ""
|
|
593
|
+
);
|
|
594
|
+
const rDim = criteriaMatch.rDim;
|
|
595
|
+
const targetDim = criteriaMatch.rDim ? dimensions.dimIndex[criteriaMatch.rDim] : void 0;
|
|
596
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
|
|
597
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
598
|
+
import_design_system5.InputComboBox,
|
|
599
|
+
{
|
|
600
|
+
...props,
|
|
601
|
+
inputValue,
|
|
602
|
+
menuShouldScrollIntoView: true,
|
|
603
|
+
value: {
|
|
604
|
+
label: (_a = targetDim == null ? void 0 : targetDim.displayName) != null ? _a : rDim && !targetDim ? `${criteriaMatch.rDim} (unknown)` : "",
|
|
605
|
+
value: (_b = criteriaMatch.rDim) != null ? _b : criteriaMatch.r ? criteriaMatch.r.toString(10) : "",
|
|
606
|
+
isDisabled: false
|
|
607
|
+
},
|
|
608
|
+
options: [
|
|
609
|
+
{
|
|
610
|
+
label: "Enter a numeric score to match, or choose another dimension to match its score",
|
|
611
|
+
value: "",
|
|
612
|
+
isDisabled: true
|
|
613
|
+
},
|
|
614
|
+
...groupDimensions(dimensions.dimensions)
|
|
615
|
+
],
|
|
616
|
+
styles: {
|
|
617
|
+
...props.styles,
|
|
618
|
+
valueContainer: (provided, state) => {
|
|
619
|
+
var _a2, _b2;
|
|
620
|
+
return {
|
|
621
|
+
...provided,
|
|
622
|
+
padding: "var(--spacing-sm)",
|
|
623
|
+
...(_b2 = (_a2 = props.styles) == null ? void 0 : _a2.valueContainer) == null ? void 0 : _b2.call(_a2, provided, state)
|
|
624
|
+
};
|
|
625
|
+
},
|
|
626
|
+
option: (provided, state) => {
|
|
627
|
+
var _a2, _b2;
|
|
628
|
+
return {
|
|
629
|
+
fontSize: state.isDisabled ? "0.8rem" : void 0,
|
|
630
|
+
...(_b2 = (_a2 = props.styles) == null ? void 0 : _a2.option) == null ? void 0 : _b2.call(_a2, provided, state)
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
},
|
|
634
|
+
onChange: (e) => {
|
|
635
|
+
var _a2;
|
|
636
|
+
if (e) {
|
|
637
|
+
onChange({ ...criteriaMatch, rDim: (_a2 = e.value) == null ? void 0 : _a2.toString(), r: void 0 });
|
|
638
|
+
setInputValue("");
|
|
639
|
+
}
|
|
640
|
+
},
|
|
641
|
+
onInputChange: (newValue, meta) => {
|
|
642
|
+
const isValueInt = isInt(newValue);
|
|
643
|
+
if (meta.action === "input-change" || meta.action === "set-value") {
|
|
644
|
+
setInputValue(newValue);
|
|
645
|
+
if (isValueInt || newValue === "") {
|
|
646
|
+
onChange({ ...criteriaMatch, r: newValue || void 0, rDim: void 0 });
|
|
647
|
+
}
|
|
648
|
+
} else if (!isValueInt && !isInt(meta.prevInputValue)) {
|
|
649
|
+
if (!newValue && criteriaMatch.r) {
|
|
650
|
+
setInputValue(criteriaMatch.r.toString());
|
|
651
|
+
} else {
|
|
652
|
+
setInputValue(newValue);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
},
|
|
656
|
+
components: {
|
|
657
|
+
...props.components,
|
|
658
|
+
Option: DimensionOption,
|
|
659
|
+
SingleValue: DimensionSingleValue,
|
|
660
|
+
GroupHeading: DimensionGroupHeading
|
|
661
|
+
},
|
|
662
|
+
noOptionsMessage: ({ inputValue: inputValue2 }) => {
|
|
663
|
+
if (isInt(inputValue2)) {
|
|
664
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
|
|
665
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { children: [
|
|
666
|
+
"Score: ",
|
|
667
|
+
inputValue2
|
|
668
|
+
] }),
|
|
669
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("small", { children: "If you want to match on another dimension\u2019s score instead, clear the score value to search for a dimension." })
|
|
670
|
+
] });
|
|
671
|
+
}
|
|
672
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
|
|
673
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { children: [
|
|
674
|
+
"No dimensions match your search \u201C",
|
|
675
|
+
inputValue2,
|
|
676
|
+
"\u201D"
|
|
677
|
+
] }),
|
|
678
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("small", { children: "If you want to match a literal score, enter a numeric value." })
|
|
679
|
+
] });
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
),
|
|
683
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(DimensionMenuErrorMessage, { message: errorMessage })
|
|
684
|
+
] });
|
|
685
|
+
}
|
|
686
|
+
function isInt(value) {
|
|
687
|
+
return /^\d+$/.test(value.toString(10));
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
// src/components/DimensionMenu/DimensionMenu.tsx
|
|
691
|
+
var import_design_system6 = require("@uniformdev/design-system");
|
|
692
|
+
var import_jsx_runtime12 = require("@emotion/react/jsx-runtime");
|
|
693
|
+
function DimensionMenu({ onChange, value, dimensions, errorMessage, ...props }) {
|
|
694
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
|
|
695
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
696
|
+
import_design_system6.InputComboBox,
|
|
697
|
+
{
|
|
698
|
+
...props,
|
|
699
|
+
value: value ? dimensionToMenuOption(value) : void 0,
|
|
700
|
+
options: groupDimensions(dimensions),
|
|
701
|
+
styles: {
|
|
702
|
+
...props.styles,
|
|
703
|
+
valueContainer: (provided, state) => {
|
|
704
|
+
var _a, _b;
|
|
705
|
+
return {
|
|
706
|
+
...provided,
|
|
707
|
+
padding: "var(--spacing-sm)",
|
|
708
|
+
...(_b = (_a = props.styles) == null ? void 0 : _a.valueContainer) == null ? void 0 : _b.call(_a, provided, state)
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
},
|
|
712
|
+
onChange: (e) => {
|
|
713
|
+
if (e) {
|
|
714
|
+
onChange(dimensions.find((d) => d.dim === e.value));
|
|
715
|
+
}
|
|
716
|
+
},
|
|
717
|
+
components: {
|
|
718
|
+
Option: DimensionOption,
|
|
719
|
+
SingleValue: DimensionSingleValue,
|
|
720
|
+
GroupHeading: DimensionGroupHeading,
|
|
721
|
+
...props.components
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
),
|
|
725
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(DimensionMenuErrorMessage, { message: errorMessage })
|
|
726
|
+
] });
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// src/components/EditLink/EditLink.tsx
|
|
730
|
+
var import_design_system7 = require("@uniformdev/design-system");
|
|
731
|
+
var import_cg = require("react-icons/cg");
|
|
732
|
+
|
|
733
|
+
// src/components/EditLink/EditLink.styles.ts
|
|
734
|
+
var import_react8 = require("@emotion/react");
|
|
735
|
+
var editLink = import_react8.css`
|
|
17
736
|
display: flex;
|
|
18
737
|
align-items: center;
|
|
19
738
|
font-weight: var(--fw-bold);
|
|
@@ -24,7 +743,36 @@
|
|
|
24
743
|
&:focus {
|
|
25
744
|
text-decoration-line: underline;
|
|
26
745
|
}
|
|
27
|
-
`;
|
|
746
|
+
`;
|
|
747
|
+
|
|
748
|
+
// src/components/EditLink/EditLink.tsx
|
|
749
|
+
var import_jsx_runtime13 = require("@emotion/react/jsx-runtime");
|
|
750
|
+
var EditLink = ({ linkTo, name, linkText = `Edit ${name} Component` }) => {
|
|
751
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
752
|
+
"a",
|
|
753
|
+
{
|
|
754
|
+
css: editLink,
|
|
755
|
+
title: `Edit ${name} component definition`,
|
|
756
|
+
rel: "noopener noreferrer",
|
|
757
|
+
target: "_blank",
|
|
758
|
+
href: linkTo,
|
|
759
|
+
children: [
|
|
760
|
+
linkText,
|
|
761
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_design_system7.Icon, { icon: import_cg.CgChevronRight, iconColor: "currentColor", size: "1.5rem" })
|
|
762
|
+
]
|
|
763
|
+
}
|
|
764
|
+
);
|
|
765
|
+
};
|
|
766
|
+
|
|
767
|
+
// src/components/EnrichmentTag/EnrichmentTag.tsx
|
|
768
|
+
var import_react9 = require("@emotion/react");
|
|
769
|
+
var import_context = require("@uniformdev/context");
|
|
770
|
+
var import_design_system8 = require("@uniformdev/design-system");
|
|
771
|
+
var import_immer = __toESM(require("immer"));
|
|
772
|
+
var import_react10 = require("react");
|
|
773
|
+
var import_cg2 = require("react-icons/cg");
|
|
774
|
+
var import_jsx_runtime14 = require("@emotion/react/jsx-runtime");
|
|
775
|
+
var addEnrichmentLink = import_react9.css`
|
|
28
776
|
flex: 2;
|
|
29
777
|
display: flex;
|
|
30
778
|
width: 50%;
|
|
@@ -35,7 +783,189 @@
|
|
|
35
783
|
&:focus {
|
|
36
784
|
text-decoration-line: underline;
|
|
37
785
|
}
|
|
38
|
-
|
|
786
|
+
`;
|
|
787
|
+
var EnrichmentTag = ({
|
|
788
|
+
value,
|
|
789
|
+
setValue,
|
|
790
|
+
contextConfig,
|
|
791
|
+
displayTitle = true
|
|
792
|
+
}) => {
|
|
793
|
+
const { loading, result: dimensions, error } = useDimensions(contextConfig);
|
|
794
|
+
const allEnrichments = (0, import_react10.useMemo)(() => {
|
|
795
|
+
if (dimensions)
|
|
796
|
+
return dimensions.dimensions.filter((dimension) => dimension.category === "ENR");
|
|
797
|
+
}, [dimensions]);
|
|
798
|
+
const remainingEnrichments = (0, import_react10.useMemo)(() => {
|
|
799
|
+
if (!value)
|
|
800
|
+
return allEnrichments;
|
|
801
|
+
if (allEnrichments)
|
|
802
|
+
return allEnrichments.filter(
|
|
803
|
+
(enr) => !value.some((val) => (0, import_context.getEnrichmentVectorKey)(val.cat, val.key) === enr.dim)
|
|
804
|
+
);
|
|
805
|
+
}, [allEnrichments, value]);
|
|
806
|
+
const [selectValue, setSelectValue] = (0, import_react10.useState)("");
|
|
807
|
+
const [score, setScore] = (0, import_react10.useState)(50);
|
|
808
|
+
const [showAddNewEnrichmentTagPanel, setShowAddNewEnrichmentTagPanel] = (0, import_react10.useState)(false);
|
|
809
|
+
const selectedEnrichment = allEnrichments == null ? void 0 : allEnrichments.find((dimension) => dimension.dim === selectValue);
|
|
810
|
+
const addEnrichment = () => {
|
|
811
|
+
const [cat, key] = selectValue.split("_");
|
|
812
|
+
update([...value != null ? value : [], { cat, key, str: score }]);
|
|
813
|
+
setSelectValue("");
|
|
814
|
+
setScore(50);
|
|
815
|
+
setShowAddNewEnrichmentTagPanel(false);
|
|
816
|
+
};
|
|
817
|
+
const update = (newValue) => {
|
|
818
|
+
let validData = [];
|
|
819
|
+
if (dimensions) {
|
|
820
|
+
validData = newValue.filter((enrichment) => {
|
|
821
|
+
const dimData = dimensions.dimIndex[(0, import_context.getEnrichmentVectorKey)(enrichment.cat, enrichment.key)];
|
|
822
|
+
return Boolean(dimData);
|
|
823
|
+
});
|
|
824
|
+
} else {
|
|
825
|
+
validData = newValue;
|
|
826
|
+
}
|
|
827
|
+
const finalValue = validData.length === 0 ? null : validData;
|
|
828
|
+
setValue(finalValue);
|
|
829
|
+
};
|
|
830
|
+
if (error)
|
|
831
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_design_system8.Callout, { type: "danger", children: error });
|
|
832
|
+
if (loading || dimensions === null)
|
|
833
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_design_system8.LoadingIndicator, {});
|
|
834
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("fieldset", { className: "enrichment-tag", children: [
|
|
835
|
+
displayTitle ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { css: { display: "flex", justifyContent: "space-between", marginBottom: "var(--spacing-base)" }, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("legend", { css: { fontSize: "var(--fs-md)", fontWeight: "var(--fw-bold)" }, children: "Enrichment Tags" }) }) : null,
|
|
836
|
+
!(allEnrichments == null ? void 0 : allEnrichments.length) ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(NoEnrichmentsView, { contextConfig }) : !showAddNewEnrichmentTagPanel && !value ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
837
|
+
import_design_system8.Callout,
|
|
838
|
+
{
|
|
839
|
+
title: "No enrichment tags assigned.",
|
|
840
|
+
type: "info",
|
|
841
|
+
css: { marginBlock: "var(--spacing-base)" },
|
|
842
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("p", { children: [
|
|
843
|
+
"Click",
|
|
844
|
+
" ",
|
|
845
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
846
|
+
"a",
|
|
847
|
+
{
|
|
848
|
+
onClick: () => setShowAddNewEnrichmentTagPanel(true),
|
|
849
|
+
target: "_blank",
|
|
850
|
+
rel: "noopener noreferrer",
|
|
851
|
+
css: { textDecorationLine: "underline" },
|
|
852
|
+
children: "here"
|
|
853
|
+
}
|
|
854
|
+
),
|
|
855
|
+
" ",
|
|
856
|
+
"to assign your first enrichment tag."
|
|
857
|
+
] })
|
|
858
|
+
}
|
|
859
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
860
|
+
dimensions && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(SelectedEnrichments, { list: value != null ? value : [], setList: update, dimIndex: dimensions.dimIndex }),
|
|
861
|
+
showAddNewEnrichmentTagPanel && remainingEnrichments && remainingEnrichments.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
862
|
+
"div",
|
|
863
|
+
{
|
|
864
|
+
className: "add-enrichment-tag",
|
|
865
|
+
css: {
|
|
866
|
+
display: "flex",
|
|
867
|
+
flexWrap: "wrap",
|
|
868
|
+
gap: "var(--spacing-lg)",
|
|
869
|
+
marginTop: "var(--spacing-md)",
|
|
870
|
+
alignItems: "center"
|
|
871
|
+
},
|
|
872
|
+
children: [
|
|
873
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { css: { flexGrow: 1 }, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
874
|
+
import_design_system8.InputSelect,
|
|
875
|
+
{
|
|
876
|
+
name: `enrichment-type`,
|
|
877
|
+
label: "Enrichment Tag",
|
|
878
|
+
showLabel: true,
|
|
879
|
+
value: selectValue,
|
|
880
|
+
options: [
|
|
881
|
+
{ label: "Select", value: "" },
|
|
882
|
+
...remainingEnrichments.map((enr) => ({
|
|
883
|
+
label: enr.displayName,
|
|
884
|
+
value: enr.dim
|
|
885
|
+
}))
|
|
886
|
+
],
|
|
887
|
+
onChange: (e) => setSelectValue(e.currentTarget.value)
|
|
888
|
+
}
|
|
889
|
+
) }),
|
|
890
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
891
|
+
ScoreCounter,
|
|
892
|
+
{
|
|
893
|
+
score,
|
|
894
|
+
setValue: setScore,
|
|
895
|
+
cap: selectedEnrichment ? selectedEnrichment.cap : 100,
|
|
896
|
+
css: { flexBasis: "9rem" }
|
|
897
|
+
}
|
|
898
|
+
),
|
|
899
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
900
|
+
import_design_system8.Button,
|
|
901
|
+
{
|
|
902
|
+
buttonType: "tertiary",
|
|
903
|
+
size: "xl",
|
|
904
|
+
css: {
|
|
905
|
+
marginBottom: "var(--spacing-xs)",
|
|
906
|
+
height: "3.5rem",
|
|
907
|
+
margin: 0,
|
|
908
|
+
alignSelf: "flex-end"
|
|
909
|
+
},
|
|
910
|
+
onClick: addEnrichment,
|
|
911
|
+
disabled: !selectValue,
|
|
912
|
+
children: "Add"
|
|
913
|
+
}
|
|
914
|
+
)
|
|
915
|
+
]
|
|
916
|
+
}
|
|
917
|
+
) : null,
|
|
918
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
919
|
+
"div",
|
|
920
|
+
{
|
|
921
|
+
className: "enrichment-cta",
|
|
922
|
+
style: { paddingTop: "10px", display: "flex", justifyContent: "space-between" },
|
|
923
|
+
children: [
|
|
924
|
+
!showAddNewEnrichmentTagPanel && remainingEnrichments && remainingEnrichments.length > 0 && value ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
925
|
+
import_design_system8.AddListButton,
|
|
926
|
+
{
|
|
927
|
+
className: "add-more",
|
|
928
|
+
buttonText: "Add More",
|
|
929
|
+
onButtonClick: () => setShowAddNewEnrichmentTagPanel(true)
|
|
930
|
+
}
|
|
931
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("a", { css: addEnrichmentLink, title: `none`, href: "#" }),
|
|
932
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
933
|
+
EditLink,
|
|
934
|
+
{
|
|
935
|
+
name: "Enrichments",
|
|
936
|
+
linkText: "Manage Enrichments",
|
|
937
|
+
linkTo: `${contextConfig.apiHost}/projects/${encodeURIComponent(
|
|
938
|
+
contextConfig.projectId
|
|
939
|
+
)}/personalization/enrichments`
|
|
940
|
+
}
|
|
941
|
+
)
|
|
942
|
+
]
|
|
943
|
+
}
|
|
944
|
+
)
|
|
945
|
+
] })
|
|
946
|
+
] });
|
|
947
|
+
};
|
|
948
|
+
var NoEnrichmentsView = ({ contextConfig }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_design_system8.Callout, { title: "No enrichments found.", type: "caution", css: { marginBlock: "var(--spacing-base)" }, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("p", { children: [
|
|
949
|
+
"Looks like you do not have any enrichment created in your connected Uniform project. Start by creating your first enrichment",
|
|
950
|
+
" ",
|
|
951
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
952
|
+
"a",
|
|
953
|
+
{
|
|
954
|
+
href: `${contextConfig.apiHost}/projects/${encodeURIComponent(
|
|
955
|
+
contextConfig.projectId
|
|
956
|
+
)}/personalization/enrichments`,
|
|
957
|
+
target: "_blank",
|
|
958
|
+
rel: "noopener noreferrer",
|
|
959
|
+
css: { ":hover": { textDecorationLine: "underline" } },
|
|
960
|
+
children: "here"
|
|
961
|
+
}
|
|
962
|
+
),
|
|
963
|
+
"."
|
|
964
|
+
] }) });
|
|
965
|
+
var getCappedValue = (value, maxCap = 100, minCap = 0) => {
|
|
966
|
+
return Math.max(Math.min(value, maxCap), minCap);
|
|
967
|
+
};
|
|
968
|
+
var scoreCounterMinusButtonStyles = import_react9.css`
|
|
39
969
|
position: absolute;
|
|
40
970
|
bottom: 0.875rem;
|
|
41
971
|
left: var(--spacing-sm);
|
|
@@ -47,28 +977,198 @@
|
|
|
47
977
|
background-color: var(--gray-100);
|
|
48
978
|
border: 1px solid var(--gray-300);
|
|
49
979
|
border-radius: var(--rounded-full);
|
|
50
|
-
|
|
51
|
-
|
|
980
|
+
`;
|
|
981
|
+
var scoreCounterPlusButtonStyles = import_react9.css`
|
|
982
|
+
${scoreCounterMinusButtonStyles}
|
|
52
983
|
left: auto;
|
|
53
984
|
right: var(--spacing-sm);
|
|
54
|
-
|
|
985
|
+
`;
|
|
986
|
+
var ScoreCounter = ({
|
|
987
|
+
score,
|
|
988
|
+
setValue,
|
|
989
|
+
cap = 100,
|
|
990
|
+
...otherProps
|
|
991
|
+
}) => {
|
|
992
|
+
const handleCounter = (symbol) => {
|
|
993
|
+
let newScore = symbol === "increment" ? score + 10 : score - 10;
|
|
994
|
+
if (newScore < 0) {
|
|
995
|
+
newScore = 0;
|
|
996
|
+
}
|
|
997
|
+
if (newScore > cap) {
|
|
998
|
+
newScore = cap;
|
|
999
|
+
}
|
|
1000
|
+
setValue(newScore);
|
|
1001
|
+
};
|
|
1002
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { css: { position: "relative" }, ...otherProps, children: [
|
|
1003
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1004
|
+
import_design_system8.Input,
|
|
1005
|
+
{
|
|
1006
|
+
label: "Strength",
|
|
1007
|
+
id: "enrichment-score",
|
|
1008
|
+
type: "number",
|
|
1009
|
+
min: 0,
|
|
1010
|
+
max: cap,
|
|
1011
|
+
value: score,
|
|
1012
|
+
onChange: (e) => setValue(getCappedValue(Number(e.currentTarget.value) || 0, cap)),
|
|
1013
|
+
css: { textAlign: "center", boxSizing: "border-box" }
|
|
1014
|
+
}
|
|
1015
|
+
),
|
|
1016
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1017
|
+
"button",
|
|
1018
|
+
{
|
|
1019
|
+
type: "button",
|
|
1020
|
+
title: "Reduce enrichment count",
|
|
1021
|
+
onClick: () => handleCounter("decrement"),
|
|
1022
|
+
disabled: score === 0,
|
|
1023
|
+
className: "scoreCounterButton",
|
|
1024
|
+
css: scoreCounterMinusButtonStyles,
|
|
1025
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_design_system8.Icon, { icon: import_cg2.CgMathMinus, iconColor: "gray", size: "1.5rem" })
|
|
1026
|
+
}
|
|
1027
|
+
),
|
|
1028
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1029
|
+
"button",
|
|
1030
|
+
{
|
|
1031
|
+
type: "button",
|
|
1032
|
+
title: "Increase enrichment count",
|
|
1033
|
+
onClick: () => handleCounter("increment"),
|
|
1034
|
+
className: "scoreCounterButton",
|
|
1035
|
+
css: scoreCounterPlusButtonStyles,
|
|
1036
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_design_system8.Icon, { icon: import_cg2.CgMathPlus, iconColor: "gray", size: "1.5rem" })
|
|
1037
|
+
}
|
|
1038
|
+
)
|
|
1039
|
+
] });
|
|
1040
|
+
};
|
|
1041
|
+
var SelectedEnrichments = ({ list, setList, dimIndex }) => {
|
|
1042
|
+
const removeEnrichment = (index) => {
|
|
1043
|
+
setList(
|
|
1044
|
+
(0, import_immer.default)(list, (draft) => {
|
|
1045
|
+
draft.splice(index, 1);
|
|
1046
|
+
})
|
|
1047
|
+
);
|
|
1048
|
+
};
|
|
1049
|
+
const updateEnrichmentScore = (index, value) => {
|
|
1050
|
+
var _a;
|
|
1051
|
+
const cap = (_a = dimIndex[`${list[index].cat}_${list[index].key}`]) == null ? void 0 : _a.cap;
|
|
1052
|
+
setList(
|
|
1053
|
+
(0, import_immer.default)(list, (draft) => {
|
|
1054
|
+
draft[index].str = getCappedValue(Number(value) || 0, cap);
|
|
1055
|
+
})
|
|
1056
|
+
);
|
|
1057
|
+
};
|
|
1058
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_jsx_runtime14.Fragment, { children: list.map((enrichment, index) => {
|
|
1059
|
+
const dimData = dimIndex[(0, import_context.getEnrichmentVectorKey)(enrichment.cat, enrichment.key)];
|
|
1060
|
+
if (!dimData)
|
|
1061
|
+
return;
|
|
1062
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
1063
|
+
"div",
|
|
1064
|
+
{
|
|
1065
|
+
css: {
|
|
1066
|
+
display: "flex",
|
|
1067
|
+
alignItems: "center",
|
|
1068
|
+
gap: "var(--spacing-base)",
|
|
1069
|
+
backgroundColor: "var(--brand-secondary-2)",
|
|
1070
|
+
boxShadow: "var(--shadow-base)",
|
|
1071
|
+
borderRadius: "var(--rounded-base)",
|
|
1072
|
+
paddingInline: "var(--spacing-base)",
|
|
1073
|
+
marginBlock: "var(--spacing-base)"
|
|
1074
|
+
},
|
|
1075
|
+
className: "selected-enrichments",
|
|
1076
|
+
children: [
|
|
1077
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1078
|
+
"span",
|
|
1079
|
+
{
|
|
1080
|
+
css: { fontWeight: "var(--fw-bold)", color: dimData ? void 0 : "var(--brand-secondary-5)" },
|
|
1081
|
+
children: dimData ? dimData.displayName : `Enrichment '${enrichment.cat}_${enrichment.key}' is unknown`
|
|
1082
|
+
}
|
|
1083
|
+
),
|
|
1084
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1085
|
+
"div",
|
|
1086
|
+
{
|
|
1087
|
+
css: {
|
|
1088
|
+
marginLeft: "auto",
|
|
1089
|
+
display: "flex",
|
|
1090
|
+
alignItems: "center",
|
|
1091
|
+
border: "0 solid var(--gray-400)",
|
|
1092
|
+
borderLeftWidth: "1px",
|
|
1093
|
+
borderRightWidth: "1px",
|
|
1094
|
+
padding: "var(--spacing-sm) var(--spacing-base)",
|
|
1095
|
+
flexBasis: "9rem"
|
|
1096
|
+
},
|
|
1097
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1098
|
+
import_design_system8.Input,
|
|
1099
|
+
{
|
|
1100
|
+
type: "text",
|
|
1101
|
+
min: 0,
|
|
1102
|
+
max: dimData.cap || 100,
|
|
1103
|
+
title: "score",
|
|
1104
|
+
value: enrichment.str,
|
|
1105
|
+
css: { textAlign: "center", width: "100px" },
|
|
1106
|
+
onChange: (e) => updateEnrichmentScore(index, e.currentTarget.value)
|
|
1107
|
+
}
|
|
1108
|
+
)
|
|
1109
|
+
}
|
|
1110
|
+
),
|
|
1111
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1112
|
+
"button",
|
|
1113
|
+
{
|
|
1114
|
+
type: "button",
|
|
1115
|
+
title: `Delete enrichment`,
|
|
1116
|
+
onClick: () => removeEnrichment(index),
|
|
1117
|
+
css: { border: 0 },
|
|
1118
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_design_system8.Icon, { icon: import_cg2.CgCloseO, iconColor: "red", size: "1.5rem" })
|
|
1119
|
+
}
|
|
1120
|
+
)
|
|
1121
|
+
]
|
|
1122
|
+
},
|
|
1123
|
+
`${enrichment.cat}-${enrichment.key}`
|
|
1124
|
+
);
|
|
1125
|
+
}) });
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
// src/components/PersonalizationCriteria/PersonalizationCriteria.tsx
|
|
1129
|
+
var import_design_system10 = require("@uniformdev/design-system");
|
|
1130
|
+
var import_react13 = require("react");
|
|
1131
|
+
var import_react_use = require("react-use");
|
|
1132
|
+
var yup = __toESM(require("yup"));
|
|
1133
|
+
|
|
1134
|
+
// src/utils/utils.ts
|
|
1135
|
+
function isEnrichmentTagData(obj) {
|
|
1136
|
+
return Array.isArray(obj) && obj.length > 0 && obj[0].cat !== void 0;
|
|
1137
|
+
}
|
|
1138
|
+
function isPersonalizationCriteriaData(obj) {
|
|
1139
|
+
return obj.crit !== void 0;
|
|
1140
|
+
}
|
|
1141
|
+
function opHasRhs(op) {
|
|
1142
|
+
return op !== "+" && op !== "-";
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
// src/components/PersonalizationCriteria/PersonalizationCriteriaStatic.tsx
|
|
1146
|
+
var import_react12 = require("@emotion/react");
|
|
1147
|
+
var import_design_system9 = require("@uniformdev/design-system");
|
|
1148
|
+
var import_immer2 = __toESM(require("immer"));
|
|
1149
|
+
var import_cg3 = require("react-icons/cg");
|
|
1150
|
+
|
|
1151
|
+
// src/components/PersonalizationCriteria/PersonalizationCriteriaStatic.styles.ts
|
|
1152
|
+
var import_react11 = require("@emotion/react");
|
|
1153
|
+
var spaceBetweenCriteriaItems = "6rem";
|
|
1154
|
+
var criteriaItem = import_react11.css`
|
|
55
1155
|
position: relative;
|
|
56
1156
|
padding: var(--spacing-md) var(--spacing-base);
|
|
57
1157
|
border: 1px solid var(--gray-300);
|
|
58
1158
|
box-shadow: var(--shadow-base);
|
|
59
1159
|
background-color: white;
|
|
60
1160
|
border-radius: var(--rounded-base);
|
|
61
|
-
margin-top: ${
|
|
1161
|
+
margin-top: ${spaceBetweenCriteriaItems};
|
|
62
1162
|
display: flex;
|
|
63
1163
|
|
|
64
1164
|
&:before {
|
|
65
1165
|
content: '';
|
|
66
1166
|
display: block;
|
|
67
1167
|
width: 1px;
|
|
68
|
-
height: ${
|
|
1168
|
+
height: ${spaceBetweenCriteriaItems};
|
|
69
1169
|
background-color: var(--gray-300);
|
|
70
1170
|
position: absolute;
|
|
71
|
-
top: -${
|
|
1171
|
+
top: -${spaceBetweenCriteriaItems};
|
|
72
1172
|
left: var(--spacing-lg);
|
|
73
1173
|
}
|
|
74
1174
|
|
|
@@ -78,27 +1178,449 @@
|
|
|
78
1178
|
display: none;
|
|
79
1179
|
}
|
|
80
1180
|
}
|
|
81
|
-
|
|
1181
|
+
`;
|
|
1182
|
+
var criteriaItemInner = import_react11.css`
|
|
82
1183
|
display: flex;
|
|
83
1184
|
gap: var(--spacing-base);
|
|
84
1185
|
flex-grow: 1;
|
|
85
1186
|
flex-wrap: wrap;
|
|
86
1187
|
margin-right: var(--spacing-base);
|
|
87
|
-
|
|
1188
|
+
`;
|
|
1189
|
+
var criteriaWrapper = import_react11.css`
|
|
88
1190
|
width: 100%;
|
|
89
1191
|
display: flex;
|
|
90
1192
|
align-items: stretch;
|
|
91
1193
|
position: relative;
|
|
92
|
-
|
|
1194
|
+
`;
|
|
1195
|
+
var criteriaOperandWrapper = import_react11.css`
|
|
93
1196
|
flex: 2;
|
|
94
1197
|
height: 52px;
|
|
95
1198
|
min-width: 200px;
|
|
96
|
-
|
|
1199
|
+
`;
|
|
1200
|
+
var criteriaOperatorWrapper = import_react11.css`
|
|
97
1201
|
flex: 1;
|
|
98
1202
|
min-width: 80px;
|
|
99
|
-
|
|
1203
|
+
`;
|
|
1204
|
+
var expand = import_react11.css`
|
|
100
1205
|
height: 100%;
|
|
101
1206
|
width: 100%;
|
|
102
|
-
`;
|
|
103
|
-
|
|
104
|
-
|
|
1207
|
+
`;
|
|
1208
|
+
|
|
1209
|
+
// src/components/PersonalizationCriteria/PersonalizationCriteriaStatic.tsx
|
|
1210
|
+
var import_jsx_runtime15 = require("@emotion/react/jsx-runtime");
|
|
1211
|
+
var PersonalizationCriteriaStatic = ({
|
|
1212
|
+
value,
|
|
1213
|
+
setValue,
|
|
1214
|
+
dimensions,
|
|
1215
|
+
onMenuOpen,
|
|
1216
|
+
onMenuClose,
|
|
1217
|
+
onAddCriteria,
|
|
1218
|
+
onRemoveCriteria,
|
|
1219
|
+
displayTitle = true,
|
|
1220
|
+
components,
|
|
1221
|
+
errors = {}
|
|
1222
|
+
}) => {
|
|
1223
|
+
const currentValue = value || {
|
|
1224
|
+
crit: []
|
|
1225
|
+
};
|
|
1226
|
+
const setOp = (op) => {
|
|
1227
|
+
const finalOp = op === "&" ? void 0 : op;
|
|
1228
|
+
setValue({
|
|
1229
|
+
...currentValue,
|
|
1230
|
+
op: finalOp
|
|
1231
|
+
});
|
|
1232
|
+
};
|
|
1233
|
+
const addToList = () => {
|
|
1234
|
+
const newValue = {
|
|
1235
|
+
...currentValue,
|
|
1236
|
+
crit: [...currentValue.crit, { l: "", op: ">", r: 0 }]
|
|
1237
|
+
};
|
|
1238
|
+
setValue(newValue);
|
|
1239
|
+
onAddCriteria == null ? void 0 : onAddCriteria(newValue);
|
|
1240
|
+
};
|
|
1241
|
+
const update = (crit, index) => {
|
|
1242
|
+
setValue(
|
|
1243
|
+
(0, import_immer2.default)(currentValue, (draft) => {
|
|
1244
|
+
draft.crit[index] = crit;
|
|
1245
|
+
})
|
|
1246
|
+
);
|
|
1247
|
+
};
|
|
1248
|
+
const removeFromList = (index) => {
|
|
1249
|
+
const newValue = (0, import_immer2.default)(currentValue, (draft) => {
|
|
1250
|
+
draft.crit.splice(index, 1);
|
|
1251
|
+
});
|
|
1252
|
+
const finalValue = newValue.crit.length === 0 ? null : newValue;
|
|
1253
|
+
setValue(finalValue);
|
|
1254
|
+
onRemoveCriteria == null ? void 0 : onRemoveCriteria(finalValue);
|
|
1255
|
+
};
|
|
1256
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("fieldset", { className: "personalization-criteria", children: [
|
|
1257
|
+
displayTitle ? (components == null ? void 0 : components.Title) ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(components.Title, {}) : /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1258
|
+
"legend",
|
|
1259
|
+
{
|
|
1260
|
+
css: {
|
|
1261
|
+
fontSize: "var(--fs-md)",
|
|
1262
|
+
fontWeight: "var(--fw-bold)"
|
|
1263
|
+
},
|
|
1264
|
+
children: "Personalize This"
|
|
1265
|
+
}
|
|
1266
|
+
) : null,
|
|
1267
|
+
(components == null ? void 0 : components.CustomVariantName) ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(components.CustomVariantName, {}) : null,
|
|
1268
|
+
!currentValue.crit.length ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_design_system9.Callout, { title: "Default variant", type: "info", css: { marginBlock: "var(--spacing-base)" }, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_design_system9.Paragraph, { children: 'This personalized variant has no match criteria and will be shown to any visitor that does not match any preceding variants. Ensure that default variants come last in the variant list. Personalize this variant by clicking "Add Criteria" to get started.' }) }) : /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { children: currentValue.crit.map((currentCriteria, index) => {
|
|
1269
|
+
var _a, _b, _c, _d;
|
|
1270
|
+
const critHasLhs = ((_a = currentCriteria.l) == null ? void 0 : _a.length) > 0;
|
|
1271
|
+
const critHasRhs = currentCriteria.op !== "+" && currentCriteria.op !== "-";
|
|
1272
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { css: criteriaItem, "data-test-id": "criteria-container", children: [
|
|
1273
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
|
|
1274
|
+
"div",
|
|
1275
|
+
{
|
|
1276
|
+
css: import_react12.css`
|
|
1277
|
+
${criteriaItemInner}/* grid-template-columns: minmax(0, 1fr) ${critHasRhs ? "minmax(0, 79px) minmax(0, 1fr)" : "minmax(0, 1fr)"} */
|
|
1278
|
+
`,
|
|
1279
|
+
className: "criteriaItemInner",
|
|
1280
|
+
children: [
|
|
1281
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1282
|
+
"div",
|
|
1283
|
+
{
|
|
1284
|
+
css: [criteriaWrapper, criteriaOperandWrapper],
|
|
1285
|
+
className: "criteria-wrapper",
|
|
1286
|
+
"data-test-id": "select-criteria",
|
|
1287
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1288
|
+
DimensionMenu,
|
|
1289
|
+
{
|
|
1290
|
+
errorMessage: (_b = errors.lhs) == null ? void 0 : _b[index],
|
|
1291
|
+
css: expand,
|
|
1292
|
+
styles: { control: (base) => ({ ...base, height: "100%" }) },
|
|
1293
|
+
dimensions: dimensions.dimensions,
|
|
1294
|
+
onChange: (dim) => {
|
|
1295
|
+
update({ ...currentCriteria, l: dim.dim }, index);
|
|
1296
|
+
},
|
|
1297
|
+
value: dimensions.dimIndex[currentCriteria.l],
|
|
1298
|
+
onMenuOpen,
|
|
1299
|
+
onMenuClose
|
|
1300
|
+
}
|
|
1301
|
+
)
|
|
1302
|
+
}
|
|
1303
|
+
),
|
|
1304
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1305
|
+
"div",
|
|
1306
|
+
{
|
|
1307
|
+
css: [criteriaWrapper, criteriaOperatorWrapper],
|
|
1308
|
+
className: "criteria-wrapper",
|
|
1309
|
+
"data-test-id": "select-operator",
|
|
1310
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1311
|
+
CriteriaOperatorMenu,
|
|
1312
|
+
{
|
|
1313
|
+
name: `op-${index}`,
|
|
1314
|
+
css: expand,
|
|
1315
|
+
styles: { control: (base) => ({ ...base, height: "100%" }) },
|
|
1316
|
+
value: currentCriteria.op,
|
|
1317
|
+
onChange: (op) => {
|
|
1318
|
+
if (op === "+" || op === "-") {
|
|
1319
|
+
update({ ...currentCriteria, op, r: void 0, rDim: void 0 }, index);
|
|
1320
|
+
} else {
|
|
1321
|
+
update({ ...currentCriteria, op }, index);
|
|
1322
|
+
}
|
|
1323
|
+
},
|
|
1324
|
+
onMenuOpen,
|
|
1325
|
+
onMenuClose
|
|
1326
|
+
}
|
|
1327
|
+
)
|
|
1328
|
+
}
|
|
1329
|
+
),
|
|
1330
|
+
critHasRhs ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1331
|
+
"div",
|
|
1332
|
+
{
|
|
1333
|
+
css: [criteriaWrapper, criteriaOperandWrapper],
|
|
1334
|
+
className: "criteria-wrapper",
|
|
1335
|
+
"data-test-id": "select-match-criteria",
|
|
1336
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1337
|
+
CriteriaMatchMenu,
|
|
1338
|
+
{
|
|
1339
|
+
errorMessage: (_c = errors.rhs) == null ? void 0 : _c[index],
|
|
1340
|
+
css: expand,
|
|
1341
|
+
styles: { control: (base) => ({ ...base, height: "100%" }) },
|
|
1342
|
+
criteriaMatch: currentCriteria,
|
|
1343
|
+
onChange: (match) => {
|
|
1344
|
+
update(match, index);
|
|
1345
|
+
},
|
|
1346
|
+
isDisabled: !critHasLhs,
|
|
1347
|
+
dimensions,
|
|
1348
|
+
onMenuOpen,
|
|
1349
|
+
onMenuClose
|
|
1350
|
+
}
|
|
1351
|
+
)
|
|
1352
|
+
}
|
|
1353
|
+
) : null
|
|
1354
|
+
]
|
|
1355
|
+
}
|
|
1356
|
+
),
|
|
1357
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1358
|
+
"button",
|
|
1359
|
+
{
|
|
1360
|
+
type: "button",
|
|
1361
|
+
onClick: () => removeFromList(index),
|
|
1362
|
+
title: `Delete Personalization`,
|
|
1363
|
+
css: { backgroundColor: "transparent", backgroundImage: "none", borderWidth: 0 },
|
|
1364
|
+
"data-test-id": "button-delete",
|
|
1365
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_design_system9.Icon, { icon: import_cg3.CgCloseO, iconColor: "red", size: "1.5rem" })
|
|
1366
|
+
}
|
|
1367
|
+
),
|
|
1368
|
+
index > 0 ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1369
|
+
"div",
|
|
1370
|
+
{
|
|
1371
|
+
className: "criteria-group-operation",
|
|
1372
|
+
css: {
|
|
1373
|
+
position: "absolute",
|
|
1374
|
+
top: "-4rem",
|
|
1375
|
+
transform: "translateX(calc(1.5rem - 50%))"
|
|
1376
|
+
},
|
|
1377
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1378
|
+
import_design_system9.InputInlineSelect,
|
|
1379
|
+
{
|
|
1380
|
+
"data-test-id": "dropdown-button-combine",
|
|
1381
|
+
disabled: index > 1,
|
|
1382
|
+
value: (_d = currentValue.op) != null ? _d : "&",
|
|
1383
|
+
options: [
|
|
1384
|
+
{ label: "AND", value: "&" },
|
|
1385
|
+
{ label: "OR", value: "|" }
|
|
1386
|
+
],
|
|
1387
|
+
onChange: (v) => {
|
|
1388
|
+
setOp(v.value);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
)
|
|
1392
|
+
}
|
|
1393
|
+
) : null
|
|
1394
|
+
] }, index);
|
|
1395
|
+
}) }),
|
|
1396
|
+
dimensions.dimensions.length === 0 ? (components == null ? void 0 : components.NoDimensionsDefined) ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(components.NoDimensionsDefined, {}) : /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_design_system9.Callout, { title: "Dimensions", type: "info", css: { marginBlock: "var(--spacing-base)" }, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { children: "You do not have any dimensions configured." }) }) : /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
1397
|
+
import_design_system9.AddListButton,
|
|
1398
|
+
{
|
|
1399
|
+
"data-test-id": "button-add-criteria",
|
|
1400
|
+
className: "add-more",
|
|
1401
|
+
buttonText: "Add Criteria",
|
|
1402
|
+
onButtonClick: addToList
|
|
1403
|
+
}
|
|
1404
|
+
)
|
|
1405
|
+
] });
|
|
1406
|
+
};
|
|
1407
|
+
|
|
1408
|
+
// src/components/PersonalizationCriteria/PersonalizationCriteria.tsx
|
|
1409
|
+
var import_jsx_runtime16 = require("@emotion/react/jsx-runtime");
|
|
1410
|
+
function convertErrorsToObj(errors) {
|
|
1411
|
+
const result = { crit: [] };
|
|
1412
|
+
errors.forEach((err) => {
|
|
1413
|
+
var _a;
|
|
1414
|
+
if (!err.path)
|
|
1415
|
+
return;
|
|
1416
|
+
const regexp = /\[(\d+)\]\.(\w+)/g;
|
|
1417
|
+
const matches = (_a = [...err.path.matchAll(regexp)]) == null ? void 0 : _a[0];
|
|
1418
|
+
if ((matches == null ? void 0 : matches.length) == 3) {
|
|
1419
|
+
const index = Number(matches[1]);
|
|
1420
|
+
const prop = matches[2];
|
|
1421
|
+
if (result.crit.length > index) {
|
|
1422
|
+
result.crit[index] = { ...result.crit[index], [prop]: err.message };
|
|
1423
|
+
} else {
|
|
1424
|
+
const variant = {};
|
|
1425
|
+
variant[prop] = err.message;
|
|
1426
|
+
result.crit.push(variant);
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
});
|
|
1430
|
+
return result;
|
|
1431
|
+
}
|
|
1432
|
+
async function validate(value, contextData) {
|
|
1433
|
+
const schema = yup.object().shape(
|
|
1434
|
+
{
|
|
1435
|
+
l: yup.string().required("Please select a dimension").oneOf(
|
|
1436
|
+
contextData == null ? void 0 : contextData.dimensions.map((d) => d.dim),
|
|
1437
|
+
"Select a criteria"
|
|
1438
|
+
),
|
|
1439
|
+
op: yup.string().required(),
|
|
1440
|
+
r: yup.mixed().nullable().when(["rDim", "op"], {
|
|
1441
|
+
is: (rDim, op) => opHasRhs(op) && !rDim,
|
|
1442
|
+
then: yup.string().required("Choose a score or dimension")
|
|
1443
|
+
}),
|
|
1444
|
+
rDim: yup.string().oneOf(
|
|
1445
|
+
contextData == null ? void 0 : contextData.dimensions.map((d) => d.dim),
|
|
1446
|
+
"Select a criteria"
|
|
1447
|
+
).when(["r", "op"], {
|
|
1448
|
+
is: (r, op) => opHasRhs(op) && !r,
|
|
1449
|
+
then: yup.string().required("Choose a score or dimension")
|
|
1450
|
+
})
|
|
1451
|
+
},
|
|
1452
|
+
["rDim", "r"]
|
|
1453
|
+
);
|
|
1454
|
+
try {
|
|
1455
|
+
await yup.object({
|
|
1456
|
+
crit: yup.array(schema)
|
|
1457
|
+
}).nullable().validate(value, { abortEarly: false });
|
|
1458
|
+
} catch (e) {
|
|
1459
|
+
return convertErrorsToObj(e.inner);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
var PersonalizationCriteria = ({
|
|
1463
|
+
contextConfig,
|
|
1464
|
+
value,
|
|
1465
|
+
setValue,
|
|
1466
|
+
...staticProps
|
|
1467
|
+
}) => {
|
|
1468
|
+
var _a, _b;
|
|
1469
|
+
const [validationError, setValidationError] = (0, import_react13.useState)(void 0);
|
|
1470
|
+
const { loading, result: dimensions, error } = useDimensions(contextConfig);
|
|
1471
|
+
(0, import_react_use.useAsync)(async () => {
|
|
1472
|
+
if (value && dimensions) {
|
|
1473
|
+
const err = await validate(value, dimensions);
|
|
1474
|
+
setValidationError(err);
|
|
1475
|
+
}
|
|
1476
|
+
}, [value, dimensions, validate]);
|
|
1477
|
+
if (error)
|
|
1478
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_design_system10.Callout, { type: "danger", children: error });
|
|
1479
|
+
if (loading || dimensions === null)
|
|
1480
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_design_system10.LoadingIndicator, {});
|
|
1481
|
+
const handleSetValue = async (value2) => {
|
|
1482
|
+
const err = await validate(value2, dimensions);
|
|
1483
|
+
setValidationError(err);
|
|
1484
|
+
setValue(value2);
|
|
1485
|
+
};
|
|
1486
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1487
|
+
PersonalizationCriteriaStatic,
|
|
1488
|
+
{
|
|
1489
|
+
...staticProps,
|
|
1490
|
+
value,
|
|
1491
|
+
setValue: handleSetValue,
|
|
1492
|
+
errors: {
|
|
1493
|
+
lhs: (_a = validationError == null ? void 0 : validationError.crit) == null ? void 0 : _a.map((err) => err == null ? void 0 : err.l),
|
|
1494
|
+
rhs: (_b = validationError == null ? void 0 : validationError.crit) == null ? void 0 : _b.map((err) => err == null ? void 0 : err.rDim)
|
|
1495
|
+
},
|
|
1496
|
+
dimensions,
|
|
1497
|
+
components: {
|
|
1498
|
+
NoDimensionsDefined: () => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_design_system10.Callout, { title: "Dimensions", type: "info", css: { marginBlock: "var(--spacing-base)" }, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("p", { children: [
|
|
1499
|
+
"You do not have any dimensions configured. Create your first",
|
|
1500
|
+
" ",
|
|
1501
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
1502
|
+
"a",
|
|
1503
|
+
{
|
|
1504
|
+
href: `${contextConfig.apiHost}/projects/${encodeURIComponent(
|
|
1505
|
+
contextConfig.projectId
|
|
1506
|
+
)}/personalization/signals`,
|
|
1507
|
+
target: "_blank",
|
|
1508
|
+
rel: "noopener noreferrer",
|
|
1509
|
+
css: { ":hover": { textDecorationLine: "underline" } },
|
|
1510
|
+
children: "Dimension"
|
|
1511
|
+
}
|
|
1512
|
+
)
|
|
1513
|
+
] }) })
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
);
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1519
|
+
// src/components/ProjectUIVersion/ProjectUIVersion.tsx
|
|
1520
|
+
var import_design_system11 = require("@uniformdev/design-system");
|
|
1521
|
+
var import_jsx_runtime17 = require("@emotion/react/jsx-runtime");
|
|
1522
|
+
function ProjectUIVersion({ children, versionMap, contextConfig }) {
|
|
1523
|
+
const { loading, result: data } = useContextData(contextConfig);
|
|
1524
|
+
if (loading)
|
|
1525
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_design_system11.LoadingIndicator, {});
|
|
1526
|
+
if (data) {
|
|
1527
|
+
const Component = versionMap[data.project.ui_version];
|
|
1528
|
+
if (Component) {
|
|
1529
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Component, {});
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_jsx_runtime17.Fragment, { children });
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
// src/hooks/useValidateContextConfig.ts
|
|
1536
|
+
var import_react14 = require("react");
|
|
1537
|
+
|
|
1538
|
+
// src/utils/validateContextConfig.ts
|
|
1539
|
+
var import_api3 = require("@uniformdev/context/api");
|
|
1540
|
+
var import_uuid = require("uuid");
|
|
1541
|
+
var validateContextConfig = async (contextConfig) => {
|
|
1542
|
+
if (!contextConfig) {
|
|
1543
|
+
return { valid: false, error: new Error("contextConfig was not defined.") };
|
|
1544
|
+
}
|
|
1545
|
+
if (!contextConfig.apiHost) {
|
|
1546
|
+
return { valid: false, error: new Error("apiHost was not defined.") };
|
|
1547
|
+
}
|
|
1548
|
+
if (!contextConfig.apiKey) {
|
|
1549
|
+
return { valid: false, error: new Error("apiKey was not defined.") };
|
|
1550
|
+
}
|
|
1551
|
+
if (!(0, import_uuid.validate)(contextConfig.apiKey) && !contextConfig.projectId) {
|
|
1552
|
+
return { valid: false, error: new Error("projectId is required when using a modern API key.") };
|
|
1553
|
+
}
|
|
1554
|
+
const client = new import_api3.UncachedManifestClient({
|
|
1555
|
+
projectId: contextConfig.projectId,
|
|
1556
|
+
apiKey: contextConfig.apiKey,
|
|
1557
|
+
apiHost: contextConfig.apiHost
|
|
1558
|
+
});
|
|
1559
|
+
try {
|
|
1560
|
+
const result = await client.get({ preview: true });
|
|
1561
|
+
return {
|
|
1562
|
+
valid: true,
|
|
1563
|
+
result
|
|
1564
|
+
};
|
|
1565
|
+
} catch (e) {
|
|
1566
|
+
return { valid: false, error: e };
|
|
1567
|
+
}
|
|
1568
|
+
};
|
|
1569
|
+
|
|
1570
|
+
// src/hooks/useValidateContextConfig.ts
|
|
1571
|
+
var useValidateContextConfig = (contextConfig) => {
|
|
1572
|
+
const [state, setState] = (0, import_react14.useState)({
|
|
1573
|
+
validating: false,
|
|
1574
|
+
error: void 0
|
|
1575
|
+
});
|
|
1576
|
+
const { apiKey, apiHost, projectId } = contextConfig || {};
|
|
1577
|
+
(0, import_react14.useEffect)(() => {
|
|
1578
|
+
if (!apiKey || !apiHost) {
|
|
1579
|
+
return;
|
|
1580
|
+
}
|
|
1581
|
+
const runEffect = async () => {
|
|
1582
|
+
setState({ validating: true, error: void 0 });
|
|
1583
|
+
const { error, result } = await validateContextConfig({ apiHost, apiKey, projectId });
|
|
1584
|
+
if (error) {
|
|
1585
|
+
setState({ error, validating: false });
|
|
1586
|
+
} else {
|
|
1587
|
+
setState({ error: void 0, validating: false, result });
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
runEffect();
|
|
1591
|
+
}, [apiHost, apiKey, projectId]);
|
|
1592
|
+
return {
|
|
1593
|
+
validating: state.validating,
|
|
1594
|
+
error: state.error,
|
|
1595
|
+
result: state.result
|
|
1596
|
+
};
|
|
1597
|
+
};
|
|
1598
|
+
|
|
1599
|
+
// src/index.ts
|
|
1600
|
+
__reExport(src_exports, require("@uniformdev/design-system"), module.exports);
|
|
1601
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1602
|
+
0 && (module.exports = {
|
|
1603
|
+
ContextData,
|
|
1604
|
+
CriteriaMatchMenu,
|
|
1605
|
+
CriteriaOperatorMenu,
|
|
1606
|
+
DimensionMenu,
|
|
1607
|
+
DimensionValue,
|
|
1608
|
+
EditLink,
|
|
1609
|
+
EnrichmentTag,
|
|
1610
|
+
PersonalizationCriteria,
|
|
1611
|
+
PersonalizationCriteriaStatic,
|
|
1612
|
+
ProjectUIVersion,
|
|
1613
|
+
addEnrichmentLink,
|
|
1614
|
+
contextCriteriaMenuOperators,
|
|
1615
|
+
convertErrorsToObj,
|
|
1616
|
+
isEnrichmentTagData,
|
|
1617
|
+
isPersonalizationCriteriaData,
|
|
1618
|
+
opHasRhs,
|
|
1619
|
+
useContextConfig,
|
|
1620
|
+
useContextData,
|
|
1621
|
+
useDimensions,
|
|
1622
|
+
useDimensionsDataContext,
|
|
1623
|
+
useManifest,
|
|
1624
|
+
useValidateContextConfig,
|
|
1625
|
+
validateContextConfig
|
|
1626
|
+
});
|