@qrvey/utils 1.1.4 → 1.1.8

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 (43) hide show
  1. package/README.md +693 -665
  2. package/dist/cjs/filters/adapters/FDToFlatUI.js +2 -1
  3. package/dist/cjs/filters/adapters/FDToUI.js +2 -1
  4. package/dist/cjs/filters/adapters/UIToFlatUI.js +2 -1
  5. package/dist/cjs/filters/adapters/UIToOldLogic.js +2 -1
  6. package/dist/cjs/filters/adapters/adaptFilterValues.d.ts +8 -0
  7. package/dist/cjs/filters/adapters/adaptFilterValues.js +18 -0
  8. package/dist/cjs/filters/adapters/flatUIToFD.js +2 -1
  9. package/dist/cjs/filters/adapters/flatUIToUI.js +2 -1
  10. package/dist/cjs/filters/adapters/logicToFlatUI.js +0 -3
  11. package/dist/cjs/filters/helpers/common/getFilterColumnLabel.js +1 -1
  12. package/dist/cjs/filters/helpers/common/getFiltersByParams.js +1 -1
  13. package/dist/cjs/filters/helpers/common/mergeFilters.js +12 -12
  14. package/dist/cjs/filters/interfaces/common/IFSValueRelativeDate.d.ts +1 -1
  15. package/dist/cjs/qrvey/getPropertyLabel.js +1 -1
  16. package/dist/filters/adapters/FDToFlatUI.js +2 -1
  17. package/dist/filters/adapters/FDToUI.js +2 -1
  18. package/dist/filters/adapters/UIToFlatUI.js +2 -1
  19. package/dist/filters/adapters/UIToOldLogic.js +2 -1
  20. package/dist/filters/adapters/adaptFilterValues.d.ts +8 -0
  21. package/dist/filters/adapters/adaptFilterValues.js +14 -0
  22. package/dist/filters/adapters/flatUIToFD.js +2 -1
  23. package/dist/filters/adapters/flatUIToUI.js +2 -1
  24. package/dist/filters/adapters/logicToFlatUI.js +0 -3
  25. package/dist/filters/helpers/common/getFilterColumnLabel.js +2 -2
  26. package/dist/filters/helpers/common/getFiltersByParams.js +1 -1
  27. package/dist/filters/helpers/common/mergeFilters.js +12 -12
  28. package/dist/filters/interfaces/common/IFSValueRelativeDate.d.ts +1 -1
  29. package/dist/qrvey/getPropertyLabel.js +1 -1
  30. package/package.json +1 -1
  31. package/src/filters/adapters/FDToFlatUI.ts +2 -1
  32. package/src/filters/adapters/FDToUI.ts +2 -0
  33. package/src/filters/adapters/UIToFlatUI.ts +2 -1
  34. package/src/filters/adapters/UIToOldLogic.ts +2 -1
  35. package/src/filters/adapters/adaptFilterValues.ts +17 -0
  36. package/src/filters/adapters/flatUIToFD.ts +2 -1
  37. package/src/filters/adapters/flatUIToUI.ts +2 -1
  38. package/src/filters/adapters/logicToFlatUI.ts +0 -3
  39. package/src/filters/helpers/common/getFilterColumnLabel.ts +2 -2
  40. package/src/filters/helpers/common/getFiltersByParams.ts +1 -1
  41. package/src/filters/helpers/common/mergeFilters.ts +12 -12
  42. package/src/filters/interfaces/common/IFSValueRelativeDate.ts +1 -1
  43. package/src/qrvey/getPropertyLabel.ts +1 -1
@@ -4,6 +4,7 @@ exports.FDToFlatUI = void 0;
4
4
  const general_1 = require("../../general");
5
5
  const helpers_1 = require("../helpers");
6
6
  const adaptDateGroupingProperty_1 = require("./adaptDateGroupingProperty");
7
+ const adaptFilterValues_1 = require("./adaptFilterValues");
7
8
  /**
8
9
  * Generates a Flattened UI filter structure from Filter Data structure.
9
10
  * @param filterData The filter data object.
@@ -84,7 +85,7 @@ function FD21ToFlatUI(scopes = [], datasetsInfo = []) {
84
85
  property: property,
85
86
  uiValues: helpers_1.getUIValues(filter),
86
87
  validator: filter.validator,
87
- values: filter.values,
88
+ values: adaptFilterValues_1.adaptFilterValues(filter),
88
89
  };
89
90
  uFilters.push(uFilter);
90
91
  });
@@ -5,6 +5,7 @@ const _1 = require(".");
5
5
  const general_1 = require("../../general");
6
6
  const constants_1 = require("../constants");
7
7
  const helpers_1 = require("../helpers");
8
+ const adaptFilterValues_1 = require("./adaptFilterValues");
8
9
  /**
9
10
  * Generates a UI filter structure from Filter Data structure.
10
11
  * @param filterData The filter data object.
@@ -60,7 +61,7 @@ function FD21ToUI(scopes = [], section = "ANYWHERE" /* ANYWHERE */, enabled = tr
60
61
  outputFormat: general_1._get(datasetInfo, 'outputFormat'),
