@gooddata/sdk-ui-dashboard 10.15.0-alpha.0 → 10.15.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/esm/__version.d.ts +1 -1
  2. package/esm/__version.js +1 -1
  3. package/esm/presentation/alerting/DefaultAlertingDialog/DefaultAlertingDialog.d.ts.map +1 -1
  4. package/esm/presentation/alerting/DefaultAlertingDialog/DefaultAlertingDialog.js +2 -2
  5. package/esm/presentation/alerting/DefaultAlertingDialog/DefaultAlertingDialog.js.map +1 -1
  6. package/esm/presentation/alerting/DefaultAlertingManagementDialog/components/Alert.d.ts.map +1 -1
  7. package/esm/presentation/alerting/DefaultAlertingManagementDialog/components/Alert.js +2 -2
  8. package/esm/presentation/alerting/DefaultAlertingManagementDialog/components/Alert.js.map +1 -1
  9. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/{AlertAttributeSelecxt.d.ts → AlertAttributeSelect.d.ts} +5 -4
  10. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/AlertAttributeSelect.d.ts.map +1 -0
  11. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/AlertAttributeSelect.js +133 -0
  12. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/AlertAttributeSelect.js.map +1 -0
  13. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/AlertMeasureSelect.d.ts.map +1 -1
  14. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/AlertMeasureSelect.js +1 -1
  15. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/AlertMeasureSelect.js.map +1 -1
  16. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/AlertsListItem.d.ts.map +1 -1
  17. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/AlertsListItem.js +3 -3
  18. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/AlertsListItem.js.map +1 -1
  19. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/CreateAlert.d.ts +3 -2
  20. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/CreateAlert.d.ts.map +1 -1
  21. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/CreateAlert.js +2 -2
  22. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/CreateAlert.js.map +1 -1
  23. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/EditAlert.d.ts +3 -2
  24. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/EditAlert.d.ts.map +1 -1
  25. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/EditAlert.js +10 -10
  26. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/EditAlert.js.map +1 -1
  27. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/hooks/useAlertValidation.d.ts.map +1 -1
  28. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/hooks/useAlertValidation.js +2 -1
  29. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/hooks/useAlertValidation.js.map +1 -1
  30. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/hooks/useEditAlert.d.ts +3 -2
  31. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/hooks/useEditAlert.d.ts.map +1 -1
  32. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/hooks/useEditAlert.js +2 -1
  33. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/hooks/useEditAlert.js.map +1 -1
  34. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/hooks/useInsightAlerting.d.ts +3 -2
  35. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/hooks/useInsightAlerting.d.ts.map +1 -1
  36. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/hooks/useInsightAlerting.js +16 -18
  37. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/hooks/useInsightAlerting.js.map +1 -1
  38. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/convertors.d.ts +7 -0
  39. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/convertors.d.ts.map +1 -0
  40. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/convertors.js +43 -0
  41. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/convertors.js.map +1 -0
  42. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/getters.d.ts +90 -0
  43. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/getters.d.ts.map +1 -0
  44. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/getters.js +219 -0
  45. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/getters.js.map +1 -0
  46. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/guards.d.ts +22 -0
  47. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/guards.d.ts.map +1 -0
  48. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/guards.js +41 -0
  49. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/guards.js.map +1 -0
  50. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/items.d.ts +14 -0
  51. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/items.d.ts.map +1 -0
  52. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/items.js +202 -0
  53. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/items.js.map +1 -0
  54. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/transformation.d.ts +60 -0
  55. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/transformation.d.ts.map +1 -0
  56. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/transformation.js +303 -0
  57. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils/transformation.js.map +1 -0
  58. package/esm/presentation/widget/insight/configuration/InsightAlerts.d.ts.map +1 -1
  59. package/esm/presentation/widget/insight/configuration/InsightAlerts.js +3 -3
  60. package/esm/presentation/widget/insight/configuration/InsightAlerts.js.map +1 -1
  61. package/esm/presentation/widget/insight/types.d.ts +1 -0
  62. package/esm/presentation/widget/insight/types.d.ts.map +1 -1
  63. package/package.json +15 -15
  64. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/AlertAttributeSelecxt.d.ts.map +0 -1
  65. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/AlertAttributeSelecxt.js +0 -139
  66. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/AlertAttributeSelecxt.js.map +0 -1
  67. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils.d.ts +0 -46
  68. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils.d.ts.map +0 -1
  69. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils.js +0 -712
  70. package/esm/presentation/widget/insight/configuration/InsightAlertConfig/utils.js.map +0 -1
