@qrvey/filters 0.0.44 → 0.1.0

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 (279) hide show
  1. package/README.md +63 -1
  2. package/dist/cjs/classes/FilterAdapter.js +1 -80
  3. package/dist/cjs/classes/FilterBuilder.js +33 -251
  4. package/dist/cjs/classes/FilterManager.js +7 -64
  5. package/dist/cjs/classes/FilterResources.js +3 -116
  6. package/dist/cjs/classes/FilterSearcher.js +0 -77
  7. package/dist/cjs/classes/FilterValidation.js +0 -93
  8. package/dist/cjs/classes/FilterValues.js +0 -24
  9. package/dist/cjs/classes/index.js +8 -21
  10. package/dist/cjs/helpers/filter-adapt.helpers.js +3 -46
  11. package/dist/cjs/helpers/filter-adapt.legacy.helpers.js +6 -53
  12. package/dist/cjs/helpers/filter-adapt.logic.helpers.js +7 -128
  13. package/dist/cjs/helpers/filter-builder.helpers.js +1 -8
  14. package/dist/cjs/helpers/filter-settings.helpers.js +6 -41
  15. package/dist/cjs/helpers/filter-validators.helpers.js +15 -9
  16. package/dist/cjs/helpers/filter-verbose.helpers.js +211 -0
  17. package/dist/cjs/helpers/getAggregateFilters.js +11 -0
  18. package/dist/cjs/helpers/getFilterId.js +1 -17
  19. package/dist/cjs/helpers/getFilterType.js +1 -8
  20. package/dist/cjs/helpers/index.js +12 -20
  21. package/dist/cjs/helpers/isDateDistinctGrouping.js +15 -0
  22. package/dist/cjs/helpers/isRankingFilter.js +10 -0
  23. package/dist/cjs/helpers/resolveFilterConditions.js +2 -10
  24. package/dist/cjs/helpers/utils.helpers.js +2 -19
  25. package/dist/cjs/index.js +5 -18
  26. package/dist/cjs/models/index.js +4 -17
  27. package/dist/cjs/resources/filter-grouping.resources.js +0 -18
  28. package/dist/cjs/resources/filter-logic.resources.js +0 -3
  29. package/dist/cjs/resources/filter-scopes.resources.js +10 -27
  30. package/dist/cjs/resources/filter-validators.resources.js +0 -3
  31. package/dist/cjs/resources/filter-verbose.resources.js +13 -0
  32. package/dist/cjs/resources/filters.resources.js +0 -12
  33. package/dist/cjs/resources/index.js +12 -24
  34. package/dist/classes/FilterAdapter.d.ts +0 -80
  35. package/dist/classes/FilterAdapter.js +1 -80
  36. package/dist/classes/FilterBuilder.d.ts +2 -177
  37. package/dist/classes/FilterBuilder.js +33 -251
  38. package/dist/classes/FilterManager.d.ts +7 -62
  39. package/dist/classes/FilterManager.js +7 -64
  40. package/dist/classes/FilterResources.d.ts +1 -115
  41. package/dist/classes/FilterResources.js +3 -116
  42. package/dist/classes/FilterSearcher.d.ts +2 -77
  43. package/dist/classes/FilterSearcher.js +0 -77
  44. package/dist/classes/FilterValidation.d.ts +1 -47
  45. package/dist/classes/FilterValidation.js +0 -93
  46. package/dist/classes/FilterValues.d.ts +0 -25
  47. package/dist/classes/FilterValues.js +0 -24
  48. package/dist/classes/index.d.ts +0 -1
  49. package/dist/helpers/filter-adapt.helpers.d.ts +0 -15
  50. package/dist/helpers/filter-adapt.helpers.js +1 -43
  51. package/dist/helpers/filter-adapt.legacy.helpers.d.ts +0 -20
  52. package/dist/helpers/filter-adapt.legacy.helpers.js +3 -49
  53. package/dist/helpers/filter-adapt.logic.helpers.d.ts +0 -22
  54. package/dist/helpers/filter-adapt.logic.helpers.js +3 -123
  55. package/dist/helpers/filter-builder.helpers.d.ts +0 -7
  56. package/dist/helpers/filter-builder.helpers.js +0 -6
  57. package/dist/helpers/filter-settings.helpers.d.ts +0 -35
  58. package/dist/helpers/filter-settings.helpers.js +0 -34
  59. package/dist/helpers/filter-validators.helpers.d.ts +3 -6
  60. package/dist/helpers/filter-validators.helpers.js +11 -7
  61. package/dist/helpers/filter-verbose.helpers.d.ts +6 -0
  62. package/dist/helpers/filter-verbose.helpers.js +206 -0
  63. package/dist/helpers/getAggregateFilters.d.ts +3 -0
  64. package/dist/helpers/getAggregateFilters.js +7 -0
  65. package/dist/helpers/getFilterId.d.ts +0 -16
  66. package/dist/helpers/getFilterId.js +0 -15
  67. package/dist/helpers/getFilterType.d.ts +0 -7
  68. package/dist/helpers/getFilterType.js +0 -6
  69. package/dist/helpers/index.d.ts +5 -1
  70. package/dist/helpers/index.js +5 -0
  71. package/dist/helpers/isDateDistinctGrouping.d.ts +2 -0
  72. package/dist/helpers/isDateDistinctGrouping.js +12 -0
  73. package/dist/helpers/isRankingFilter.d.ts +2 -0
  74. package/dist/helpers/isRankingFilter.js +7 -0
  75. package/dist/helpers/resolveFilterConditions.d.ts +0 -8
  76. package/dist/helpers/resolveFilterConditions.js +1 -8
  77. package/dist/helpers/utils.helpers.d.ts +0 -17
  78. package/dist/helpers/utils.helpers.js +0 -16
  79. package/dist/index.d.ts +0 -1
  80. package/dist/models/filter-builder.models.d.ts +0 -156
  81. package/dist/models/filter-resources.models.d.ts +0 -53
  82. package/dist/models/filter-searcher.models.d.ts +5 -34
  83. package/dist/models/filter-validation.models.d.ts +0 -40
  84. package/dist/models/index.d.ts +0 -1
  85. package/dist/resources/filter-functions.resources.d.ts +0 -49
  86. package/dist/resources/filter-grouping.resources.d.ts +0 -7
  87. package/dist/resources/filter-grouping.resources.js +0 -18
  88. package/dist/resources/filter-logic.resources.d.ts +0 -79
  89. package/dist/resources/filter-logic.resources.js +0 -3
  90. package/dist/resources/filter-operators.resources.d.ts +0 -1
  91. package/dist/resources/filter-panel.interfaces.d.ts +0 -49
  92. package/dist/resources/filter-scopes.resources.d.ts +2 -25
  93. package/dist/resources/filter-scopes.resources.js +10 -27
  94. package/dist/resources/filter-validation.resources.d.ts +0 -1
  95. package/dist/resources/filter-validators.resources.d.ts +0 -1
  96. package/dist/resources/filter-validators.resources.js +0 -3
  97. package/dist/resources/filter-values.resources.d.ts +0 -13
  98. package/dist/resources/filter-verbose.resources.d.ts +23 -0
  99. package/dist/resources/filter-verbose.resources.js +10 -0
  100. package/dist/resources/filter-visual.resources.d.ts +0 -50
  101. package/dist/resources/filters.resources.d.ts +1 -102
  102. package/dist/resources/filters.resources.js +0 -12
  103. package/dist/resources/index.d.ts +1 -1
  104. package/dist/resources/index.js +1 -0
  105. package/package.json +59 -44
  106. package/.eslintignore +0 -6
  107. package/.eslintrc.json +0 -122
  108. package/.husky/pre-commit +0 -4
  109. package/.lintstagedrc +0 -7
  110. package/.prettierignore +0 -6
  111. package/.prettierrc.json +0 -1
  112. package/CHANGELOG.md +0 -268
  113. package/CODE_OF_CONDUCT.md +0 -132
  114. package/bitbucket-pipelines.yml +0 -92
  115. package/dist/cjs/classes/FilterAdapter.d.ts +0 -107
  116. package/dist/cjs/classes/FilterAdapter.d.ts.map +0 -1
  117. package/dist/cjs/classes/FilterBuilder.d.ts +0 -206
  118. package/dist/cjs/classes/FilterBuilder.d.ts.map +0 -1
  119. package/dist/cjs/classes/FilterManager.d.ts +0 -84
  120. package/dist/cjs/classes/FilterManager.d.ts.map +0 -1
  121. package/dist/cjs/classes/FilterResources.d.ts +0 -139
  122. package/dist/cjs/classes/FilterResources.d.ts.map +0 -1
  123. package/dist/cjs/classes/FilterSearcher.d.ts +0 -90
  124. package/dist/cjs/classes/FilterSearcher.d.ts.map +0 -1
  125. package/dist/cjs/classes/FilterValidation.d.ts +0 -58
  126. package/dist/cjs/classes/FilterValidation.d.ts.map +0 -1
  127. package/dist/cjs/classes/FilterValues.d.ts +0 -33
  128. package/dist/cjs/classes/FilterValues.d.ts.map +0 -1
  129. package/dist/cjs/classes/index.d.ts +0 -8
  130. package/dist/cjs/classes/index.d.ts.map +0 -1
  131. package/dist/cjs/helpers/filter-adapt.helpers.d.ts +0 -21
  132. package/dist/cjs/helpers/filter-adapt.helpers.d.ts.map +0 -1
  133. package/dist/cjs/helpers/filter-adapt.legacy.helpers.d.ts +0 -26
  134. package/dist/cjs/helpers/filter-adapt.legacy.helpers.d.ts.map +0 -1
  135. package/dist/cjs/helpers/filter-adapt.logic.helpers.d.ts +0 -29
  136. package/dist/cjs/helpers/filter-adapt.logic.helpers.d.ts.map +0 -1
  137. package/dist/cjs/helpers/filter-builder.helpers.d.ts +0 -11
  138. package/dist/cjs/helpers/filter-builder.helpers.d.ts.map +0 -1
  139. package/dist/cjs/helpers/filter-settings.helpers.d.ts +0 -42
  140. package/dist/cjs/helpers/filter-settings.helpers.d.ts.map +0 -1
  141. package/dist/cjs/helpers/filter-validators.helpers.d.ts +0 -8
  142. package/dist/cjs/helpers/filter-validators.helpers.d.ts.map +0 -1
  143. package/dist/cjs/helpers/getFilterId.d.ts +0 -18
  144. package/dist/cjs/helpers/getFilterId.d.ts.map +0 -1
  145. package/dist/cjs/helpers/getFilterType.d.ts +0 -11
  146. package/dist/cjs/helpers/getFilterType.d.ts.map +0 -1
  147. package/dist/cjs/helpers/index.d.ts +0 -7
  148. package/dist/cjs/helpers/index.d.ts.map +0 -1
  149. package/dist/cjs/helpers/resolveFilterConditions.d.ts +0 -11
  150. package/dist/cjs/helpers/resolveFilterConditions.d.ts.map +0 -1
  151. package/dist/cjs/helpers/utils.helpers.d.ts +0 -26
  152. package/dist/cjs/helpers/utils.helpers.d.ts.map +0 -1
  153. package/dist/cjs/index.d.ts +0 -5
  154. package/dist/cjs/index.d.ts.map +0 -1
  155. package/dist/cjs/models/filter-builder.models.d.ts +0 -203
  156. package/dist/cjs/models/filter-builder.models.d.ts.map +0 -1
  157. package/dist/cjs/models/filter-resources.models.d.ts +0 -71
  158. package/dist/cjs/models/filter-resources.models.d.ts.map +0 -1
  159. package/dist/cjs/models/filter-searcher.models.d.ts +0 -42
  160. package/dist/cjs/models/filter-searcher.models.d.ts.map +0 -1
  161. package/dist/cjs/models/filter-validation.models.d.ts +0 -59
  162. package/dist/cjs/models/filter-validation.models.d.ts.map +0 -1
  163. package/dist/cjs/models/index.d.ts +0 -4
  164. package/dist/cjs/models/index.d.ts.map +0 -1
  165. package/dist/cjs/resources/filter-functions.resources.d.ts +0 -94
  166. package/dist/cjs/resources/filter-functions.resources.d.ts.map +0 -1
  167. package/dist/cjs/resources/filter-grouping.resources.d.ts +0 -103
  168. package/dist/cjs/resources/filter-grouping.resources.d.ts.map +0 -1
  169. package/dist/cjs/resources/filter-logic.resources.d.ts +0 -135
  170. package/dist/cjs/resources/filter-logic.resources.d.ts.map +0 -1
  171. package/dist/cjs/resources/filter-operators.resources.d.ts +0 -16
  172. package/dist/cjs/resources/filter-operators.resources.d.ts.map +0 -1
  173. package/dist/cjs/resources/filter-panel.interfaces.d.ts +0 -80
  174. package/dist/cjs/resources/filter-panel.interfaces.d.ts.map +0 -1
  175. package/dist/cjs/resources/filter-scopes.resources.d.ts +0 -62
  176. package/dist/cjs/resources/filter-scopes.resources.d.ts.map +0 -1
  177. package/dist/cjs/resources/filter-validation.resources.d.ts +0 -20
  178. package/dist/cjs/resources/filter-validation.resources.d.ts.map +0 -1
  179. package/dist/cjs/resources/filter-validators.resources.d.ts +0 -80
  180. package/dist/cjs/resources/filter-validators.resources.d.ts.map +0 -1
  181. package/dist/cjs/resources/filter-values.resources.d.ts +0 -40
  182. package/dist/cjs/resources/filter-values.resources.d.ts.map +0 -1
  183. package/dist/cjs/resources/filter-visual.resources.d.ts +0 -77
  184. package/dist/cjs/resources/filter-visual.resources.d.ts.map +0 -1
  185. package/dist/cjs/resources/filters.resources.d.ts +0 -168
  186. package/dist/cjs/resources/filters.resources.d.ts.map +0 -1
  187. package/dist/cjs/resources/index.d.ts +0 -11
  188. package/dist/cjs/resources/index.d.ts.map +0 -1
  189. package/dist/classes/FilterAdapter.d.ts.map +0 -1
  190. package/dist/classes/FilterBuilder.d.ts.map +0 -1
  191. package/dist/classes/FilterManager.d.ts.map +0 -1
  192. package/dist/classes/FilterResources.d.ts.map +0 -1
  193. package/dist/classes/FilterSearcher.d.ts.map +0 -1
  194. package/dist/classes/FilterValidation.d.ts.map +0 -1
  195. package/dist/classes/FilterValues.d.ts.map +0 -1
  196. package/dist/classes/index.d.ts.map +0 -1
  197. package/dist/helpers/filter-adapt.helpers.d.ts.map +0 -1
  198. package/dist/helpers/filter-adapt.legacy.helpers.d.ts.map +0 -1
  199. package/dist/helpers/filter-adapt.logic.helpers.d.ts.map +0 -1
  200. package/dist/helpers/filter-builder.helpers.d.ts.map +0 -1
  201. package/dist/helpers/filter-settings.helpers.d.ts.map +0 -1
  202. package/dist/helpers/filter-validators.helpers.d.ts.map +0 -1
  203. package/dist/helpers/getFilterId.d.ts.map +0 -1
  204. package/dist/helpers/getFilterType.d.ts.map +0 -1
  205. package/dist/helpers/index.d.ts.map +0 -1
  206. package/dist/helpers/resolveFilterConditions.d.ts.map +0 -1
  207. package/dist/helpers/utils.helpers.d.ts.map +0 -1
  208. package/dist/index.d.ts.map +0 -1
  209. package/dist/models/filter-builder.models.d.ts.map +0 -1
  210. package/dist/models/filter-resources.models.d.ts.map +0 -1
  211. package/dist/models/filter-searcher.models.d.ts.map +0 -1
  212. package/dist/models/filter-validation.models.d.ts.map +0 -1
  213. package/dist/models/index.d.ts.map +0 -1
  214. package/dist/resources/filter-functions.resources.d.ts.map +0 -1
  215. package/dist/resources/filter-grouping.resources.d.ts.map +0 -1
  216. package/dist/resources/filter-logic.resources.d.ts.map +0 -1
  217. package/dist/resources/filter-operators.resources.d.ts.map +0 -1
  218. package/dist/resources/filter-panel.interfaces.d.ts.map +0 -1
  219. package/dist/resources/filter-scopes.resources.d.ts.map +0 -1
  220. package/dist/resources/filter-validation.resources.d.ts.map +0 -1
  221. package/dist/resources/filter-validators.resources.d.ts.map +0 -1
  222. package/dist/resources/filter-values.resources.d.ts.map +0 -1
  223. package/dist/resources/filter-visual.resources.d.ts.map +0 -1
  224. package/dist/resources/filters.resources.d.ts.map +0 -1
  225. package/dist/resources/index.d.ts.map +0 -1
  226. package/jest.config.js +0 -10
  227. package/jsdoc.config.json +0 -14
  228. package/scripts/clean-build/index.js +0 -62
  229. package/sonar-project.properties +0 -2
  230. package/src/classes/FilterAdapter.ts +0 -208
  231. package/src/classes/FilterBuilder.ts +0 -821
  232. package/src/classes/FilterManager.ts +0 -126
  233. package/src/classes/FilterResources.ts +0 -411
  234. package/src/classes/FilterSearcher.ts +0 -243
  235. package/src/classes/FilterValidation.ts +0 -221
  236. package/src/classes/FilterValues.ts +0 -89
  237. package/src/classes/index.ts +0 -7
  238. package/src/helpers/filter-adapt.helpers.ts +0 -204
  239. package/src/helpers/filter-adapt.legacy.helpers.ts +0 -298
  240. package/src/helpers/filter-adapt.logic.helpers.ts +0 -631
  241. package/src/helpers/filter-builder.helpers.ts +0 -28
  242. package/src/helpers/filter-settings.helpers.ts +0 -133
  243. package/src/helpers/filter-validators.helpers.ts +0 -15
  244. package/src/helpers/getFilterId.ts +0 -35
  245. package/src/helpers/getFilterType.ts +0 -23
  246. package/src/helpers/index.ts +0 -6
  247. package/src/helpers/resolveFilterConditions.ts +0 -29
  248. package/src/helpers/utils.helpers.ts +0 -37
  249. package/src/index.ts +0 -4
  250. package/src/models/filter-builder.models.ts +0 -256
  251. package/src/models/filter-resources.models.ts +0 -89
  252. package/src/models/filter-searcher.models.ts +0 -61
  253. package/src/models/filter-validation.models.ts +0 -71
  254. package/src/models/index.ts +0 -3
  255. package/src/resources/filter-functions.resources.ts +0 -132
  256. package/src/resources/filter-grouping.resources.ts +0 -531
  257. package/src/resources/filter-logic.resources.ts +0 -148
  258. package/src/resources/filter-operators.resources.ts +0 -40
  259. package/src/resources/filter-panel.interfaces.ts +0 -86
  260. package/src/resources/filter-scopes.resources.ts +0 -152
  261. package/src/resources/filter-validation.resources.ts +0 -90
  262. package/src/resources/filter-validators.resources.ts +0 -411
  263. package/src/resources/filter-values.resources.ts +0 -57
  264. package/src/resources/filter-visual.resources.ts +0 -86
  265. package/src/resources/filters.resources.ts +0 -232
  266. package/src/resources/index.ts +0 -10
  267. package/tests/classes/FilterAdapter.test.ts +0 -124
  268. package/tests/classes/FilterBuilder.test.ts +0 -903
  269. package/tests/classes/FilterResources.test.ts +0 -267
  270. package/tests/classes/FilterSearcher.test.ts +0 -188
  271. package/tests/classes/FilterValidation.test.ts +0 -54
  272. package/tests/helpers/getFilterId.test.ts +0 -121
  273. package/tests/mock/datasets.mock.ts +0 -61
  274. package/tests/mock/filters-adapter.mock.ts +0 -646
  275. package/tests/mock/filters-interactive-table.mock.ts +0 -59
  276. package/tests/mock/filters.mock.ts +0 -277
  277. package/tsconfig.doc.json +0 -4
  278. package/tsconfig.eslint.json +0 -4
  279. package/tsconfig.json +0 -113