61
62
  qrveyid: filter.column.qrveyid,
62
63
  type: (columnInfo === null || columnInfo === void 0 ? void 0 : columnInfo.type) || filter.column.type,
63
- }, property, uiValues: helpers_1.getUIValues(filter) });
64
+ }, property, uiValues: helpers_1.getUIValues(filter), values: adaptFilterValues_1.adaptFilterValues(filter) });
64
65
  }) });
65
66
  }) })));
66
67
  return ufData;
@@ -4,6 +4,7 @@ exports.UIToFlatUI = void 0;
4
4
  const _1 = require(".");
5
5
  const general_1 = require("../../general");
6
6
  const helpers_1 = require("../helpers");
7
+ const adaptFilterValues_1 = require("./adaptFilterValues");
7
8
  /**
8
9
  * Generates a Flattened UI filter structure from UI Filter Data structure.
9
10
  * @param filterData The UI filter data object.
@@ -83,7 +84,7 @@ function UI21ToFlatUI(scopes = [], datasetsInfo = []) {
83
84
  property,
84
85
  uiValues: helpers_1.getUIValues(filter),
85
86
  validator: filter.validator,
86
- values: filter.values,
87
+ values: adaptFilterValues_1.adaptFilterValues(filter),
87
88
  };
88
89
  uFilters.push(uFilter);
89
90
  });
@@ -4,6 +4,7 @@ exports.UIToOldLogic = void 0;
4
4
  const _1 = require(".");
5
5
  const general_1 = require("../../general");
6
6
  const helpers_1 = require("../helpers");
7
+ const adaptFilterValues_1 = require("./adaptFilterValues");
7
8
  const flatUIToOldLogic_1 = require("./flatUIToOldLogic");
8
9
  const UIToFlatUI_1 = require("./UIToFlatUI");
9
10
  function UIToOldLogic(uFilterData, flattedMethod = true) {
@@ -141,6 +142,6 @@ const getFilterDetail = (filter, scope, dataset) => {
141
142
  section: filter.extras.section,
142
143
  uiValue: helpers_1.getUIValues(filter, true),
143
144
  validator: filter.validator,
144
- values: filter.values
145
+ values: adaptFilterValues_1.adaptFilterValues(filter)
145
146
  };
146
147
  };
@@ -0,0 +1,8 @@
1
+ import { IFSFilter, IFValue } from "..";
2
+ /**
3
+ * [TODO: For 2022, eliminate this adapter]
4
+ * Gets an adapted filter value array. Validates the enabled property and sets
5
+ * @param filter The filter
6
+ * @returns A new value array with the filled properties.
7
+ */
8
+ export declare function adaptFilterValues(filter: IFSFilter): IFValue[];
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.adaptFilterValues = void 0;
4
+ const __1 = require("../..");
5
+ /**
6
+ * [TODO: For 2022, eliminate this adapter]
7
+ * Gets an adapted filter value array. Validates the enabled property and sets
8
+ * @param filter The filter
9
+ * @returns A new value array with the filled properties.
10
+ */
11
+ function adaptFilterValues(filter) {
12
+ const setValue = value => (Object.assign(Object.assign({}, value), { enabled: __1.isEmpty(value.enabled) ? true : value.enabled }));
13
+ if (filter.column.type === __1.COLUMN.RANKING && __1.isEmpty(filter.column.aggregate)) {
14
+ return filter.values.map(rValues => rValues.map(setValue));
15
+ }
16
+ return filter.values.map(setValue);
17
+ }
18
+ exports.adaptFilterValues = adaptFilterValues;
@@ -4,6 +4,7 @@ exports.flatUIToFD = void 0;
4
4
  const _1 = require(".");
5
5
  const general_1 = require("../../general");
6
6
  const constants_1 = require("../constants");
