@dhis2/analytics 24.10.0 → 25.0.0

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 (86) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/build/cjs/__demo__/CalculationModal.stories.js +448 -0
  3. package/build/cjs/api/analytics/AnalyticsRequest.js +12 -1
  4. package/build/cjs/api/dimensions.js +1 -1
  5. package/build/cjs/api/expression.js +67 -0
  6. package/build/cjs/assets/DimensionItemIcons/CalculationIcon.js +25 -0
  7. package/build/cjs/assets/FormulaIcon.js +40 -0
  8. package/build/cjs/components/DataDimension/Calculation/CalculationModal.js +447 -0
  9. package/build/cjs/components/DataDimension/Calculation/DataElementOption.js +77 -0
  10. package/build/cjs/components/DataDimension/Calculation/DataElementSelector.js +306 -0
  11. package/build/cjs/components/DataDimension/Calculation/DndContext.js +213 -0
  12. package/build/cjs/components/DataDimension/Calculation/DragHandleIcon.js +23 -0
  13. package/build/cjs/components/DataDimension/Calculation/DraggingItem.js +58 -0
  14. package/build/cjs/components/DataDimension/Calculation/DropZone.js +58 -0
  15. package/build/cjs/components/DataDimension/Calculation/FormulaField.js +121 -0
  16. package/build/cjs/components/DataDimension/Calculation/FormulaItem.js +232 -0
  17. package/build/cjs/components/DataDimension/Calculation/MathOperatorSelector.js +57 -0
  18. package/build/cjs/components/DataDimension/Calculation/Operator.js +81 -0
  19. package/build/cjs/components/DataDimension/Calculation/styles/CalculationModal.style.js +13 -0
  20. package/build/cjs/components/DataDimension/Calculation/styles/DataElementOption.style.js +13 -0
  21. package/build/cjs/components/DataDimension/Calculation/styles/DataElementSelector.style.js +13 -0
  22. package/build/cjs/components/DataDimension/Calculation/styles/DraggingItem.style.js +13 -0
  23. package/build/cjs/components/DataDimension/Calculation/styles/DropZone.style.js +13 -0
  24. package/build/cjs/components/DataDimension/Calculation/styles/FormulaField.style.js +13 -0
  25. package/build/cjs/components/DataDimension/Calculation/styles/FormulaItem.style.js +13 -0
  26. package/build/cjs/components/DataDimension/Calculation/styles/MathOperatorSelector.style.js +13 -0
  27. package/build/cjs/components/DataDimension/Calculation/styles/Operator.style.js +13 -0
  28. package/build/cjs/components/DataDimension/DataDimension.js +22 -6
  29. package/build/cjs/components/DataDimension/DataTypeSelector.js +5 -3
  30. package/build/cjs/components/DataDimension/ItemSelector.js +111 -73
  31. package/build/cjs/components/TransferOption.js +13 -4
  32. package/build/cjs/components/styles/DimensionSelector.style.js +2 -2
  33. package/build/cjs/components/styles/TransferOption.style.js +2 -2
  34. package/build/cjs/index.js +6 -0
  35. package/build/cjs/locales/en/translations.json +32 -7
  36. package/build/cjs/modules/__tests__/expressions.spec.js +139 -0
  37. package/build/cjs/modules/__tests__/hash.spec.js +92 -0
  38. package/build/cjs/modules/__tests__/parseExpression.spec.js +46 -0
  39. package/build/cjs/modules/dataTypes.js +8 -1
  40. package/build/cjs/modules/dimensionListItem.js +82 -0
  41. package/build/cjs/modules/expressions.js +164 -0
  42. package/build/cjs/modules/hash.js +28 -0
  43. package/build/cjs/visualizations/config/generators/dhis/singleValue.js +2 -2
  44. package/build/es/__demo__/CalculationModal.stories.js +440 -0
  45. package/build/es/api/analytics/AnalyticsRequest.js +11 -1
  46. package/build/es/api/dimensions.js +1 -1
  47. package/build/es/api/expression.js +57 -0
  48. package/build/es/assets/DimensionItemIcons/CalculationIcon.js +13 -0
  49. package/build/es/assets/FormulaIcon.js +30 -0
  50. package/build/es/components/DataDimension/Calculation/CalculationModal.js +418 -0
  51. package/build/es/components/DataDimension/Calculation/DataElementOption.js +60 -0
  52. package/build/es/components/DataDimension/Calculation/DataElementSelector.js +280 -0
  53. package/build/es/components/DataDimension/Calculation/DndContext.js +194 -0
  54. package/build/es/components/DataDimension/Calculation/DragHandleIcon.js +11 -0
  55. package/build/es/components/DataDimension/Calculation/DraggingItem.js +40 -0
  56. package/build/es/components/DataDimension/Calculation/DropZone.js +43 -0
  57. package/build/es/components/DataDimension/Calculation/FormulaField.js +98 -0
  58. package/build/es/components/DataDimension/Calculation/FormulaItem.js +207 -0
  59. package/build/es/components/DataDimension/Calculation/MathOperatorSelector.js +41 -0
  60. package/build/es/components/DataDimension/Calculation/Operator.js +64 -0
  61. package/build/es/components/DataDimension/Calculation/styles/CalculationModal.style.js +4 -0
  62. package/build/es/components/DataDimension/Calculation/styles/DataElementOption.style.js +4 -0
  63. package/build/es/components/DataDimension/Calculation/styles/DataElementSelector.style.js +4 -0
  64. package/build/es/components/DataDimension/Calculation/styles/DraggingItem.style.js +4 -0
  65. package/build/es/components/DataDimension/Calculation/styles/DropZone.style.js +4 -0
  66. package/build/es/components/DataDimension/Calculation/styles/FormulaField.style.js +4 -0
  67. package/build/es/components/DataDimension/Calculation/styles/FormulaItem.style.js +4 -0
  68. package/build/es/components/DataDimension/Calculation/styles/MathOperatorSelector.style.js +4 -0
  69. package/build/es/components/DataDimension/Calculation/styles/Operator.style.js +4 -0
  70. package/build/es/components/DataDimension/DataDimension.js +21 -6
  71. package/build/es/components/DataDimension/DataTypeSelector.js +6 -4
  72. package/build/es/components/DataDimension/ItemSelector.js +111 -73
  73. package/build/es/components/TransferOption.js +14 -5
  74. package/build/es/components/styles/DimensionSelector.style.js +2 -2
  75. package/build/es/components/styles/TransferOption.style.js +2 -2
  76. package/build/es/index.js +1 -1
  77. package/build/es/locales/en/translations.json +32 -7
  78. package/build/es/modules/__tests__/expressions.spec.js +136 -0
  79. package/build/es/modules/__tests__/hash.spec.js +88 -0
  80. package/build/es/modules/__tests__/parseExpression.spec.js +43 -0
  81. package/build/es/modules/dataTypes.js +6 -0
  82. package/build/es/modules/dimensionListItem.js +61 -0
  83. package/build/es/modules/expressions.js +131 -0
  84. package/build/es/modules/hash.js +12 -0
  85. package/build/es/visualizations/config/generators/dhis/singleValue.js +2 -2
  86. package/package.json +6 -1