@@ -1,712 +0,0 @@
1
- // (C) 2024 GoodData Corporation
2
- import { attributeAlias, bucketAttributes, bucketMeasures, insightBucket, insightVisualizationType, isArithmeticMeasure, isAttributeElementsByValue, isLocalIdRef, isNegativeAttributeFilter, isPoPMeasure, isPositiveAttributeFilter, isPreviousPeriodMeasure, isSimpleMeasure, measureAlias, measureIdentifier, measureTitle, } from "@gooddata/sdk-model";
3
- import { BucketNames } from "@gooddata/sdk-ui";
4
- import { AlertMetricComparatorType, } from "../../types.js";
5
- import { COMPARISON_OPERATORS, RELATIVE_OPERATORS, ARITHMETIC_OPERATORS, DEFAULT_MEASURE_FORMAT, } from "./constants.js";
6
- import { messages } from "./messages.js";
7
- /**
8
- * @internal
9
- */
10
- export const getMeasureTitle = (measure) => {
11
- return measure ? measureAlias(measure) ?? measureTitle(measure) : undefined;
12
- };
13
- /**
14
- * @internal
15
- */
16
- export const getAttributeTitle = (attribute) => {
17
- return attribute ? attributeAlias(attribute) : undefined;
18
- };
19
- export const getOperatorTitle = (intl, alert) => {
20
- if (alert?.condition.type === "relative") {
21
- return getRelativeOperatorTitle(alert.condition.operator, alert.condition.measure.operator, intl);
22
- }
23
- if (alert?.condition.type === "comparison") {
24
- return getComparisonOperatorTitle(alert.condition.operator, intl);
25
- }
26
- return "";
27
- };
28
- /**
29
- * @internal
30
- */
31
- const getComparisonOperatorTitle = (operator, intl) => {
32
- const titleByOperator = {
33
- [COMPARISON_OPERATORS.COMPARISON_OPERATOR_LESS_THAN]: messages.comparisonOperatorLessThan.id,
34
- [COMPARISON_OPERATORS.COMPARISON_OPERATOR_LESS_THAN_OR_EQUAL_TO]: messages.comparisonOperatorLessThanOrEquals.id,
35
- [COMPARISON_OPERATORS.COMPARISON_OPERATOR_GREATER_THAN]: messages.comparisonOperatorGreaterThan.id,
36
- [COMPARISON_OPERATORS.COMPARISON_OPERATOR_GREATER_THAN_OR_EQUAL_TO]: messages.comparisonOperatorGreaterThanOrEquals.id,
37
- };
38
- return intl.formatMessage({ id: titleByOperator[operator] });
39
- };
40
- /**
41
- * @internal
42
- */
43
- const getRelativeOperatorTitle = (operator, art, intl) => {
44
- const titleByOperator = {
45
- [`${ARITHMETIC_OPERATORS.ARITHMETIC_OPERATOR_CHANGE}.${RELATIVE_OPERATORS.RELATIVE_OPERATOR_INCREASE_BY}`]: messages.comparisonOperatorChangeIncreasesBy.id,
46
- [`${ARITHMETIC_OPERATORS.ARITHMETIC_OPERATOR_CHANGE}.${RELATIVE_OPERATORS.RELATIVE_OPERATOR_DECREASE_BY}`]: messages.comparisonOperatorChangeDecreasesBy.id,
47
- [`${ARITHMETIC_OPERATORS.ARITHMETIC_OPERATOR_CHANGE}.${RELATIVE_OPERATORS.RELATIVE_OPERATOR_CHANGES_BY}`]: messages.comparisonOperatorChangeChangesBy.id,
48
- [`${ARITHMETIC_OPERATORS.ARITHMETIC_OPERATOR_DIFFERENCE}.${RELATIVE_OPERATORS.RELATIVE_OPERATOR_INCREASE_BY}`]: messages.comparisonOperatorDifferenceIncreasesBy.id,
49
- [`${ARITHMETIC_OPERATORS.ARITHMETIC_OPERATOR_DIFFERENCE}.${RELATIVE_OPERATORS.RELATIVE_OPERATOR_DECREASE_BY}`]: messages.comparisonOperatorDifferenceDecreasesBy.id,
50
- [`${ARITHMETIC_OPERATORS.ARITHMETIC_OPERATOR_DIFFERENCE}.${RELATIVE_OPERATORS.RELATIVE_OPERATOR_CHANGES_BY}`]: messages.comparisonOperatorDifferenceChangesBy.id,
51
- };
52
- return intl.formatMessage({ id: titleByOperator[`${art}.${operator}`] });
53
- };
54
- /**
55
- * @internal
56
- */
57
- export const createDefaultAlert = (filters, metrics, measure, notificationChannelId, currentUser, catalogMeasures = [], comparisonOperator = "GREATER_THAN") => {
58
- const condition = {
59
- type: "comparison",
60
- left: {
61
- id: measure.measure.measure.localIdentifier,
62
- format: getMeasureFormat(measure.measure, catalogMeasures),
63
- title: getMeasureTitle(measure.measure),
64
- },
65
- operator: comparisonOperator,
66
- right: undefined,
67
- };
68
- const execution = {
69
- attributes: [],
70
- measures: [measure.measure],
71
- filters,
72
- };
73
- return {
74
- type: "automation",
75
- title: getMeasureTitle(measure.measure),
76
- notificationChannel: notificationChannelId,
77
- alert: {
78
- condition,
79
- execution: {
80
- ...execution,
81
- ...transformAlertExecutionByMetric(metrics, condition, {
82
- attributes: [],
83
- measures: [measure.measure],
84
- filters,
85
- }, measure),
86
- },
87
- trigger: {
88
- state: "ACTIVE",
89
- },
90
- },
91
- recipients: [currentUser],
92
- };
93
- };
94
- export const getSupportedInsightMeasuresByInsight = (insight) => {
95
- const insightType = insight ? insightVisualizationType(insight) : null;
96
- const { primaries, others } = collectAllMetric(insight);
97
- const simpleMetrics = [
98
- ...primaries.map(transformMeasure(true)).filter(Boolean),
99
- ...others.map(transformMeasure(false)).filter(Boolean),
100
- ];
101
- //NOTE: For now only headline insight support previous period and same period previous year,
102
- // if we want to support other insight types, just add the logic here or remove the condition at
103
- // all to support all insight types
104
- if (insightType === "headline") {
105
- transformPreviousPeriodMeasure(primaries, simpleMetrics, true);
106
- transformPreviousPeriodMeasure(others, simpleMetrics, false);
107
- transformPoPMeasure(primaries, simpleMetrics, true);
108
- transformPoPMeasure(others, simpleMetrics, false);
109
- }
110
- return simpleMetrics;
111
- };
112
- export const getSupportedInsightAttributesByInsight = (insight) => {
113
- const attributes = collectAllAttributes(insight);
114
- return attributes
115
- .map(transformAttribute())
116
- .filter(Boolean);
117
- };
118
- function transformMeasure(isPrimary) {
119
- return (measure) => {
120
- if (isSimpleMeasure(measure) || isArithmeticMeasure(measure)) {
121
- return {
122
- measure,
123
- isPrimary,
124
- comparators: [],
125
- };
126
- }
127
- return undefined;
128
- };
129
- }
130
- function transformAttribute() {
131
- return (attribute) => {
132
- return {
133
- attribute,
134
- };
135
- };
136
- }
137
- function transformPreviousPeriodMeasure(metrics, simpleMetrics, isPrimary) {
138
- const previousPeriodMetrics = metrics.filter((measure) => isPreviousPeriodMeasure(measure));
139
- previousPeriodMetrics.forEach((measure) => {
140
- const found = simpleMetrics.find((simpleMetric) => simpleMetric.measure.measure.localIdentifier ===
141
- measure.measure.definition.previousPeriodMeasure.measureIdentifier);
142
- if (found) {
143
- found.comparators.push({
144
- measure,
145
- isPrimary,
146
- comparator: AlertMetricComparatorType.PreviousPeriod,
147
- });
148
- }
149
- });
150
- }
151
- function transformPoPMeasure(metrics, simpleMetrics, isPrimary) {
152
- const popMetrics = metrics.filter((measure) => isPoPMeasure(measure));
153
- popMetrics.forEach((measure) => {
154
- const found = simpleMetrics.find((simpleMetric) => simpleMetric.measure.measure.localIdentifier ===
155
- measure.measure.definition.popMeasureDefinition.measureIdentifier);
156
- if (found) {
157
- found.comparators.push({
158
- measure,
159
- isPrimary,
160
- comparator: AlertMetricComparatorType.SamePeriodPreviousYear,
161
- });
162
- }
163
- });
164
- }
165
- function collectAllMetric(insight) {
166
- const insightType = insight ? insightVisualizationType(insight) : null;
167
- if (!insight) {
168
- return {
169
- primaries: [],
170
- others: [],
171
- };
172
- }
173
- switch (insightType) {
174
- case "headline":
175
- case "bar":
176
- case "column":
177
- case "line":
178
- case "area":
179
- case "combo2":
180
- case "scatter":
181
- case "bubble":
182
- case "bullet":
183
- case "pie":
184
- case "donut":
185
- case "treemap":
186
- case "funnel":
187
- case "pyramid":
188
- case "heatmap":
189
- case "waterfall":
190
- case "dependencywheel":
191
- case "sankey":
192
- case "table": {
193
- return collectAllMetricsDefault(insight);
194
- }
195
- case "pushpin": {
196
- return collectAllMetricsPushpin(insight);
197
- }
198
- case "repeater": {
199
- return collectAllMetricsRepeater(insight);
200
- }
201
- default: {
202
- return {
203
- primaries: [],
204
- others: [],
205
- };
206
- }
207
- }
208
- }
209
- function collectAllMetricsDefault(insight) {
210
- const insightMeasuresBucket = insight
211
- ? insightBucket(insight, BucketNames.MEASURES)
212
- : undefined;
213
- const insightSecondaryMeasuresBucket = insight
214
- ? insightBucket(insight, BucketNames.SECONDARY_MEASURES)
215
- : undefined;
216
- const insightTertiaryMeasuresBucket = insight
217
- ? insightBucket(insight, BucketNames.TERTIARY_MEASURES)
218
- : undefined;
219
- return {
220
- primaries: insightMeasuresBucket ? bucketMeasures(insightMeasuresBucket) : [],
221
- others: [
222
- ...(insightSecondaryMeasuresBucket ? bucketMeasures(insightSecondaryMeasuresBucket) : []),
223
- ...(insightTertiaryMeasuresBucket ? bucketMeasures(insightTertiaryMeasuresBucket) : []),
224
- ],
225
- };
226
- }
227
- function collectAllMetricsPushpin(insight) {
228
- const insightSizeBucket = insight
229
- ? insightBucket(insight, BucketNames.SIZE)
230
- : undefined;
231
- const insightColorBucket = insight
232
- ? insightBucket(insight, BucketNames.COLOR)
233
- : undefined;
234
- return {
235
- primaries: [
236
- ...(insightSizeBucket ? bucketMeasures(insightSizeBucket) : []),
237
- ...(insightColorBucket ? bucketMeasures(insightColorBucket) : []),
238
- ],
239
- others: [],
240
- };
241
- }
242
- function collectAllMetricsRepeater(insight) {
243
- const insightColumnsBucket = insight
244
- ? insightBucket(insight, BucketNames.COLUMNS)
245
- : undefined;
246
- return {
247
- primaries: insightColumnsBucket ? bucketMeasures(insightColumnsBucket) : [],
248
- others: [],
249
- };
250
- }
251
- function collectAllAttributes(insight) {
252
- const insightType = insight ? insightVisualizationType(insight) : null;
253
- if (!insight) {
254
- return [];
255
- }
256
- switch (insightType) {
257
- case "headline":
258
- case "bar":
259
- case "column":
260
- case "line":
261
- case "area":
262
- case "combo2":
263
- case "scatter":
264
- case "bubble":
265
- case "bullet":
266
- case "pie":
267
- case "donut":
268
- case "treemap":
269
- case "funnel":
270
- case "pyramid":
271
- case "heatmap":
272
- case "waterfall":
273
- case "dependencywheel":
274
- case "sankey":
275
- case "pushpin":
276
- case "repeater":
277
- case "table": {
278
- return collectAllAttributesDefault(insight);
279
- }
280
- default: {
281
- return [];
282
- }
283
- }
284
- }
285
- function collectAllAttributesDefault(insight) {
286
- const insightAttributeBucket = insight
287
- ? insightBucket(insight, BucketNames.ATTRIBUTE)
288
- : undefined;
289
- const insightAttributesBucket = insight
290
- ? insightBucket(insight, BucketNames.ATTRIBUTES)
291
- : undefined;
292
- const insightTrendBucket = insight
293
- ? insightBucket(insight, BucketNames.TREND)
294
- : undefined;
295
- const insightSegmentBucket = insight
296
- ? insightBucket(insight, BucketNames.SEGMENT)
297
- : undefined;
298
- const insightColumnsBucket = insight
299
- ? insightBucket(insight, BucketNames.COLUMNS)
300
- : undefined;
301
- const insightViewBucket = insight
302
- ? insightBucket(insight, BucketNames.VIEW)
303
- : undefined;
304
- const insightStackBucket = insight
305
- ? insightBucket(insight, BucketNames.STACK)
306
- : undefined;
307
- const insightAttributeFromBucket = insight
308
- ? insightBucket(insight, BucketNames.ATTRIBUTE_FROM)
309
- : undefined;
310
- const insightAttributeToBucket = insight
311
- ? insightBucket(insight, BucketNames.ATTRIBUTE_TO)
312
- : undefined;
313
- return [
314
- ...(insightAttributeBucket ? bucketAttributes(insightAttributeBucket) : []),
315
- ...(insightAttributesBucket ? bucketAttributes(insightAttributesBucket) : []),
316
- ...(insightTrendBucket ? bucketAttributes(insightTrendBucket) : []),
317
- ...(insightSegmentBucket ? bucketAttributes(insightSegmentBucket) : []),
318
- ...(insightColumnsBucket ? bucketAttributes(insightColumnsBucket) : []),
319
- ...(insightViewBucket ? bucketAttributes(insightViewBucket) : []),
320
- ...(insightStackBucket ? bucketAttributes(insightStackBucket) : []),
321
- ...(insightAttributeFromBucket ? bucketAttributes(insightAttributeFromBucket) : []),
322
- ...(insightAttributeToBucket ? bucketAttributes(insightAttributeToBucket) : []),
323
- ];
324
- }
325
- export function getValueSuffix(alert) {
326
- if (isChangeOperator(alert)) {
327
- return "%";
328
- }
329
- if (isDifferenceOperator(alert)) {
330
- return undefined;
331
- }
332
- return undefined;
333
- }
334
- export function isChangeOperator(alert) {
335
- if (alert?.condition?.type === "relative") {
336
- return alert.condition.measure.operator === ARITHMETIC_OPERATORS.ARITHMETIC_OPERATOR_CHANGE;
337
- }
338
- return false;
339
- }
340
- export function isDifferenceOperator(alert) {
341
- if (alert?.condition?.type === "relative") {
342
- return alert.condition.measure.operator === ARITHMETIC_OPERATORS.ARITHMETIC_OPERATOR_DIFFERENCE;
343
- }
344
- return false;
345
- }
346
- export function isChangeOrDifferenceOperator(alert) {
347
- return isChangeOperator(alert) || isDifferenceOperator(alert);
348
- }
349
- export function isAlertValueDefined(alert) {
350
- if (alert?.condition?.type === "relative") {
351
- return typeof alert.condition.threshold !== "undefined";
352
- }
353
- return typeof alert?.condition?.right !== "undefined";
354
- }
355
- export function isAlertRecipientsValid(alert) {
356
- return !!alert?.recipients?.length;
357
- }
358
- export function getAlertThreshold(alert) {
359
- if (alert?.condition?.type === "relative") {
360
- return alert.condition.threshold;
361
- }
362
- return alert?.condition?.right;
363
- }
364
- export function getAlertMeasure(measures, alert) {
365
- const condition = alert?.condition;
366
- if (condition?.type === "relative") {
367
- return (measures.find((m) => m.measure.measure.localIdentifier === condition.measure.left.id) ??
368
- measures.find((m) => m.measure.measure.localIdentifier === condition.measure.right.id));
369
- }
370
- return measures.find((m) => m.measure.measure.localIdentifier === condition?.left.id);
371
- }
372
- export function getAlertAttribute(attributes, alert) {
373
- const attr = alert?.alert?.execution.attributes[0];
374
- if (attr?.attribute) {
375
- const { attribute, filterValue } = getAttributeRelatedFilterInfo(attributes, alert, attr);
376
- return [attribute, filterValue];
377
- }
378
- return [undefined, undefined];
379
- }
380
- export function getAlertFilters(alert) {
381
- const filters = alert?.alert?.execution?.filters ?? [];
382
- const attrs = (alert?.alert?.execution.attributes ?? []).map((a) => a.attribute.localIdentifier);
383
- return filters.filter((f) => {
384
- if (isPositiveAttributeFilter(f) && isLocalIdRef(f.positiveAttributeFilter.displayForm)) {
385
- return !attrs.includes(f.positiveAttributeFilter.displayForm.localIdentifier);
386
- }
387
- if (isNegativeAttributeFilter(f) && isLocalIdRef(f.negativeAttributeFilter.displayForm)) {
388
- return !attrs.includes(f.negativeAttributeFilter.displayForm.localIdentifier);
389
- }
390
- return true;
391
- });
392
- }
393
- export function getAlertCompareOperator(alert) {
394
- if (alert?.condition.type === "comparison") {
395
- return alert.condition.operator;
396
- }
397
- return undefined;
398
- }
399
- export function getAlertRelativeOperator(alert) {
400
- if (alert?.condition.type === "relative") {
401
- return [alert.condition.operator, alert.condition.measure.operator];
402
- }
403
- return undefined;
404
- }
405
- //alerts transformations
406
- export function transformAlertByMetric(metrics, alert, measure, catalogMeasures) {
407
- const periodMeasure = measure.comparators.find((c) => c.comparator === AlertMetricComparatorType.PreviousPeriod ||
408
- c.comparator === AlertMetricComparatorType.SamePeriodPreviousYear);
409
- if (alert.alert?.condition.type === "relative" && periodMeasure) {
410
- const cond = transformToRelativeCondition(alert.alert.condition);
411
- const condition = {
412
- ...cond,
413
- measure: {
414
- ...cond.measure,
415
- ...transformRelativeCondition(measure, periodMeasure, catalogMeasures),
416
- },
417
- };
418
- return {
419
- ...alert,
420
- title: getMeasureTitle(measure.measure) ?? "",
421
- alert: {
422
- ...alert.alert,
423
- condition,
424
- execution: transformAlertExecutionByMetric(metrics, condition, alert.alert.execution, measure),
425
- },
426
- };
427
- }
428
- const cond = transformToComparisonCondition(alert.alert.condition);
429
- const condition = {
430
- ...cond,
431
- left: {
432
- id: measure.measure.measure.localIdentifier,
433
- format: getMeasureFormat(measure.measure, catalogMeasures),
434
- title: getMeasureTitle(measure.measure),
435
- },
436
- };
437
- return {
438
- ...alert,
439
- title: getMeasureTitle(measure.measure) ?? "",
440
- alert: {
441
- ...alert.alert,
442
- condition,
443
- execution: transformAlertExecutionByMetric(metrics, condition, alert.alert.execution, measure),
444
- },
445
- };
446
- }
447
- /**
448
- * This function get selected attributed and optionally value amd added this attribute to execution.
449
- * If value is provided, it creates positive attribute filter with this value, otherwise it creates negative attribute filter
450
- * that is empty for now.
451
- * @param attributes - all available attributes
452
- * @param alert - alert to transform
453
- * @param attr - optionally selected attribute
454
- * @param value - optionally selected value
455
- */
456
- export function transformAlertByAttribute(attributes, alert, attr, value) {
457
- const { filterDefinition } = getAttributeRelatedFilterInfo(attributes, alert, alert.alert?.execution.attributes[0]);
458
- const originalFilters = alert.alert?.execution.filters.filter((f) => f !== filterDefinition) ?? [];
459
- const customFilters = [];
460
- if (attr) {
461
- if (value !== undefined) {
462
- customFilters.push({
463
- positiveAttributeFilter: {
464
- displayForm: {
465
- localIdentifier: attr.attribute.attribute.localIdentifier,
466
- },
467
- in: {
468
- values: [value],
469
- },
470
- },
471
- });
472
- }
473
- else {
474
- customFilters.push({
475
- negativeAttributeFilter: {
476
- displayForm: {
477
- localIdentifier: attr.attribute.attribute.localIdentifier,
478
- },
479
- notIn: {
480
- values: [],
481
- },
482
- },
483
- });
484
- }
485
- }
486
- return {
487
- ...alert,
488
- alert: {
489
- ...alert.alert,
490
- execution: {
491
- ...alert.alert.execution,
492
- attributes: attr ? [attr.attribute] : [],
493
- filters: [...originalFilters, ...customFilters],
494
- },
495
- },
496
- };
497
- }
498
- export function transformAlertByComparisonOperator(metrics, alert, measure, comparisonOperator) {
499
- const cond = transformToComparisonCondition(alert.alert.condition);
500
- const condition = {
501
- ...cond,
502
- operator: comparisonOperator,
503
- };
504
- return {
505
- ...alert,
506
- alert: {
507
- ...alert.alert,
508
- condition,
509
- execution: transformAlertExecutionByMetric(metrics, condition, alert.alert.execution, measure),
510
- },
511
- };
512
- }
513
- export function transformAlertByRelativeOperator(metrics, alert, measure, relativeOperator, arithmeticOperator, catalogMeasures) {
514
- const periodMeasure = measure.comparators.find((c) => c.comparator === AlertMetricComparatorType.PreviousPeriod ||
515
- c.comparator === AlertMetricComparatorType.SamePeriodPreviousYear);
516
- const cond = transformToRelativeCondition(alert.alert.condition);
517
- const condition = {
518
- ...cond,
519
- measure: {
520
- ...cond.measure,
521
- operator: arithmeticOperator,
522
- ...transformRelativeCondition(measure, periodMeasure, catalogMeasures),
523
- },
524
- operator: relativeOperator,
525
- };
526
- return {
527
- ...alert,
528
- alert: {
529
- ...alert.alert,
530
- condition,
531
- execution: transformAlertExecutionByMetric(metrics, condition, alert.alert.execution, measure),
532
- },
533
- };
534
- }
535
- export function transformAlertByValue(alert, value) {
536
- if (alert.alert?.condition.type === "relative") {
537
- return {
538
- ...alert,
539
- alert: {
540
- ...alert.alert,
541
- condition: {
542
- ...alert.alert.condition,
543
- threshold: value,
544
- },
545
- },
546
- };
547
- }
548
- return {
549
- ...alert,
550
- alert: {
551
- ...alert.alert,
552
- condition: {
553
- ...alert.alert.condition,
554
- right: value,
555
- },
556
- },
557
- };
558
- }
559
- export function transformAlertByDestination(alert, notificationChannel, recipients) {
560
- return {
561
- ...alert,
562
- ...(recipients ? { recipients } : {}),
563
- notificationChannel,
564
- };
565
- }
566
- //alerts transformations utils
567
- function transformToComparisonCondition(condition) {
568
- if (condition.type === "relative") {
569
- return {
570
- type: "comparison",
571
- operator: COMPARISON_OPERATORS.COMPARISON_OPERATOR_GREATER_THAN,
572
- left: condition.measure.left,
573
- right: condition.threshold,
574
- };
575
- }
576
- return {
577
- type: "comparison",
578
- operator: condition.operator,
579
- right: condition.right,
580
- left: condition.left,
581
- };
582
- }
583
- function transformToRelativeCondition(condition) {
584
- if (condition.type === "comparison") {
585
- return {
586
- type: "relative",
587
- operator: RELATIVE_OPERATORS.RELATIVE_OPERATOR_INCREASE_BY,
588
- measure: {
589
- operator: ARITHMETIC_OPERATORS.ARITHMETIC_OPERATOR_CHANGE,
590
- left: condition.left,
591
- right: undefined,
592
- },
593
- threshold: condition.right,
594
- };
595
- }
596
- return {
597
- type: "relative",
598
- operator: condition.operator,
599
- measure: condition.measure,
600
- threshold: condition.threshold,
601
- };
602
- }
603
- function transformAlertExecutionByMetric(metrics, condition, execution, measure) {
604
- const periodMeasure = measure.comparators.find((c) => c.comparator === AlertMetricComparatorType.PreviousPeriod ||
605
- c.comparator === AlertMetricComparatorType.SamePeriodPreviousYear);
606
- if (condition.type === "relative" && periodMeasure) {
607
- return {
608
- ...execution,
609
- measures: [measure.measure, periodMeasure.measure],
610
- auxMeasures: [
611
- ...collectAllRelatedMeasures(metrics, measure.measure),
612
- ...collectAllRelatedMeasures(metrics, periodMeasure.measure),
613
- ],
614
- };
615
- }
616
- return {
617
- ...execution,
618
- measures: [measure.measure],
619
- auxMeasures: collectAllRelatedMeasures(metrics, measure.measure),
620
- };
621
- }
622
- function collectAllRelatedMeasures(metrics, measure) {
623
- if (isArithmeticMeasure(measure)) {
624
- const included = measure.measure.definition.arithmeticMeasure.measureIdentifiers;
625
- const related = metrics.filter((m) => {
626
- return included.includes(m.measure.measure.localIdentifier);
627
- });
628
- return related.map((m) => m.measure);
629
- }
630
- return [];
631
- }
632
- function transformRelativeCondition(measure, periodMeasure, catalogMeasures) {
633
- return {
634
- ...(periodMeasure?.isPrimary && {
635
- left: {
636
- id: periodMeasure.measure.measure.localIdentifier,
637
- format: getMeasureFormat(periodMeasure.measure, catalogMeasures),
638
- title: getMeasureTitle(periodMeasure.measure),
639
- },
640
- right: {
641
- id: measure.measure.measure.localIdentifier,
642
- format: getMeasureFormat(measure.measure, catalogMeasures),
643
- title: getMeasureTitle(measure.measure),
644
- },
645
- }),
646
- ...(!periodMeasure?.isPrimary && {
647
- left: {
648
- id: measure.measure.measure.localIdentifier,
649
- format: getMeasureFormat(measure.measure, catalogMeasures),
650
- title: getMeasureTitle(measure.measure),
651
- },
652
- right: {
653
- id: periodMeasure?.measure.measure.localIdentifier,
654
- format: getMeasureFormat(periodMeasure?.measure, catalogMeasures),
655
- title: periodMeasure?.measure ? getMeasureTitle(periodMeasure?.measure) : undefined,
656
- },
657
- }),
658
- };
659
- }
660
- const getMeasureFormat = (measure, catalogMeasures) => {
661
- if (!measure) {
662
- return DEFAULT_MEASURE_FORMAT;
663
- }
664
- // custom format set in the bucket
665
- if (measure?.measure.format) {
666
- return measure.measure.format;
667
- }
668
- // measure format from the catalog
669
- const catalogMeasure = findMeasureInCatalog(measure, catalogMeasures);
670
- return catalogMeasure?.measure.format ?? DEFAULT_MEASURE_FORMAT;
671
- };
672
- const findMeasureInCatalog = (measure, catalogMeasures) => {
673
- return catalogMeasures?.find((m) => m.measure.id === measureIdentifier(measure));
674
- };
675
- function getAttributeRelatedFilterInfo(attributes, alert, attr) {
676
- const attribute = attributes.find((a) => a.attribute.attribute.localIdentifier === attr?.attribute.localIdentifier);
677
- return {
678
- attribute,
679
- ...getAttributeRelatedFilter(attribute, alert),
680
- };
681
- }
682
- function getAttributeRelatedFilter(attr, alert) {
683
- const filter = alert?.alert?.execution.filters.filter((f) => {
684
- if (isPositiveAttributeFilter(f) && isLocalIdRef(f.positiveAttributeFilter.displayForm)) {
685
- return (f.positiveAttributeFilter.displayForm.localIdentifier ===
686
- attr?.attribute.attribute.localIdentifier);
687
- }
688
- if (isNegativeAttributeFilter(f) && isLocalIdRef(f.negativeAttributeFilter.displayForm)) {
689
- return (f.negativeAttributeFilter.displayForm.localIdentifier ===
690
- attr?.attribute.attribute.localIdentifier);
691
- }
692
- return false;
693
- })[0];
694
- if (isPositiveAttributeFilter(filter) && isAttributeElementsByValue(filter.positiveAttributeFilter.in)) {
695
- return {
696
- filterDefinition: filter,
697
- filterValue: filter.positiveAttributeFilter.in.values[0],
698
- };
699
- }
700
- if (isNegativeAttributeFilter(filter) &&
701
- isAttributeElementsByValue(filter.negativeAttributeFilter.notIn)) {
702
- return {
703
- filterDefinition: filter,
704
- filterValue: undefined,
705
- };
706
- }
707
- return {
708
- filterDefinition: undefined,
709
- filterValue: undefined,
710
- };
711
- }
712
- //# sourceMappingURL=utils.js.map