7
+ const adaptFilterValues_1 = require("./adaptFilterValues");
7
8
  /**
8
9
  * Generates a filter data structure from the flatttened UI filters.
9
10
  * @param uFilters Array of flattened filters from UI
@@ -102,6 +103,6 @@ function buildFilter(uFilter) {
102
103
  operator: uFilter.operator,
103
104
  property,
104
105
  validator: uFilter.validator,
105
- values: uFilter.values,
106
+ values: adaptFilterValues_1.adaptFilterValues(uFilter),
106
107
  };
107
108
  }
@@ -5,6 +5,7 @@ const _1 = require(".");
5
5
  const general_1 = require("../../general");
6
6
  const constants_1 = require("../constants");
7
7
  const helpers_1 = require("../helpers");
8
+ const adaptFilterValues_1 = require("./adaptFilterValues");
8
9
  /**
9
10
  * Generates a UI filter data structure from the flatttened UI filters.
10
11
  * @param uFilters Array of flattened filters from UI
@@ -117,6 +118,6 @@ function buildFilter(uFilter) {
117
118
  property,
118
119
  uiValues: helpers_1.getUIValues(uFilter),
119
120
  validator: uFilter.validator,
120
- values: uFilter.values,
121
+ values: adaptFilterValues_1.adaptFilterValues(uFilter),
121
122
  };
122
123
  }
@@ -25,9 +25,6 @@ function logicToFlatUI(logics = []) {
25
25
  buildFilterByExpression(expression2, scopeItem, uFilters);
26
26
  }) : buildFilterByExpression(expression1, scopeItem, uFilters);
27
27
  });
28
- // (filterItem.expressions[0].expressions as OLD_IFilterExpression[]).forEach((expression: OLD_IFilterExpression) => {
29
- // buildFilterByExpression(expression, scopeItem, uFilters);
30
- // });
31
28
  });
32
29
  }
33
30
  });
@@ -13,7 +13,7 @@ function getFilterColumnLabel(column) {
13
13
  if (isComplexColumn_1.isComplexColumn(column) && column.property != null)
14
14
  labels.push(constants_1.COLUMN_COMPLEX_VALUE[column.property].shortLabel);
15
15
  if (column.aggregate != null)
16
- labels.push(column.aggregate);
16
+ labels.push(constants_1.AGGREGATE_ABBREVIATION[column.aggregate]);
17
17
  if (column.calculation != null)
18
18
  labels.push(column.calculation);
19
19
  return labels.length > 0 ? `(${labels.join(' - ')})` : '';
@@ -37,7 +37,7 @@ function getFiltersByParams(filterData, params, settings) {
37
37
  return Object.assign(Object.assign({}, filter), { values: filter.values.map((value) => {
38
38
  if (Array.isArray(value) && value.length > 0) {
39
39
  const rankingValues = value;
40
- rankingValues.map(rValue => {
40
+ return rankingValues.map(rValue => {
41
41
  if (!general_1._hasProperty(params, 'enableds') || !general_1._hasProperty(params.enableds, 'values') || params.enableds.values === rValue.enabled)
42
42
  return rValue;
43
43
  }).filter(Boolean);
@@ -116,28 +116,28 @@ function mergeValues(filter1, filter2, overwrite = false) {
116
116
  let newValues = [];
117
117
  if (!overwrite) {
118
118
  if (isInValidator_1.isInValidator(filter1.validator)) {
119
- newValues = filter1.values.reduce((values, value1) => {
120
- const value2Index = filter2.values.findIndex(value2 => value2.anchor === value1.anchor && value2.cursor === value1.cursor && value2.includeCurrent === value1.includeCurrent && value2.isCalendarDate === value1.isCalendarDate && value2.number === value1.number && value2.unit === value1.unit);
121
- if (value2Index === -1) {
122
- values.push(filter2.values[value2Index]);
119
+ newValues = filter2.values.reduce((values, value2) => {
120
+ const value1Index = filter1.values.findIndex(value1 => value2.anchor === value1.anchor && value2.cursor === value1.cursor && value2.includeCurrent === value1.includeCurrent && value2.isCalendarDate === value1.isCalendarDate && value2.number === value1.number && value2.unit === value1.unit);
121
+ if (value1Index === -1) {
122
+ values.push(value2);
123
123
  }
124
124
  return values;
125
125
  }, filter1.values);
126
126
  }
127
127
  else if (isRangeValidator_1.isRangeValidator(filter1.validator)) {
128
- newValues = filter1.values.reduce((values, value1) => {
129
- const value2Index = filter2.values.findIndex(value2 => value2.max === value1.max && value2.min === value1.min);
130
- if (value2Index === -1) {
131
- values.push(filter2.values[value2Index]);
128
+ newValues = filter2.values.reduce((values, value2) => {
129
+ const value1Index = filter1.values.findIndex(value1 => value2.max === value1.max && value2.min === value1.min);
130
+ if (value1Index === -1) {
131
+ values.push(value2);
132
132
  }
133
133
  return values;
134
134
  }, filter1.values);
135
135
  }
136
136
  else if (isRegularValidator_1.isRegularValidator(filter1.validator) || isNullValidator_1.isNullValidator(filter1.validator)) {
137
- newValues = filter1.values.reduce((values, value1) => {
138
- const value2Index = filter2.values.findIndex(value2 => value2.imageUrl === value1.imageUrl && value2.value === value1.value);
139
- if (value2Index === -1) {
140
- values.push(filter2.values[value2Index]);
137
+ newValues = filter2.values.reduce((values, value2) => {
138
+ const value1Index = filter1.values.findIndex(value1 => value2.imageUrl === value1.imageUrl && value2.value === value1.value);
139
+ if (value1Index === -1) {
140
+ values.push(value2);
141
141
  }
142
142
  return values;
143
143
  }, filter1.values);
@@ -1,4 +1,4 @@
1
1
  import { RelativeStatement } from "../../../date";
2
2
  export declare type IFSValueRelativeDate = {
3
- enabled: boolean;
3
+ enabled?: boolean;
4
4
  } & RelativeStatement;
@@ -6,7 +6,7 @@ const __1 = require("..");
6
6
  function getPropertyLabel(column, property) {
7
7
  var _a;
8
8
  let propertyLabel;
9
- const propertyValues = __1.COLUMN_PROPERTY_VALUE[_1.isDateColumn(column) ? column.type + '-complete' : column.type];
9
+ const propertyValues = __1.COLUMN_PROPERTY_VALUE[_1.isDateColumn(column) ? 'DATE-complete' : column.type];
10
10
  if (!__1.isEmpty(propertyValues))
11
11
  propertyLabel = (_a = propertyValues.find(pValue => pValue.value === property)) === null || _a === void 0 ? void 0 : _a.label;
12
12
  return propertyLabel;
@@ -1,6 +1,7 @@
1
1
  import { cloneDeep, isEmpty, _get } from "../../general";
2
2
  import { getUIValues } from "../helpers";
3
3
  import { adaptDateGroupingProperty } from "./adaptDateGroupingProperty";
4
+ import { adaptFilterValues } from "./adaptFilterValues";
4
5
  /**
5
6
  * Generates a Flattened UI filter structure from Filter Data structure.
6
7
  * @param filterData The filter data object.
@@ -80,7 +81,7 @@ function FD21ToFlatUI(scopes = [], datasetsInfo = []) {
80
81
  property: property,
81
82
  uiValues: getUIValues(filter),
82
83
  validator: filter.validator,
83
- values: filter.values,
84
+ values: adaptFilterValues(filter),
84
85
  };
85
86
  uFilters.push(uFilter);
86
87
  });
@@ -2,6 +2,7 @@ import { adaptDateGroupingProperty } from ".";
2
2
  import { cloneDeep, isEmpty, _get } from "../../general";
3
3
  import { FILTER_STRUCTURE_VERSION } from "../constants";
4
4
  import { getUIValues } from "../helpers";
5
+ import { adaptFilterValues } from "./adaptFilterValues";
5
6
  /**
6
7
  * Generates a UI filter structure from Filter Data structure.
7
8
  * @param filterData The filter data object.
@@ -56,7 +57,7 @@ function FD21ToUI(scopes = [], section = "ANYWHERE" /* ANYWHERE */, enabled = tr
56
57
  outputFormat: _get(datasetInfo, 'outputFormat'),