@@ -0,0 +1,418 @@
1
+ import _JSXStyle from "styled-jsx/style";
2
+ import { useAlert, useDataMutation, useDataQuery } from '@dhis2/app-runtime';
3
+ import { Button, Modal, ModalTitle, ModalContent, ModalActions, ButtonStrip, InputField } from '@dhis2/ui';
4
+ import cx from 'classnames';
5
+ import PropTypes from 'prop-types';
6
+ import React, { useEffect, useState } from 'react';
7
+ import { createCalculationMutation, deleteCalculationMutation, updateCalculationMutation, validateExpressionMutation } from '../../../api/expression.js';
8
+ import i18n from '../../../locales/index.js';
9
+ import { parseExpressionToArray, parseArrayToExpression, validateExpression, EXPRESSION_TYPE_DATA, EXPRESSION_TYPE_NUMBER, INVALID_EXPRESSION, VALID_EXPRESSION, getItemIdsFromExpression } from '../../../modules/expressions.js';
10
+ import { OfflineTooltip as Tooltip } from '../../OfflineTooltip.js';
11
+ import DataElementSelector from './DataElementSelector.js';
12
+ import DndContext, { OPTIONS_PANEL } from './DndContext.js';
13
+ import FormulaField, { LAST_DROPZONE_ID, FORMULA_BOX_ID } from './FormulaField.js';
14
+ import MathOperatorSelector from './MathOperatorSelector.js';
15
+ import styles from './styles/CalculationModal.style.js';
16
+ const FIRST_POSITION = 0;
17
+ const LAST_POSITION = -1;
18
+
19
+ const CalculationModal = _ref => {
20
+ let {
21
+ calculation,
22
+ onSave,
23
+ onClose,
24
+ onDelete,
25
+ displayNameProp
26
+ } = _ref;
27
+ const {
28
+ show: showError
29
+ } = useAlert(error => error, {
30
+ critical: true
31
+ });
32
+ const mutationParams = {
33
+ onError: error => showError(error)
34
+ };
35
+ const [createCalculation, {
36
+ loading: isCreatingCalculation
37
+ }] = useDataMutation(createCalculationMutation, mutationParams);
38
+ const [updateCalculation, {
39
+ loading: isUpdatingCalculation
40
+ }] = useDataMutation(updateCalculationMutation, mutationParams);
41
+ const [deleteCalculation, {
42
+ loading: isDeletingCalculation
43
+ }] = useDataMutation(deleteCalculationMutation, mutationParams);
44
+ const [doBackendValidation, {
45
+ loading: isValidating
46
+ }] = useDataMutation(validateExpressionMutation, {
47
+ onError: error => showError(error)
48
+ });
49
+ const query = {
50
+ dataElements: {
51
+ resource: 'dataElements',
52
+ params: _ref2 => {
53
+ let {
54
+ ids = []
55
+ } = _ref2;
56
+ return {
57
+ fields: "id,".concat(displayNameProp, "~rename(name)"),
58
+ filter: "id:in:[".concat(ids.join(','), "]"),
59
+ paging: false
60
+ };
61
+ }
62
+ },
63
+ dataElementOperands: {
64
+ resource: 'dataElementOperands',
65
+ params: _ref3 => {
66
+ let {
67
+ ids = []
68
+ } = _ref3;
69
+ return {
70
+ fields: "id,".concat(displayNameProp, "~rename(name)"),
71
+ filter: "id:in:[".concat(ids.join(','), "]"),
72
+ paging: false
73
+ };
74
+ }
75
+ }
76
+ };
77
+ const {
78
+ data,
79
+ refetch
80
+ } = useDataQuery(query, {
81
+ lazy: true
82
+ });
83
+ useEffect(() => {
84
+ const ids = getItemIdsFromExpression(calculation.expression); // only fetch data if there are ids
85
+
86
+ if (ids !== null && ids !== void 0 && ids.length) {
87
+ refetch({
88
+ ids
89
+ });
90
+ } else {
91
+ setExpressionArray(parseExpressionToArray(calculation.expression).map((item, i) => ({ ...item,
92
+ id: "".concat(item.type, "-").concat(-i)
93
+ })));
94
+ }
95
+ }, [refetch, calculation.expression]);
96
+ useEffect(() => {
97
+ if (data) {
98
+ var _data$dataElements, _data$dataElementOper;
99
+
100
+ const metadata = [...(((_data$dataElements = data.dataElements) === null || _data$dataElements === void 0 ? void 0 : _data$dataElements.dataElements) || []), ...(((_data$dataElementOper = data.dataElementOperands) === null || _data$dataElementOper === void 0 ? void 0 : _data$dataElementOper.dataElementOperands) || [])];
101
+ setExpressionArray(parseExpressionToArray(calculation.expression, metadata).map((item, i) => ({ ...item,
102
+ id: "".concat(item.type, "-").concat(-i)
103
+ })));
104
+ }
105
+ }, [data, calculation.expression]);
106
+ const [newIdCount, setNewIdCount] = useState(1);
107
+ const [validationOutput, setValidationOutput] = useState(null);
108
+ const [expressionArray, setExpressionArray] = useState();
109
+ const [name, setName] = useState(calculation.name);
110
+ const [showDeletePrompt, setShowDeletePrompt] = useState(false);
111
+ const [isSavingCalculation, setIsSavingCalculation] = useState();
112
+ const [focusItemId, setFocusItemId] = useState(null);
113
+ const [selectedItemId, setSelectedItemId] = useState(null);
114
+ const expressionStatus = validationOutput === null || validationOutput === void 0 ? void 0 : validationOutput.status;
115
+
116
+ const selectItem = itemId => setSelectedItemId(prevSelected => prevSelected !== itemId ? itemId : null);
117
+
118
+ const isLoading = isCreatingCalculation || isUpdatingCalculation || isDeletingCalculation || isSavingCalculation || isValidating;
119
+
120
+ const addItem = _ref4 => {
121
+ let {
122
+ label,
123
+ value,
124
+ type,
125
+ destIndex = LAST_POSITION
126
+ } = _ref4;
127
+
128
+ if (isLoading) {
129
+ return null;
130
+ }
131
+
132
+ setValidationOutput();
133
+ const newItem = {
134
+ id: "".concat(type, "-").concat(newIdCount),
135
+ value: type === EXPRESSION_TYPE_DATA ? "#{".concat(value, "}") : value,
136
+ label,
137
+ type
138
+ };
139
+ setNewIdCount(newIdCount + 1);
140
+
141
+ if (destIndex === LAST_POSITION) {
142
+ setExpressionArray(prevArray => prevArray.concat([newItem]));
143
+ } else if (destIndex === FIRST_POSITION) {
144
+ setExpressionArray(prevArray => [newItem].concat(prevArray));
145
+ } else {
146
+ const items = Array.from(expressionArray);
147
+ const newFormulaItems = [...items.slice(0, destIndex), newItem, ...items.slice(destIndex)];
148
+ setExpressionArray(newFormulaItems);
149
+ }
150
+
151
+ if (newItem.type === EXPRESSION_TYPE_NUMBER) {
152
+ setFocusItemId(newItem.id);
153
+ }
154
+ };
155
+
156
+ const moveItem = _ref5 => {
157
+ let {
158
+ sourceIndex,
159
+ destIndex
160
+ } = _ref5;
161
+
162
+ if (isLoading) {
163
+ return null;
164
+ }
165
+
166
+ setValidationOutput();
167
+ const sourceList = Array.from(expressionArray);
168
+ const [moved] = sourceList.splice(sourceIndex, 1);
169
+ sourceList.splice(destIndex, 0, moved);
170
+ setExpressionArray(sourceList);
171
+ };
172
+
173
+ const setItemValue = _ref6 => {
174
+ let {
175
+ itemId,
176
+ value
177
+ } = _ref6;
178
+ const updatedItems = expressionArray.map(item => item.id === itemId ? Object.assign({}, item, {
179
+ value
180
+ }) : item);
181
+ setExpressionArray(updatedItems);
182
+ };
183
+
184
+ const removeItem = itemId => {
185
+ if (!isLoading && itemId !== null) {
186
+ setValidationOutput();
187
+ const index = expressionArray.findIndex(item => item.id === itemId);
188
+ const sourceList = Array.from(expressionArray);
189
+ sourceList.splice(index, 1);
190
+ setExpressionArray(sourceList);
191
+ setSelectedItemId(null);
192
+ }
193
+ };
194
+
195
+ const addOrMoveDraggedItem = _ref7 => {
196
+ let {
197
+ item,
198
+ destination
199
+ } = _ref7;
200
+ const destContainerId = destination.containerId;
201
+ let destIndex = FIRST_POSITION;
202
+
203
+ if (item.sourceContainerId === OPTIONS_PANEL) {
204
+ if (destContainerId === LAST_DROPZONE_ID) {
205
+ destIndex = LAST_POSITION;
206
+ } else if (destContainerId === FORMULA_BOX_ID) {
207
+ destIndex = destination.index + 1;
208
+ }
209
+
210
+ addItem({ ...item.data,
211
+ destIndex
212
+ });
213
+ } else {
214
+ if (destContainerId === LAST_DROPZONE_ID) {
215
+ destIndex = expressionArray.length;
216
+ } else if (destContainerId === FORMULA_BOX_ID) {
217
+ destIndex = destination.index;
218
+ }
219
+
220
+ moveItem({
221
+ sourceIndex: item.sourceIndex,
222
+ destIndex
223
+ });
224
+ }
225
+ };
226
+
227
+ const validate = async () => {
228
+ var _result;
229
+
230
+ setValidationOutput();
231
+ const expression = parseArrayToExpression(expressionArray);
232
+ let result = validateExpression(expression);
233
+
234
+ if (!result) {
235
+ result = await doBackendValidation({
236
+ expression
237
+ });
238
+ }
239
+
240
+ setValidationOutput(result);
241
+ return (_result = result) === null || _result === void 0 ? void 0 : _result.status;
242
+ };
243
+
244
+ const onSaveClick = async () => {
245
+ setIsSavingCalculation(true);
246
+ let status = expressionStatus;
247
+
248
+ if (status !== VALID_EXPRESSION) {
249
+ status = await validate();
250
+ }
251
+
252
+ if (status === VALID_EXPRESSION) {
253
+ var _response;
254
+
255
+ let response;
256
+ const expression = parseArrayToExpression(expressionArray);
257
+
258
+ if (calculation.id) {
259
+ response = await updateCalculation({
260
+ id: calculation.id,
261
+ name,
262
+ expression
263
+ });
264
+ } else {
265
+ response = await createCalculation({
266
+ name,
267
+ expression
268
+ });
269
+ }
270
+
271
+ onSave({
272
+ id: calculation.id || ((_response = response) === null || _response === void 0 ? void 0 : _response.response.uid),
273
+ name,
274
+ isNew: !calculation.id,
275
+ expression
276
+ });
277
+ }
278
+
279
+ setIsSavingCalculation(false);
280
+ };
281
+
282
+ const onDeleteClick = async () => {
283
+ setShowDeletePrompt();
284
+ await deleteCalculation({
285
+ id: calculation.id
286
+ });
287
+ onDelete({
288
+ id: calculation.id
289
+ });
290
+ };
291
+
292
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Modal, {
293
+ dataTest: "calculation-modal",
294
+ position: "top",
295
+ large: true
296
+ }, /*#__PURE__*/React.createElement(ModalTitle, {
297
+ dataTest: "calculation-modal-title"
298
+ }, calculation.id ? i18n.t('Data / Edit calculation') : i18n.t('Data / New calculation')), /*#__PURE__*/React.createElement(ModalContent, {
299
+ dataTest: "calculation-modal-content"
300
+ }, /*#__PURE__*/React.createElement(DndContext, {
301
+ onDragStart: () => setFocusItemId(null),
302
+ onDragEnd: addOrMoveDraggedItem
303
+ }, /*#__PURE__*/React.createElement("div", {
304
+ className: "jsx-".concat(styles.__hash) + " " + "content"
305
+ }, /*#__PURE__*/React.createElement("div", {
306
+ className: "jsx-".concat(styles.__hash) + " " + "left-section"
307
+ }, /*#__PURE__*/React.createElement(DataElementSelector, {
308
+ displayNameProp: displayNameProp,
309
+ onDoubleClick: addItem
310
+ }), /*#__PURE__*/React.createElement(MathOperatorSelector, {
311
+ onDoubleClick: addItem
312
+ })), /*#__PURE__*/React.createElement("div", {
313
+ className: "jsx-".concat(styles.__hash) + " " + "right-section"
314
+ }, /*#__PURE__*/React.createElement(FormulaField, {
315
+ items: expressionArray,
316
+ selectedItemId: selectedItemId,
317
+ focusItemId: focusItemId,
318
+ onChange: setItemValue,
319
+ onClick: selectItem,
320
+ onDoubleClick: removeItem,
321
+ loading: !expressionArray,
322
+ disabled: isLoading
323
+ }), /*#__PURE__*/React.createElement("div", {
324
+ className: "jsx-".concat(styles.__hash) + " " + "actions-wrapper"
325
+ }, /*#__PURE__*/React.createElement("div", {
326
+ className: "jsx-".concat(styles.__hash) + " " + "button-container"
327
+ }, /*#__PURE__*/React.createElement("div", {
328
+ className: "jsx-".concat(styles.__hash) + " " + "remove-button"
329
+ }, /*#__PURE__*/React.createElement(Button, {
330
+ small: true,
331
+ secondary: true,
332
+ onClick: () => removeItem(selectedItemId),
333
+ dataTest: "remove-button",
334
+ disabled: !selectedItemId
335
+ }, i18n.t('Remove item'))), /*#__PURE__*/React.createElement("div", {
336
+ className: "jsx-".concat(styles.__hash) + " " + "validate-button"
337
+ }, /*#__PURE__*/React.createElement(Button, {
338
+ small: true,
339
+ secondary: true,
340
+ onClick: validate,
341
+ dataTest: "validate-button",
342
+ loading: isValidating,
343
+ disabled: isLoading
344
+ }, i18n.t('Check formula')))), /*#__PURE__*/React.createElement("span", {
345
+ "data-test": "validation-message",
346
+ className: "jsx-".concat(styles.__hash) + " " + (cx('validation-message', {
347
+ 'validation-error': expressionStatus === INVALID_EXPRESSION,
348
+ 'validation-success': expressionStatus === VALID_EXPRESSION
349
+ }) || "")
350
+ }, validationOutput === null || validationOutput === void 0 ? void 0 : validationOutput.message), /*#__PURE__*/React.createElement("div", {
351
+ className: "jsx-".concat(styles.__hash) + " " + "name-input"
352
+ }, /*#__PURE__*/React.createElement(InputField, {
353
+ label: i18n.t('Calculation name'),
354
+ helpText: i18n.t('Shown in table headers and chart axes/legends'),
355
+ onChange: _ref8 => {
356
+ let {
357
+ value
358
+ } = _ref8;
359
+ return setName(value.substr(0, 50));
360
+ },
361
+ value: name,
362
+ dataTest: "calculation-label",
363
+ dense: true
364
+ }))))))), /*#__PURE__*/React.createElement(ModalActions, {
365
+ dataTest: "calculation-modal-actions"
366
+ }, /*#__PURE__*/React.createElement(ButtonStrip, null, calculation.id && /*#__PURE__*/React.createElement("div", {
367
+ className: "jsx-".concat(styles.__hash) + " " + "delete-button"
368
+ }, /*#__PURE__*/React.createElement(Button, {
369
+ secondary: true,
370
+ onClick: () => setShowDeletePrompt(true),
371
+ dataTest: "delete-button",
372
+ loading: isDeletingCalculation,
373
+ disabled: isUpdatingCalculation
374
+ }, i18n.t('Delete calculation'))), /*#__PURE__*/React.createElement(Button, {
375
+ secondary: true,
376
+ onClick: onClose,
377
+ disabled: isLoading,
378
+ dataTest: "cancel-button"
379
+ }, i18n.t('Cancel')), /*#__PURE__*/React.createElement(Tooltip, {
380
+ content: expressionStatus === INVALID_EXPRESSION ? i18n.t('The calculation can only be saved with a valid formula') : i18n.t('Add a name to save this calculation'),
381
+ disabled: expressionStatus === INVALID_EXPRESSION || !name,
382
+ disabledWhenOffline: false
383
+ }, /*#__PURE__*/React.createElement(Button, {
384
+ primary: true,
385
+ onClick: onSaveClick,
386
+ disabled: expressionStatus === INVALID_EXPRESSION || !name || isDeletingCalculation || isValidating,
387
+ loading: isCreatingCalculation || isUpdatingCalculation || isSavingCalculation,
388
+ dataTest: "save-button"
389
+ }, i18n.t('Save calculation')))))), showDeletePrompt && /*#__PURE__*/React.createElement(Modal, {
390
+ small: true
391
+ }, /*#__PURE__*/React.createElement(ModalTitle, null, i18n.t('Delete calculation')), /*#__PURE__*/React.createElement(ModalContent, null, i18n.t('Are you sure you want to delete this calculation? It may be used by other visualizations.')), /*#__PURE__*/React.createElement(ModalActions, null, /*#__PURE__*/React.createElement(ButtonStrip, {
392
+ end: true
393
+ }, /*#__PURE__*/React.createElement(Button, {
394
+ secondary: true,
395
+ onClick: () => setShowDeletePrompt()
396
+ }, i18n.t('Cancel')), /*#__PURE__*/React.createElement(Button, {
397
+ onClick: onDeleteClick,
398
+ destructive: true
399
+ }, i18n.t('Yes, delete'))))), /*#__PURE__*/React.createElement(_JSXStyle, {
400
+ id: styles.__hash
401
+ }, styles));
402
+ };
403
+
404
+ CalculationModal.propTypes = {
405
+ displayNameProp: PropTypes.string.isRequired,
406
+ onClose: PropTypes.func.isRequired,
407
+ onDelete: PropTypes.func.isRequired,
408
+ onSave: PropTypes.func.isRequired,
409
+ calculation: PropTypes.shape({
410
+ expression: PropTypes.string,
411
+ id: PropTypes.string,
412
+ name: PropTypes.string
413
+ })
414
+ };
415
+ CalculationModal.defaultProps = {
416
+ calculation: {}
417
+ };
418
+ export default CalculationModal;
@@ -0,0 +1,60 @@
1
+ import _JSXStyle from "styled-jsx/style";
2
+
3
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
+
5
+ import { useSortable } from '@dnd-kit/sortable';
6
+ import { CSS } from '@dnd-kit/utilities';
7
+ import PropTypes from 'prop-types';
8
+ import React from 'react';
9
+ import { DIMENSION_TYPE_DATA_ELEMENT } from '../../../modules/dataTypes.js';
10
+ import { getIcon } from '../../../modules/dimensionListItem.js';
11
+ import { EXPRESSION_TYPE_DATA } from '../../../modules/expressions.js';
12
+ import styles from './styles/DataElementOption.style.js';
13
+
14
+ const DataElementOption = _ref => {
15
+ let {
16
+ label,
17
+ value,
18
+ onDoubleClick
19
+ } = _ref;
20
+ const data = {
21
+ label,
22
+ value,
23
+ type: EXPRESSION_TYPE_DATA
24
+ };
25
+ const {
26
+ attributes,
27
+ listeners,
28
+ setNodeRef,
29
+ transform
30
+ } = useSortable({
31
+ id: value,
32
+ data
33
+ });
34
+ const style = {
35
+ transform: CSS.Translate.toString(transform)
36
+ };
37
+ return /*#__PURE__*/React.createElement("div", {
38
+ className: "jsx-".concat(styles.__hash) + " " + "wrapper"
39
+ }, /*#__PURE__*/React.createElement("div", _extends({}, attributes, listeners, {
40
+ ref: setNodeRef,
41
+ style: style,
42
+ className: "jsx-".concat(styles.__hash) + " " + (listeners && listeners.className != null && listeners.className || attributes && attributes.className != null && attributes.className || "draggable-item")
43
+ }), /*#__PURE__*/React.createElement("div", {
44
+ onDoubleClick: () => onDoubleClick(data),
45
+ className: "jsx-".concat(styles.__hash) + " " + "chip"
46
+ }, /*#__PURE__*/React.createElement("span", {
47
+ className: "jsx-".concat(styles.__hash) + " " + "icon"
48
+ }, getIcon(DIMENSION_TYPE_DATA_ELEMENT)), /*#__PURE__*/React.createElement("span", {
49
+ className: "jsx-".concat(styles.__hash) + " " + "label"
50
+ }, label))), /*#__PURE__*/React.createElement(_JSXStyle, {
51
+ id: styles.__hash
52
+ }, styles));
53
+ };
54
+
55
+ DataElementOption.propTypes = {
56
+ label: PropTypes.string,
57
+ value: PropTypes.string,
58
+ onDoubleClick: PropTypes.func
59
+ };
60
+ export default DataElementOption;