@qrvey/utils 1.1.2-0 → 1.1.4
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.
- package/README.md +458 -378
- package/dist/cjs/constants/COLUMN_PROPERTY.d.ts +6 -6
- package/dist/cjs/constants/COLUMN_PROPERTY_VALUE.d.ts +1 -2
- package/dist/cjs/constants/COLUMN_PROPERTY_VALUE.js +3 -8
- package/dist/cjs/date/constants/DATE_PROPERTY_VALUE.d.ts +6 -6
- package/dist/cjs/date/constants/DATE_PROPERTY_VALUE.js +6 -6
- package/dist/cjs/date/constants/DATE_P_PROPERTIES.js +6 -6
- package/dist/cjs/date/constants/DATE_P_VALUES.js +3 -3
- package/dist/cjs/date/constants/DATE_TIME_P_VALUES.js +3 -3
- package/dist/cjs/date/constants/DATE_TIME_VALUES.js +3 -3
- package/dist/cjs/date/constants/DATE_VALUES.d.ts +6 -0
- package/dist/cjs/date/constants/DATE_VALUES.js +10 -0
- package/dist/cjs/filters/adapters/FDToFlatUI.js +3 -1
- package/dist/cjs/filters/adapters/FDToUI.js +3 -1
- package/dist/cjs/filters/adapters/UIToFlatUI.js +3 -1
- package/dist/cjs/filters/adapters/UIToOldLogic.js +3 -1
- package/dist/cjs/filters/adapters/adaptDateGroupingProperty.d.ts +8 -0
- package/dist/cjs/filters/adapters/adaptDateGroupingProperty.js +19 -0
- package/dist/cjs/filters/adapters/adaptFilterData.js +1 -1
- package/dist/cjs/filters/adapters/flatUIToFD.js +3 -1
- package/dist/cjs/filters/adapters/flatUIToOldLogic.js +1 -5
- package/dist/cjs/filters/adapters/flatUIToUI.js +3 -1
- package/dist/cjs/filters/adapters/index.d.ts +1 -0
- package/dist/cjs/filters/adapters/index.js +1 -0
- package/dist/cjs/filters/adapters/logicToFlatUI.js +77 -63
- package/dist/cjs/filters/helpers/backend/getBackendGroupValue.js +4 -3
- package/dist/cjs/filters/helpers/backend/getBackendProperty.js +1 -5
- package/dist/cjs/filters/helpers/ui/getFilterPropertyLabel.d.ts +7 -0
- package/dist/cjs/filters/helpers/ui/getFilterPropertyLabel.js +13 -0
- package/dist/cjs/filters/helpers/ui/index.d.ts +1 -0
- package/dist/cjs/filters/helpers/ui/index.js +1 -0
- package/dist/cjs/general/array/filterNestedTree.d.ts +5 -2
- package/dist/cjs/general/array/filterNestedTree.js +13 -5
- package/dist/cjs/general/mix/getTag.d.ts +7 -0
- package/dist/cjs/general/mix/getTag.js +16 -0
- package/dist/cjs/general/mix/index.d.ts +1 -0
- package/dist/cjs/general/mix/index.js +1 -0
- package/dist/cjs/general/mix/isEmpty.js +8 -4
- package/dist/cjs/general/mix/isNull.js +1 -1
- package/dist/cjs/general/mix/randomId.d.ts +6 -3
- package/dist/cjs/general/mix/randomId.js +24 -7
- package/dist/cjs/general/mix/size.d.ts +5 -5
- package/dist/cjs/general/mix/size.js +9 -6
- package/dist/cjs/general/object/get.d.ts +1 -1
- package/dist/cjs/general/object/getAttribute.d.ts +9 -2
- package/dist/cjs/general/object/getAttribute.js +39 -8
- package/dist/cjs/general/object/hasProperty.d.ts +1 -1
- package/dist/cjs/general/object/hasProperty.js +10 -2
- package/dist/cjs/general/object/index.d.ts +1 -0
- package/dist/cjs/general/object/index.js +1 -0
- package/dist/cjs/general/object/isObject.js +2 -1
- package/dist/cjs/general/object/objectCopy.d.ts +7 -0
- package/dist/cjs/general/object/objectCopy.js +32 -0
- package/dist/cjs/general/string/capitalize.d.ts +3 -3
- package/dist/cjs/general/string/capitalize.js +6 -3
- package/dist/cjs/qrvey/getPropertyLabel.d.ts +2 -0
- package/dist/cjs/qrvey/getPropertyLabel.js +14 -0
- package/dist/cjs/qrvey/index.d.ts +1 -0
- package/dist/cjs/qrvey/index.js +1 -0
- package/dist/constants/COLUMN_PROPERTY.d.ts +6 -6
- package/dist/constants/COLUMN_PROPERTY_VALUE.d.ts +1 -2
- package/dist/constants/COLUMN_PROPERTY_VALUE.js +4 -9
- package/dist/date/constants/DATE_PROPERTY_VALUE.d.ts +6 -6
- package/dist/date/constants/DATE_PROPERTY_VALUE.js +6 -6
- package/dist/date/constants/DATE_P_PROPERTIES.js +6 -6
- package/dist/date/constants/DATE_P_VALUES.js +3 -3
- package/dist/date/constants/DATE_TIME_P_VALUES.js +3 -3
- package/dist/date/constants/DATE_TIME_VALUES.js +3 -3
- package/dist/date/constants/DATE_VALUES.d.ts +6 -0
- package/dist/date/constants/DATE_VALUES.js +7 -0
- package/dist/filters/adapters/FDToFlatUI.js +3 -1
- package/dist/filters/adapters/FDToUI.js +3 -1
- package/dist/filters/adapters/UIToFlatUI.js +3 -1
- package/dist/filters/adapters/UIToOldLogic.js +3 -1
- package/dist/filters/adapters/adaptDateGroupingProperty.d.ts +8 -0
- package/dist/filters/adapters/adaptDateGroupingProperty.js +15 -0
- package/dist/filters/adapters/adaptFilterData.js +1 -1
- package/dist/filters/adapters/flatUIToFD.js +3 -1
- package/dist/filters/adapters/flatUIToOldLogic.js +1 -5
- package/dist/filters/adapters/flatUIToUI.js +3 -1
- package/dist/filters/adapters/index.d.ts +1 -0
- package/dist/filters/adapters/index.js +1 -0
- package/dist/filters/adapters/logicToFlatUI.js +79 -65
- package/dist/filters/helpers/backend/getBackendGroupValue.js +4 -3
- package/dist/filters/helpers/backend/getBackendProperty.js +2 -6
- package/dist/filters/helpers/ui/getFilterPropertyLabel.d.ts +7 -0
- package/dist/filters/helpers/ui/getFilterPropertyLabel.js +9 -0
- package/dist/filters/helpers/ui/index.d.ts +1 -0
- package/dist/filters/helpers/ui/index.js +1 -0
- package/dist/general/array/filterNestedTree.d.ts +5 -2
- package/dist/general/array/filterNestedTree.js +13 -5
- package/dist/general/mix/getTag.d.ts +7 -0
- package/dist/general/mix/getTag.js +12 -0
- package/dist/general/mix/index.d.ts +1 -0
- package/dist/general/mix/index.js +1 -0
- package/dist/general/mix/isEmpty.js +8 -4
- package/dist/general/mix/isNull.js +1 -1
- package/dist/general/mix/randomId.d.ts +6 -3
- package/dist/general/mix/randomId.js +24 -7
- package/dist/general/mix/size.d.ts +5 -5
- package/dist/general/mix/size.js +9 -6
- package/dist/general/object/get.d.ts +1 -1
- package/dist/general/object/getAttribute.d.ts +9 -2
- package/dist/general/object/getAttribute.js +39 -8
- package/dist/general/object/hasProperty.d.ts +1 -1
- package/dist/general/object/hasProperty.js +8 -0
- package/dist/general/object/index.d.ts +1 -0
- package/dist/general/object/index.js +1 -0
- package/dist/general/object/isObject.js +2 -1
- package/dist/general/object/objectCopy.d.ts +7 -0
- package/dist/general/object/objectCopy.js +28 -0
- package/dist/general/string/capitalize.d.ts +3 -3
- package/dist/general/string/capitalize.js +6 -3
- package/dist/qrvey/getPropertyLabel.d.ts +2 -0
- package/dist/qrvey/getPropertyLabel.js +10 -0
- package/dist/qrvey/index.d.ts +1 -0
- package/dist/qrvey/index.js +1 -0
- package/package.json +1 -1
- package/src/constants/COLUMN_PROPERTY.ts +7 -7
- package/src/constants/COLUMN_PROPERTY_VALUE.ts +4 -10
- package/src/date/constants/DATE_P_VALUES.ts +3 -3
- package/src/date/constants/DATE_TIME_P_VALUES.ts +3 -3
- package/src/date/constants/DATE_TIME_VALUES.ts +3 -3
- package/src/date/constants/DATE_VALUES.ts +9 -0
- package/src/filters/adapters/FDToFlatUI.ts +3 -1
- package/src/filters/adapters/FDToUI.ts +4 -0
- package/src/filters/adapters/UIToFlatUI.ts +3 -1
- package/src/filters/adapters/UIToOldLogic.ts +4 -1
- package/src/filters/adapters/adaptDateGroupingProperty.ts +18 -0
- package/src/filters/adapters/adaptFilterData.ts +1 -1
- package/src/filters/adapters/flatUIToFD.ts +4 -1
- package/src/filters/adapters/flatUIToOldLogic.ts +1 -3
- package/src/filters/adapters/flatUIToUI.ts +4 -1
- package/src/filters/adapters/index.ts +1 -0
- package/src/filters/adapters/logicToFlatUI.ts +87 -70
- package/src/filters/helpers/backend/getAggFiltersBySummaryIndex.ts +1 -1
- package/src/filters/helpers/backend/getBackendGroupValue.ts +4 -3
- package/src/filters/helpers/backend/getBackendProperty.ts +2 -4
- package/src/filters/helpers/ui/getFilterPropertyLabel.ts +11 -0
- package/src/filters/helpers/ui/index.ts +1 -0
- package/src/general/array/filterNestedTree.ts +13 -4
- package/src/general/mix/getTag.ts +12 -0
- package/src/general/mix/index.ts +1 -0
- package/src/general/mix/isEmpty.ts +9 -4
- package/src/general/mix/isNull.ts +1 -1
- package/src/general/mix/randomId.ts +24 -7
- package/src/general/mix/size.ts +10 -6
- package/src/general/object/get.ts +1 -1
- package/src/general/object/getAttribute.ts +47 -9
- package/src/general/object/hasProperty.ts +10 -1
- package/src/general/object/index.ts +1 -0
- package/src/general/object/isObject.ts +3 -1
- package/src/general/object/objectCopy.ts +35 -0
- package/src/general/string/capitalize.ts +7 -3
- package/src/qrvey/getPropertyLabel.ts +9 -0
- package/src/qrvey/index.ts +1 -0
- package/test/general/array/filterNestedTree.test.js +115 -0
- package/test/general/mix/getTag.test.js +101 -0
- package/test/general/mix/isEmpty.test.js +30 -24
- package/test/general/mix/isNull.test.js +72 -0
- package/test/general/mix/randomId.test.js +134 -0
- package/test/general/mix/size.test.js +87 -0
- package/test/general/object/cloneDeep.test.js +8 -16
- package/test/general/object/getAttribute.test.js +316 -0
- package/test/general/object/hasProperty.test.js +103 -0
- package/test/general/object/objectCopy.test.js +105 -0
- package/test/general/string/capitalize.test.js +87 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// FROM Logic structure = Old logic structure (v2.0)
|
|
2
2
|
// TO Logic structure = Cleaner logic structure
|
|
3
3
|
|
|
4
|
+
import { adaptDateGroupingProperty } from ".";
|
|
4
5
|
import { COLUMN } from "../../constants";
|
|
5
|
-
import { isEmpty, _get } from "../../general";
|
|
6
|
+
import { isEmpty, _get, _hasProperty } from "../../general";
|
|
6
7
|
import { FILTER_BACKEND_VALIDATOR, FILTER_SCOPE, FILTER_VALIDATOR_VALUE } from "../constants";
|
|
7
|
-
import { getFilterid, getUIValues, isNullValidator } from "../helpers";
|
|
8
|
+
import { getFilterid, getUIValues, isNullValidator, } from "../helpers";
|
|
8
9
|
import { IFSValueRanking, IFUFlattenedFilter, OLD_IFilterDetail, OLD_IFilterExpression, OLD_IFilterLogic } from "../interfaces";
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -19,81 +20,97 @@ export function logicToFlatUI(logics: OLD_IFilterLogic[] = []): IFUFlattenedFilt
|
|
|
19
20
|
logics.forEach(scopeItem => {
|
|
20
21
|
if (scopeItem.filters.length > 0) {
|
|
21
22
|
scopeItem.filters.forEach(filterItem => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const scopeid = scopeItem.scope !== FILTER_SCOPE.GLOBAL ? _get(scopeItem, 'uiExtras.scopeid') : undefined;
|
|
27
|
-
const info = !isEmpty(uiExtras.info) ? { icon: uiExtras.info.icon, label: uiExtras.info.label } : undefined;
|
|
28
|
-
const uFilter: IFUFlattenedFilter = {
|
|
29
|
-
collapsed: uiExtras.collapsed,
|
|
30
|
-
column: {
|
|
31
|
-
id: uiExtras.column?.id,
|
|
32
|
-
formulaType: uiExtras.column?.formulaType,
|
|
33
|
-
linkid: uiExtras.column?.linkid,
|
|
34
|
-
linked: uiExtras.column?.linked,
|
|
35
|
-
qrveyid: uiExtras.column?.qrveyid,
|
|
36
|
-
aggregate: uiExtras.column?.aggregate?.label,
|
|
37
|
-
calculation: uiExtras.column?.calculation?.value,
|
|
38
|
-
label: uiExtras.column?.text,
|
|
39
|
-
property: uiExtras.column.property,
|
|
40
|
-
sorting: uiExtras.column.sorting,
|
|
41
|
-
outputFormat: uiExtras.column?.outputFormat,
|
|
42
|
-
type: uiExtras.column?.type,
|
|
43
|
-
},
|
|
44
|
-
dateSection: uiExtras.dateSection,
|
|
45
|
-
displayed: true,
|
|
46
|
-
enabled: expression.enabled,
|
|
47
|
-
extras: {
|
|
48
|
-
...uiExtras.extras,
|
|
49
|
-
panelid: uiExtras.panelid,
|
|
50
|
-
filterLabel: uiExtras.panelName,
|
|
51
|
-
info,
|
|
52
|
-
scopeid,
|
|
53
|
-
scope: scopeItem.scope,
|
|
54
|
-
section: uiExtras.section,
|
|
55
|
-
scopeInfo: {
|
|
56
|
-
collapsed: scopeItem.uiExtras?.collapsed,
|
|
57
|
-
enabled: scopeItem.enabled,
|
|
58
|
-
displayed: true,
|
|
59
|
-
scope: scopeItem.scope,
|
|
60
|
-
scopeid,
|
|
61
|
-
},
|
|
62
|
-
dataset: {
|
|
63
|
-
collapsed: false,
|
|
64
|
-
enabled: true,
|
|
65
|
-
displayed: true,
|
|
66
|
-
qrveyid: uiExtras.column?.qrveyid,
|
|
67
|
-
label: uiExtras.column?.dataset?.name,
|
|
68
|
-
linkid: uiExtras.column?.linkid,
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
filterid: undefined,
|
|
72
|
-
lookupDisplayIndex: uiExtras.lookupDisplayIndex,
|
|
73
|
-
nullValues: uiExtras.nullValues,
|
|
74
|
-
operator: uiExtras.operator,
|
|
75
|
-
property: uiExtras.property,
|
|
76
|
-
uiValues: getUIValues(uiExtras as any),
|
|
77
|
-
validator: uiExtras.validator,
|
|
78
|
-
values: getValues(uiExtras),
|
|
79
|
-
};
|
|
80
|
-
uFilter.filterid = getFilterid(uFilter);
|
|
81
|
-
uFilters.push(uFilter);
|
|
82
|
-
}
|
|
83
|
-
if (uiExtras.column.type === COLUMN.RANKING && isEmpty(uiExtras.column.aggregate)) {
|
|
84
|
-
// Restore uiExtras.values array into single IFilterDetail object values array
|
|
85
|
-
if (index > -1) uFilters[index].values.push(uiExtras.values[0]);
|
|
86
|
-
const refinedRankingValues = refineRankingValues((index > -1 ? uFilters[index].values : uiExtras.values ) as IFSValueRanking[][], uiExtras.uiValue);
|
|
87
|
-
if (index > -1) uFilters[index].values = refinedRankingValues;
|
|
88
|
-
else uFilters[uFilters.length - 1].values = refinedRankingValues;
|
|
89
|
-
}
|
|
23
|
+
filterItem.expressions.forEach((expression1: OLD_IFilterExpression) => {
|
|
24
|
+
_hasProperty(expression1, 'expressions') ? expression1.expressions.forEach((expression2: OLD_IFilterExpression) => {
|
|
25
|
+
buildFilterByExpression(expression2, scopeItem, uFilters);
|
|
26
|
+
}) : buildFilterByExpression(expression1, scopeItem, uFilters);
|
|
90
27
|
});
|
|
28
|
+
// (filterItem.expressions[0].expressions as OLD_IFilterExpression[]).forEach((expression: OLD_IFilterExpression) => {
|
|
29
|
+
// buildFilterByExpression(expression, scopeItem, uFilters);
|
|
30
|
+
// });
|
|
91
31
|
});
|
|
92
32
|
}
|
|
93
33
|
});
|
|
94
34
|
return uFilters;
|
|
95
35
|
}
|
|
96
36
|
|
|
37
|
+
function buildFilterByExpression(expression: OLD_IFilterExpression, scopeItem: OLD_IFilterLogic, uFilters: IFUFlattenedFilter[]) {
|
|
38
|
+
const uiExtras = expression.uiExtras;
|
|
39
|
+
const index = uiExtras.column.type === COLUMN.RANKING ? getFilter(uFilters, expression.uiExtras, true) as number : -1;
|
|
40
|
+
if (index === -1 && (!uiExtras.nullValues || expression.validationType !== FILTER_BACKEND_VALIDATOR.IS_NULL)) {
|
|
41
|
+
const uFilter: IFUFlattenedFilter = getFilterByExpression(expression, scopeItem);
|
|
42
|
+
uFilter.filterid = getFilterid(uFilter);
|
|
43
|
+
uFilters.push(uFilter);
|
|
44
|
+
}
|
|
45
|
+
if (uiExtras.column.type === COLUMN.RANKING && isEmpty(uiExtras.column.aggregate)) {
|
|
46
|
+
// Restore uiExtras.values array into single IFilterDetail object values array
|
|
47
|
+
if (index > -1) uFilters[index].values.push(uiExtras.values[0]);
|
|
48
|
+
const refinedRankingValues = refineRankingValues((index > -1 ? uFilters[index].values : uiExtras.values ) as IFSValueRanking[][], uiExtras.uiValue);
|
|
49
|
+
if (index > -1) uFilters[index].values = refinedRankingValues;
|
|
50
|
+
else uFilters[uFilters.length - 1].values = refinedRankingValues;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function getFilterByExpression(expression: OLD_IFilterExpression, scopeItem: OLD_IFilterLogic) {
|
|
55
|
+
const uiExtras = expression.uiExtras;
|
|
56
|
+
const scopeid = scopeItem.scope !== FILTER_SCOPE.GLOBAL ? _get(scopeItem, 'uiExtras.scopeid') : undefined;
|
|
57
|
+
const info = !isEmpty(uiExtras.info) ? { icon: uiExtras.info.icon, label: uiExtras.info.label } : undefined;
|
|
58
|
+
const property = adaptDateGroupingProperty(uiExtras.property);
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
collapsed: uiExtras.collapsed,
|
|
62
|
+
column: {
|
|
63
|
+
id: uiExtras.column?.id,
|
|
64
|
+
formulaType: uiExtras.column?.formulaType,
|
|
65
|
+
linkid: uiExtras.column?.linkid,
|
|
66
|
+
linked: uiExtras.column?.linked,
|
|
67
|
+
qrveyid: uiExtras.column?.qrveyid,
|
|
68
|
+
aggregate: uiExtras.column?.aggregate?.label,
|
|
69
|
+
calculation: uiExtras.column?.calculation?.value,
|
|
70
|
+
label: uiExtras.column?.text,
|
|
71
|
+
property: uiExtras.column.property,
|
|
72
|
+
sorting: uiExtras.column.sorting,
|
|
73
|
+
outputFormat: uiExtras.column?.outputFormat,
|
|
74
|
+
type: uiExtras.column?.type,
|
|
75
|
+
},
|
|
76
|
+
dateSection: uiExtras.dateSection,
|
|
77
|
+
displayed: true,
|
|
78
|
+
enabled: expression.enabled,
|
|
79
|
+
extras: {
|
|
80
|
+
...uiExtras.extras,
|
|
81
|
+
panelid: uiExtras.panelid,
|
|
82
|
+
filterLabel: uiExtras.panelName,
|
|
83
|
+
info,
|
|
84
|
+
scopeid,
|
|
85
|
+
scope: scopeItem.scope,
|
|
86
|
+
section: uiExtras.section,
|
|
87
|
+
scopeInfo: {
|
|
88
|
+
collapsed: scopeItem.uiExtras?.collapsed,
|
|
89
|
+
enabled: scopeItem.enabled,
|
|
90
|
+
displayed: true,
|
|
91
|
+
scope: scopeItem.scope,
|
|
92
|
+
scopeid,
|
|
93
|
+
},
|
|
94
|
+
dataset: {
|
|
95
|
+
collapsed: false,
|
|
96
|
+
enabled: true,
|
|
97
|
+
displayed: true,
|
|
98
|
+
qrveyid: uiExtras.column?.qrveyid,
|
|
99
|
+
label: uiExtras.column?.dataset?.name,
|
|
100
|
+
linkid: uiExtras.column?.linkid,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
filterid: undefined,
|
|
104
|
+
lookupDisplayIndex: uiExtras.lookupDisplayIndex,
|
|
105
|
+
nullValues: uiExtras.nullValues,
|
|
106
|
+
operator: uiExtras.operator,
|
|
107
|
+
property,
|
|
108
|
+
uiValues: getUIValues(uiExtras as any),
|
|
109
|
+
validator: uiExtras.validator,
|
|
110
|
+
values: getValues(uiExtras),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
97
114
|
function getValues(uiExtras: OLD_IFilterDetail) {
|
|
98
115
|
if (isNullValidator(uiExtras.validator) && isEmpty(uiExtras.values)) {
|
|
99
116
|
return [{ value: FILTER_VALIDATOR_VALUE[uiExtras.validator].label, enabled: uiExtras.uiValue[0].enabled != null ? uiExtras.uiValue[0].enabled : true }];
|
|
@@ -9,7 +9,7 @@ import { IFBFilterAggregate } from "../../interfaces";
|
|
|
9
9
|
*/
|
|
10
10
|
export function getAggFiltersBySummaryIndex(aggFilters: IFBFilterAggregate, summaryIndex: number): IFBFilterAggregate {
|
|
11
11
|
if (!aggFilters) return undefined;
|
|
12
|
-
const expressions = filterNestedTree(aggFilters.expressions, 'expressions', expression => {
|
|
12
|
+
const expressions = filterNestedTree(aggFilters.expressions as any, 'expressions', expression => {
|
|
13
13
|
const isSameSummary = expression.summaryIndex === summaryIndex;
|
|
14
14
|
if (isSameSummary) expression.summaryIndex = 0;
|
|
15
15
|
return isSameSummary;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { adaptDateGroupingProperty } from "../..";
|
|
1
2
|
import { isEmpty } from "../../../general";
|
|
2
3
|
import { isDateColumn } from "../../../qrvey/isDateColumn";
|
|
3
4
|
import { IFProperty, IFSFilter } from "../../interfaces";
|
|
4
|
-
import { arePropertiesDateP } from "../common";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Gets a group value for the backend logic structure
|
|
@@ -9,7 +9,8 @@ import { arePropertiesDateP } from "../common";
|
|
|
9
9
|
* @returns a property
|
|
10
10
|
*/
|
|
11
11
|
export function getBackendGroupValue(filter: IFSFilter): IFProperty {
|
|
12
|
-
if (
|
|
13
|
-
|
|
12
|
+
if (isEmpty(filter.column.aggregate) && isDateColumn(filter.column as any) && filter.property != null) {
|
|
13
|
+
const property = adaptDateGroupingProperty(filter.property);
|
|
14
|
+
return property;
|
|
14
15
|
}
|
|
15
16
|
}
|
|
@@ -2,7 +2,7 @@ import { COLUMN, COLUMN_PROPERTY } from "../../../constants";
|
|
|
2
2
|
import { isEmpty } from "../../../general";
|
|
3
3
|
import { isDateColumn } from "../../../qrvey/isDateColumn";
|
|
4
4
|
import { IFProperty, IFSFilter } from "../../interfaces";
|
|
5
|
-
import {
|
|
5
|
+
import { isNullValidator } from "../common";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Gets a property for the logic structure
|
|
@@ -11,10 +11,8 @@ import { arePropertiesDateP, isNullValidator } from "../common";
|
|
|
11
11
|
*/
|
|
12
12
|
export function getBackendProperty(filter: IFSFilter): IFProperty {
|
|
13
13
|
if (isEmpty(filter.column.aggregate)) {
|
|
14
|
-
if (isNullValidator(filter.validator)) {
|
|
14
|
+
if (isNullValidator(filter.validator) || isDateColumn(filter.column as any)) {
|
|
15
15
|
return undefined;
|
|
16
|
-
} else if (isDateColumn(filter.column as any)) {
|
|
17
|
-
return arePropertiesDateP(filter.column, filter.property) ? filter.property?.split('p&')[1] as IFProperty : undefined;
|
|
18
16
|
} else if (filter.column.type === COLUMN.EXPRESSION && filter.property != null) {
|
|
19
17
|
return undefined;
|
|
20
18
|
} else if (filter.column.type === COLUMN.LOOKUP && filter.property === COLUMN_PROPERTY.LOOKUP_DISPLAY && filter.lookupDisplayIndex != null) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IFSFilter, IFUFilter } from "../..";
|
|
2
|
+
import { getPropertyLabel } from "../../..";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Gets the label of the filter property
|
|
6
|
+
* @param filter The UI Filter
|
|
7
|
+
* @returns a string of the filter property label
|
|
8
|
+
*/
|
|
9
|
+
export function getFilterPropertyLabel(filter: IFUFilter | IFSFilter): string {
|
|
10
|
+
return getPropertyLabel(filter.column as any, filter.property);
|
|
11
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './excludeUIFiltersByAggregate';
|
|
2
2
|
export * from './excludeUIFlatFiltersByScopes';
|
|
3
|
+
export * from './getFilterPropertyLabel';
|
|
3
4
|
export * from './getOutputFormatByColumn';
|
|
4
5
|
export * from './getUIFlatFilterByParams';
|
|
5
6
|
export * from './getUIFlatFiltersByParams';
|
|
@@ -2,18 +2,27 @@ import { isEmpty } from "../mix";
|
|
|
2
2
|
import { cloneDeep } from "../object/cloneDeep";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Filters a nested tree array by a custom condition on the
|
|
5
|
+
* Filters a nested tree array by a custom condition on the last child node
|
|
6
|
+
* - If the given arguments are not valid, the function returns the first argument.
|
|
7
|
+
* - If the childArrKey is not matched in the object, the condition tries to resolve the filter anyway and returns an empty array.
|
|
8
|
+
* - If the condition is not fulfilled, the function returns a filtered array, probably a empty array inside of the child array
|
|
6
9
|
* @param arr nested tree array
|
|
7
10
|
* @param childArrKey property representing the children array on the nested tree
|
|
8
11
|
* @param condition function callback that determines if the filter is applied on the last child node of the nested tree
|
|
9
12
|
* @returns array filtered
|
|
10
13
|
*/
|
|
11
|
-
export function filterNestedTree(arr:
|
|
12
|
-
if (
|
|
14
|
+
export function filterNestedTree<T = any>(arr: T[] = [], childArrKey = '', condition: any = undefined): T[] {
|
|
15
|
+
if (!isValid(arr, childArrKey, condition)) return arr;
|
|
13
16
|
|
|
14
17
|
return cloneDeep(arr).filter(obj => {
|
|
15
|
-
const hasChildArr = Array.isArray(obj[childArrKey]) && obj[childArrKey].length;
|
|
18
|
+
const hasChildArr = Array.isArray(obj[childArrKey]) && obj[childArrKey].length > 0;
|
|
16
19
|
if (hasChildArr) obj[childArrKey] = filterNestedTree(obj[childArrKey], childArrKey, condition);
|
|
17
20
|
return hasChildArr || condition(obj);
|
|
18
21
|
});
|
|
19
22
|
}
|
|
23
|
+
|
|
24
|
+
function isValid<T = any>(arr: T[] = [], childArrKey = '', condition: any = undefined): boolean {
|
|
25
|
+
return (!isEmpty(arr) && Array.isArray(arr))
|
|
26
|
+
&& (!isEmpty(childArrKey) && typeof childArrKey === 'string')
|
|
27
|
+
&& (!isEmpty(condition) && typeof condition === "function");
|
|
28
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets the `toStringTag` of `value`.
|
|
3
|
+
*
|
|
4
|
+
* @param {*} value The value to query.
|
|
5
|
+
* @returns {string} Returns the `toStringTag`.
|
|
6
|
+
*/
|
|
7
|
+
export function getTag(value: any): string {
|
|
8
|
+
if (value == null) {
|
|
9
|
+
return value === undefined ? '[object Undefined]' : '[object Null]';
|
|
10
|
+
}
|
|
11
|
+
return Object.prototype.toString.call(value);
|
|
12
|
+
}
|
package/src/general/mix/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { getTag } from ".";
|
|
2
|
+
import { isObject } from "..";
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Validates if the given argument is empty
|
|
3
6
|
* @param variable the given variable
|
|
@@ -5,11 +8,13 @@
|
|
|
5
8
|
* @returns true: the given argument is empty; false: is not.
|
|
6
9
|
*/
|
|
7
10
|
export function isEmpty<T = any>(variable: T, includeFalsy = false): boolean {
|
|
8
|
-
return
|
|
9
|
-
|| variable == null
|
|
11
|
+
return variable == null
|
|
10
12
|
|| (typeof variable == 'number' && includeFalsy && (Number(variable) === 0 || Object.is(variable, -0) || isNaN(variable)))
|
|
11
|
-
|| (typeof variable == 'string' && variable ===
|
|
13
|
+
|| (typeof variable == 'string' && variable.length === 0)
|
|
12
14
|
|| (typeof variable == 'boolean' && includeFalsy && variable === false)
|
|
13
15
|
|| (Array.isArray(variable) && variable.length === 0)
|
|
14
|
-
|| (variable
|
|
16
|
+
|| ((getTag(variable) === '[object Map]' || getTag(variable) === '[object Set]') && (variable as any | Set<T>).size === 0)
|
|
17
|
+
|| (variable instanceof Date && isNaN(variable.valueOf()))
|
|
18
|
+
|| (typeof variable === 'function' && Object.prototype.toString.call(variable).indexOf("Function") === 0)
|
|
19
|
+
|| ((!(variable instanceof Date) && typeof variable !== 'function') && isObject(variable) && Object.entries(variable).length === 0);
|
|
15
20
|
}
|
|
@@ -1,14 +1,31 @@
|
|
|
1
|
+
import { isEmpty, isNull } from ".";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
4
|
+
* Creates a random string
|
|
5
|
+
* - If the first given argument is different than a length number, the variable is replaced by a default number
|
|
6
|
+
* - If the optional second given argument is passed the random string is permutated.
|
|
3
7
|
* @param {Number} length size of the generated string. Default 8
|
|
4
|
-
* @
|
|
8
|
+
* @param {Array} exclude collection of strings that is going to be excluded of the random string.
|
|
9
|
+
* @return {String} Random string
|
|
5
10
|
*/
|
|
6
|
-
export function randomId
|
|
11
|
+
export function randomId(length = 8, exclude: string[] = []): string {
|
|
12
|
+
if (typeof length !== 'number') length = 8;
|
|
13
|
+
if (isNull(exclude) || !Array.isArray(exclude)) exclude = [];
|
|
14
|
+
exclude = exclude.filter(e => typeof e === 'string');
|
|
15
|
+
|
|
7
16
|
const charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_';
|
|
17
|
+
const blackList = [];
|
|
8
18
|
let id = '';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
id
|
|
12
|
-
|
|
19
|
+
|
|
20
|
+
do {
|
|
21
|
+
if (!isEmpty(id) && !blackList.includes(id)) blackList.push(id);
|
|
22
|
+
id = '';
|
|
23
|
+
for (let i = 0; i < length; i++) {
|
|
24
|
+
const randPos = Math.floor(Math.random() * charSet.length);
|
|
25
|
+
id += charSet[randPos];
|
|
26
|
+
}
|
|
27
|
+
} while (exclude.length > 0 && exclude.includes(id) && blackList.length < exclude.length);
|
|
28
|
+
|
|
29
|
+
if (exclude.length > 0 && blackList.length >= exclude.length) id = '';
|
|
13
30
|
return id;
|
|
14
31
|
}
|
package/src/general/mix/size.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { isEmpty } from ".";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* For `null` or `undefined` argument the returned value will be 0.
|
|
5
|
-
* @param {Any} obj
|
|
6
|
-
* @returns {Number}
|
|
4
|
+
* Gets the length of the given array.
|
|
5
|
+
* - Useful for Object, Array and string type.
|
|
6
|
+
* - For `null` or `undefined` or else argument the returned value will be 0.
|
|
7
|
+
* @param {Any} obj Any object-type variable
|
|
8
|
+
* @returns {Number} the size of the given variable
|
|
7
9
|
*/
|
|
8
10
|
export function size(obj: any): number {
|
|
9
|
-
|
|
11
|
+
if (isEmpty(obj)) return 0;
|
|
12
|
+
|
|
13
|
+
return Object.keys(obj).length;
|
|
10
14
|
}
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* _get({ item1: { item11: 'Hello Again' }, item2: {} }, ['item1', 'item11'])
|
|
27
27
|
* @returns the resolved value.
|
|
28
28
|
*/
|
|
29
|
-
export function _get(baseObject:
|
|
29
|
+
export function _get<T = any>(baseObject: T, path: string | string[], defaultValue?: any): any {
|
|
30
30
|
if (validateToReturnDefaultValue(baseObject, path)) return defaultValue;
|
|
31
31
|
|
|
32
32
|
const keys = Array.isArray(path) ? path : path.replace(/(\[(\d)\])/g, '.$2').split('.').filter(k => k.length);
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Searchs for properties in different case styles such as: lower, upper, camel and pascal
|
|
3
|
+
* - To optimize the searching, it is required a key in a snake_case style
|
|
4
|
+
* - List of cases that do not match
|
|
5
|
+
* -- From lower to snake case
|
|
6
|
+
* -- From upper to snake case
|
|
7
|
+
* -- From lower to camel case
|
|
8
|
+
* -- From upper to camel case
|
|
9
|
+
* -- From lower to pascal case
|
|
10
|
+
* -- From upper to pascal case
|
|
4
11
|
* @param {object} obj object to look for
|
|
5
12
|
* @param {string} key String attribute in snake_case style
|
|
6
13
|
*
|
|
@@ -8,11 +15,42 @@
|
|
|
8
15
|
* getAttribute(obj, 'snake_case') //it search for: obj.snake_case || obj.snakeCase || obj.SnakeCase || obj.snakecase || obj.SNAKECASE
|
|
9
16
|
*/
|
|
10
17
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
import { isObject } from ".";
|
|
19
|
+
import { isEmpty } from "..";
|
|
20
|
+
|
|
21
|
+
export function getAttribute(obj: any, key: string): any {
|
|
22
|
+
if (!isValid(obj, key)) return;
|
|
23
|
+
|
|
24
|
+
const snake = getSnakeCase(key);
|
|
25
|
+
const camel = getCamelCase(snake);
|
|
26
|
+
const pascal = getPascalCase(camel);
|
|
27
|
+
const lower = getLowerCase(pascal);
|
|
28
|
+
const upper = getUpperCase(lower);
|
|
29
|
+
|
|
30
|
+
return obj[key] ?? obj[snake] ?? obj[camel] ?? obj[pascal] ?? obj[lower] ?? obj[upper];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getSnakeCase(key: string): string {
|
|
34
|
+
return key.replace(/[A-Z]/g, (a, i) => i == 0 ? a.toLowerCase() : '_'+ a.toLowerCase());
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getCamelCase(key: string): string {
|
|
38
|
+
return key.replace(/(.)/, (_, a) => a.toLowerCase()).replace(/_(.)/g, (_, a) => a.toUpperCase());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getPascalCase(key: string): string {
|
|
42
|
+
return key.replace(/(.)/, (_, a) => a.toUpperCase());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getLowerCase(key: string): string {
|
|
46
|
+
return key.replace(/_/g, '').toLowerCase();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getUpperCase(key: string): string {
|
|
50
|
+
return key.toUpperCase();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isValid(obj: any, key: string): boolean {
|
|
54
|
+
return (!isEmpty(obj) && isObject(obj))
|
|
55
|
+
&& (!isEmpty(key) && typeof key === 'string');
|
|
18
56
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { isObject } from ".";
|
|
2
|
+
import { isEmpty } from "..";
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Use the hasOwnProperty in order to verify if the given property exists in the object.
|
|
3
6
|
*
|
|
@@ -14,7 +17,13 @@
|
|
|
14
17
|
* const obj2 = { prop1: 'hello world' }
|
|
15
18
|
* _hasProperty(ob1, prop2) // false
|
|
16
19
|
*/
|
|
20
|
+
export function _hasProperty(obj = {}, property: string | number = ''): boolean {
|
|
21
|
+
if (!isValid(obj, property)) return false;
|
|
17
22
|
|
|
18
|
-
export function _hasProperty(obj = {}, property = ''): boolean {
|
|
19
23
|
return Object.prototype.hasOwnProperty.call(obj, property);
|
|
20
24
|
}
|
|
25
|
+
|
|
26
|
+
function isValid(obj, property): boolean {
|
|
27
|
+
return !isEmpty(obj) && (isObject(obj) || Array.isArray(obj))
|
|
28
|
+
&& !isEmpty(property) && (typeof property === 'string' || typeof property === 'number');
|
|
29
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { getTag } from "..";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Checks if the given argument is an object type
|
|
3
5
|
* @param obj the variable to check
|
|
4
6
|
* @returns True: It is an object; False: It is not.
|
|
5
7
|
*/
|
|
6
8
|
export function isObject(obj: any): boolean {
|
|
7
|
-
return Object
|
|
9
|
+
return obj === Object(obj) || getTag(obj) === '[object Object]';
|
|
8
10
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created a new reference of the given argument
|
|
3
|
+
* @param entity The variable to be copied
|
|
4
|
+
* @param cache
|
|
5
|
+
* @returns A new reference of the given argument
|
|
6
|
+
*/
|
|
7
|
+
export function objectCopy(entity, cache = new WeakMap()): any {
|
|
8
|
+
if (!isClonable(entity)) return entity;
|
|
9
|
+
|
|
10
|
+
if (cache.has(entity)) return cache.get(entity);
|
|
11
|
+
|
|
12
|
+
const c = new (entity as any).constructor;
|
|
13
|
+
|
|
14
|
+
if (c.name === 'Date') return new Date(entity as any) as any;
|
|
15
|
+
|
|
16
|
+
if (entity instanceof Map) {
|
|
17
|
+
entity.forEach((value, key) => c.set(objectCopy(key), objectCopy(value)));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (entity instanceof Set) {
|
|
21
|
+
entity.forEach((value) => c.add(objectCopy(value)));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
cache.set(entity, c);
|
|
25
|
+
|
|
26
|
+
return Object.assign(c,
|
|
27
|
+
...Object.keys(entity).map((prop) => ({ [prop]: objectCopy(entity[prop], cache) }))
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isClonable(entity) {
|
|
32
|
+
const referenceTypes = ['Array', 'Object', 'Map', 'Set', 'Date'];
|
|
33
|
+
const entityName = entity && entity.constructor.name;
|
|
34
|
+
return referenceTypes.includes(entityName);
|
|
35
|
+
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { isEmpty } from "..";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* Upper case
|
|
4
|
+
* Upper case the first letter of a given text
|
|
3
5
|
* @param {String} text
|
|
4
|
-
* @returns {String}
|
|
6
|
+
* @returns {String} a capitalized text
|
|
5
7
|
*/
|
|
6
|
-
export function capitalize(text
|
|
8
|
+
export function capitalize(text = ''): string {
|
|
9
|
+
if (isEmpty(text) || typeof text !== 'string') return text;
|
|
10
|
+
|
|
7
11
|
return text.toLowerCase().replace(/^\w/, c => c.toUpperCase());
|
|
8
12
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { isDateColumn } from ".";
|
|
2
|
+
import { COLUMN_PROPERTY, COLUMN_PROPERTY_VALUE, IQrveyColumn, isEmpty } from "..";
|
|
3
|
+
|
|
4
|
+
export function getPropertyLabel(column: IQrveyColumn, property: COLUMN_PROPERTY): string {
|
|
5
|
+
let propertyLabel;
|
|
6
|
+
const propertyValues = COLUMN_PROPERTY_VALUE[isDateColumn(column) ? column.type + '-complete' : column.type];
|
|
7
|
+
if (!isEmpty(propertyValues)) propertyLabel = propertyValues.find(pValue => pValue.value === property)?.label;
|
|
8
|
+
return propertyLabel;
|
|
9
|
+
}
|
package/src/qrvey/index.ts
CHANGED