@@ -1,126 +0,0 @@
1
- import { IDataset } from "@qrvey/utils";
2
-
3
- import { FilterAdapter } from "./FilterAdapter";
4
- import { FilterBuilder } from "./FilterBuilder";
5
- import { FilterSearcher } from "./FilterSearcher";
6
-
7
- import { IFilterPanelInteractiveTable } from "../resources";
8
- import { IFilter } from "../resources/filters.resources";
9
-
10
- /**
11
- * Class to manage the filters
12
- */
13
- export class FilterManager {
14
- /**
15
- * Instance to adapt filters
16
- */
17
- private _adapt: FilterAdapter;
18
-
19
- /**
20
- * Instance to build filters
21
- */
22
- private _builder: FilterBuilder;
23
-
24
- /**
25
- * Instance to search filters
26
- */
27
- private _searchEngine: FilterSearcher;
28
-
29
- /**
30
- * Constructor
31
- * @param _filters the collection of filters
32
- * @param datasets the collection of datasets info
33
- * @param _interactiveTable table of interaction properties for each section
34
- */
35
- constructor(
36
- protected _filters: IFilter[] = [],
37
- protected datasets: IDataset[] = [],
38
- private _interactiveTable?: IFilterPanelInteractiveTable,
39
- ) {
40
- this._searchEngine = new FilterSearcher(_filters);
41
- this._builder = new FilterBuilder(_filters);
42
- this._adapt = new FilterAdapter(_filters, datasets, _interactiveTable);
43
- }
44
-
45
- /**
46
- * **************************************************************************************************
47
- ****************************************** Getters *************************************************
48
- ****************************************************************************************************
49
- */
50
-
51
- /**
52
- * Gets the adapt methods
53
- * @returns the adapt methods
54
- */
55
- public get adapt(): FilterAdapter {
56
- return this._adapt;
57
- }
58
-
59
- /**
60
- * Gets the builder methods
61
- * @returns the builder methods
62
- */
63
- public get builder(): FilterBuilder {
64
- return this._builder;
65
- }
66
-
67
- /**
68
- * Gets the filter collections
69
- * @returns the filters
70
- */
71
- public get filters(): IFilter[] {
72
- return this._filters;
73
- }
74
-
75
- /**
76
- * Gets the interactive table
77
- * @returns the interactive table
78
- */
79
- public get interactiveTable(): IFilterPanelInteractiveTable | undefined {
80
- return this._interactiveTable;
81
- }
82
-
83
- /**
84
- * Gets the search methods
85
- * @returns the search methods
86
- */
87
- public get search(): FilterSearcher {
88
- return this._searchEngine;
89
- }
90
-
91
- /**
92
- * **************************************************************************************************
93
- ****************************************** Setters *************************************************
94
- ****************************************************************************************************
95
- */
96
-
97
- /**
98
- * Sets the datasets
99
- * @param datasets the collection of dataset info
100
- */
101
- public setDatasets(datasets: IDataset[]): void {
102
- this._adapt.setDatasets(datasets);
103
- }
104
-
105
- /**
106
- * Sets the filters
107
- * @param filters the new collection of filters to set
108
- */
109
- public setFilters(filters: IFilter[] = []): void {
110
- this._filters = filters;
111
- this._builder.setFilters(filters);
112
- this._searchEngine.setFilters(filters);
113
- this._adapt.setFilters(filters);
114
- }
115
-
116
- /**
117
- * Sets the table of interactive table
118
- * @param interactiveTable table of interaction properties for each section
119
- */
120
- public setInteractiveTable(
121
- interactiveTable: IFilterPanelInteractiveTable,
122
- ): void {
123
- this._interactiveTable = interactiveTable;
124
- this._adapt.setInteractiveTable(this._interactiveTable);
125
- }
126
- }
@@ -1,411 +0,0 @@
1
- import {
2
- COLUMN,
3
- COLUMN_BY_FORMULA,
4
- FORMULA,
5
- getDateByTimezone,
6
- IColumnVsFormulaType,
7
- IDTimezone,
8
- intersectObjectArrays,
9
- isEmpty,
10
- objectCopy,
11
- } from "@qrvey/utils";
12
-
13
- import { getFilterType } from "../helpers/getFilterType";
14
- import { getInfoGroupingsByColumnTypeSettings } from "../helpers/filter-settings.helpers";
15
- import {
16
- IFilterValue,
17
- IFilterValueRange,
18
- IFilterValueRegular,
19
- IFilterValueRelativeDate,
20
- } from "../resources/filter-values.resources";
21
- import {
22
- IFilterGroupingInfoByColumnTypeSettings,
23
- IFilterGroupingInfoByFilterSettings,
24
- IFilterGroupingInfoListByColumnSettings,
25
- } from "../resources/filter-functions.resources";
26
- import {
27
- FILTER_GROUPING,
28
- FILTER_GROUPING_INFO,
29
- FILTER_GROUPING_INFO_BY_COLUMN_TYPE,
30
- FILTER_GROUPING_INFO_BY_DATE_TIME,
31
- FILTER_GROUPING_INFO_BY_DISTINCT_DATE,
32
- FILTER_GROUPING_INFO_BY_DISTINCT_DATE_TIME,
33
- FILTER_GROUPING_INFO_LIST,
34
- FILTER_GROUPINGS,
35
- IColumnTypeWithGrouping,
36
- IFilterGrouping,
37
- IFilterGroupingInfo,
38
- } from "../resources/filter-grouping.resources";
39
- import {
40
- FILTER_VALIDATOR_INFO,
41
- FILTER_VALIDATOR_INFO_LIST,
42
- FILTER_VALIDATORS,
43
- FILTER_VALIDATORS_INFO_BY_COLUMN_TYPE,
44
- IFilterValidator,
45
- IFilterValidatorInfo,
46
- } from "../resources/filter-validators.resources";
47
- import { IFilter, FILTER_TYPE } from "../resources/filters.resources";
48
- import {
49
- FILTER_SCOPES,
50
- IFilterScope,
51
- } from "../resources/filter-scopes.resources";
52
- import { FilterValidation } from "./FilterValidation";
53
-
54
- /**
55
- * Class to search, build and get resources for the filters.
56
- */
57
- export class FilterResources {
58
- /**
59
- * **************************************************************************************************
60
- **************************************** Grouping **************************************************
61
- ****************************************************************************************************
62
- */
63
-
64
- /**
65
- * Gets a grouping info by a grouping type
66
- * @param grouping the grouping type
67
- * @returns a single grouping info
68
- */
69
- public static getGroupingInfo(
70
- grouping: IFilterGrouping,
71
- ): IFilterGroupingInfo {
72
- return FILTER_GROUPING_INFO[grouping];
73
- }
74
-
75
- /**
76
- * Gets a collection of groupings info by a column type
77
- * @param type the object with column and formula type
78
- * @param settings settings for the function
79
- * @returns a collection of grouping info
80
- */
81
- public static getGroupingInfoListByColumnType(
82
- type: IColumnVsFormulaType,
83
- settings?: IFilterGroupingInfoListByColumnSettings,
84
- ): IFilterGroupingInfo[] {
85
- const { type: columnType, formulaType } = type;
86
-
87
- const completeSettings = getInfoGroupingsByColumnTypeSettings(settings);
88
-
89
- let newType = columnType;
90
- if (formulaType != null) {
91
- newType = COLUMN_BY_FORMULA[formulaType];
92
- }
93
- let groupinInfoList =
94
- FILTER_GROUPING_INFO_BY_COLUMN_TYPE[newType as IColumnTypeWithGrouping];
95
-
96
- if (newType === COLUMN.EXPRESSION)
97
- groupinInfoList = this.getGroupingInfoListOnExpressions(
98
- groupinInfoList,
99
- completeSettings,
100
- );
101
- if (newType === COLUMN.IMAGEUPLOAD)
102
- groupinInfoList = this.getGroupingInfoListOnImageUploads(
103
- groupinInfoList,
104
- completeSettings,
105
- );
106
- if (
107
- newType === COLUMN.DATE ||
108
- newType === COLUMN.DATE_FORMULA ||
109
- formulaType === FORMULA.DATE
110
- )
111
- groupinInfoList = this.getGroupingInfoListOnDates(
112
- groupinInfoList,
113
- completeSettings,
114
- );
115
-
116
- return groupinInfoList;
117
- }
118
-
119
- /**
120
- * Gets a grouping info by a column type and grouping
121
- * @param type the object with column and formula type
122
- * @param grouping the grouping type
123
- * @param settings settings for the function
124
- * @returns the grouping info
125
- */
126
- public static getGroupingInfoByColumnType(
127
- type: IColumnVsFormulaType,
128
- grouping?: IFilterGrouping,
129
- settings?: IFilterGroupingInfoByColumnTypeSettings,
130
- ): IFilterGroupingInfo | undefined {
131
- if (grouping == null) return;
132
-
133
- const groupingInfoList = FilterResources.getGroupingInfoListByColumnType(
134
- type,
135
- settings,
136
- );
137
- const groupingInfo = groupingInfoList.find(
138
- (gInfo) => gInfo.value === grouping,
139
- );
140
- return groupingInfo == null ? groupingInfoList[0] : groupingInfo;
141
- }
142
-
143
- /**
144
- * Gets a grouping info by a filter
145
- * @param filter the filter object
146
- * @returns the grouping info
147
- */
148
- public static getGroupingInfoByFilter(
149
- filter: IFilter,
150
- settings?: IFilterGroupingInfoByFilterSettings,
151
- ): IFilterGroupingInfo | undefined {
152
- if (
153
- !FilterValidation.isGroupingValid(
154
- filter.columnType as IColumnTypeWithGrouping,
155
- filter.validator,
156
- )
157
- )
158
- return;
159
-
160
- return this.getGroupingInfoByColumnType(
161
- { type: filter.columnType, formulaType: filter.formulaType },
162
- filter.grouping,
163
- settings,
164
- );
165
- }
166
-
167
- /**
168
- * Gets a collection of groupings info by a column type
169
- * - The resulting grouping info collection is an intersection of mulitple grouping info collections
170
- * @param types the collection of objects with column and formula types
171
- * @param settings settings for the function
172
- * @returns a collection of grouping info
173
- */
174
- public static getGroupingInfoListByColumnTypes(
175
- types: IColumnVsFormulaType[],
176
- settings?: IFilterGroupingInfoListByColumnSettings[],
177
- ): IFilterGroupingInfo[] {
178
- if (!Array.isArray(types)) return [];
179
-
180
- const infoGroupings = types.map((type, index) =>
181
- FilterResources.getGroupingInfoListByColumnType(type, settings?.[index]),
182
- );
183
- return intersectObjectArrays(infoGroupings, "value");
184
- }
185
-
186
- /**
187
- * Gets the grouping info of Date column type
188
- * @param groupinInfoList the original grouping info list
189
- * @param settings settings for the function
190
- * @returns the new grouping info list
191
- */
192
- public static getGroupingInfoListOnDates(
193
- groupinInfoList: IFilterGroupingInfo[],
194
- settings: IFilterGroupingInfoListByColumnSettings,
195
- ): IFilterGroupingInfo[] {
196
- let newGroupInfoList = groupinInfoList;
197
- if (settings.hasDateTime) {
198
- newGroupInfoList = [
199
- ...newGroupInfoList,
200
- ...FILTER_GROUPING_INFO_BY_DATE_TIME,
201
- ];
202
- }
203
- if (settings.hasDistinctDate) {
204
- newGroupInfoList = [
205
- ...newGroupInfoList,
206
- ...FILTER_GROUPING_INFO_BY_DISTINCT_DATE,
207
- ];
208
- }
209
- if (settings.hasDistinctDateTime) {
210
- newGroupInfoList = [
211
- ...newGroupInfoList,
212
- ...FILTER_GROUPING_INFO_BY_DISTINCT_DATE_TIME,
213
- ];
214
- }
215
-
216
- return newGroupInfoList;
217
- }
218
-
219
- /**
220
- * Gets the grouping info of Expression column type
221
- * @param groupinInfoList the original grouping info list
222
- * @param settings settings for the function
223
- * @returns the new grouping info list
224
- */
225
- public static getGroupingInfoListOnExpressions(
226
- groupinInfoList: IFilterGroupingInfo[],
227
- settings: IFilterGroupingInfoListByColumnSettings,
228
- ): IFilterGroupingInfo[] {
229
- if (!settings.isExpressionCategorizable) return [];
230
-
231
- return groupinInfoList;
232
- }
233
-
234
- /**
235
- * Gets the grouping info of Image Upload column type
236
- * @param groupinInfoList the original grouping info list
237
- * @param settings settings for the function
238
- * @returns the new grouping info list
239
- */
240
- public static getGroupingInfoListOnImageUploads(
241
- groupinInfoList: IFilterGroupingInfo[],
242
- settings: IFilterGroupingInfoListByColumnSettings,
243
- ): IFilterGroupingInfo[] {
244
- if (settings.hasImageUploadAnalysis) return groupinInfoList;
245
-
246
- return groupinInfoList.filter(
247
- (groupingInfo) =>
248
- groupingInfo.value !== FILTER_GROUPING.IMAGEUPLOAD_IMAGEWORDS,
249
- );
250
- }
251
-
252
- /**
253
- * Gets the complete collection of grouping types
254
- * @returns the collection of grouping types
255
- */
256
- public static getGroupings(): IFilterGrouping[] {
257
- return FILTER_GROUPINGS;
258
- }
259
-
260
- /**
261
- * Gets the complete collection of validator info
262
- * @returns the collection of validator info
263
- */
264
- public static getGroupingsInfoList(): IFilterGroupingInfo[] {
265
- return FILTER_GROUPING_INFO_LIST;
266
- }
267
-
268
- /**
269
- * **************************************************************************************************
270
- **************************************** Scopes *************************************************
271
- ****************************************************************************************************
272
- */
273
-
274
- /**
275
- * Gets the collection of filter scopes in order of hierarchy
276
- * @returns the collection of validator info
277
- */
278
- public static getHierarchyScopes(): IFilterScope[] {
279
- return FILTER_SCOPES;
280
- }
281
-
282
- /**
283
- * **************************************************************************************************
284
- **************************************** Timezone *************************************************
285
- ****************************************************************************************************
286
- */
287
-
288
- /**
289
- * Gets the filters transformed by the given timezone
290
- * @param filters the filters to transform
291
- * @param timezone the timezone info
292
- * @returns the transformed filters to a new timezone
293
- */
294
- public static getFiltersByTimezone(
295
- filters: IFilter[],
296
- timezone: IDTimezone,
297
- ): IFilter[] {
298
- if (isEmpty(filters) || !Array.isArray(filters)) return [];
299
-
300
- const newFilters: IFilter[] = objectCopy(filters);
301
- return newFilters.map((filter) => {
302
- const type = getFilterType(filter.columnType, filter.validator);
303
-
304
- let values: IFilterValue[] = filter.values || [];
305
- switch (type) {
306
- case FILTER_TYPE.RANGE:
307
- values = (values as IFilterValueRange[]).map((value) => ({
308
- ...value,
309
- min:
310
- value.min != null
311
- ? getDateByTimezone(value.min, timezone)
312
- : undefined,
313
- max:
314
- value.max != null
315
- ? getDateByTimezone(value.max, timezone)
316
- : undefined,
317
- }));
318
- break;
319
- case FILTER_TYPE.REGULAR:
320
- values = (values as IFilterValueRegular[]).map((value) => ({
321
- ...value,
322
- value:
323
- value.value != null
324
- ? getDateByTimezone(value.value, timezone)
325
- : undefined,
326
- }));
327
- break;
328
- case FILTER_TYPE.RELATIVE:
329
- values = (values as IFilterValueRelativeDate[]).map((value) => ({
330
- ...value,
331
- anchor:
332
- typeof value.anchor === "string"
333
- ? getDateByTimezone(value.anchor, timezone)
334
- : value.anchor,
335
- }));
336
- break;
337
- }
338
- return {
339
- ...filter,
340
- values,
341
- };
342
- });
343
- }
344
-
345
- /**
346
- * **************************************************************************************************
347
- **************************************** Validator *************************************************
348
- ****************************************************************************************************
349
- */
350
-
351
- /**
352
- * Gets a validator info by a validator type
353
- * @param validator the validator type
354
- * @returns a single validator info
355
- */
356
- public static getValidatorInfo(
357
- validator: IFilterValidator,
358
- ): IFilterValidatorInfo {
359
- return FILTER_VALIDATOR_INFO[validator];
360
- }
361
-
362
- /**
363
- * Gets the complete collection of validator info
364
- * @returns the collection of validator info
365
- */
366
- public static getValidatorInfoList(): IFilterValidatorInfo[] {
367
- return FILTER_VALIDATOR_INFO_LIST;
368
- }
369
-
370
- /**
371
- * Gets a collection of validator info by a column type
372
- * @param type the object with column and formula type
373
- * @returns a collection of validator info
374
- */
375
- public static getValidatorInfoListByColumnType(
376
- type: IColumnVsFormulaType,
377
- ): IFilterValidatorInfo[] {
378
- const { type: colummType, formulaType } = type;
379
-
380
- let newType = colummType;
381
- if (formulaType != null) {
382
- newType = COLUMN_BY_FORMULA[formulaType];
383
- }
384
- return FILTER_VALIDATORS_INFO_BY_COLUMN_TYPE[newType];
385
- }
386
-
387
- /**
388
- * Gets a collection of validator info by a mutiple column types
389
- * - The resulting validator info collection is an intersection of mulitple validator info collections
390
- * @param types a collection of objects with column and formula types
391
- * @returns a collection of validator info
392
- */
393
- public static getValidatorInfoListByColumnTypes(
394
- types: IColumnVsFormulaType[],
395
- ): IFilterValidatorInfo[] {
396
- if (!Array.isArray(types)) return [];
397
-
398
- const infoValidators = types.map((type) =>
399
- FilterResources.getValidatorInfoListByColumnType(type),
400
- );
401
- return intersectObjectArrays(infoValidators, "value");
402
- }
403
-
404
- /**
405
- * Gets the complete collection of validator types
406
- * @returns the collection of validator types
407
- */
408
- public static getValidators(): IFilterValidator[] {
409
- return FILTER_VALIDATORS;
410
- }
411
- }