57
58
  qrveyid: filter.column.qrveyid,
58
59
  type: (columnInfo === null || columnInfo === void 0 ? void 0 : columnInfo.type) || filter.column.type,
59
- }, property, uiValues: getUIValues(filter) });
60
+ }, property, uiValues: getUIValues(filter), values: adaptFilterValues(filter) });
60
61
  }) });
61
62
  }) })));
62
63
  return ufData;
@@ -1,6 +1,7 @@
1
1
  import { adaptDateGroupingProperty } from ".";
2
2
  import { cloneDeep, isEmpty } from "../../general";
3
3
  import { getUIValues } from "../helpers";
4
+ import { adaptFilterValues } from "./adaptFilterValues";
4
5
  /**
5
6
  * Generates a Flattened UI filter structure from UI Filter Data structure.
6
7
  * @param filterData The UI filter data object.
@@ -79,7 +80,7 @@ function UI21ToFlatUI(scopes = [], datasetsInfo = []) {
79
80
  property,
80
81
  uiValues: getUIValues(filter),
81
82
  validator: filter.validator,
82
- values: filter.values,
83
+ values: adaptFilterValues(filter),
83
84
  };
84
85
  uFilters.push(uFilter);
85
86
  });
@@ -1,6 +1,7 @@
1
1
  import { adaptDateGroupingProperty } from ".";
2
2
  import { cloneDeep, isEmpty } from "../../general";
3
3
  import { getBackendGroupValue, getBackendProperty, getBackendValidator, getBackendValues, getUIValues } from "../helpers";
4
+ import { adaptFilterValues } from "./adaptFilterValues";
4
5
  import { flatUIToOldLogic } from "./flatUIToOldLogic";
5
6
  import { UIToFlatUI } from "./UIToFlatUI";
6
7
  export function UIToOldLogic(uFilterData, flattedMethod = true) {
@@ -137,6 +138,6 @@ const getFilterDetail = (filter, scope, dataset) => {
137
138
  section: filter.extras.section,
138
139
  uiValue: getUIValues(filter, true),
139
140
  validator: filter.validator,
140
- values: filter.values
141
+ values: adaptFilterValues(filter)
141
142
  };
142
143
  };
@@ -0,0 +1,8 @@
1
+ import { IFSFilter, IFValue } from "..";
2
+ /**
3
+ * [TODO: For 2022, eliminate this adapter]
4
+ * Gets an adapted filter value array. Validates the enabled property and sets
5
+ * @param filter The filter
6
+ * @returns A new value array with the filled properties.
7
+ */
8
+ export declare function adaptFilterValues(filter: IFSFilter): IFValue[];
@@ -0,0 +1,14 @@
1
+ import { COLUMN, isEmpty } from "../..";
2
+ /**
3
+ * [TODO: For 2022, eliminate this adapter]
4
+ * Gets an adapted filter value array. Validates the enabled property and sets
5
+ * @param filter The filter
6
+ * @returns A new value array with the filled properties.
7
+ */
8
+ export function adaptFilterValues(filter) {
9
+ const setValue = value => (Object.assign(Object.assign({}, value), { enabled: isEmpty(value.enabled) ? true : value.enabled }));
10
+ if (filter.column.type === COLUMN.RANKING && isEmpty(filter.column.aggregate)) {
11
+ return filter.values.map(rValues => rValues.map(setValue));
12
+ }
13
+ return filter.values.map(setValue);
14
+ }
@@ -1,6 +1,7 @@
1
1
  import { adaptDateGroupingProperty } from ".";
