@sankhyalabs/core 5.20.0-dev.69 → 5.20.0-dev.70
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/.docs/classes/ColumnFilterManager.md +145 -0
- package/.docs/classes/DataUnitInMemoryLoader.md +303 -0
- package/.docs/classes/DataUnitLoaderUtils.md +151 -0
- package/.docs/classes/FieldComparator.md +2 -2
- package/.docs/enumerations/RECORD_DATE_FORMAT.md +27 -0
- package/.docs/globals.md +6 -0
- package/.docs/interfaces/DataUnitInMemoryLoaderConfig.md +37 -0
- package/.docs/interfaces/PaginationInfoBuilderParams.md +37 -0
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.d.ts +9 -0
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js +6 -0
- package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js.map +1 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.d.ts +25 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.js +131 -0
- package/dist/dataunit/loader/dataUnitInMemoryLoader.js.map +1 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.d.ts +20 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js +62 -0
- package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js.map +1 -0
- package/dist/dataunit/sorting/FieldComparator.d.ts +2 -2
- package/dist/dataunit/sorting/FieldComparator.js +4 -9
- package/dist/dataunit/sorting/FieldComparator.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/ColumnFilterManager.d.ts +19 -0
- package/dist/utils/ColumnFilterManager.js +73 -0
- package/dist/utils/ColumnFilterManager.js.map +1 -0
- package/package.json +1 -1
- package/reports/test-report.xml +136 -96
- package/src/dataunit/loader/DataUnitInMemoryLoaderConfig.ts +10 -0
- package/src/dataunit/loader/dataUnitInMemoryLoader.ts +176 -0
- package/src/dataunit/loader/utils/dataUnitLoaderUtils.ts +86 -0
- package/src/dataunit/sorting/FieldComparator.ts +18 -32
- package/src/index.ts +11 -1
- package/src/utils/ColumnFilterManager.ts +104 -0
- package/test/dataunit/loader/dataUnitInMemoryLoader.spec.ts +221 -0
- package/test/dataunit/loader/utils/dataUnitLoaderUtils.spec.ts +158 -0
- package/test/util/ColumnFilterManager.spec.ts +133 -0
package/reports/test-report.xml
CHANGED
|
@@ -1,170 +1,184 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
2
|
<unitTest version="1">
|
|
3
|
-
<file path="/builds/dti/design-system/sankhyacore/test/http/HttpProvider.spec.ts">
|
|
4
|
-
<testCase name="HttpProvider Metodo GET" duration="4"/>
|
|
5
|
-
</file>
|
|
6
|
-
<file path="/builds/dti/design-system/sankhyacore/test/http/SkwHttpProvider.ts.spec.ts">
|
|
7
|
-
<testCase name="HttpProvider Metodo POST" duration="190"/>
|
|
8
|
-
</file>
|
|
9
3
|
<file path="/builds/dti/design-system/sankhyacore/test/util/CriteriaModel.spec.ts">
|
|
10
|
-
<testCase name="StringUtils it should return the undefined and [] to Criteria Props through new class with empty constructor" duration="
|
|
4
|
+
<testCase name="StringUtils it should return the undefined and [] to Criteria Props through new class with empty constructor" duration="8"/>
|
|
11
5
|
<testCase name="StringUtils it should modify "expressions" and "parameters" properties through Setters methods" duration="1"/>
|
|
12
|
-
<testCase name="StringUtils it should return "expression" and "parameters" setted through constructor method" duration="
|
|
13
|
-
<testCase name="StringUtils it should return a Criteria class with "expression" and "parameters" as needed setted through "append" method" duration="
|
|
14
|
-
<testCase name="StringUtils it should return a Criteria class with "Criteria class" and "parameters" concatenaded as needed setted through "append" method" duration="
|
|
6
|
+
<testCase name="StringUtils it should return "expression" and "parameters" setted through constructor method" duration="1"/>
|
|
7
|
+
<testCase name="StringUtils it should return a Criteria class with "expression" and "parameters" as needed setted through "append" method" duration="1"/>
|
|
8
|
+
<testCase name="StringUtils it should return a Criteria class with "Criteria class" and "parameters" concatenaded as needed setted through "append" method" duration="2"/>
|
|
15
9
|
<testCase name="StringUtils it should return undefined as "expression" and "[]" as parameters as we use an empty criteria as first entry in the constructor" duration="1"/>
|
|
16
10
|
<testCase name="StringUtils it should return a Criteria class with "Expression" and "parameters" concatenaded as needed setted through "OR" method" duration="1"/>
|
|
11
|
+
<testCase name="StringUtils it should return a Criteria class with "Criteria class" and "parameters" concatenaded as needed setted through "OR" method" duration="0"/>
|
|
17
12
|
<testCase name="StringUtils it should return a Criteria class with "Criteria class" and "parameters" concatenaded as needed setted through "OR" method" duration="1"/>
|
|
18
|
-
<testCase name="StringUtils it should return a Criteria class with "
|
|
19
|
-
<testCase name="StringUtils it should return a Criteria class with "Expression" and "parameters" concatenaded as needed setted through "AND" method" duration="1"/>
|
|
13
|
+
<testCase name="StringUtils it should return a Criteria class with "Expression" and "parameters" concatenaded as needed setted through "AND" method" duration="68"/>
|
|
20
14
|
<testCase name="StringUtils it should return a Criteria class with "Criteria class" and "parameters" concatenaded as needed setted through "AND" method" duration="1"/>
|
|
21
15
|
<testCase name="StringUtils it should return a Criteria class with "Criteria class" and "parameters" concatenaded as needed setted through "AND" method" duration="1"/>
|
|
22
|
-
<testCase name="StringUtils it should return a toJSON object with "Criteria class" and "parameters" concatenaded as needed setted through "AND" method" duration="
|
|
16
|
+
<testCase name="StringUtils it should return a toJSON object with "Criteria class" and "parameters" concatenaded as needed setted through "AND" method" duration="1"/>
|
|
23
17
|
<testCase name="StringUtils it should return a toJSON object with through empty constructor" duration="0"/>
|
|
24
18
|
</file>
|
|
25
|
-
<file path="/builds/dti/design-system/sankhyacore/test/util/CriteriaParameter.spec.ts">
|
|
26
|
-
<testCase name="StringUtils it should return the correct values of "value" and "type" through the getters methods initial setted by the constructor" duration="2"/>
|
|
27
|
-
<testCase name="StringUtils it should return the correct values of "value" and "type" through the getters methods initial setted by the setters methods" duration="0"/>
|
|
28
|
-
<testCase name="StringUtils it should return the correct JSON/Object value through the buildParam method" duration="0"/>
|
|
29
|
-
</file>
|
|
30
|
-
<file path="/builds/dti/design-system/sankhyacore/src/utils/test/objectUtils.spec.ts">
|
|
31
|
-
<testCase name="ObjectUtils hasEquivalentValues should return true if both objects have the same property value" duration="91"/>
|
|
32
|
-
<testCase name="ObjectUtils hasEquivalentValues should return false if both objects have different property values" duration="1"/>
|
|
33
|
-
<testCase name="ObjectUtils hasEquivalentValues should return true if both objects are equivalent with custom property to compare" duration="1"/>
|
|
34
|
-
<testCase name="ObjectUtils hasEquivalentValues should return false if both objects are not equivalent with custom property to compare" duration="1"/>
|
|
35
|
-
<testCase name="ObjectUtils hasEquivalentValues should return false if one object does not have the property" duration="1"/>
|
|
36
|
-
<testCase name="ObjectUtils hasEquivalentValues should return true if comparing primitive values directly" duration="1"/>
|
|
37
|
-
<testCase name="ObjectUtils hasEquivalentValues should return false if comparing different primitive values" duration="1"/>
|
|
38
|
-
<testCase name="ObjectUtils hasEquivalentValues should return true when comparing object with a null value" duration="0"/>
|
|
39
|
-
<testCase name="ObjectUtils hasEquivalentValues should return false when comparing object with null and non-null value" duration="0"/>
|
|
40
|
-
<testCase name="ObjectUtils hasEquivalentValues should return true when comparing non-object values that are equal" duration="1"/>
|
|
41
|
-
<testCase name="ObjectUtils should get an object value based on its path" duration="1"/>
|
|
42
|
-
<testCase name="ObjectUtils should get an object value based on its path" duration="1"/>
|
|
43
|
-
<testCase name="ObjectUtils should return undefined if the path doesn't exist in the object" duration="1"/>
|
|
44
|
-
</file>
|
|
45
19
|
<file path="/builds/dti/design-system/sankhyacore/test/util/MaskFormatter.spec.ts">
|
|
46
|
-
<testCase name="Mask Formatter mask:CPF complete valid" duration="
|
|
47
|
-
<testCase name="Mask Formatter mask:CPF complete valid literals" duration="
|
|
20
|
+
<testCase name="Mask Formatter mask:CPF complete valid" duration="3"/>
|
|
21
|
+
<testCase name="Mask Formatter mask:CPF complete valid literals" duration="1"/>
|
|
48
22
|
<testCase name="Mask Formatter mask:CPF incomplete valid" duration="0"/>
|
|
49
|
-
<testCase name="Mask Formatter mask:CPF incomplete valid placeholder" duration="
|
|
50
|
-
<testCase name="Mask Formatter mask:CPF too long valid" duration="
|
|
51
|
-
<testCase name="Mask Formatter mask:CPF invalid for string" duration="
|
|
23
|
+
<testCase name="Mask Formatter mask:CPF incomplete valid placeholder" duration="1"/>
|
|
24
|
+
<testCase name="Mask Formatter mask:CPF too long valid" duration="1"/>
|
|
25
|
+
<testCase name="Mask Formatter mask:CPF invalid for string" duration="315"/>
|
|
52
26
|
<testCase name="Mask Formatter mask:CPF invalid for being too long" duration="0"/>
|
|
53
|
-
<testCase name="Mask Formatter mask:Licence plate valid uppercase" duration="
|
|
27
|
+
<testCase name="Mask Formatter mask:Licence plate valid uppercase" duration="1"/>
|
|
54
28
|
<testCase name="Mask Formatter mask:Licence plate valid lowercase" duration="1"/>
|
|
55
29
|
<testCase name="Mask Formatter mask:Licence plate invalid" duration="2"/>
|
|
56
|
-
<testCase name="Mask Formatter mask:Licence plate invalid for being too short" duration="
|
|
30
|
+
<testCase name="Mask Formatter mask:Licence plate invalid for being too short" duration="71"/>
|
|
57
31
|
<testCase name="Mask Formatter mask:Licence plate invalid for being too short with placeholder" duration="1"/>
|
|
58
|
-
<testCase name="Mask Formatter mask:Licence plate invalid" duration="
|
|
59
|
-
<testCase name="Mask Formatter mask:Licence plate with AlphaNumerical Mask" duration="91"/>
|
|
60
|
-
<testCase name="Mask Formatter mask:Licence plate with AlphaNumerical Mask with placeholder" duration="1"/>
|
|
61
|
-
<testCase name="Mask Formatter mask:Licence plate invalid" duration="2"/>
|
|
32
|
+
<testCase name="Mask Formatter mask:Licence plate invalid" duration="3"/>
|
|
62
33
|
<testCase name="Mask Formatter mask:Licence plate with AlphaNumerical Mask" duration="1"/>
|
|
63
34
|
<testCase name="Mask Formatter mask:Licence plate with AlphaNumerical Mask with placeholder" duration="1"/>
|
|
64
35
|
<testCase name="Mask Formatter mask:Licence plate invalid" duration="1"/>
|
|
65
36
|
<testCase name="Mask Formatter mask:Licence plate with AlphaNumerical Mask" duration="1"/>
|
|
66
|
-
<testCase name="Mask Formatter mask:Licence plate with AlphaNumerical Mask with placeholder" duration="
|
|
37
|
+
<testCase name="Mask Formatter mask:Licence plate with AlphaNumerical Mask with placeholder" duration="0"/>
|
|
38
|
+
<testCase name="Mask Formatter mask:Licence plate invalid" duration="1"/>
|
|
39
|
+
<testCase name="Mask Formatter mask:Licence plate with AlphaNumerical Mask" duration="0"/>
|
|
40
|
+
<testCase name="Mask Formatter mask:Licence plate with AlphaNumerical Mask with placeholder" duration="16"/>
|
|
67
41
|
<testCase name="Mask Formatter mask:Licence plate invalid" duration="1"/>
|
|
68
42
|
</file>
|
|
69
|
-
<file path="/builds/dti/design-system/sankhyacore/test/util/
|
|
70
|
-
<testCase name="
|
|
71
|
-
<testCase name="
|
|
72
|
-
<testCase name="
|
|
43
|
+
<file path="/builds/dti/design-system/sankhyacore/test/util/NumberUtils.spec.ts">
|
|
44
|
+
<testCase name="StringUtils stringToNumber" duration="109"/>
|
|
45
|
+
<testCase name="StringUtils format" duration="179"/>
|
|
46
|
+
<testCase name="StringUtils format without formatnumber parameter" duration="1"/>
|
|
47
|
+
<testCase name="StringUtils format without formatnumber parameter" duration="2"/>
|
|
48
|
+
<testCase name="StringUtils format round number" duration="2"/>
|
|
49
|
+
</file>
|
|
50
|
+
<file path="/builds/dti/design-system/sankhyacore/test/dataunit/loader/utils/dataUnitLoaderUtils.spec.ts">
|
|
51
|
+
<testCase name="Utility Functions applyFilter should return the original records if no filters are provided" duration="79"/>
|
|
52
|
+
<testCase name="Utility Functions applyFilter should filter records based on provided filters" duration="2"/>
|
|
53
|
+
<testCase name="Utility Functions buildPaginationInfo function should return correct pagination info with default values" duration="2"/>
|
|
54
|
+
<testCase name="Utility Functions buildPaginationInfo function should redosLenth as same size as recordsPerPage" duration="1"/>
|
|
55
|
+
<testCase name="Utility Functions buildPaginationInfo function should handle case when totalRecordsLength and offset 0" duration="1"/>
|
|
56
|
+
<testCase name="Utility Functions buildPaginationInfo function should handle case when currentPageLength is less than totalRecordsLength and lastPage" duration="0"/>
|
|
57
|
+
<testCase name="Utility Functions applySorting function should return the original records if no sorting is provided" duration="1"/>
|
|
58
|
+
<testCase name="Utility Functions applySorting function should sort records based on provided sorting criteria" duration="1"/>
|
|
59
|
+
</file>
|
|
60
|
+
<file path="/builds/dti/design-system/sankhyacore/src/utils/test/objectUtils.spec.ts">
|
|
61
|
+
<testCase name="ObjectUtils hasEquivalentValues should return true if both objects have the same property value" duration="14"/>
|
|
62
|
+
<testCase name="ObjectUtils hasEquivalentValues should return false if both objects have different property values" duration="1"/>
|
|
63
|
+
<testCase name="ObjectUtils hasEquivalentValues should return true if both objects are equivalent with custom property to compare" duration="0"/>
|
|
64
|
+
<testCase name="ObjectUtils hasEquivalentValues should return false if both objects are not equivalent with custom property to compare" duration="1"/>
|
|
65
|
+
<testCase name="ObjectUtils hasEquivalentValues should return false if one object does not have the property" duration="0"/>
|
|
66
|
+
<testCase name="ObjectUtils hasEquivalentValues should return true if comparing primitive values directly" duration="1"/>
|
|
67
|
+
<testCase name="ObjectUtils hasEquivalentValues should return false if comparing different primitive values" duration="0"/>
|
|
68
|
+
<testCase name="ObjectUtils hasEquivalentValues should return true when comparing object with a null value" duration="0"/>
|
|
69
|
+
<testCase name="ObjectUtils hasEquivalentValues should return false when comparing object with null and non-null value" duration="0"/>
|
|
70
|
+
<testCase name="ObjectUtils hasEquivalentValues should return true when comparing non-object values that are equal" duration="0"/>
|
|
71
|
+
<testCase name="ObjectUtils should get an object value based on its path" duration="0"/>
|
|
72
|
+
<testCase name="ObjectUtils should get an object value based on its path" duration="1"/>
|
|
73
|
+
<testCase name="ObjectUtils should return undefined if the path doesn't exist in the object" duration="0"/>
|
|
74
|
+
</file>
|
|
75
|
+
<file path="/builds/dti/design-system/sankhyacore/test/util/OverflowWatcher.spec.ts">
|
|
76
|
+
<testCase name="OverflowWatcher should initialize with provided parameters" duration="77"/>
|
|
77
|
+
<testCase name="OverflowWatcher should disconect ResizeObserver when destroy is called" duration="2"/>
|
|
78
|
+
<testCase name="OverflowWatcher Should call callback on forceUpdate" duration="307"/>
|
|
79
|
+
<testCase name="OverflowWatcher Should call callback on forceUpdate with childSpan" duration="86"/>
|
|
80
|
+
<testCase name="OverflowWatcher Should call callback on forceUpdate with childSpan when notOverFlow is empty" duration="13"/>
|
|
81
|
+
<testCase name="OverflowWatcher Should call callback on forceUpdate with childSpan considering overflowed elements" duration="7"/>
|
|
82
|
+
<testCase name="OverflowWatcher Should call callback on forceUpdate with empty list" duration="4"/>
|
|
83
|
+
<testCase name="OverflowWatcher should ignore elements that can not overflow" duration="90"/>
|
|
84
|
+
<testCase name="OverflowWatcher Should not call callback on forceUpdate" duration="1"/>
|
|
85
|
+
</file>
|
|
86
|
+
<file path="/builds/dti/design-system/sankhyacore/test/http/HttpProvider.spec.ts">
|
|
87
|
+
<testCase name="HttpProvider Metodo GET" duration="1"/>
|
|
73
88
|
</file>
|
|
74
89
|
<file path="/builds/dti/design-system/sankhyacore/test/util/StringUtils.spec.ts">
|
|
75
|
-
<testCase name="StringUtils valor vazio" duration="
|
|
76
|
-
<testCase name="StringUtils valor em branco" duration="
|
|
90
|
+
<testCase name="StringUtils valor vazio" duration="1"/>
|
|
91
|
+
<testCase name="StringUtils valor em branco" duration="0"/>
|
|
77
92
|
<testCase name="StringUtils valor null" duration="0"/>
|
|
78
|
-
<testCase name="StringUtils valor undefined" duration="
|
|
79
|
-
<testCase name="StringUtils valor 0" duration="
|
|
80
|
-
<testCase name="StringUtils com valor" duration="
|
|
93
|
+
<testCase name="StringUtils valor undefined" duration="0"/>
|
|
94
|
+
<testCase name="StringUtils valor 0" duration="1"/>
|
|
95
|
+
<testCase name="StringUtils com valor" duration="84"/>
|
|
81
96
|
<testCase name="StringUtils substitui vogais com acento por vogais sem acento" duration="1"/>
|
|
82
97
|
<testCase name="StringUtils should return the original value when called with an object without a toString method" duration="2"/>
|
|
83
98
|
<testCase name="StringUtils should return the original value when called with undefined" duration="1"/>
|
|
84
99
|
</file>
|
|
85
|
-
<file path="/builds/dti/design-system/sankhyacore/test/util/
|
|
86
|
-
<testCase name="
|
|
87
|
-
<testCase name="
|
|
88
|
-
<testCase name="
|
|
89
|
-
<testCase name="
|
|
90
|
-
<testCase name="
|
|
100
|
+
<file path="/builds/dti/design-system/sankhyacore/test/util/ColumnFilterManager.spec.ts">
|
|
101
|
+
<testCase name="ColumnFilterManager getColumnFilters should return an empty map if filters are undefined or empty" duration="2"/>
|
|
102
|
+
<testCase name="ColumnFilterManager getColumnFilters should return a map of filters matching the pattern and not the provided fieldName" duration="1"/>
|
|
103
|
+
<testCase name="ColumnFilterManager getFilterFunction should return undefined if no filters are provided" duration="0"/>
|
|
104
|
+
<testCase name="ColumnFilterManager getFilterFunction should return a function that evaluates records based on filters" duration="2"/>
|
|
105
|
+
<testCase name="ColumnFilterManager getFilterFunction should return a function that evaluates records and return false" duration="2"/>
|
|
106
|
+
<testCase name="ColumnFilterManager compileDistinct should return an array of distinct field values formatted correctly" duration="2"/>
|
|
107
|
+
<testCase name="ColumnFilterManager compileDistinct should filter records if a load request is present" duration="1"/>
|
|
108
|
+
</file>
|
|
109
|
+
<file path="/builds/dti/design-system/sankhyacore/test/http/SkwHttpProvider.ts.spec.ts">
|
|
110
|
+
<testCase name="HttpProvider Metodo POST" duration="1"/>
|
|
111
|
+
</file>
|
|
112
|
+
<file path="/builds/dti/design-system/sankhyacore/test/util/CriteriaParameter.spec.ts">
|
|
113
|
+
<testCase name="StringUtils it should return the correct values of "value" and "type" through the getters methods initial setted by the constructor" duration="2"/>
|
|
114
|
+
<testCase name="StringUtils it should return the correct values of "value" and "type" through the getters methods initial setted by the setters methods" duration="0"/>
|
|
115
|
+
<testCase name="StringUtils it should return the correct JSON/Object value through the buildParam method" duration="1"/>
|
|
91
116
|
</file>
|
|
92
117
|
<file path="/builds/dti/design-system/sankhyacore/src/dataunit/state/slice/test/RecordsSlice.spec.ts">
|
|
93
118
|
<testCase name="RecordsSlice should return newlines at the end" duration="2"/>
|
|
94
119
|
</file>
|
|
95
|
-
<file path="/builds/dti/design-system/sankhyacore/test/util/
|
|
96
|
-
<testCase name="
|
|
97
|
-
<testCase name="
|
|
98
|
-
<testCase name="
|
|
99
|
-
<testCase name="OverflowWatcher Should call callback on forceUpdate with childSpan" duration="102"/>
|
|
100
|
-
<testCase name="OverflowWatcher Should call callback on forceUpdate with childSpan when notOverFlow is empty" duration="6"/>
|
|
101
|
-
<testCase name="OverflowWatcher Should call callback on forceUpdate with childSpan considering overflowed elements" duration="87"/>
|
|
102
|
-
<testCase name="OverflowWatcher Should call callback on forceUpdate with empty list" duration="3"/>
|
|
103
|
-
<testCase name="OverflowWatcher should ignore elements that can not overflow" duration="196"/>
|
|
104
|
-
<testCase name="OverflowWatcher Should not call callback on forceUpdate" duration="1"/>
|
|
120
|
+
<file path="/builds/dti/design-system/sankhyacore/test/util/TimeFormatter.spec.ts">
|
|
121
|
+
<testCase name="TimeFormatter Case: input string unformated with showSeconds" duration="2"/>
|
|
122
|
+
<testCase name="TimeFormatter Case: input string unformated without showSeconds" duration="1"/>
|
|
123
|
+
<testCase name="TimeFormatter Case: validateTime" duration="2"/>
|
|
105
124
|
</file>
|
|
106
125
|
<file path="/builds/dti/design-system/sankhyacore/src/dataunit/test/DataUnit.spec.ts">
|
|
107
126
|
<testCase name="DataUnit should return false when not waiting to reload" duration="3"/>
|
|
108
|
-
<testCase name="DataUnit should set waitingToReload to true" duration="
|
|
127
|
+
<testCase name="DataUnit should set waitingToReload to true" duration="0"/>
|
|
109
128
|
<testCase name="DataUnit should set waitingToReload to false" duration="1"/>
|
|
110
129
|
<testCase name="DataUnit should dispatch SAVING_CANCELED action with correct fields and recordId" duration="1"/>
|
|
111
130
|
</file>
|
|
112
131
|
<file path="/builds/dti/design-system/sankhyacore/test/util/DataUnitStorage.spec.ts">
|
|
113
|
-
<testCase name="DataUnitStorage put should store a DataUnit instance in the DataUnitStorage" duration="
|
|
114
|
-
<testCase name="DataUnitStorage get should return the stored DataUnit instance from the DataUnitStorage" duration="
|
|
132
|
+
<testCase name="DataUnitStorage put should store a DataUnit instance in the DataUnitStorage" duration="2"/>
|
|
133
|
+
<testCase name="DataUnitStorage get should return the stored DataUnit instance from the DataUnitStorage" duration="1"/>
|
|
115
134
|
<testCase name="DataUnitStorage get should return undefined if the DataUnit instance is not found in the DataUnitStorage" duration="1"/>
|
|
116
135
|
<testCase name="DataUnitStorage remove should remove the specified DataUnit instance from the DataUnitStorage" duration="1"/>
|
|
117
136
|
<testCase name="DataUnitStorage remove should remove the DataUnit instance with the specified name from the DataUnitStorage" duration="1"/>
|
|
118
137
|
<testCase name="DataUnitStorage remove should not remove any DataUnit instance if the specified DataUnit instance or name is not found in the DataUnitStorage" duration="1"/>
|
|
119
138
|
</file>
|
|
120
139
|
<file path="/builds/dti/design-system/sankhyacore/test/util/ElementIDUtils.spec.ts">
|
|
121
|
-
<testCase name="addIDInfo 1 - should add data-element-id with valid id "movFinanceira_snkApplication"" duration="
|
|
140
|
+
<testCase name="addIDInfo 1 - should add data-element-id with valid id "movFinanceira_snkApplication"" duration="11"/>
|
|
122
141
|
<testCase name="addIDInfo 2 - should add data-element-id with valid id "brComSankhyaFinCadMovimentacaofinanceira_snkApplication"" duration="2"/>
|
|
123
142
|
<testCase name="addIDInfo 3 - should add data-element-id with valid id "movFinanceira_br.com.sankhya.fin.cad.movimentacaoFinanceira"" duration="1"/>
|
|
124
143
|
<testCase name="addIDInfo 4 - should add data-element-id with valid id "meuID2_snkApplication"" duration="1"/>
|
|
125
|
-
<testCase name="addIDInfo 5 - should add data-element-id with valid id "movFinanceira_snkApplication"" duration="
|
|
144
|
+
<testCase name="addIDInfo 5 - should add data-element-id with valid id "movFinanceira_snkApplication"" duration="1"/>
|
|
126
145
|
<testCase name="addIDInfo 6 - should add data-element-id with valid id "movFinanceira_snkApplication"" duration="1"/>
|
|
127
146
|
<testCase name="addIDInfo 7 - should add data-element-id with valid id "componenteNameTest_snkApplication"" duration="1"/>
|
|
128
147
|
<testCase name="addIDInfo 8 - should add data-element-id with valid id "componentLabel_snkApplication"" duration="1"/>
|
|
129
|
-
<testCase name="addIDInfo 9 - should add data-element-id with valid id "dataunitFinanceiro_br.com.sankhya.fin.cad.movimentacaoFinanceira"" duration="
|
|
148
|
+
<testCase name="addIDInfo 9 - should add data-element-id with valid id "dataunitFinanceiro_br.com.sankhya.fin.cad.movimentacaoFinanceira"" duration="2"/>
|
|
130
149
|
<testCase name="addIDInfo 10 - should add data-element-id with valid id "dataunitFinanceiro_meuIDTeste_br.com.sankhya.fin.cad.movimentacaoFinanceira"" duration="1"/>
|
|
131
|
-
<testCase name="addIDInfo 11 - should add data-element-id with valid id "dataunitFinanceiro_meuIDTeste_movimentacaoFinanceira"" duration="
|
|
150
|
+
<testCase name="addIDInfo 11 - should add data-element-id with valid id "dataunitFinanceiro_meuIDTeste_movimentacaoFinanceira"" duration="2"/>
|
|
132
151
|
<testCase name="addIDInfo 12 - should add data-element-id with valid id "dataunitFinanceiro_movFinanceira_movimentacaoFinanceira"" duration="1"/>
|
|
133
152
|
<testCase name="addIDInfo 13 - should add data-element-id with valid id "dataunitFinanceiro_meuIDTeste_movimentacaoFinanceira"" duration="1"/>
|
|
134
|
-
<testCase name="addIDInfo 14 - should add data-element-id with valid id "dataunitFinanceiro_meuIdTeste_movimentacaoFinanceira"" duration="
|
|
153
|
+
<testCase name="addIDInfo 14 - should add data-element-id with valid id "dataunitFinanceiro_meuIdTeste_movimentacaoFinanceira"" duration="67"/>
|
|
135
154
|
<testCase name="addIDInfo 15 - should add data-element-id with valid id "dataunitFinanceiro_meuIdTeste_snkApplication"" duration="1"/>
|
|
136
|
-
<testCase name="addIDInfo 16 - should add data-element-id with valid id "dataunitFinanceiro_meuIdTeste_snkApplication"" duration="
|
|
155
|
+
<testCase name="addIDInfo 16 - should add data-element-id with valid id "dataunitFinanceiro_meuIdTeste_snkApplication"" duration="1"/>
|
|
137
156
|
<testCase name="addIDInfo 17 - should add data-element-id with valid id "movFinanceira_movimentacaoFinanceira"" duration="1"/>
|
|
138
157
|
<testCase name="addIDInfo 18 - should add data-element-id with valid id "movFinanceira_movimentacaoFinanceira"" duration="1"/>
|
|
139
|
-
<testCase name="addIDInfo 19 - should add data-element-id with valid id "movFinanceira_movimentacaoFinanceira"" duration="
|
|
158
|
+
<testCase name="addIDInfo 19 - should add data-element-id with valid id "movFinanceira_movimentacaoFinanceira"" duration="1"/>
|
|
140
159
|
<testCase name="addIDInfo 20 - should add data-element-id with valid id "movFinanceira_movimentacaoFinanceira"" duration="1"/>
|
|
141
|
-
<testCase name="addIDInfo 21 - should add data-element-id with valid id "movFinanceira_movimentacaoFinanceira"" duration="
|
|
160
|
+
<testCase name="addIDInfo 21 - should add data-element-id with valid id "movFinanceira_movimentacaoFinanceira"" duration="1"/>
|
|
142
161
|
<testCase name="addIDInfo 22 - should add data-element-id with valid id "bancoObrigatorio_movimentacaoFinanceira"" duration="1"/>
|
|
143
162
|
</file>
|
|
144
|
-
<file path="/builds/dti/design-system/sankhyacore/test/util/ElementUtils.spec.ts">
|
|
145
|
-
<testCase name="calcMarginSize should calculate correctly the size of horizontal margin" duration="26"/>
|
|
146
|
-
<testCase name="calcMarginSize should calculate correctly the size of vertical margin" duration="2"/>
|
|
147
|
-
<testCase name="calcMarginSize should threat values defined as zero" duration="2"/>
|
|
148
|
-
</file>
|
|
149
163
|
<file path="/builds/dti/design-system/sankhyacore/test/dataunit/formatting/PrettyFormatter.spec.ts">
|
|
150
|
-
<testCase name="getFormattedValue should return empty string when value is null" duration="
|
|
151
|
-
<testCase name="getFormattedValue should return empty string when value is not an array" duration="
|
|
152
|
-
<testCase name="getFormattedValue should return empty string when value is an empty array" duration="
|
|
153
|
-
<testCase name="getFormattedValue should return file name when value is an array with one file object" duration="
|
|
164
|
+
<testCase name="getFormattedValue should return empty string when value is null" duration="62"/>
|
|
165
|
+
<testCase name="getFormattedValue should return empty string when value is not an array" duration="1"/>
|
|
166
|
+
<testCase name="getFormattedValue should return empty string when value is an empty array" duration="0"/>
|
|
167
|
+
<testCase name="getFormattedValue should return file name when value is an array with one file object" duration="1"/>
|
|
154
168
|
<testCase name="getFormattedValue should return file count when value is an array with multiple file objects" duration="0"/>
|
|
155
169
|
<testCase name="getFormattedValue should return empty string for undefined file" duration="1"/>
|
|
156
170
|
<testCase name="getFormattedValue should handle OBJECT type with value field" duration="0"/>
|
|
157
171
|
<testCase name="getFormattedValue should return empty string when value is undefined" duration="0"/>
|
|
158
172
|
<testCase name="getFormattedValue should return value as string when value is not an object" duration="0"/>
|
|
159
173
|
<testCase name="getFormattedValue should return value.toString() when value is an object without value property" duration="0"/>
|
|
160
|
-
<testCase name="getFormattedValue should handle BOOLEAN type" duration="
|
|
174
|
+
<testCase name="getFormattedValue should handle BOOLEAN type" duration="0"/>
|
|
161
175
|
<testCase name="getFormattedValue should format numbers correctly" duration="10"/>
|
|
162
|
-
<testCase name="getFormattedValue should format dates correctly" duration="
|
|
163
|
-
<testCase name="getFormattedValue should format times correctly" duration="
|
|
164
|
-
<testCase name="getFormattedValue should format datetime correctly" duration="
|
|
176
|
+
<testCase name="getFormattedValue should format dates correctly" duration="5"/>
|
|
177
|
+
<testCase name="getFormattedValue should format times correctly" duration="0"/>
|
|
178
|
+
<testCase name="getFormattedValue should format datetime correctly" duration="1"/>
|
|
165
179
|
<testCase name="getFormattedValue should call toString with correct parameters" duration="1"/>
|
|
166
|
-
<testCase name="getFormattedValue should handle undefined descriptor gracefully" duration="
|
|
167
|
-
<testCase name="getFormattedValue should format value correctly with OPTIONSELECTOR and matching option" duration="
|
|
180
|
+
<testCase name="getFormattedValue should handle undefined descriptor gracefully" duration="0"/>
|
|
181
|
+
<testCase name="getFormattedValue should format value correctly with OPTIONSELECTOR and matching option" duration="1"/>
|
|
168
182
|
<testCase name="getFormattedValue should return value with OPTIONSELECTOR and no matching option" duration="0"/>
|
|
169
183
|
<testCase name="getFormattedValue should format value correctly with OPTIONSELECTOR and value as object" duration="1"/>
|
|
170
184
|
<testCase name="getFormattedValue should return empty string with OPTIONSELECTOR and value as null" duration="0"/>
|
|
@@ -172,4 +186,30 @@
|
|
|
172
186
|
<testCase name="getFormattedValue should return value with OPTIONSELECTOR and options as empty array" duration="0"/>
|
|
173
187
|
<testCase name="getFormattedValue should format masked values correctly" duration="1"/>
|
|
174
188
|
</file>
|
|
189
|
+
<file path="/builds/dti/design-system/sankhyacore/test/dataunit/loader/dataUnitInMemoryLoader.spec.ts">
|
|
190
|
+
<testCase name="DataUnitInMemoryLoader - loadData should be called load data when auto load is true" duration="68"/>
|
|
191
|
+
<testCase name="DataUnitInMemoryLoader - loadData should be called load data when auto load is undefined" duration="2"/>
|
|
192
|
+
<testCase name="DataUnitInMemoryLoader - loadData should not be called load data when auto load is false" duration="1"/>
|
|
193
|
+
<testCase name="DataUnitInMemoryLoader - loadData should be called load data when config is undefined" duration="1"/>
|
|
194
|
+
<testCase name="DataUnitInMemoryLoader - getConvertedValue should return the original string if descriptor is undefined" duration="1"/>
|
|
195
|
+
<testCase name="DataUnitInMemoryLoader - getConvertedValue should return the original string if dataType is TEXT" duration="1"/>
|
|
196
|
+
<testCase name="DataUnitInMemoryLoader - getConvertedValue should convert to boolean when dataType is BOOLEAN" duration="0"/>
|
|
197
|
+
<testCase name="DataUnitInMemoryLoader - getConvertedValue should convert to number when dataType is NUMBER" duration="0"/>
|
|
198
|
+
<testCase name="DataUnitInMemoryLoader - getConvertedValue should parse JSON when dataType is OBJECT" duration="2"/>
|
|
199
|
+
<testCase name="DataUnitInMemoryLoader - getConvertedValue should convert to date when dataType is DATE and format is ISO" duration="1"/>
|
|
200
|
+
<testCase name="DataUnitInMemoryLoader - getConvertedValue should convert to date when dataType is DATE and format is not ISO" duration="1"/>
|
|
201
|
+
<testCase name="DataUnitInMemoryLoader - getConvertedValue should return the original string if no dataType matches" duration="1"/>
|
|
202
|
+
<testCase name="DataUnitInMemoryLoader - removeLoader should resolve with the provided record IDs" duration="1"/>
|
|
203
|
+
<testCase name="DataUnitInMemoryLoader - removeLoader should handle empty record ID array" duration="2"/>
|
|
204
|
+
<testCase name="DataUnitInMemoryLoader - removeLoader should resolve the promise" duration="1"/>
|
|
205
|
+
<testCase name="DataUnitInMemoryLoader - buildInitialRecords (indiretamente via set records) should build initial records and convert field values based on metadata" duration="3"/>
|
|
206
|
+
<testCase name="DataUnitInMemoryLoader - buildInitialRecords (indiretamente via set records) should generate unique IDs for records without "__record__id__"" duration="5"/>
|
|
207
|
+
<testCase name="DataUnitInMemoryLoader - buildInitialRecords (indiretamente via set records) should leave fields untouched if no matching metadata exists" duration="2"/>
|
|
208
|
+
<testCase name="DataUnitInMemoryLoader - buildInitialRecords (indiretamente via set records) should skip conversion for non-string field values" duration="1"/>
|
|
209
|
+
</file>
|
|
210
|
+
<file path="/builds/dti/design-system/sankhyacore/test/util/ElementUtils.spec.ts">
|
|
211
|
+
<testCase name="calcMarginSize should calculate correctly the size of horizontal margin" duration="84"/>
|
|
212
|
+
<testCase name="calcMarginSize should calculate correctly the size of vertical margin" duration="2"/>
|
|
213
|
+
<testCase name="calcMarginSize should threat values defined as zero" duration="6"/>
|
|
214
|
+
</file>
|
|
175
215
|
</unitTest>
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Change,
|
|
3
|
+
ChangeOperation,
|
|
4
|
+
DataType,
|
|
5
|
+
DataUnit,
|
|
6
|
+
DateUtils,
|
|
7
|
+
FieldDescriptor,
|
|
8
|
+
LoadDataRequest,
|
|
9
|
+
LoadDataResponse,
|
|
10
|
+
Record,
|
|
11
|
+
SavedRecord,
|
|
12
|
+
StringUtils,
|
|
13
|
+
UnitMetadata,
|
|
14
|
+
} from '../../index.js';
|
|
15
|
+
import { DataUnitInMemoryLoaderConfig, RECORD_DATE_FORMAT } from './DataUnitInMemoryLoaderConfig.js';
|
|
16
|
+
import { DataUnitLoaderUtils } from './utils/dataUnitLoaderUtils.js';
|
|
17
|
+
|
|
18
|
+
export class DataUnitInMemoryLoader {
|
|
19
|
+
private _dataUnit: DataUnit;
|
|
20
|
+
private _metadata: UnitMetadata | undefined;
|
|
21
|
+
private _initialRecords: Array<Record> = [];
|
|
22
|
+
private recordDateFormat: RECORD_DATE_FORMAT;
|
|
23
|
+
public static readonly IN_MEMORY_DATA_UNIT_NAME = 'InMemoryDataUnit';
|
|
24
|
+
public static readonly DEFAULT_PAGE_SIZE = 150;
|
|
25
|
+
|
|
26
|
+
constructor(metadata?: UnitMetadata, records?: Array<Record>, config?: DataUnitInMemoryLoaderConfig) {
|
|
27
|
+
|
|
28
|
+
this.metadata = metadata as UnitMetadata;
|
|
29
|
+
this.recordDateFormat = config?.recordDateFormat ?? RECORD_DATE_FORMAT.DD_MM_YYYY;
|
|
30
|
+
this.records = records ?? [] as Array<Record>;
|
|
31
|
+
|
|
32
|
+
this._dataUnit = new DataUnit(DataUnitInMemoryLoader.IN_MEMORY_DATA_UNIT_NAME);
|
|
33
|
+
this._dataUnit.pageSize = config?.pageSize ?? DataUnitInMemoryLoader.DEFAULT_PAGE_SIZE;
|
|
34
|
+
this._dataUnit.metadataLoader = () => this.metadaLoader();
|
|
35
|
+
this._dataUnit.dataLoader = (dataUnit: DataUnit, request: LoadDataRequest) => this.inMemoryLoader(dataUnit, request, this.getRecordsToLoad());
|
|
36
|
+
this._dataUnit.saveLoader = (_dataUnit: DataUnit, changes: Array<Change>) => this.saveLoader(_dataUnit, changes);
|
|
37
|
+
this._dataUnit.removeLoader = (_dataUnit: DataUnit, recordIds: Array<string>) => this.removeLoader(_dataUnit, recordIds);
|
|
38
|
+
|
|
39
|
+
this.dataUnit.loadMetadata().then(() => {
|
|
40
|
+
if (config?.autoLoad !== false) {
|
|
41
|
+
this.dataUnit.loadData();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private getRecordsToLoad(): Array<Record> {
|
|
47
|
+
if (this._initialRecords == undefined && this.dataUnit.records.length > 0) {
|
|
48
|
+
this._initialRecords = this.dataUnit.records;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const addedRecords = this.dataUnit.getAddedRecords();
|
|
52
|
+
if (addedRecords) {
|
|
53
|
+
return [...this._initialRecords, ...addedRecords];
|
|
54
|
+
}
|
|
55
|
+
return this._initialRecords;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public get dataUnit(): DataUnit {
|
|
59
|
+
return this._dataUnit;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public get records(): Array<Record> {
|
|
63
|
+
return this.dataUnit.records;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public set records(records: Array<Record>) {
|
|
67
|
+
const columns = this.buildColumns();
|
|
68
|
+
|
|
69
|
+
this._initialRecords = this.buildInitialRecords(records, columns);
|
|
70
|
+
|
|
71
|
+
if (!this._dataUnit) return;
|
|
72
|
+
|
|
73
|
+
//Isso força o refresh internamente no datunit
|
|
74
|
+
this._dataUnit.loadData();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public static getConvertedValue(descriptor: FieldDescriptor, strValue: string, dateFormat?: RECORD_DATE_FORMAT) {
|
|
78
|
+
if (!descriptor) return strValue;
|
|
79
|
+
if (descriptor.dataType === DataType.BOOLEAN) return strValue === 'S';
|
|
80
|
+
if (descriptor.dataType === DataType.NUMBER) return Number(strValue);
|
|
81
|
+
if (descriptor.dataType === DataType.OBJECT) return JSON.parse(strValue);
|
|
82
|
+
|
|
83
|
+
if (descriptor.dataType === DataType.DATE) {
|
|
84
|
+
return dateFormat === RECORD_DATE_FORMAT.ISO
|
|
85
|
+
? DateUtils.validateDate(new Date(strValue), true)
|
|
86
|
+
: DateUtils.strToDate(strValue, true);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return strValue;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private buildColumns() {
|
|
93
|
+
return this._metadata
|
|
94
|
+
? new Map(this._metadata.fields.map(descriptor => [descriptor.name, descriptor]))
|
|
95
|
+
: undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private buildInitialRecords(records: Array<Record>, columns: Map<string, FieldDescriptor> | undefined) {
|
|
99
|
+
const newRecords = records?.map(record => {
|
|
100
|
+
|
|
101
|
+
if (!record['__record__id__']) {
|
|
102
|
+
record['__record__id__'] = this.generateUniqueId();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (!columns) return record;
|
|
106
|
+
|
|
107
|
+
for (const fieldName in record) {
|
|
108
|
+
const value = record[fieldName];
|
|
109
|
+
const fieldDescriptor = columns.get(fieldName);
|
|
110
|
+
|
|
111
|
+
if (typeof value === 'string' && fieldDescriptor) {
|
|
112
|
+
record[fieldName] = DataUnitInMemoryLoader.getConvertedValue(fieldDescriptor, value, this.recordDateFormat);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return record;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return newRecords;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public get metadata(): UnitMetadata {
|
|
123
|
+
return this._metadata as UnitMetadata;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public set metadata(metadata: UnitMetadata) {
|
|
127
|
+
this._metadata = metadata;
|
|
128
|
+
|
|
129
|
+
if (this._dataUnit) {
|
|
130
|
+
this._dataUnit.metadata = metadata as UnitMetadata;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private generateUniqueId(): string {
|
|
135
|
+
return StringUtils.generateUUID();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private inMemoryLoader(dataUnit: DataUnit, request: LoadDataRequest, recordsIn: Array<Record>): Promise<LoadDataResponse> {
|
|
139
|
+
return DataUnitLoaderUtils.buildLoadDataResponse(recordsIn, dataUnit, request);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private metadaLoader(): Promise<UnitMetadata> {
|
|
143
|
+
return Promise.resolve(this._metadata as UnitMetadata);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private saveLoader(_dataUnit: DataUnit, changes: Array<Change>): Promise<Array<SavedRecord>> {
|
|
147
|
+
return new Promise((resolve) => {
|
|
148
|
+
let dataUnitRecords: SavedRecord[] = [];
|
|
149
|
+
|
|
150
|
+
changes.forEach(change => {
|
|
151
|
+
let { record, updatingFields, operation } = change;
|
|
152
|
+
|
|
153
|
+
const changedRecord = { ...record, ...updatingFields };
|
|
154
|
+
|
|
155
|
+
if (operation === ChangeOperation.INSERT ||
|
|
156
|
+
operation === ChangeOperation.COPY) {
|
|
157
|
+
changedRecord['__old__id__'] = record['__record__id__'];
|
|
158
|
+
changedRecord['__record__id__'] = this.generateUniqueId();
|
|
159
|
+
|
|
160
|
+
this.records.push(changedRecord);
|
|
161
|
+
} else {
|
|
162
|
+
const recordIndex = this.records.findIndex(r => r['__record__id__'] == changedRecord['__record__id__']);
|
|
163
|
+
this.records[recordIndex] = changedRecord;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
dataUnitRecords.push(changedRecord);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
resolve(dataUnitRecords);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public removeLoader(_dataUnit: DataUnit, recordIds: Array<string>): Promise<Array<string>> {
|
|
174
|
+
return new Promise((resolve) => resolve(recordIds));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import DataUnit, { Record } from '../../DataUnit.js';
|
|
2
|
+
import { Filter, Sort } from '../../metadata/UnitMetadata.js';
|
|
3
|
+
import { LoadDataRequest } from '../../loading/LoadDataRequest.js';
|
|
4
|
+
import { PaginationInfo } from '../../loading/PaginationInfo.js';
|
|
5
|
+
import { IColumnFilter, ColumnFilterManager } from '../../../utils/ColumnFilterManager.js';
|
|
6
|
+
import SortingUtils from '../../../utils/SortingUtils.js';
|
|
7
|
+
|
|
8
|
+
export class DataUnitLoaderUtils {
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
public static applyFilter(records: Array<Record>, dataUnit: DataUnit, filters: Array<Filter>): Array<Record> {
|
|
12
|
+
const columnFilters: Map<string, IColumnFilter> = ColumnFilterManager.getColumnFilters(filters, "");
|
|
13
|
+
if (!columnFilters?.size) return records;
|
|
14
|
+
|
|
15
|
+
const filterFunction: ((record: Record) => boolean) | undefined = ColumnFilterManager.getFilterFunction(dataUnit, Array.from(columnFilters.values()));
|
|
16
|
+
return (filterFunction) ? records.filter(filterFunction) : records;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
public static buildLoadDataResponse(recordsIn: Array<Record>, dataUnit: DataUnit, request: LoadDataRequest) {
|
|
21
|
+
let records = recordsIn ? [...recordsIn] : [];
|
|
22
|
+
records = DataUnitLoaderUtils.applyFilter(records, dataUnit, request?.filters ?? []);
|
|
23
|
+
records = DataUnitLoaderUtils.applySorting(records, dataUnit, request?.sort ?? []);
|
|
24
|
+
|
|
25
|
+
const { offset, limit } = request;
|
|
26
|
+
|
|
27
|
+
const paginationInfoBuilderParams = {
|
|
28
|
+
recordsLength: records.length,
|
|
29
|
+
offset,
|
|
30
|
+
recordsPerPage: limit,
|
|
31
|
+
} as PaginationInfoBuilderParams;
|
|
32
|
+
|
|
33
|
+
return Promise.resolve({
|
|
34
|
+
records: DataUnitLoaderUtils.getPagesByRecords(records, offset, limit),
|
|
35
|
+
paginationInfo: dataUnit.pageSize ? DataUnitLoaderUtils.buildPaginationInfo(paginationInfoBuilderParams) : undefined,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
public static applySorting(records: Array<Record>, dataUnit: DataUnit, sorting: Array<Sort>): Array<Record> {
|
|
41
|
+
if (sorting == undefined || sorting.length == 0) {
|
|
42
|
+
return records;
|
|
43
|
+
}
|
|
44
|
+
const sortingFunction = SortingUtils.getSortingFunction(dataUnit, sorting);
|
|
45
|
+
if (sortingFunction == undefined) {
|
|
46
|
+
return records;
|
|
47
|
+
}
|
|
48
|
+
return records.sort(sortingFunction);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public static getPagesByRecords(records: Record[], offset = 0, limit = 0){
|
|
52
|
+
if(!records || !records.length || !this.hasValidLimitAndOffset(offset, limit)) return [];
|
|
53
|
+
if(limit === 0 && offset === 0) return records;
|
|
54
|
+
return records.slice(offset, offset + limit);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private static hasValidLimitAndOffset(offset: number, limit: number) {
|
|
58
|
+
return offset >= 0 && limit >= 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public static buildPaginationInfo({recordsLength = 0, offset = 0, recordsPerPage = 0}: PaginationInfoBuilderParams): PaginationInfo | undefined {
|
|
62
|
+
|
|
63
|
+
if (!recordsLength) {
|
|
64
|
+
return { currentPage: 0, firstRecord: 0, lastRecord: 0, total: 0, hasMore: false };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const lastRecordIndex = offset + recordsPerPage;
|
|
68
|
+
const lastRecord = lastRecordIndex ? Math.min(lastRecordIndex, recordsLength) : recordsLength;
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
currentPage: recordsPerPage === 0 ? 0 : Math.ceil(offset / recordsPerPage),
|
|
72
|
+
firstRecord: offset + 1,
|
|
73
|
+
lastRecord: lastRecord,
|
|
74
|
+
total: recordsLength,
|
|
75
|
+
hasMore: lastRecord < recordsLength,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
export interface PaginationInfoBuilderParams {
|
|
83
|
+
recordsLength: number,
|
|
84
|
+
offset: number,
|
|
85
|
+
recordsPerPage: number
|
|
86
|
+
}
|