@qrvey/utils 1.5.0-2 → 1.5.0-5

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 (46) hide show
  1. package/README.md +1 -1
  2. package/dist/charts/adapters/endpointData.d.ts +90 -0
  3. package/dist/charts/adapters/endpointData.js +511 -0
  4. package/dist/charts/adapters/endpointDataGet.d.ts +14 -0
  5. package/dist/charts/adapters/endpointDataGet.js +428 -0
  6. package/dist/charts/adapters/endpointDataValidators.d.ts +4 -0
  7. package/dist/charts/adapters/endpointDataValidators.js +54 -0
  8. package/dist/charts/adapters/index.d.ts +3 -0
  9. package/dist/charts/adapters/index.js +3 -0
  10. package/dist/charts/index.d.ts +1 -0
  11. package/dist/charts/index.js +1 -0
  12. package/dist/cjs/charts/adapters/endpointData.d.ts +90 -0
  13. package/dist/cjs/charts/adapters/endpointData.js +517 -0
  14. package/dist/cjs/charts/adapters/endpointDataGet.d.ts +14 -0
  15. package/dist/cjs/charts/adapters/endpointDataGet.js +444 -0
  16. package/dist/cjs/charts/adapters/endpointDataValidators.d.ts +4 -0
  17. package/dist/cjs/charts/adapters/endpointDataValidators.js +61 -0
  18. package/dist/cjs/charts/adapters/index.d.ts +3 -0
  19. package/dist/cjs/charts/adapters/index.js +19 -0
  20. package/dist/cjs/charts/index.d.ts +1 -0
  21. package/dist/cjs/charts/index.js +1 -0
  22. package/dist/cjs/column_format/helpers/defineTableChartFormat.js +19 -10
  23. package/dist/cjs/constants/Charts.Const.d.ts +1 -0
  24. package/dist/cjs/constants/Charts.Const.js +1 -0
  25. package/dist/cjs/dates/constants/DATETIME_COLUMN_FORMAT.js +1 -0
  26. package/dist/cjs/format/duration/durationFormatter.js +1 -1
  27. package/dist/cjs/globalization/interfaces/common/II18nCommon.d.ts +1 -0
  28. package/dist/cjs/globalization/interfaces/panel/II18nPanelMenu.d.ts +1 -0
  29. package/dist/cjs/globalization/interfaces/style_themes/II18nStyleThemesTheme.d.ts +1 -0
  30. package/dist/cjs/globalization/labels/chart_builder/I18N_CHART_BUILDER_STYLE_OPTIONS.js +2 -2
  31. package/dist/cjs/globalization/labels/common/I18N_COMMON.js +1 -0
  32. package/dist/cjs/globalization/labels/panel/I18N_PANEL.js +1 -0
  33. package/dist/cjs/globalization/labels/style_themes/I18N_STYLE_THEMES.js +1 -0
  34. package/dist/column_format/helpers/defineTableChartFormat.js +19 -10
  35. package/dist/constants/Charts.Const.d.ts +1 -0
  36. package/dist/constants/Charts.Const.js +1 -0
  37. package/dist/dates/constants/DATETIME_COLUMN_FORMAT.js +1 -0
  38. package/dist/format/duration/durationFormatter.js +1 -1
  39. package/dist/globalization/interfaces/common/II18nCommon.d.ts +1 -0
  40. package/dist/globalization/interfaces/panel/II18nPanelMenu.d.ts +1 -0
  41. package/dist/globalization/interfaces/style_themes/II18nStyleThemesTheme.d.ts +1 -0
  42. package/dist/globalization/labels/chart_builder/I18N_CHART_BUILDER_STYLE_OPTIONS.js +2 -2
  43. package/dist/globalization/labels/common/I18N_COMMON.js +1 -0
  44. package/dist/globalization/labels/panel/I18N_PANEL.js +1 -0
  45. package/dist/globalization/labels/style_themes/I18N_STYLE_THEMES.js +1 -0
  46. package/package.json +1 -1
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [@qrvey/utils](https://bitbucket.org/qrvey/qrvey_utils/wiki/Home) *1.5.0-2*
1
+ # [@qrvey/utils](https://bitbucket.org/qrvey/qrvey_utils/wiki/Home) *1.5.0-5*
2
2
 
3
3
  > Helper, Utils for all Qrvey Projects
4
4
 
@@ -0,0 +1,90 @@
1
+ import { IFUData } from "../../filters";
2
+ export declare function configSetup(config?: any): {
3
+ config: {
4
+ id: any;
5
+ data: any;
6
+ type: any;
7
+ domain: any;
8
+ model: any;
9
+ tab_id: any;
10
+ app_id: any;
11
+ api_key: any;
12
+ user_id: any;
13
+ view_id: any;
14
+ page_id: any;
15
+ chart_id: any;
16
+ qv_token: any;
17
+ qrvey_id: any;
18
+ question: any;
19
+ metric_id: any;
20
+ summary_id: any;
21
+ formulaType: any;
22
+ summary_type: any;
23
+ custom_tokens: any;
24
+ section: any;
25
+ panel_view: any;
26
+ previewFilters: any;
27
+ filterData: any;
28
+ i18n: any;
29
+ visibleFilters: IFUData;
30
+ appliedFilters: IFUData;
31
+ customDrillLogic: any[];
32
+ isFromAN: any;
33
+ editable: any;
34
+ inBuilder: any;
35
+ clickable: any;
36
+ userFilters: any;
37
+ customdrill: any;
38
+ widgetConfig: any;
39
+ drilldowns: any;
40
+ filterPermissions: any;
41
+ chartBuilderConfig: any;
42
+ other_config: any;
43
+ predefined_filters: any;
44
+ locale: any;
45
+ lang: string;
46
+ panel: {
47
+ header: {
48
+ menu: any;
49
+ filter: any;
50
+ draggable: any;
51
+ title_prefix: any;
52
+ fit_panel: any;
53
+ visible: any;
54
+ ui: {
55
+ isFiltered: boolean;
56
+ isDisplayReady: boolean;
57
+ isScrollableXY: boolean;
58
+ };
59
+ externalDownload: any;
60
+ };
61
+ body: {
62
+ popup: any;
63
+ tooltip: any;
64
+ hasTimeout: boolean;
65
+ hasOverlay: any;
66
+ stylesTheme: {
67
+ original_match_color: any;
68
+ match_color: any;
69
+ };
70
+ ui: {
71
+ isLoading: boolean;
72
+ settingsStyle: any;
73
+ timeoutMessage: string;
74
+ };
75
+ };
76
+ footer: {
77
+ visible: any;
78
+ };
79
+ };
80
+ };
81
+ data: {};
82
+ scopes: {};
83
+ baseConfig: {};
84
+ customdrills: any[];
85
+ };
86
+ export declare function configMetricData(metricObj?: any): any;
87
+ export declare function configChartData(chartData: any, model: any, setup?: any): {
88
+ charts: any;
89
+ logic: import("../../filters").IFBLogic[];
90
+ };
@@ -0,0 +1,511 @@
1
+ import { CHART_TYPE } from "../../constants";
2
+ import { adaptFilterData, excludeFiltersByAggregateColumn, FDToLogic, FILTER_SCOPE, FILTER_STRUCTURE_VERSION, getAvailableScopes, getAvailableScopesIDsByConfig, UIToOldLogic, } from "../../filters";
3
+ import { chooseLang, getLang } from "../../format";
4
+ import { cloneDeep, getAttribute, isEmpty, _get, _hasProperty, } from "../../general";
5
+ import { getAggFiltersResults, getCategoryBody, getComboBody, getDrilldownId, getLayerBody, getPivotBody, getRefenceBody, getRefenceBodyU, getSmallMultipleBody, getSummariesBody, getTrendBody, getValidSortingType, } from "./endpointDataGet";
6
+ import { hasMinorVersion, isNotValid, validChartTypeWithEndPoint, } from "./endpointDataValidators";
7
+ function makeBodyRequest(body, filters = []) {
8
+ if (!body)
9
+ return;
10
+ const category = _get(body, "layerList[0].category");
11
+ if (category && category.bucketId)
12
+ category.id = category.bucketId;
13
+ const distribution = _get(body, "layerList[0].distribution");
14
+ const categoryId = category
15
+ ? category.id
16
+ : distribution
17
+ ? distribution.id
18
+ : null;
19
+ const dataType = _get(body, "layerList[0].category.type");
20
+ const maxDataPoints = _get(body, "globalSettings.maxNumDataPoints", 50);
21
+ const sorting = _get(body, "globalSettings.sortX", {});
22
+ const sortOption = {
23
+ sortBy: getValidSortingType(body) === "Label" ? "CATEGORY" : "VALUE",
24
+ sortDirection: (sorting.order || "ASC").toUpperCase(),
25
+ };
26
+ let label;
27
+ if (categoryId) {
28
+ label = {
29
+ questionid: categoryId,
30
+ qrveyid: (category || distribution).qrveyid || body.qrveyid,
31
+ property: (category || distribution).property || body.property,
32
+ type: (category || distribution).type || body.type,
33
+ };
34
+ }
35
+ if (body.layerList)
36
+ return body.layerList.reduce(function (charts, layer, index) {
37
+ if (index > 0 && !_get(layer, "combopt.label"))
38
+ return charts;
39
+ let chart;
40
+ if (index > 0 && layer.combopt.label == "MULTI") {
41
+ chart = { type: "MULTI_SERIE" };
42
+ }
43
+ else if (index > 0 &&
44
+ ["TREND", "REFERENCE"].includes(layer.combopt.label)) {
45
+ chart =
46
+ layer.combopt.label == "TREND"
47
+ ? getTrendBody(layer)
48
+ : getRefenceBody(layer);
49
+ if (typeof chart.value == "object" && !chart.value.qrveyid)
50
+ chart.value.qrveyid = body.qrveyid;
51
+ }
52
+ else if (_get(layer, "combopt.label") !== "SMALL_MULTIPLES") {
53
+ if (layer.value)
54
+ layer.value.qrveyid = layer.value.qrveyid || body.qrveyid;
55
+ chart = getLayerBody(layer, body.dateGroup || layer.dateGroup, body.qrveyid);
56
+ if (chart) {
57
+ chart.labelId = categoryId;
58
+ chart.dataType = dataType;
59
+ // this object is for new datalink feature
60
+ if (chart.value)
61
+ chart.label = label;
62
+ if (layer.type === "BOXWHISKER_CHART") {
63
+ if (!dataType) {
64
+ delete chart.label;
65
+ delete chart.labelId;
66
+ }
67
+ if (distribution) {
68
+ chart.distribution = {
69
+ aggregate: chart.aggregate,
70
+ questionid: distribution.id || distribution.bucketId,
71
+ qrveyid: body.qrveyid,
72
+ type: distribution.type,
73
+ };
74
+ }
75
+ delete chart.aggregate;
76
+ }
77
+ if ((layer.type == "WORD_CLOUD" ||
78
+ (layer.type == "GEO_CHART" &&
79
+ _get(layer, "mapType.label") == "DOT")) &&
80
+ !chart.value) {
81
+ chart.label = label;
82
+ if (label.type !== "BUCKET") {
83
+ // AN-7111 so far charts doesn't support bucket columns as value
84
+ chart.value = label;
85
+ }
86
+ }
87
+ if ([CHART_TYPE.GEO_CHART, CHART_TYPE.GEO_CHART_BUBBLE].includes(layer.type)) {
88
+ chart.aggFilters = getAggFiltersResults(filters, [
89
+ Object.assign(Object.assign({}, chart.value), { aggregate: chart.aggregate }),
90
+ ]);
91
+ if (chart.label)
92
+ chart.property = chart.label.property;
93
+ }
94
+ }
95
+ }
96
+ if (chart) {
97
+ chart.id = index;
98
+ if (_get(body, "globalSettings.maxDataPoints", false))
99
+ chart.maxDataPoints = maxDataPoints;
100
+ chart.sortOption = sortOption;
101
+ const bucketData = category;
102
+ if (bucketData && bucketData.type === "BUCKET" && bucketData.bucketId) {
103
+ chart.labelBucketId = bucketData.bucketId;
104
+ delete chart.label; // deleted unnecessary chart label property in buckets
105
+ }
106
+ charts.push(chart);
107
+ }
108
+ return charts;
109
+ }, []);
110
+ }
111
+ function makeBodyRequestU(body, filters, newModel = false) {
112
+ var _a, _b, _c;
113
+ if (!body)
114
+ return;
115
+ const pSmallMultiple = getSmallMultipleBody(body.layerList.find((ly) => _get(ly, "combopt.label") === "SMALL_MULTIPLES"), body);
116
+ let pSummaries = getSummariesBody(_get(body, "layerList[0]"), body);
117
+ const pCategory = getCategoryBody(_get(body, "layerList[0]"), body);
118
+ const pPivot = getPivotBody(_get(body, "layerList[0]"), body);
119
+ const aggFilters = getAggFiltersResults(filters, pSummaries);
120
+ let requestBody = [];
121
+ if (body.layerList) {
122
+ requestBody = body.layerList.reduce(function (charts, layer, index) {
123
+ if (index <= 0 || !_get(layer, "combopt.label"))
124
+ return charts;
125
+ let chart;
126
+ switch (layer.combopt.label) {
127
+ case "TREND":
128
+ chart = getTrendBody(layer);
129
+ break;
130
+ case "REFERENCE":
131
+ chart = getRefenceBodyU(layer, body);
132
+ break;
133
+ case "COMBO":
134
+ chart = getComboBody(layer, body, filters, newModel);
135
+ break;
136
+ case "MULTI":
137
+ chart = {
138
+ type: layer.combopt.label,
139
+ };
140
+ break;
141
+ }
142
+ if (chart)
143
+ charts.push(chart);
144
+ return charts;
145
+ }, []);
146
+ }
147
+ if (newModel) {
148
+ const dimensions = [];
149
+ if (pSmallMultiple)
150
+ dimensions.push(pSmallMultiple);
151
+ if (pCategory)
152
+ dimensions.push(pCategory);
153
+ if (pPivot)
154
+ dimensions.push(pPivot);
155
+ if (!pSummaries[0].aggregate && !((_c = (_b = (_a = pCategory.sortOption) === null || _a === void 0 ? void 0 : _a.order) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.hidden)) {
156
+ let sortValue = {};
157
+ if (_get(pCategory, "sortOption.sortBy") === "VALUE") {
158
+ sortValue = Object.assign({}, pCategory.sortOption);
159
+ sortValue.sortBy = "CATEGORY";
160
+ pCategory.sortOption = {};
161
+ }
162
+ const newSummary = Object.assign(pSummaries[0], {
163
+ maxDataPoints: body.globalSettings.maxNumValuePoints,
164
+ });
165
+ if (!newSummary.sortOption)
166
+ newSummary.sortOption = sortValue;
167
+ dimensions.push(newSummary);
168
+ pSummaries = [];
169
+ }
170
+ // TODO: Mejorar estructura para que la propiedad venga directamente del chart builder
171
+ if (body.type == "HEATMAP_CHART" &&
172
+ pSummaries &&
173
+ pSummaries[0].calculations) {
174
+ const direction = _get(body.globalSettings, "calculation_direction", "Across") === "Down"
175
+ ? "vertical"
176
+ : "horizontal";
177
+ pSummaries[0].calculations.direction = direction;
178
+ }
179
+ requestBody.unshift({
180
+ dimensions: dimensions,
181
+ summaries: pSummaries,
182
+ aggFilters: aggFilters,
183
+ });
184
+ }
185
+ else {
186
+ requestBody.unshift({
187
+ category: pCategory,
188
+ summaries: pSummaries,
189
+ aggFilters: aggFilters,
190
+ pivot: pPivot,
191
+ });
192
+ }
193
+ return requestBody;
194
+ }
195
+ export function configSetup(config) {
196
+ var _a;
197
+ const cfg = cloneDeep(config || {});
198
+ cfg.panel = cfg.panel || {};
199
+ const body = getAttribute(cfg.panel, "body") || {};
200
+ const header = getAttribute(cfg.panel, "header") || {};
201
+ const footer = getAttribute(cfg.panel, "footer") || {};
202
+ let filterSettings = header.filter;
203
+ filterSettings = {
204
+ button: {
205
+ display: _get(header.filter, "button.display", _get(header, "filter", false)),
206
+ disable: _get(header.filter, "button.disable", false),
207
+ },
208
+ card: {
209
+ display: _get(header.filter, "card.display", true),
210
+ addFilter: _get(header.filter, "card.addFilter", true),
211
+ editFilter: _get(header.filter, "card.editFilter", true),
212
+ removeFilter: _get(header.filter, "card.removeFilter", true),
213
+ },
214
+ };
215
+ cfg.panel.styles = cfg.panel.styles || {};
216
+ const ctx = {
217
+ config: {
218
+ id: cfg.id,
219
+ data: cfg.data,
220
+ type: cfg.type,
221
+ domain: cfg.domain,
222
+ model: getAttribute(cfg, "model"),
223
+ tab_id: getAttribute(cfg, "tab_id"),
224
+ app_id: getAttribute(cfg, "app_id"),
225
+ api_key: getAttribute(cfg, "api_key"),
226
+ user_id: getAttribute(cfg, "user_id"),
227
+ view_id: getAttribute(cfg, "view_id"),
228
+ page_id: getAttribute(cfg, "page_id"),
229
+ chart_id: getAttribute(cfg, "chart_id"),
230
+ qv_token: getAttribute(cfg, "qv_token"),
231
+ qrvey_id: getAttribute(cfg, "qrvey_id"),
232
+ question: getAttribute(cfg, "question"),
233
+ metric_id: getAttribute(cfg, "metric_id"),
234
+ summary_id: getAttribute(cfg, "summary_id"),
235
+ formulaType: _get(cfg, "question.formulaType"),
236
+ summary_type: getAttribute(cfg, "summary_type"),
237
+ custom_tokens: getAttribute(cfg, "custom_tokens"),
238
+ section: getAttribute(cfg, "section") || "ANYWHERE",
239
+ panel_view: getAttribute(cfg, "panel_view") || "ANYWHERE",
240
+ previewFilters: cfg.previewFilters || [],
241
+ filterData: !isEmpty(cfg.filterData)
242
+ ? cfg.filterData
243
+ : { scopes: [], version: FILTER_STRUCTURE_VERSION },
244
+ i18n: cfg.i18n,
245
+ visibleFilters: {},
246
+ appliedFilters: {},
247
+ customDrillLogic: [],
248
+ isFromAN: cfg.isFromAN,
249
+ editable: cfg.editable,
250
+ inBuilder: cfg.inBuilder,
251
+ clickable: cfg.clickable,
252
+ userFilters: cfg.userFilters,
253
+ customdrill: cfg.customdrill,
254
+ widgetConfig: cfg.widgetConfig,
255
+ drilldowns: cfg.drilldowns || {},
256
+ filterPermissions: cfg.filterPermissions,
257
+ chartBuilderConfig: cfg.chartBuilderConfig,
258
+ other_config: getAttribute(cfg, "other_config"),
259
+ predefined_filters: getAttribute(cfg, "predefined_filters"),
260
+ locale: getLang((_a = cfg === null || cfg === void 0 ? void 0 : cfg.i18n) === null || _a === void 0 ? void 0 : _a.locale) || cfg.locale,
261
+ lang: chooseLang(cfg),
262
+ panel: {
263
+ header: {
264
+ menu: header.menu,
265
+ filter: filterSettings,
266
+ draggable: header.draggable,
267
+ title_prefix: header.title_prefix,
268
+ fit_panel: header.fit_panel || false,
269
+ visible: _hasProperty(header, "visible") ? header.visible : true,
270
+ ui: {
271
+ isFiltered: false,
272
+ isDisplayReady: false,
273
+ isScrollableXY: false,
274
+ },
275
+ externalDownload: header.externalDownload,
276
+ },
277
+ body: {
278
+ popup: body.popup,
279
+ tooltip: body.tooltip,
280
+ hasTimeout: cfg.type === "CHART",
281
+ hasOverlay: _hasProperty(body, "hasOverlay") ? body.hasOverlay : true,
282
+ stylesTheme: {
283
+ original_match_color: _get(cfg, "panel.styles.match_color", _get(cfg, "stylesTheme.match_color")),
284
+ match_color: undefined,
285
+ },
286
+ ui: {
287
+ isLoading: true,
288
+ settingsStyle: cfg.panel.styles,
289
+ timeoutMessage: `Calculating ${(cfg.type || "").toLowerCase()}. This process may take a while.`,
290
+ },
291
+ },
292
+ footer: {
293
+ visible: _hasProperty(footer, "visible") ? footer.visible : false,
294
+ },
295
+ },
296
+ },
297
+ data: {},
298
+ scopes: {},
299
+ baseConfig: {},
300
+ customdrills: [],
301
+ };
302
+ ctx.baseConfig = {
303
+ pb_version: cfg.pb_version,
304
+ lang: ctx.config.lang,
305
+ domain: ctx.config.domain,
306
+ app_id: ctx.config.app_id,
307
+ api_key: ctx.config.api_key,
308
+ user_id: ctx.config.user_id,
309
+ qrvey_id: ctx.config.qrvey_id,
310
+ qv_token: ctx.config.qv_token,
311
+ custom_tokens: ctx.config.custom_tokens,
312
+ };
313
+ ctx.scopes = getAvailableScopes(Object.assign(Object.assign({}, getAvailableScopesIDsByConfig(ctx.config)), { predefinedScopes: [{ label: FILTER_SCOPE.DATA, id: ctx.config.qrvey_id }] }));
314
+ return ctx;
315
+ }
316
+ function updateDimensionsByChart(data, model) {
317
+ var _a, _b, _c, _d;
318
+ if (!((_a = data === null || data === void 0 ? void 0 : data.globalSettings) === null || _a === void 0 ? void 0 : _a.chartVersion) &&
319
+ ((_b = data === null || data === void 0 ? void 0 : data.globalSettings) === null || _b === void 0 ? void 0 : _b.match_colors)) {
320
+ data.globalSettings.match_colors = false;
321
+ }
322
+ if (((_c = data === null || data === void 0 ? void 0 : data.globalSettings) === null || _c === void 0 ? void 0 : _c.match_colors) &&
323
+ hasMinorVersion(((_d = data === null || data === void 0 ? void 0 : data.globalSettings) === null || _d === void 0 ? void 0 : _d.chartVersion) || "1.0", "2.0")) {
324
+ data.globalSettings.match_colors = false;
325
+ data.globalSettings.chartVersion = "2.0";
326
+ }
327
+ const questions = _get(model, "questions.data");
328
+ if (!isEmpty(questions)) {
329
+ if (!isEmpty(_get(data, "chart.fields"))) {
330
+ Object.keys(data.chart.fields).forEach((field) => {
331
+ data.chart.fields[field].forEach((column, index) => {
332
+ const question = questions.find((q) => q.id === column.data.id);
333
+ if (!isEmpty(question) && question.text !== column.data.text) {
334
+ if (column.data.text === column.data.label)
335
+ data.chart.fields[field][index].data.label = question.text;
336
+ if (column.data.text === column.label)
337
+ data.chart.fields[field][index].label = question.text;
338
+ data.chart.fields[field][index].data.text = question.text;
339
+ }
340
+ });
341
+ });
342
+ }
343
+ if (!isEmpty(_get(data, "layerList"))) {
344
+ data.layerList.forEach((layer, index) => {
345
+ if (!isEmpty(layer.category)) {
346
+ const question = questions.find((q) => q.id === layer.category.id);
347
+ if (!isEmpty(question)) {
348
+ data.layerList[index].category.text = question.text;
349
+ }
350
+ }
351
+ if (!isEmpty(layer.value)) {
352
+ const question = questions.find((q) => q.id === layer.value.id);
353
+ if (!isEmpty(question)) {
354
+ data.layerList[index].value.text = question.text;
355
+ }
356
+ }
357
+ if (!isEmpty(_get(layer, "multiserie.serie"))) {
358
+ const question = questions.find((q) => q.id === layer.multiserie.serie.id);
359
+ if (!isEmpty(question)) {
360
+ data.layerList[index].multiserie.serie.text = question.text;
361
+ }
362
+ }
363
+ });
364
+ }
365
+ if (!isEmpty(_get(data, "v2.dimensions"))) {
366
+ Object.keys(data.v2.dimensions).forEach((dimension) => {
367
+ data.v2.dimensions[dimension].forEach((column, index) => {
368
+ const question = questions.find((q) => q.id === column.id);
369
+ if (!isEmpty(question) && question.text !== column.text) {
370
+ if (column.text === column.label)
371
+ data.v2.dimensions[dimension][index].label = question.text;
372
+ data.v2.dimensions[dimension][index].text = question.text;
373
+ }
374
+ });
375
+ });
376
+ }
377
+ }
378
+ return data;
379
+ }
380
+ export function configMetricData(metricObj //
381
+ ) {
382
+ var _a, _b;
383
+ const body = {};
384
+ const data = metricObj.data;
385
+ try {
386
+ metricObj.logic = FDToLogic(Object.assign({}, excludeFiltersByAggregateColumn((_a = metricObj === null || metricObj === void 0 ? void 0 : metricObj.defaultFilters) === null || _a === void 0 ? void 0 : _a.data)));
387
+ body.logic = (_b = metricObj.logic) !== null && _b !== void 0 ? _b : {};
388
+ body.qrveyid = data.dataSet.qrveyid;
389
+ body.apptype = data.dataSet.appType;
390
+ body.valueDetails = {
391
+ id: data.value.id,
392
+ aggType: data.valueAggregate.label,
393
+ dataType: data.value.type,
394
+ property: data.value.property,
395
+ };
396
+ }
397
+ catch (e) {
398
+ return false;
399
+ }
400
+ if (data.dateColumn) {
401
+ const dateColum = data.dateColumn.id;
402
+ const timeZoneOffset = 0;
403
+ // TIME PERIOD
404
+ try {
405
+ const timePeriod = data.timePeriod.label;
406
+ body.timePeriodDetails = {
407
+ id: dateColum,
408
+ type: timePeriod,
409
+ dataType: data.dateColumn.type,
410
+ timeZoneOffset,
411
+ };
412
+ if (timePeriod === "CUSTOM_RANGE") {
413
+ const type = data.timePeriodCustomRange.label;
414
+ body.timePeriodDetails.customRangeType = type;
415
+ body.timePeriodDetails.range = {};
416
+ if ("AFTER" === type) {
417
+ if (!data.timePeriodDate)
418
+ throw 0;
419
+ body.timePeriodDetails.range.from = data.timePeriodDate;
420
+ }
421
+ else if ("BEFORE" === type) {
422
+ if (!data.timePeriodDate)
423
+ throw 0;
424
+ body.timePeriodDetails.range.to = data.timePeriodDate;
425
+ }
426
+ else {
427
+ if (!data.timePeriodDate || !data.timePeriodEndDate)
428
+ throw 0;
429
+ body.timePeriodDetails.range.from = data.timePeriodDate;
430
+ body.timePeriodDetails.range.to = data.timePeriodEndDate;
431
+ }
432
+ }
433
+ }
434
+ catch (e) {
435
+ delete body.timePeriodDetails;
436
+ }
437
+ try {
438
+ const comparison = data.comparison.label;
439
+ body.comparisonDetails = {
440
+ id: dateColum,
441
+ type: comparison,
442
+ dataType: data.dateColumn.type,
443
+ timeZoneOffset,
444
+ };
445
+ if (comparison === "CUSTOM_RANGE") {
446
+ const type = data.comparisonCustomRange.label;
447
+ body.comparisonDetails.customRangeType = type;
448
+ body.comparisonDetails.range = {};
449
+ if ("AFTER" === type) {
450
+ if (!data.comparisonDate)
451
+ throw 0;
452
+ body.comparisonDetails.range.from = data.comparisonDate;
453
+ }
454
+ else if ("BEFORE" === type) {
455
+ if (!data.comparisonDate)
456
+ throw 0;
457
+ body.comparisonDetails.range.to = data.comparisonDate;
458
+ }
459
+ else {
460
+ if (!data.comparisonDate || !data.comparisonEndDate)
461
+ throw 0;
462
+ body.comparisonDetails.range.from = data.comparisonDate;
463
+ body.comparisonDetails.range.to = data.comparisonEndDate;
464
+ }
465
+ }
466
+ }
467
+ catch (e) {
468
+ delete body.comparisonDetails;
469
+ }
470
+ }
471
+ return body;
472
+ }
473
+ export function configChartData(chartData, model, setup) {
474
+ var _a, _b;
475
+ const ctx = configSetup(setup);
476
+ chartData = updateDimensionsByChart(chartData, model);
477
+ if (!chartData.defaultFilters)
478
+ chartData.defaultFilters = {};
479
+ if (!isEmpty(chartData.defaultFilters) &&
480
+ isEmpty(_get(chartData.defaultFilters, "data.version"))) {
481
+ chartData.defaultFilters = {
482
+ data: adaptFilterData(chartData.defaultFilters),
483
+ };
484
+ }
485
+ const logic = FDToLogic(Object.assign({}, excludeFiltersByAggregateColumn(chartData.defaultFilters.data)));
486
+ const chart = {
487
+ data: chartData,
488
+ type: chartData.layerList[0].type,
489
+ };
490
+ if (isNotValid(_get(chartData, "layerList[0]")))
491
+ return;
492
+ let drillData = {};
493
+ const customData = {};
494
+ const drilldowns = ctx.config.drilldowns[getDrilldownId(ctx, chartData)] || [];
495
+ if (drilldowns.length > 0)
496
+ drillData = Object.assign({}, drilldowns[drilldowns.length - 1]);
497
+ if (drillData.chart)
498
+ customData.chart = Object.assign({}, drillData.chart);
499
+ if (((_a = drillData.filters) === null || _a === void 0 ? void 0 : _a.length) > 0)
500
+ customData.filters = [...drillData.filters];
501
+ const validEndPoint = validChartTypeWithEndPoint(chart.type);
502
+ const bodyRequest = customData.chart || chartData;
503
+ const filterRequest = (_b = UIToOldLogic(chartData.defaultFilters.data)) === null || _b === void 0 ? void 0 : _b.logic;
504
+ const charts = validEndPoint
505
+ ? makeBodyRequestU(bodyRequest, filterRequest, true)
506
+ : makeBodyRequest(bodyRequest, filterRequest);
507
+ return {
508
+ charts,
509
+ logic,
510
+ };
511
+ }
@@ -0,0 +1,14 @@
1
+ import { OLD_IFilterLogic, IFBFilterAggregate } from "../../filters";
2
+ export declare function getDrilldownId(ctx: any, data: any): string;
3
+ export declare function getPivotBody(layer: any, body: any): any;
4
+ export declare function getValidSortingType(body: any): "Value" | "Label";
5
+ export declare function getCategoryBody(layer: any, body: any): any;
6
+ export declare function getComboBody(layer: any, body: any, filters: any, newModel?: boolean): any;
7
+ export declare function getSmallMultipleBody(layer: any, body: any): any;
8
+ export declare function getAggFiltersResults(logics?: OLD_IFilterLogic[], summaries?: any[]): IFBFilterAggregate;
9
+ export declare function getRefenceBody(layer: any): any;
10
+ export declare function getTrendBody(layer: any): any;
11
+ export declare function getRefenceBodyU(layer: any, body: any): any;
12
+ export declare function getLayerBody(layer: any, dateGroup: any, qrveyid: any): any;
13
+ export declare function setDateGroup(column: any, body: any, obj: any): void;
14
+ export declare function getSummariesBody(layer: any, body: any): any;