2
2
  import { isEmpty } from "../../general";
3
3
  import { FILTER_STRUCTURE_VERSION } from "../constants";
4
+ import { adaptFilterValues } from "./adaptFilterValues";
4
5
  /**
5
6
  * Generates a filter data structure from the flatttened UI filters.
6
7
  * @param uFilters Array of flattened filters from UI
@@ -98,6 +99,6 @@ function buildFilter(uFilter) {
98
99
  operator: uFilter.operator,
99
100
  property,
100
101
  validator: uFilter.validator,
101
- values: uFilter.values,
102
+ values: adaptFilterValues(uFilter),
102
103
  };
103
104
  }
@@ -2,6 +2,7 @@ import { adaptDateGroupingProperty } from ".";
2
2
  import { isEmpty, getLastIndexFromArray } from "../../general";
3
3
  import { FILTER_STRUCTURE_VERSION } from "../constants";
4
4
  import { getUIValues } from "../helpers";
5
+ import { adaptFilterValues } from "./adaptFilterValues";
5
6
  /**
6
7
  * Generates a UI filter data structure from the flatttened UI filters.
7
8
  * @param uFilters Array of flattened filters from UI
@@ -113,6 +114,6 @@ function buildFilter(uFilter) {
113
114
  property,
114
115
  uiValues: getUIValues(uFilter),
115
116
  validator: uFilter.validator,
116
- values: uFilter.values,
117
+ values: adaptFilterValues(uFilter),
117
118
  };
118
119
  }
@@ -22,9 +22,6 @@ export function logicToFlatUI(logics = []) {
22
22
  buildFilterByExpression(expression2, scopeItem, uFilters);
23
23
  }) : buildFilterByExpression(expression1, scopeItem, uFilters);
24
24
  });
25
- // (filterItem.expressions[0].expressions as OLD_IFilterExpression[]).forEach((expression: OLD_IFilterExpression) => {
26
- // buildFilterByExpression(expression, scopeItem, uFilters);
27
- // });
28
25
  });
29
26
  }
30
27
  });
@@ -1,5 +1,5 @@
1
1
  import { isComplexColumn } from "../../../qrvey/isComplexColumn";
2
- import { COLUMN_COMPLEX_VALUE } from "../../../constants";
2
+ import { AGGREGATE_ABBREVIATION, COLUMN_COMPLEX_VALUE } from "../../../constants";
3
3
  /**
4
4
  * Get an string of the properties of the given filter column.
5
5
  * @param column The filter column
@@ -10,7 +10,7 @@ export function getFilterColumnLabel(column) {
10
10
  if (isComplexColumn(column) && column.property != null)
11
11
  labels.push(COLUMN_COMPLEX_VALUE[column.property].shortLabel);
12
12
  if (column.aggregate != null)
13
- labels.push(column.aggregate);
13
+ labels.push(AGGREGATE_ABBREVIATION[column.aggregate]);
14
14
  if (column.calculation != null)
15
15
  labels.push(column.calculation);
16
16
  return labels.length > 0 ? `(${labels.join(' - ')})` : '';
@@ -34,7 +34,7 @@ export function getFiltersByParams(filterData, params, settings) {
34
34
  return Object.assign(Object.assign({}, filter), { values: filter.values.map((value) => {
35
35
  if (Array.isArray(value) && value.length > 0) {
36
36
  const rankingValues = value;
37
- rankingValues.map(rValue => {
37
+ return rankingValues.map(rValue => {
38
38
  if (!_hasProperty(params, 'enableds') || !_hasProperty(params.enableds, 'values') || params.enableds.values === rValue.enabled)
39
39
  return rValue;
40
40
  }).filter(Boolean);
@@ -112,28 +112,28 @@ function mergeValues(filter1, filter2, overwrite = false) {
112
112
  let newValues = [];
113
113
  if (!overwrite) {
114
114
  if (isInValidator(filter1.validator)) {
115
- newValues = filter1.values.reduce((values, value1) => {
116
- const value2Index = filter2.values.findIndex(value2 => value2.anchor === value1.anchor && value2.cursor === value1.cursor && value2.includeCurrent === value1.includeCurrent && value2.isCalendarDate === value1.isCalendarDate && value2.number === value1.number && value2.unit === value1.unit);
117
- if (value2Index === -1) {
118
- values.push(filter2.values[value2Index]);
115
+ newValues = filter2.values.reduce((values, value2) => {
116
+ const value1Index = filter1.values.findIndex(value1 => value2.anchor === value1.anchor && value2.cursor === value1.cursor && value2.includeCurrent === value1.includeCurrent && value2.isCalendarDate === value1.isCalendarDate && value2.number === value1.number && value2.unit === value1.unit);
117
+ if (value1Index === -1) {
118
+ values.push(value2);
119
119
  }
120
120
  return values;
121
121
  }, filter1.values);
122
122
  }
123
123
  else if (isRangeValidator(filter1.validator)) {
124
- newValues = filter1.values.reduce((values, value1) => {
125
- const value2Index = filter2.values.findIndex(value2 => value2.max === value1.max && value2.min === value1.min);
126
- if (value2Index === -1) {
127
- values.push(filter2.values[value2Index]);
124
+ newValues = filter2.values.reduce((values, value2) => {
125
+ const value1Index = filter1.values.findIndex(value1 => value2.max === value1.max && value2.min === value1.min);
126
+ if (value1Index === -1) {
127
+ values.push(value2);
128
128
  }
129
129
  return values;
130
130
  }, filter1.values);
131
131
  }
132
132
  else if (isRegularValidator(filter1.validator) || isNullValidator(filter1.validator)) {
133
- newValues = filter1.values.reduce((values, value1) => {
134
- const value2Index = filter2.values.findIndex(value2 => value2.imageUrl === value1.imageUrl && value2.value === value1.value);
135
- if (value2Index === -1) {
136
- values.push(filter2.values[value2Index]);
133
+ newValues = filter2.values.reduce((values, value2) => {
134
+ const value1Index = filter1.values.findIndex(value1 => value2.imageUrl === value1.imageUrl && value2.value === value1.value);
135
+ if (value1Index === -1) {
136
+ values.push(value2);
137
137
  }
138
138
  return values;
139
139
  }, filter1.values);
@@ -1,4 +1,4 @@
1
1
  import { RelativeStatement } from "../../../date";
2
2
  export declare type IFSValueRelativeDate = {
3
- enabled: boolean;
3
+ enabled?: boolean;
4
4
  } & RelativeStatement;
@@ -3,7 +3,7 @@ import { COLUMN_PROPERTY_VALUE, isEmpty } from "..";
3
3
  export function getPropertyLabel(column, property) {
4
4
  var _a;
5
5
  let propertyLabel;
6
- const propertyValues = COLUMN_PROPERTY_VALUE[isDateColumn(column) ? column.type + '-complete' : column.type];
6
+ const propertyValues = COLUMN_PROPERTY_VALUE[isDateColumn(column) ? 'DATE-complete' : column.type];
7
7
  if (!isEmpty(propertyValues))
8
8
  propertyLabel = (_a = propertyValues.find(pValue => pValue.value === property)) === null || _a === void 0 ? void 0 : _a.label;
9
9
  return propertyLabel;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/utils",
3
- "version": "1.1.4",
3
+ "version": "1.1.8",
4
4
  "description": "Helper, Utils for all Qrvey Projects",
5
5
  "homepage": "https://bitbucket.org/qrvey/qrvey_utils/wiki/Home",
6
6
  "main": "dist/index.js",
@@ -3,6 +3,7 @@ import { IQrveyColumn, IQrveyDataset } from "../../interfaces/Qrvey.Interface";
3
3
  import { getUIValues } from "../helpers";
4
4
  import { IFSData, IFSScope, IFUFlattenedFilter } from "../interfaces";
5
5
  import { adaptDateGroupingProperty } from "./adaptDateGroupingProperty";
6
+ import { adaptFilterValues } from "./adaptFilterValues";
6
7
 
7
8
  /**
8
9
  * Generates a Flattened UI filter structure from Filter Data structure.
@@ -93,7 +94,7 @@ function FD21ToFlatUI(scopes: IFSScope[] = [], datasetsInfo: IQrveyDataset[] = [
93
94
  property: property,
94
95
  uiValues: getUIValues(filter),
95
96
  validator: filter.validator,
96
- values: filter.values,
97
+ values: adaptFilterValues(filter),
97
98
  };
98
99
  uFilters.push(uFilter);
99
100
  });
@@ -4,6 +4,7 @@ import { IQrveyColumn, IQrveyDataset } from "../../interfaces";
4
4
  import { FILTER_SECTION, FILTER_STRUCTURE_VERSION } from "../constants";
5
5
  import { getUIValues } from "../helpers";
6
6
  import { IFSData, IFSection, IFSScope, IFUData, IFUScope } from "../interfaces";
7
+ import { adaptFilterValues } from "./adaptFilterValues";
7
8
 
8
9
  /**
9
10
  * Generates a UI filter structure from Filter Data structure.
@@ -70,6 +71,7 @@ import { IFSData, IFSection, IFSScope, IFUData, IFUScope } from "../interfaces";
70
71
  },
71
72
  property,
72
73
  uiValues: getUIValues(filter),
74
+ values: adaptFilterValues(filter),
73
75
  };
74
76
  })
75
77
  };
@@ -3,6 +3,7 @@ import { cloneDeep, isEmpty } from "../../general";
3
3
  import { IQrveyColumn, IQrveyDataset } from "../../interfaces/Qrvey.Interface";
4
4
  import { getUIValues } from "../helpers";
5
5
  import { IFUData, IFUFlattenedFilter, IFUScope } from "../interfaces";
6
+ import { adaptFilterValues } from "./adaptFilterValues";
6
7
 
7
8
  /**
8
9
  * Generates a Flattened UI filter structure from UI Filter Data structure.
@@ -92,7 +93,7 @@ function UI21ToFlatUI(scopes: IFUScope[] = [], datasetsInfo: IQrveyDataset[] = [
92
93
  property,
93
94
  uiValues: getUIValues(filter),
94
95
  validator: filter.validator,
95
- values: filter.values,
96
+ values: adaptFilterValues(filter),
96
97
  };
97
98
  uFilters.push(uFilter);
98
99
  });
@@ -3,6 +3,7 @@ import { cloneDeep, isEmpty } from "../../general";
3
3
  import { FILTER_OPERATOR } from "../constants";
4
4
  import { getBackendGroupValue, getBackendProperty, getBackendValidator, getBackendValues, getUIValues } from "../helpers";
5
5
  import { IFSection, IFUData, IFUDataset, IFUFilter, IFUScope, OLD_IFilterData, OLD_IFilterDetail, OLD_IFilterExpression, OLD_IFilterFilters, OLD_IFilterLogic } from "../interfaces";
6
+ import { adaptFilterValues } from "./adaptFilterValues";
6
7
  import { flatUIToOldLogic } from "./flatUIToOldLogic";
7
8
  import { UIToFlatUI } from "./UIToFlatUI";
8
9
 
@@ -146,6 +147,6 @@ const getFilterDetail = (filter: IFUFilter, scope: IFUScope, dataset: IFUDataset
146
147
  section: filter.extras.section,
147
148
  uiValue: getUIValues(filter, true),
148
149
  validator: filter.validator,
149
- values: filter.values
150
+ values: adaptFilterValues(filter)
150
151
  };
151
152
  };
@@ -0,0 +1,17 @@
1
+ import { IFSFilter, IFSValue, IFSValueRange, IFSValueRanking, IFSValueRelativeDate, IFValue } from "..";
2
+ import {COLUMN, isEmpty } from "../..";
3
+
4
+ /**
5
+ * [TODO: For 2022, eliminate this adapter]
6
+ * Gets an adapted filter value array. Validates the enabled property and sets
7
+ * @param filter The filter
8
+ * @returns A new value array with the filled properties.
9
+ */
10
+ export function adaptFilterValues(filter: IFSFilter): IFValue[] {
11
+ const setValue = value => ({ ...value, enabled: isEmpty(value.enabled) ? true : value.enabled });
12
+
13
+ if (filter.column.type === COLUMN.RANKING && isEmpty(filter.column.aggregate)) {
14
+ return (filter.values as IFSValueRanking[][]).map(rValues => rValues.map(setValue));
15
+ }
16
+ return (filter.values as IFSValue[] | IFSValueRange[] | IFSValueRelativeDate[]).map(setValue);
17
+ }
@@ -2,6 +2,7 @@ import { adaptDateGroupingProperty } from ".";
2
2
  import { isEmpty } from "../../general";
