@adaptabletools/adaptable 11.0.0-canary.6 → 11.0.1

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 (164) hide show
  1. package/README.md +4 -4
  2. package/agGrid.d.ts +5 -4
  3. package/agGrid.js +7 -5
  4. package/base.css +3 -4
  5. package/bundle.cjs.js +120 -115
  6. package/index.css +3 -4
  7. package/package.json +1 -1
  8. package/publishTimestamp.d.ts +1 -1
  9. package/publishTimestamp.js +1 -1
  10. package/src/AdaptableInterfaces/IAdaptable.d.ts +3 -1
  11. package/src/AdaptableOptions/AdaptableOptions.d.ts +3 -5
  12. package/src/AdaptableOptions/{QueryLanguageOptions.d.ts → AdaptableQLOptions.d.ts} +34 -2
  13. package/src/AdaptableOptions/{QueryLanguageOptions.js → AdaptableQLOptions.js} +0 -0
  14. package/src/AdaptableOptions/FilterOptions.d.ts +4 -0
  15. package/src/AdaptableOptions/GeneralOptions.d.ts +0 -7
  16. package/src/AdaptableOptions/SearchOptions.d.ts +0 -9
  17. package/src/AdaptableOptions/SettingsPanelOptions.d.ts +7 -6
  18. package/src/AdaptableOptions/StateOptions.d.ts +7 -7
  19. package/src/AdaptableOptions/ToolPanelOptions.d.ts +2 -2
  20. package/src/Api/CalculatedColumnApi.d.ts +2 -9
  21. package/src/Api/GridApi.d.ts +12 -3
  22. package/src/Api/Implementation/AlertApiImpl.js +1 -2
  23. package/src/Api/Implementation/ApiBase.d.ts +3 -2
  24. package/src/Api/Implementation/ApiBase.js +5 -2
  25. package/src/Api/Implementation/CalculatedColumnApiImpl.js +3 -4
  26. package/src/Api/Implementation/ColumnApiImpl.js +1 -1
  27. package/src/Api/Implementation/GridApiImpl.d.ts +2 -0
  28. package/src/Api/Implementation/GridApiImpl.js +41 -21
  29. package/src/Api/Implementation/InternalApiImpl.d.ts +2 -3
  30. package/src/Api/Implementation/InternalApiImpl.js +5 -4
  31. package/src/Api/Implementation/QueryLanguageApiImpl.d.ts +3 -0
  32. package/src/Api/Implementation/QueryLanguageApiImpl.js +15 -2
  33. package/src/Api/Implementation/SettingsPanelApiImpl.js +1 -1
  34. package/src/Api/Implementation/ToolPanelApiImpl.js +1 -1
  35. package/src/Api/InternalApi.d.ts +2 -3
  36. package/src/Api/QueryApi.d.ts +2 -2
  37. package/src/Api/QueryLanguageApi.d.ts +13 -0
  38. package/src/Api/SettingsPanelApi.d.ts +4 -5
  39. package/src/PredefinedConfig/AlertState.d.ts +5 -1
  40. package/src/PredefinedConfig/CalculatedColumnState.d.ts +8 -3
  41. package/src/PredefinedConfig/Common/AdaptableColumn.d.ts +1 -1
  42. package/src/PredefinedConfig/Common/AdaptableFormat.d.ts +3 -0
  43. package/src/PredefinedConfig/Common/AdaptableQuery.d.ts +0 -1
  44. package/src/PredefinedConfig/Common/AdaptableQuery.js +1 -5
  45. package/src/PredefinedConfig/Common/SpecialColumnSettings.d.ts +1 -1
  46. package/src/PredefinedConfig/Common/Types.d.ts +6 -1
  47. package/src/PredefinedConfig/Common/Types.js +1 -0
  48. package/src/PredefinedConfig/ConditionalStyleState.d.ts +2 -2
  49. package/src/PredefinedConfig/FormatColumnState.d.ts +15 -0
  50. package/src/PredefinedConfig/PlusMinusState.d.ts +1 -1
  51. package/src/PredefinedConfig/Selection/GridCellRange.d.ts +3 -1
  52. package/src/PredefinedConfig/ToolPanelState.d.ts +3 -0
  53. package/src/Redux/ActionsReducers/AlertRedux.d.ts +1 -1
  54. package/src/Redux/ActionsReducers/AlertRedux.js +4 -4
  55. package/src/Redux/ActionsReducers/ConditionalStyleRedux.d.ts +1 -1
  56. package/src/Redux/ActionsReducers/ConditionalStyleRedux.js +4 -4
  57. package/src/Redux/ActionsReducers/CustomSortRedux.d.ts +1 -1
  58. package/src/Redux/ActionsReducers/CustomSortRedux.js +4 -4
  59. package/src/Redux/ActionsReducers/FlashingCellRedux.d.ts +12 -12
  60. package/src/Redux/ActionsReducers/FlashingCellRedux.js +33 -29
  61. package/src/Redux/ActionsReducers/FormatColumnRedux.d.ts +1 -1
  62. package/src/Redux/ActionsReducers/FormatColumnRedux.js +4 -4
  63. package/src/Redux/ActionsReducers/PlusMinusRedux.d.ts +1 -1
  64. package/src/Redux/ActionsReducers/PlusMinusRedux.js +4 -4
  65. package/src/Redux/ActionsReducers/ScheduleRedux.d.ts +5 -5
  66. package/src/Redux/ActionsReducers/ScheduleRedux.js +16 -16
  67. package/src/Redux/ActionsReducers/ShortcutRedux.d.ts +1 -1
  68. package/src/Redux/ActionsReducers/ShortcutRedux.js +4 -4
  69. package/src/Redux/ActionsReducers/SystemRedux.js +1 -1
  70. package/src/Redux/Store/AdaptableReduxMerger.js +1 -1
  71. package/src/Redux/Store/AdaptableStore.js +47 -22
  72. package/src/Strategy/AlertModule.js +4 -4
  73. package/src/Strategy/CalculatedColumnModule.js +4 -4
  74. package/src/Strategy/ChartingModule.d.ts +3 -3
  75. package/src/Strategy/ChartingModule.js +2 -2
  76. package/src/Strategy/FlashingCellModule.js +4 -4
  77. package/src/Strategy/FreeTextColumnModule.js +1 -0
  78. package/src/Strategy/{SetingsPanelModule.d.ts → SettingsPanelModule.d.ts} +0 -0
  79. package/src/Strategy/{SetingsPanelModule.js → SettingsPanelModule.js} +0 -0
  80. package/src/Strategy/Utilities/getAlertPreviewViewItems.js +1 -1
  81. package/src/Strategy/Utilities/getExpressionViewItems.d.ts +2 -2
  82. package/src/Strategy/Utilities/getExpressionViewItems.js +2 -1
  83. package/src/Strategy/Utilities/getRuleViewItems.js +1 -2
  84. package/src/Utilities/Constants/DocumentationLinkConstants.d.ts +3 -2
  85. package/src/Utilities/Constants/DocumentationLinkConstants.js +12 -10
  86. package/src/Utilities/Defaults/DefaultAdaptableOptions.js +18 -13
  87. package/src/Utilities/ExpressionFunctions/aggregatedBooleanExpressionFunctions.js +1 -1
  88. package/src/Utilities/ExpressionFunctions/aggregatedScalarExpressionFunctions.d.ts +18 -1
  89. package/src/Utilities/ExpressionFunctions/aggregatedScalarExpressionFunctions.js +311 -14
  90. package/src/Utilities/ExpressionFunctions/expressionFunctionUtils.d.ts +2 -2
  91. package/src/Utilities/ExpressionFunctions/expressionFunctionUtils.js +8 -8
  92. package/src/Utilities/ExpressionFunctions/groupingMap.d.ts +2 -3
  93. package/src/Utilities/ExpressionFunctions/groupingMap.js +3 -2
  94. package/src/Utilities/ExpressionFunctions/observableExpressionFunctions.js +3 -2
  95. package/src/Utilities/ExpressionFunctions/scalarAggregationHelper.d.ts +33 -0
  96. package/src/Utilities/ExpressionFunctions/scalarAggregationHelper.js +154 -0
  97. package/src/Utilities/Helpers/AdaptableHelper.js +2 -1
  98. package/src/Utilities/Services/AlertService.js +5 -1
  99. package/src/Utilities/Services/CalculatedColumnExpressionService.d.ts +7 -3
  100. package/src/Utilities/Services/CalculatedColumnExpressionService.js +143 -18
  101. package/src/Utilities/Services/Interface/IAdaptableService.d.ts +1 -1
  102. package/src/Utilities/Services/Interface/ICalculatedColumnExpressionService.d.ts +6 -3
  103. package/src/Utilities/Services/Interface/IQueryLanguageService.d.ts +7 -1
  104. package/src/Utilities/Services/LicenseService.js +1 -1
  105. package/src/Utilities/Services/ModuleService.js +33 -40
  106. package/src/Utilities/Services/QueryLanguageService.d.ts +9 -2
  107. package/src/Utilities/Services/QueryLanguageService.js +81 -22
  108. package/src/View/AdaptableWizardView/AdaptableConfigurationDialog/ConfigurationForm.js +5 -3
  109. package/src/View/Alert/Wizard/AlertDisplayWizardSection.d.ts +1 -0
  110. package/src/View/Alert/Wizard/AlertDisplayWizardSection.js +2 -2
  111. package/src/View/Alert/Wizard/isValidAlertRules.js +3 -3
  112. package/src/View/CalculatedColumn/CalculatedColumnSharedEntity.js +3 -3
  113. package/src/View/CalculatedColumn/CalculatedColumnSummary.js +2 -4
  114. package/src/View/CalculatedColumn/Wizard/CalculatedColumnExpressionWizardSection.js +43 -12
  115. package/src/View/CalculatedColumn/Wizard/CalculatedColumnSettingsWizardSection.js +1 -2
  116. package/src/View/ColorPicker.d.ts +1 -1
  117. package/src/View/Components/AdaptableDateInput/index.d.ts +1 -1
  118. package/src/View/Components/AdaptableInput/index.d.ts +1 -1
  119. package/src/View/Components/Buttons/ButtonDelete.d.ts +1 -1
  120. package/src/View/Components/EntityRulesEditor/index.d.ts +1 -1
  121. package/src/View/Components/EntityRulesEditor/index.js +3 -4
  122. package/src/View/Components/Forms/AdaptableFormControlTextClear.d.ts +1 -1
  123. package/src/View/Components/Panels/PanelWithImage.d.ts +1 -1
  124. package/src/View/Components/Popups/AdaptablePopup/AdaptablePopup.js +4 -8
  125. package/src/View/Components/Popups/AdaptablePopup/useMenuItems.js +1 -2
  126. package/src/View/Components/Popups/AdaptablePopupAlert.d.ts +1 -0
  127. package/src/View/Components/Popups/AdaptablePopupAlert.js +1 -1
  128. package/src/View/Components/ToolPanel/CustomToolPanelContent.js +1 -1
  129. package/src/View/Components/ValueSelector/index.js +1 -1
  130. package/src/View/Dashboard/DashboardPopup.js +1 -1
  131. package/src/View/FlashingCell/Wizard/isValidFlashingCellRules.js +1 -1
  132. package/src/View/Layout/Wizard/LayoutEditor/index.js +1 -1
  133. package/src/View/License/LicenseWatermark.js +1 -1
  134. package/src/View/PlusMinus/Wizard/PlusMinusSettingsWizardSection.d.ts +1 -1
  135. package/src/View/Query/Wizard/NamedQueryExpressionWizardSection.js +2 -2
  136. package/src/View/Schedule/Wizard/ScheduleWizard.js +3 -3
  137. package/src/agGrid/Adaptable.d.ts +4 -1
  138. package/src/agGrid/Adaptable.js +71 -48
  139. package/src/agGrid/CheckboxRenderer.d.ts +8 -1
  140. package/src/agGrid/CheckboxRenderer.js +18 -3
  141. package/src/agGrid/agGridHelper.d.ts +1 -1
  142. package/src/agGrid/agGridHelper.js +9 -10
  143. package/src/components/AdaptableFormComponent/AdaptableFormComponent.d.ts +4 -2
  144. package/src/components/AdaptableFormComponent/AdaptableFormComponent.js +4 -4
  145. package/src/components/Datepicker/index.d.ts +1 -1
  146. package/src/components/ExpressionEditor/EditorInput.d.ts +1 -1
  147. package/src/components/ExpressionEditor/EditorInput.js +5 -2
  148. package/src/components/ExpressionEditor/ExpressionFunctionDocumentation.js +1 -1
  149. package/src/components/ExpressionEditor/editorButtonsAggregatedScalar.d.ts +2 -0
  150. package/src/components/ExpressionEditor/editorButtonsAggregatedScalar.js +45 -0
  151. package/src/components/ExpressionEditor/editorButtonsReactive.js +8 -13
  152. package/src/components/ExpressionEditor/index.d.ts +2 -1
  153. package/src/components/ExpressionEditor/index.js +9 -2
  154. package/src/components/Input/index.d.ts +1 -1
  155. package/src/components/List/ListGroupItem/index.d.ts +1 -1
  156. package/src/components/Logo/index.js +8 -7
  157. package/src/components/PopupWithFooter.d.ts +1 -1
  158. package/src/components/Textarea/index.d.ts +1 -1
  159. package/src/components/icons/calculated-column.js +2 -1
  160. package/src/metamodel/adaptable.metamodel.d.ts +235 -41
  161. package/src/metamodel/adaptable.metamodel.js +435 -149
  162. package/src/types.d.ts +5 -5
  163. package/version.d.ts +1 -1
  164. package/version.js +1 -1