3
3
  import { FILTER_SECTION, FILTER_STRUCTURE_VERSION } from "../constants";
4
4
  import { IFSData, IFSDataset, IFSection, IFSFilter, IFSScope, IFUFlattenedFilter } from "../interfaces";
5
+ import { adaptFilterValues } from "./adaptFilterValues";
5
6
 
6
7
  /**
7
8
  * Generates a filter data structure from the flatttened UI filters.
@@ -114,6 +115,6 @@ function buildFilter(uFilter: IFUFlattenedFilter): IFSFilter {
114
115
  operator: uFilter.operator,
115
116
  property,
116
117
  validator: uFilter.validator,
117
- values: uFilter.values,
118
+ values: adaptFilterValues(uFilter),
118
119
  };
119
120
  }
@@ -3,6 +3,7 @@ import { isEmpty, getLastIndexFromArray } from "../../general";
3
3
  import { FILTER_SECTION, FILTER_STRUCTURE_VERSION } from "../constants";
4
4
  import { getUIValues } from "../helpers";
5
5
  import { IFSection, IFUData, IFUDataset, IFUFilter, IFUFlattenedFilter, IFUScope } from "../interfaces";
6
+ import { adaptFilterValues } from "./adaptFilterValues";
6
7
 
7
8
  /**
8
9
  * Generates a UI filter data structure from the flatttened UI filters.
@@ -128,6 +129,6 @@ function buildFilter(uFilter: IFUFlattenedFilter): IFUFilter {
128
129
  property,
129
130
  uiValues: getUIValues(uFilter),
130
131
  validator: uFilter.validator,
131
- values: uFilter.values,
132
+ values: adaptFilterValues(uFilter),
132
133
  };
133
134
  }
@@ -25,9 +25,6 @@ export function logicToFlatUI(logics: OLD_IFilterLogic[] = []): IFUFlattenedFilt
25
25
  buildFilterByExpression(expression2, scopeItem, uFilters);
26
26
  }) : buildFilterByExpression(expression1, scopeItem, uFilters);
27
27
  });
28
- // (filterItem.expressions[0].expressions as OLD_IFilterExpression[]).forEach((expression: OLD_IFilterExpression) => {
29
- // buildFilterByExpression(expression, scopeItem, uFilters);
30
- // });
31
28
  });
32
29
  }
33
30
  });
@@ -1,6 +1,6 @@
1
1
  import { isComplexColumn } from "../../../qrvey/isComplexColumn";
2
2
  import { IFUColumn } from "../../interfaces";
3
- import { COLUMN_COMPLEX_VALUE } from "../../../constants";
3
+ import { AGGREGATE_ABBREVIATION, COLUMN_COMPLEX_VALUE } from "../../../constants";
4
4
 
5
5
  /**
6
6
  * Get an string of the properties of the given filter column.
@@ -10,7 +10,7 @@ import { COLUMN_COMPLEX_VALUE } from "../../../constants";
10
10
  export function getFilterColumnLabel(column: IFUColumn): string {
11
11
  const labels: string[] = [];
12
12
  if (isComplexColumn(column as any) && column.property != null) labels.push(COLUMN_COMPLEX_VALUE[column.property].shortLabel);
13
- if (column.aggregate != null) labels.push(column.aggregate);
13
+ if (column.aggregate != null) labels.push(AGGREGATE_ABBREVIATION[column.aggregate]);
14
14
  if (column.calculation != null) labels.push(column.calculation);
15
15
 
16
16
  return labels.length > 0 ? `(${labels.join(' - ')})` : '';
@@ -42,7 +42,7 @@ export function getFiltersByParams(filterData: IFSData | IFUData, params: IFSPar
42
42
  values: filter.values.map((value: IFValue) => {
43
43
  if (Array.isArray(value) && value.length > 0) {
44
44
  const rankingValues = value as IFSValueRanking[];
45
- rankingValues.map(rValue => {
45
+ return rankingValues.map(rValue => {
46
46
  if (!_hasProperty(params, 'enableds') || !_hasProperty(params.enableds, 'values') || params.enableds.values === rValue.enabled) return rValue;
47
47
  }).filter(Boolean);
48
48
  } else {