@@ -2,19 +2,316 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.aggregatedScalarExpressionFunctions = void 0;
4
4
  const expressionFunctionUtils_1 = require("./expressionFunctionUtils");
5
+ const ExpressionEvaluationError_1 = require("../../parser/src/ExpressionEvaluationError");
5
6
  exports.aggregatedScalarExpressionFunctions = {
6
- CUMSUM: {
7
+ SUM: {
7
8
  handler(args, context) {
8
- const cumulatedColumnParameter = expressionFunctionUtils_1.extractColumnParameter('SUM', args);
9
- expressionFunctionUtils_1.validateColumnType(cumulatedColumnParameter.value, ['Number'], 'CUMSUM', context.api);
10
- const overColumnParameter = expressionFunctionUtils_1.extractParameter('CUMSUM', 'operand', ['OVER'], args);
11
- // sort over all rowNodes by overColumn
12
- // cumulate
13
- //save to map
9
+ const sumColumnParameter = expressionFunctionUtils_1.extractColumnParameter('SUM', args);
10
+ const sumColumnName = sumColumnParameter.value;
11
+ expressionFunctionUtils_1.validateColumnType(sumColumnName, ['Number'], 'SUM', context.api);
12
+ const groupByParameter = expressionFunctionUtils_1.extractParameter('SUM', 'operand', ['GROUP_BY'], args, true);
13
+ const aggregationExpressionEvaluation = {
14
+ aggregationParams: {
15
+ reducers: {
16
+ SUM: {
17
+ name: 'SUM',
18
+ field: sumColumnName,
19
+ initialValue: 0,
20
+ reducer: (totalSum, rowValue) => {
21
+ if (!rowValue) {
22
+ return totalSum;
23
+ }
24
+ return totalSum + rowValue;
25
+ },
26
+ },
27
+ },
28
+ },
29
+ columnDependencies: [sumColumnName],
30
+ };
31
+ if (groupByParameter) {
32
+ const groupByColumnName = groupByParameter.value;
33
+ aggregationExpressionEvaluation.aggregationParams.groupBy = [
34
+ {
35
+ field: groupByColumnName,
36
+ },
37
+ ];
38
+ aggregationExpressionEvaluation.columnDependencies.push(groupByColumnName);
39
+ }
40
+ const result = {
41
+ name: 'SUM',
42
+ type: 'aggregation',
43
+ value: aggregationExpressionEvaluation,
44
+ };
45
+ return result;
46
+ },
47
+ description: 'Aggregates a column over multiple rows by summing up the column values\nOptionally the aggregation may be computed within provided individual groups',
48
+ signatures: [
49
+ 'SUM( [colName] )',
50
+ 'SUM( COL(name: string))',
51
+ 'SUM( [colNameA], GROUP_BY( [colNameB] ))',
52
+ 'SUM( COL(nameA: string), GROUP_BY( COL(nameB: string)))',
53
+ ],
54
+ examples: ['SUM([colA])', 'SUM([colA], GROUP_BY([colB]))'],
55
+ },
56
+ PERCENTAGE: {
57
+ handler(args, context) {
58
+ var _a;
59
+ const percentageColumnParameter = expressionFunctionUtils_1.extractColumnParameter('PERCENTAGE', args);
60
+ const percentageColumnName = percentageColumnParameter.value;
61
+ expressionFunctionUtils_1.validateColumnType(percentageColumnName, ['Number'], 'PERCENTAGE', context.api);
62
+ const sumOperand = expressionFunctionUtils_1.extractParameter('PERCENTAGE', 'aggregation', ['SUM'], args, true);
63
+ const groupByOperand = expressionFunctionUtils_1.extractParameter('PERCENTAGE', 'operand', ['GROUP_BY'], args, true);
64
+ if (sumOperand && groupByOperand) {
65
+ throw new ExpressionEvaluationError_1.ExpressionEvaluationError('PERCENTAGE', `expects either a SUM or a GROUP_BY argument`);
66
+ }
67
+ const sumAggregationColumnName = sumOperand
68
+ ? sumOperand.value.aggregationParams.reducers['SUM'].field
69
+ : percentageColumnName;
70
+ const groupByColumnName = groupByOperand
71
+ ? groupByOperand.value
72
+ : (_a = sumOperand === null || sumOperand === void 0 ? void 0 : sumOperand.value.aggregationParams.groupBy) === null || _a === void 0 ? void 0 : _a[0].field;
73
+ const aggregationExpressionEvaluation = {
74
+ aggregationParams: {
75
+ reducers: {
76
+ PERCENTAGE: {
77
+ name: 'PERCENTAGE',
78
+ field: sumAggregationColumnName,
79
+ initialValue: 0,
80
+ reducer: (totalSum, rowValue) => {
81
+ if (!rowValue) {
82
+ return totalSum;
83
+ }
84
+ return totalSum + rowValue;
85
+ },
86
+ },
87
+ },
88
+ },
89
+ rowValueGetter: (rowNode, aggregationValue) => {
90
+ return ((context.api.gridApi.getRawValueFromRowNode(rowNode, percentageColumnName) /
91
+ aggregationValue) *
92
+ 100);
93
+ },
94
+ columnDependencies: [...new Set([percentageColumnName, sumAggregationColumnName])],
95
+ };
96
+ if (groupByColumnName) {
97
+ aggregationExpressionEvaluation.aggregationParams.groupBy = [
98
+ {
99
+ field: groupByColumnName,
100
+ },
101
+ ];
102
+ aggregationExpressionEvaluation.columnDependencies.push(groupByColumnName);
103
+ }
104
+ const result = {
105
+ name: 'PERCENTAGE',
106
+ type: 'aggregation',
107
+ value: aggregationExpressionEvaluation,
108
+ };
109
+ return result;
110
+ },
111
+ description: 'Divides each column value by the aggregated sum of a column\nThe column with the aggregated value and the column with the percentage value do not necessarily have to be identical',
112
+ signatures: [
113
+ 'PERCENTAGE( [colName] )',
114
+ 'PERCENTAGE( [colNameA], GROUP_BY( [colNameB] ))',
115
+ 'PERCENTAGE( [colNameA], SUM ( [colNameB] ))',
116
+ 'PERCENTAGE( [colNameA], SUM ( [colNameB], GROUP_BY( [colNameC] )))',
117
+ ],
118
+ examples: [
119
+ 'PERCENTAGE( [colName] )',
120
+ 'PERCENTAGE( [colNameA], GROUP_BY( [colNameB] ))',
121
+ 'PERCENTAGE( [colNameA], SUM ( [colNameB] ))',
122
+ 'PERCENTAGE( [colNameA], SUM ( [colNameB], GROUP_BY( [colNameC] )))',
123
+ ],
124
+ },
125
+ AVG: {
126
+ handler(args, context) {
127
+ const avgColumnParameter = expressionFunctionUtils_1.extractColumnParameter('AVG', args);
128
+ const avgColumnName = avgColumnParameter.value;
129
+ expressionFunctionUtils_1.validateColumnType(avgColumnName, ['Number'], 'AVG', context.api);
130
+ const groupByParameter = expressionFunctionUtils_1.extractParameter('AVG', 'operand', ['GROUP_BY'], args, true);
131
+ const aggregationExpressionEvaluation = {
132
+ aggregationParams: {
133
+ reducers: {
134
+ SUM: {
135
+ name: 'AVG',
136
+ field: avgColumnName,
137
+ initialValue: 0,
138
+ reducer: (totalSum, rowValue) => {
139
+ if (!rowValue) {
140
+ return totalSum;
141
+ }
142
+ return totalSum + rowValue;
143
+ },
144
+ done: (value, dataArray) => {
145
+ return dataArray.length ? value / dataArray.length : 0;
146
+ },
147
+ },
148
+ },
149
+ },
150
+ columnDependencies: [avgColumnName],
151
+ };
152
+ if (groupByParameter) {
153
+ const groupByColumnName = groupByParameter.value;
154
+ aggregationExpressionEvaluation.aggregationParams.groupBy = [
155
+ {
156
+ field: groupByColumnName,
157
+ },
158
+ ];
159
+ aggregationExpressionEvaluation.columnDependencies.push(groupByColumnName);
160
+ }
161
+ const result = {
162
+ name: 'AVG',
163
+ type: 'aggregation',
164
+ value: aggregationExpressionEvaluation,
165
+ };
166
+ return result;
167
+ },
168
+ description: 'Aggregates a column over multiple rows by computing the average value (arithmetic mean) of the column values\nOptionally the aggregation may be computed within provided individual groups',
169
+ signatures: [
170
+ 'AVG( [colName] )',
171
+ 'AVG( COL(name: string))',
172
+ 'AVG( [colNameA], GROUP_BY( [colNameB] ))',
173
+ 'AVG( COL(nameA: string), GROUP_BY( COL(nameB: string)))',
174
+ ],
175
+ examples: ['AVG([colA])', 'AVG([colA], GROUP_BY([colB]))'],
176
+ },
177
+ MIN: {
178
+ handler(args, context) {
179
+ const minColumnParameter = expressionFunctionUtils_1.extractColumnParameter('MIN', args);
180
+ const minColumnName = minColumnParameter.value;
181
+ expressionFunctionUtils_1.validateColumnType(minColumnName, ['Number'], 'MIN', context.api);
182
+ const groupByParameter = expressionFunctionUtils_1.extractParameter('MIN', 'operand', ['GROUP_BY'], args, true);
183
+ const aggregationExpressionEvaluation = {
184
+ aggregationParams: {
185
+ reducers: {
186
+ SUM: {
187
+ name: 'MIN',
188
+ field: minColumnName,
189
+ initialValue: Number.MAX_VALUE,
190
+ reducer: (minValue, rowValue) => {
191
+ if (!rowValue) {
192
+ return minValue;
193
+ }
194
+ return rowValue < minValue ? rowValue : minValue;
195
+ },
196
+ },
197
+ },
198
+ },
199
+ columnDependencies: [minColumnName],
200
+ };
201
+ if (groupByParameter) {
202
+ const groupByColumnName = groupByParameter.value;
203
+ aggregationExpressionEvaluation.aggregationParams.groupBy = [
204
+ {
205
+ field: groupByColumnName,
206
+ },
207
+ ];
208
+ aggregationExpressionEvaluation.columnDependencies.push(groupByColumnName);
209
+ }
210
+ const result = {
211
+ name: 'MIN',
212
+ type: 'aggregation',
213
+ value: aggregationExpressionEvaluation,
214
+ };
215
+ return result;
216
+ },
217
+ description: 'Aggregates a column over multiple rows by computing the minimum of the column values\nOptionally the aggregation may be computed within provided individual groups',
218
+ signatures: [
219
+ 'MIN( [colName] )',
220
+ 'MIN( COL(name: string))',
221
+ 'MIN( [colNameA], GROUP_BY( [colNameB] ))',
222
+ 'MIN( COL(nameA: string), GROUP_BY( COL(nameB: string)))',
223
+ ],
224
+ examples: ['MIN([colA])', 'MIN([colA], GROUP_BY([colB]))'],
225
+ },
226
+ MAX: {
227
+ handler(args, context) {
228
+ const maxColumnParameter = expressionFunctionUtils_1.extractColumnParameter('MAX', args);
229
+ const maxColumnName = maxColumnParameter.value;
230
+ expressionFunctionUtils_1.validateColumnType(maxColumnName, ['Number'], 'MAX', context.api);
231
+ const groupByParameter = expressionFunctionUtils_1.extractParameter('MAX', 'operand', ['GROUP_BY'], args, true);
232
+ const aggregationExpressionEvaluation = {
233
+ aggregationParams: {
234
+ reducers: {
235
+ SUM: {
236
+ name: 'MAX',
237
+ field: maxColumnName,
238
+ initialValue: Number.MIN_VALUE,
239
+ reducer: (maxValue, rowValue) => {
240
+ if (!rowValue) {
241
+ return maxValue;
242
+ }
243
+ return rowValue > maxValue ? rowValue : maxValue;
244
+ },
245
+ },
246
+ },
247
+ },
248
+ columnDependencies: [maxColumnName],
249
+ };
250
+ if (groupByParameter) {
251
+ const groupByColumnName = groupByParameter.value;
252
+ aggregationExpressionEvaluation.aggregationParams.groupBy = [
253
+ {
254
+ field: groupByColumnName,
255
+ },
256
+ ];
257
+ aggregationExpressionEvaluation.columnDependencies.push(groupByColumnName);
258
+ }
259
+ const result = {
260
+ name: 'MAX',
261
+ type: 'aggregation',
262
+ value: aggregationExpressionEvaluation,
263
+ };
264
+ return result;
265
+ },
266
+ description: 'Aggregates a column over multiple rows by computing the maximum of the column values\nOptionally the aggregation may be computed within provided individual groups',
267
+ signatures: [
268
+ 'MAX( [colName] )',
269
+ 'MAX( COL(name: string))',
270
+ 'MAX( [colNameA], GROUP_BY( [colNameB] ))',
271
+ 'MAX( COL(nameA: string), GROUP_BY( COL(nameB: string)))',
272
+ ],
273
+ examples: ['MIN([colA])', 'MIN([colA], GROUP_BY([colB]))'],
274
+ },
275
+ GROUP_BY: {
276
+ handler(args, context) {
277
+ const columnParameter = expressionFunctionUtils_1.extractColumnParameter('GROUP_BY', args);
278
+ const result = {
279
+ type: 'operand',
280
+ name: 'GROUP_BY',
281
+ value: columnParameter.value,
282
+ };
283
+ return result;
284
+ },
285
+ description: 'Groups an aggregation operation within the rows that have the same value in the specified column',
286
+ signatures: ['GROUP_BY( [colName] )', 'GROUP_BY( COL(name: string))'],
287
+ examples: ['GROUP_BY( [colName] )', `GROUP_BY( COL('colName'))`],
288
+ },
289
+ CUMUL: {
290
+ handler(args, context) {
291
+ var _a;
292
+ const aggregationParameter = expressionFunctionUtils_1.extractParameter('CUMUL', 'aggregation', ['SUM', 'MIN', 'MAX', 'PERCENTAGE', 'AVG'], args);
293
+ if (aggregationParameter.name === 'AVG' || aggregationParameter.name === 'PERCENTAGE') {
294
+ throw new ExpressionEvaluationError_1.ExpressionEvaluationError('CUMUL', `supports only following aggregations: SUM, MIN, MAX`);
295
+ }
296
+ if ((_a = aggregationParameter.value.aggregationParams.groupBy) === null || _a === void 0 ? void 0 : _a.length) {
297
+ throw new ExpressionEvaluationError_1.ExpressionEvaluationError('CUMUL', `supports only aggregations without any grouping (GROUP_BY clauses)`);
298
+ }
299
+ const overColumnParameter = expressionFunctionUtils_1.extractParameter('CUMUL', 'operand', ['OVER'], args);
300
+ aggregationParameter.value.cumulateOver = overColumnParameter.value;
301
+ const result = {
302
+ name: 'CUMUL',
303
+ type: 'aggregation',
304
+ value: aggregationParameter.value,
305
+ };
306
+ return result;
14
307
  },
15
- description: 'TODO',
16
- signatures: ['TODO'],
17
- examples: ['TODO'],
308
+ description: 'Performs a cumulative aggregation (running total) with the given aggregation operation over a provided column',
309
+ signatures: ['CUMUL( aggregationOp: SUM|MIN|MAX, OVER( [colNameB] ))'],
310
+ examples: [
311
+ 'CUMUL( SUM([colNameA]), OVER( [colNameB] ))',
312
+ 'CUMUL( MIN([colNameA]), OVER( [colNameB] ))',
313
+ 'CUMUL( MAX([colNameA]), OVER( [colNameB] ))',
314
+ ],
18
315
  },
19
316
  OVER: {
20
317
  handler(args, context) {
@@ -27,15 +324,15 @@ exports.aggregatedScalarExpressionFunctions = {
27
324
  };
28
325
  return result;
29
326
  },
30
- description: 'TODO',
31
- signatures: ['TODO'],
32
- examples: ['TODO'],
327
+ description: 'Defines an accumulative dimension (order) for the enclosing cumulative aggregation',
328
+ signatures: ['OVER( [colName] )', 'OVER( COL(name: string))'],
329
+ examples: ['OVER( [colName] )', `OVER( COL('colName'))`],
33
330
  },
34
331
  COL: {
35
332
  handler(args, context) {
36
333
  return expressionFunctionUtils_1.handleColumnFunction(args, context);
37
334
  },
38
- description: 'Returns the value of a column',
335
+ description: 'References a column by its unique identifier',
39
336
  signatures: ['[colName]', 'COL(name: string)'],
40
337
  examples: ['[col1]', 'COL("col1")'],
41
338
  },
@@ -14,8 +14,8 @@ export declare const getStringValue: (context: ExpressionContext, stringArgument
14
14
  export declare const isTextSearchCaseInsensitive: (context: ExpressionContext) => boolean;
15
15
  export declare const getDataChangeLog$: (context: ExpressionContext, columnNameFilter: string) => Observable<DataChangedInfo>;
16
16
  export declare const handleWhereFunction: (args: any[], context: ExpressionContext) => any;
17
- export declare const extractColumnParameter: (consumingFunctionName: string, args: BaseParameter[], validateType?: 'number') => ColumnParameter;
18
- export declare const extractParameter: <T extends BaseParameter<string, string>>(consumingFunctionName: string, allowedType: string, allowedOperands: string[], args?: BaseParameter[]) => T;
17
+ export declare const extractColumnParameter: (consumingFunctionName: string, args: BaseParameter[]) => ColumnParameter;
18
+ export declare const extractParameter: <T extends BaseParameter<string, string>>(consumingFunctionName: string, allowedType: T["type"], allowedOperands: T["name"][], args: BaseParameter[], isOptional?: boolean) => T;
19
19
  export declare const handleColumnFunction: (args: any[], context: ExpressionContext) => ColumnParameter;
20
20
  export declare const getNumericValue: (input: unknown) => number;
21
21
  export declare const validateColumnType: (columnId: string, validColumnTypes: ('Number' | 'String' | 'Date')[], consumingFunction: string, api: AdaptableApi) => void;
@@ -49,19 +49,19 @@ exports.handleWhereFunction = (args, context) => {
49
49
  filterFn,
50
50
  });
51
51
  };
52
- exports.extractColumnParameter = (consumingFunctionName, args, validateType) => {
53
- const result = exports.extractParameter(consumingFunctionName, 'config', ['COL'], args);
54
- if (validateType) {
55
- }
56
- return result;
52
+ exports.extractColumnParameter = (consumingFunctionName, args) => {
53
+ return exports.extractParameter(consumingFunctionName, 'config', ['COL'], args);
57
54
  };
58
- exports.extractParameter = (consumingFunctionName, allowedType, allowedOperands, args = []) => {
55
+ exports.extractParameter = (consumingFunctionName, allowedType, allowedOperands, args, isOptional) => {
59
56
  const result = args.filter((arg) => (arg === null || arg === void 0 ? void 0 : arg.type) === allowedType && allowedOperands.includes(arg === null || arg === void 0 ? void 0 : arg.name));
57
+ if (isOptional && !result.length) {
58
+ return;
59
+ }
60
60
  if (result.length > 1) {
61
- throw new ExpressionEvaluationError_1.ExpressionEvaluationError(consumingFunctionName, `expects only 1 argument of type '${[...new Set(result.map((op) => op.name))].join(' / ')}'`);
61
+ throw new ExpressionEvaluationError_1.ExpressionEvaluationError(consumingFunctionName, `expects only 1 argument of type '${[...new Set(result.map((op) => op.name))].join(`' / '`)}'`);
62
62
  }
63
63
  if (!result.length) {
64
- throw new ExpressionEvaluationError_1.ExpressionEvaluationError(consumingFunctionName, `expects an argument of type '${allowedOperands.join(' / ')}'`);
64
+ throw new ExpressionEvaluationError_1.ExpressionEvaluationError(consumingFunctionName, `expects an argument of type '${allowedOperands.join(`' / '`)}'`);
65
65
  }
66
66
  return result[0];
67
67
  };
@@ -3,7 +3,6 @@ export declare type GroupKeyType<T extends any = any> = T;
3
3
  export declare type GroupBy<DataType, KeyType> = {
4
4
  field: keyof DataType;
5
5
  toKey?: (value: any, data: DataType) => GroupKeyType<KeyType>;
6
- column?: string;
7
6
  };
8
7
  export declare type GroupParams<DataType, KeyType> = {
9
8
  groupBy: GroupBy<DataType, KeyType>[];
@@ -22,12 +21,12 @@ export declare type DataGroupResult<DataType, KeyType extends any> = {
22
21
  deepMap: DeepMap<GroupKeyType<KeyType>, DeepMapGroupValueType<DataType, KeyType>>;
23
22
  groupParams: GroupParams<DataType, KeyType>;
24
23
  initialData: DataType[];
25
- reducerResults?: Record<string, AggregationReducerResult>;
24
+ reducerResults?: Record<string, any>;
26
25
  };
27
26
  export declare type DeepMapGroupValueType<DataType, KeyType> = {
28
27
  items: DataType[];
29
28
  commonData?: Partial<DataType>;
30
- reducerResults: Record<string, AggregationReducerResult>;
29
+ reducerResults: Record<string, any>;
31
30
  };
32
31
  export declare type AggregationReducerResult<AggregationResultType extends any = any> = {
33
32
  value: AggregationResultType;
@@ -36,13 +36,14 @@ function group(groupParams, data) {
36
36
  }
37
37
  currentGroupKeys.length = 0;
38
38
  }
39
- if (reducers) {
39
+ const hasReducersWithDoneFn = reducers && Object.values(reducers).some((reducer) => reducer.done);
40
+ if (hasReducersWithDoneFn) {
40
41
  deepMap.visitDepthFirst((deepMapValue, _keys, _indexInGroup, next) => {
41
42
  completeReducers(reducers, deepMapValue.reducerResults, deepMapValue.items);
42
43
  next === null || next === void 0 ? void 0 : next();
43
44
  });
44
45
  }
45
- if (reducers) {
46
+ if (hasReducersWithDoneFn) {
46
47
  completeReducers(reducers, globalReducerResults, data);
47
48
  }
48
49
  const result = {
@@ -105,7 +105,7 @@ exports.observableExpressionFunctions = {
105
105
  handler(args, context) {
106
106
  return expressionFunctionUtils_1.handleColumnFunction(args, context);
107
107
  },
108
- description: 'References a grid column by name',
108
+ description: 'References a column by its unique identifier',
109
109
  signatures: ['[colName]', 'COL(name: string)'],
110
110
  examples: ['[col1]', "COL('col1')"],
111
111
  },
@@ -417,7 +417,8 @@ const getSlidingTimeframe$ = (source$, timeframeDuration, onTimeframeEnter, onTi
417
417
  }));
418
418
  };
419
419
  const getMaxTimeframeSize = (expressionValue, context) => {
420
- let maxTimeframeSize = context.api.internalApi.getAdaptableOptions().queryLanguageOptions.maxTimeframeSize;
420
+ let maxTimeframeSize = context.api.internalApi.getAdaptableOptions().adaptableQLOptions.expressionOptions
421
+ .maxTimeframeSize;
421
422
  if (maxTimeframeSize > SYSTEM_MAX_TIMEFRAME_SIZE) {
422
423
  maxTimeframeSize = SYSTEM_MAX_TIMEFRAME_SIZE;
423
424
  }
@@ -0,0 +1,33 @@
1
+ import { DeepMap } from './deepMap';
2
+ export declare type GroupKeyType<T extends any = any> = T;
3
+ export declare type GroupBy<DataType, KeyType> = {
4
+ field: keyof DataType & string;
5
+ toKey?: (value: any, data: DataType) => GroupKeyType<KeyType>;
6
+ };
7
+ export declare type AggregateParams<DataType, KeyType> = {
8
+ reducers: Record<string, DataAggregationReducer<DataType, any>>;
9
+ groupBy?: GroupBy<DataType, KeyType>[];
10
+ defaultToKey?: (value: any, item: DataType) => GroupKeyType<KeyType>;
11
+ };
12
+ export declare type DataAggregationReducer<T, AggregationResultType> = {
13
+ name?: string;
14
+ field?: keyof T & string;
15
+ initialValue?: AggregationResultType;
16
+ getter?: (data: T) => any;
17
+ reducer: string | ((accumulator: any, value: any, data: T) => AggregationResultType | any);
18
+ done?: (accumulatedValue: AggregationResultType | any, array: T[]) => AggregationResultType;
19
+ };
20
+ export declare type DataAggregationResult<DataType, KeyType extends any> = {
21
+ deepMap: DeepMap<GroupKeyType<KeyType>, DeepMapAggregationValueType<DataType, KeyType>>;
22
+ aggregateParams: AggregateParams<DataType, KeyType>;
23
+ initialData: DataType[];
24
+ reducerResults?: Record<string, AggregationReducerResult>;
25
+ };
26
+ export declare type DeepMapAggregationValueType<DataType, KeyType> = {
27
+ items: DataType[];
28
+ commonData?: Partial<DataType>;
29
+ reducerResults: Record<string, AggregationReducerResult>;
30
+ };
31
+ export declare type AggregationReducerResult = number;
32
+ export declare function aggregate<DataType, KeyType = any>(aggregateParams: AggregateParams<DataType, KeyType>, data: DataType[]): DataAggregationResult<DataType, KeyType>;
33
+ export declare function cumulate<DataType, KeyType = any>(aggregateParams: AggregateParams<DataType, KeyType>, data: DataType[]): DataAggregationResult<DataType, KeyType>;
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cumulate = exports.aggregate = void 0;
4
+ const deepMap_1 = require("./deepMap");
5
+ function DEFAULT_TO_KEY(value) {
6
+ return value;
7
+ }
8
+ function aggregate(aggregateParams, data) {
9
+ const { groupBy = [], defaultToKey = DEFAULT_TO_KEY, reducers } = aggregateParams;
10
+ const groupByLength = groupBy.length;
11
+ const deepMap = new deepMap_1.DeepMap();
12
+ let currentGroupKeys = [];
13
+ const initialReducerValue = initReducers(reducers);
14
+ const globalReducerResults = Object.assign({}, initialReducerValue);
15
+ for (let i = 0, len = data.length; i < len; i++) {
16
+ let item = data[i];
17
+ for (let groupByIndex = 0; groupByIndex < groupByLength; groupByIndex++) {
18
+ const { field: groupByProperty, toKey: groupToKey } = groupBy[groupByIndex];
19
+ const key = (groupToKey || defaultToKey)(item[groupByProperty], item);
20
+ currentGroupKeys.push(key);
21
+ if (!deepMap.has(currentGroupKeys)) {
22
+ const deepMapGroupValue = {
23
+ items: [],
24
+ reducerResults: Object.assign({}, initialReducerValue),
25
+ };
26
+ deepMap.set(currentGroupKeys, deepMapGroupValue);
27
+ }
28
+ const { items: currentGroupItems, reducerResults } = deepMap.get(currentGroupKeys);
29
+ currentGroupItems.push(item);
30
+ if (reducers) {
31
+ computeReducersFor(item, reducers, reducerResults);
32
+ }
33
+ }
34
+ if (reducers) {
35
+ computeReducersFor(item, reducers, globalReducerResults);
36
+ }
37
+ currentGroupKeys.length = 0;
38
+ }
39
+ if (reducers) {
40
+ deepMap.visitDepthFirst((deepMapValue, _keys, _indexInGroup, next) => {
41
+ completeReducers(reducers, deepMapValue.reducerResults, deepMapValue.items);
42
+ next === null || next === void 0 ? void 0 : next();
43
+ });
44
+ }
45
+ if (reducers) {
46
+ completeReducers(reducers, globalReducerResults, data);
47
+ }
48
+ const result = {
49
+ deepMap,
50
+ aggregateParams,
51
+ initialData: data,
52
+ reducerResults: globalReducerResults,
53
+ };
54
+ return result;
55
+ }
56
+ exports.aggregate = aggregate;
57
+ function cumulate(aggregateParams, data) {
58
+ const { groupBy = [], defaultToKey = DEFAULT_TO_KEY, reducers } = aggregateParams;
59
+ const groupByLength = groupBy.length;
60
+ const deepMap = new deepMap_1.DeepMap();
61
+ let currentGroupKeys = [];
62
+ let initialReducerValue = initReducers(reducers);
63
+ const globalReducerResults = Object.assign({}, initialReducerValue);
64
+ for (let i = 0, len = data.length; i < len; i++) {
65
+ let item = data[i];
66
+ for (let groupByIndex = 0; groupByIndex < groupByLength; groupByIndex++) {
67
+ const { field: groupByProperty, toKey: groupToKey } = groupBy[groupByIndex];
68
+ const key = (groupToKey || defaultToKey)(item[groupByProperty], item);
69
+ currentGroupKeys.push(key);
70
+ if (!deepMap.has(currentGroupKeys)) {
71
+ const deepMapGroupValue = {
72
+ items: [],
73
+ reducerResults: Object.assign({}, initialReducerValue),
74
+ };
75
+ deepMap.set(currentGroupKeys, deepMapGroupValue);
76
+ }
77
+ const { items: currentGroupItems, reducerResults } = deepMap.get(currentGroupKeys);
78
+ currentGroupItems.push(item);
79
+ if (reducers) {
80
+ computeReducersFor(item, reducers, reducerResults);
81
+ }
82
+ }
83
+ if (reducers) {
84
+ computeReducersFor(item, reducers, globalReducerResults);
85
+ }
86
+ initialReducerValue = Object.assign({}, deepMap.get(currentGroupKeys).reducerResults);
87
+ currentGroupKeys.length = 0;
88
+ }
89
+ if (reducers) {
90
+ deepMap.visitDepthFirst((deepMapValue, _keys, _indexInGroup, next) => {
91
+ completeReducers(reducers, deepMapValue.reducerResults, deepMapValue.items);
92
+ next === null || next === void 0 ? void 0 : next();
93
+ });
94
+ }
95
+ if (reducers) {
96
+ completeReducers(reducers, globalReducerResults, data);
97
+ }
98
+ const result = {
99
+ deepMap,
100
+ aggregateParams,
101
+ initialData: data,
102
+ reducerResults: globalReducerResults,
103
+ };
104
+ return result;
105
+ }
106
+ exports.cumulate = cumulate;
107
+ function initReducers(reducers) {
108
+ if (!reducers || !Object.keys(reducers).length) {
109
+ return {};
110
+ }
111
+ const result = {};
112
+ for (let key in reducers)
113
+ if (reducers.hasOwnProperty(key)) {
114
+ result[key] = reducers[key].initialValue;
115
+ }
116
+ return result;
117
+ }
118
+ /**
119
+ *
120
+ * This fn mutates the reducerResults array!!!
121
+ *
122
+ * @param data data item
123
+ * @param reducers an array of reducers
124
+ * @param reducerResults the results on which to operate
125
+ *
126
+ */
127
+ function computeReducersFor(data, reducers, reducerResults) {
128
+ var _a, _b;
129
+ if (!reducers || !Object.keys(reducers).length) {
130
+ return;
131
+ }
132
+ for (let key in reducers)
133
+ if (reducers.hasOwnProperty(key)) {
134
+ const reducer = reducers[key];
135
+ if (typeof reducer.reducer !== 'function') {
136
+ continue;
137
+ }
138
+ const currentValue = reducerResults[key];
139
+ const value = reducer.field ? data[reducer.field] : (_b = (_a = reducer.getter) === null || _a === void 0 ? void 0 : _a.call(reducer, data)) !== null && _b !== void 0 ? _b : null;
140
+ reducerResults[key] = reducer.reducer(currentValue, value, data);
141
+ }
142
+ }
143
+ function completeReducers(reducers, reducerResults, items) {
144
+ if (reducers) {
145
+ for (let key in reducers)
146
+ if (reducers.hasOwnProperty(key)) {
147
+ const reducer = reducers[key];
148
+ if (reducer.done) {
149
+ reducerResults[key] = reducer.done(reducerResults[key], items);
150
+ }
151
+ }
152
+ }
153
+ return reducerResults;
154
+ }
@@ -11,6 +11,8 @@ function assignAdaptableOptions(adaptableOptions) {
11
11
  var _a;
12
12
  const returnedAdaptableOptions = Object.assign({}, DefaultAdaptableOptions_1.DefaultAdaptableOptions, adaptableOptions);
13
13
  returnedAdaptableOptions.adaptableStateKey = (_a = returnedAdaptableOptions.adaptableStateKey) !== null && _a !== void 0 ? _a : returnedAdaptableOptions.adaptableId;
14
+ returnedAdaptableOptions.adaptableQLOptions = Object.assign({}, DefaultAdaptableOptions_1.DefaultAdaptableOptions.adaptableQLOptions, adaptableOptions.adaptableQLOptions);
15
+ returnedAdaptableOptions.adaptableQLOptions.expressionOptions = Object.assign({}, DefaultAdaptableOptions_1.DefaultAdaptableOptions.adaptableQLOptions.expressionOptions, returnedAdaptableOptions.adaptableQLOptions.expressionOptions);
14
16
  returnedAdaptableOptions.layoutOptions = Object.assign({}, DefaultAdaptableOptions_1.DefaultAdaptableOptions.layoutOptions, adaptableOptions.layoutOptions);
15
17
  returnedAdaptableOptions.notificationsOptions = Object.assign({}, DefaultAdaptableOptions_1.DefaultAdaptableOptions.notificationsOptions, adaptableOptions.notificationsOptions);
16
18
  returnedAdaptableOptions.alertOptions = Object.assign({}, DefaultAdaptableOptions_1.DefaultAdaptableOptions.alertOptions, adaptableOptions.alertOptions);
@@ -29,7 +31,6 @@ function assignAdaptableOptions(adaptableOptions) {
29
31
  returnedAdaptableOptions.exportOptions = Object.assign({}, DefaultAdaptableOptions_1.DefaultAdaptableOptions.exportOptions, adaptableOptions.exportOptions);
30
32
  returnedAdaptableOptions.teamSharingOptions = Object.assign({}, DefaultAdaptableOptions_1.DefaultAdaptableOptions.teamSharingOptions, adaptableOptions.teamSharingOptions);
31
33
  returnedAdaptableOptions.toolPanelOptions = Object.assign({}, DefaultAdaptableOptions_1.DefaultAdaptableOptions.toolPanelOptions, adaptableOptions.toolPanelOptions);
32
- returnedAdaptableOptions.queryLanguageOptions = Object.assign({}, DefaultAdaptableOptions_1.DefaultAdaptableOptions.queryLanguageOptions, adaptableOptions.queryLanguageOptions);
33
34
  returnedAdaptableOptions.dataChangeHistoryOptions = Object.assign({}, DefaultAdaptableOptions_1.DefaultAdaptableOptions.dataChangeHistoryOptions, adaptableOptions.dataChangeHistoryOptions);
34
35
  returnedAdaptableOptions.settingsPanelOptions = Object.assign({}, DefaultAdaptableOptions_1.DefaultAdaptableOptions.settingsPanelOptions, adaptableOptions.settingsPanelOptions);
35
36
  const { predefinedConfig } = returnedAdaptableOptions;