@qrvey/utils 1.3.0-18 → 1.3.0-19
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/dist/cjs/filters/helpers/backend/getLogicByDatasets.d.ts +11 -0
- package/dist/cjs/filters/helpers/backend/getLogicByDatasets.js +34 -0
- package/dist/cjs/filters/helpers/backend/getLogicByDatasetsColumns.d.ts +12 -0
- package/dist/cjs/filters/helpers/backend/getLogicByDatasetsColumns.js +47 -0
- package/dist/cjs/filters/helpers/backend/index.d.ts +2 -0
- package/dist/cjs/filters/helpers/backend/index.js +2 -0
- package/dist/cjs/filters/interfaces/backend/IFBExpression.d.ts +1 -0
- package/dist/cjs/filters/interfaces/functions/IFFGetLogicByDatasets.d.ts +6 -0
- package/dist/cjs/filters/interfaces/functions/IFFGetLogicByDatasets.js +2 -0
- package/dist/cjs/filters/interfaces/functions/IFFGetLogicByDatasetsColumns.d.ts +7 -0
- package/dist/cjs/filters/interfaces/functions/IFFGetLogicByDatasetsColumns.js +2 -0
- package/dist/cjs/filters/interfaces/functions/index.d.ts +2 -0
- package/dist/cjs/filters/interfaces/functions/index.js +2 -0
- package/dist/cjs/filters/services/Filters.api.js +2 -1
- package/dist/filters/helpers/backend/getLogicByDatasets.d.ts +11 -0
- package/dist/filters/helpers/backend/getLogicByDatasets.js +30 -0
- package/dist/filters/helpers/backend/getLogicByDatasetsColumns.d.ts +12 -0
- package/dist/filters/helpers/backend/getLogicByDatasetsColumns.js +43 -0
- package/dist/filters/helpers/backend/index.d.ts +2 -0
- package/dist/filters/helpers/backend/index.js +2 -0
- package/dist/filters/interfaces/backend/IFBExpression.d.ts +1 -0
- package/dist/filters/interfaces/functions/IFFGetLogicByDatasets.d.ts +6 -0
- package/dist/filters/interfaces/functions/IFFGetLogicByDatasets.js +1 -0
- package/dist/filters/interfaces/functions/IFFGetLogicByDatasetsColumns.d.ts +7 -0
- package/dist/filters/interfaces/functions/IFFGetLogicByDatasetsColumns.js +1 -0
- package/dist/filters/interfaces/functions/index.d.ts +2 -0
- package/dist/filters/interfaces/functions/index.js +2 -0
- package/dist/filters/services/Filters.api.js +2 -1
- package/package.json +1 -1
- package/src/filters/helpers/backend/getLogicByDatasets.ts +37 -0
- package/src/filters/helpers/backend/getLogicByDatasetsColumns.ts +52 -0
- package/src/filters/helpers/backend/index.ts +2 -0
- package/src/filters/interfaces/backend/IFBExpression.ts +1 -0
- package/src/filters/interfaces/functions/IFFGetLogicByDatasets.ts +6 -0
- package/src/filters/interfaces/functions/IFFGetLogicByDatasetsColumns.ts +7 -0
- package/src/filters/interfaces/functions/index.ts +2 -0
- package/src/filters/services/Filters.api.ts +2 -1
- package/test/filters/backend/getLogicByDatasetsColumns.test.js +312 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IFBLogic } from "../../interfaces/backend/IFBLogic";
|
|
2
|
+
import { IFFGetLogicByDatasets } from "../../interfaces/functions/IFFGetLogicByDatasets";
|
|
3
|
+
/**
|
|
4
|
+
* [TODO: Add filterEmptyArrays to the filterNestedTree filter condition. Firstly, that function should accept this argument]
|
|
5
|
+
* Filters the logic by a qrveyids array
|
|
6
|
+
* If an qrveyid is not provided in the expression the filter passes normally
|
|
7
|
+
* @param logic The logic of the filter
|
|
8
|
+
* @param datasets The collection of qrveyids
|
|
9
|
+
* @returns a new filtered logic
|
|
10
|
+
*/
|
|
11
|
+
export declare function getLogicByDatasets(logic: IFBLogic[], datasets?: string[], settings?: IFFGetLogicByDatasets): IFBLogic[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLogicByDatasets = void 0;
|
|
4
|
+
const general_1 = require("../../../general");
|
|
5
|
+
const isEmpty_1 = require("../../../general/mix/isEmpty");
|
|
6
|
+
/**
|
|
7
|
+
* [TODO: Add filterEmptyArrays to the filterNestedTree filter condition. Firstly, that function should accept this argument]
|
|
8
|
+
* Filters the logic by a qrveyids array
|
|
9
|
+
* If an qrveyid is not provided in the expression the filter passes normally
|
|
10
|
+
* @param logic The logic of the filter
|
|
11
|
+
* @param datasets The collection of qrveyids
|
|
12
|
+
* @returns a new filtered logic
|
|
13
|
+
*/
|
|
14
|
+
function getLogicByDatasets(logic, datasets = [], settings) {
|
|
15
|
+
if ((0, isEmpty_1.isEmpty)(logic))
|
|
16
|
+
return;
|
|
17
|
+
if ((0, isEmpty_1.isEmpty)(datasets))
|
|
18
|
+
return logic;
|
|
19
|
+
settings = getGetLogicByDatasetsSettings(settings);
|
|
20
|
+
return logic.map(_l => (Object.assign(Object.assign({}, _l), { filters: (0, general_1.filterNestedTree)(_l.filters, 'expressions', (expression) => {
|
|
21
|
+
const dataset = datasets.find(_data => _data === expression.qrveyid);
|
|
22
|
+
return (settings.letPassUndefinedProperties.qrveyid && !(0, general_1._hasProperty)(expression, 'qrveyid')) || !(0, isEmpty_1.isEmpty)(dataset);
|
|
23
|
+
}) })));
|
|
24
|
+
}
|
|
25
|
+
exports.getLogicByDatasets = getLogicByDatasets;
|
|
26
|
+
function getGetLogicByDatasetsSettings(settings) {
|
|
27
|
+
var _a, _b, _c;
|
|
28
|
+
return {
|
|
29
|
+
filterEmptyArrays: (_a = settings === null || settings === void 0 ? void 0 : settings.filterEmptyArrays) !== null && _a !== void 0 ? _a : true,
|
|
30
|
+
letPassUndefinedProperties: {
|
|
31
|
+
qrveyid: (_c = (_b = settings === null || settings === void 0 ? void 0 : settings.letPassUndefinedProperties) === null || _b === void 0 ? void 0 : _b.qrveyid) !== null && _c !== void 0 ? _c : true
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IDataset } from "../../../qrvey/interfaces/IDataset";
|
|
2
|
+
import { IFBLogic } from "../../interfaces/backend/IFBLogic";
|
|
3
|
+
import { IFFGetLogicByDatasetsColumns } from "../../interfaces/functions/IFFGetLogicByDatasetsColumns";
|
|
4
|
+
/**
|
|
5
|
+
* @todo MODULE NO READY
|
|
6
|
+
* Filters the logic by a datasets array
|
|
7
|
+
* If an qrveyid is not provided in the expression a the filter passes normally
|
|
8
|
+
* @param logic The logic of the filter
|
|
9
|
+
* @param datasets The collection of datasets
|
|
10
|
+
* @returns a new filtered logic
|
|
11
|
+
*/
|
|
12
|
+
export declare function getLogicByDatasetsColumns(logic: IFBLogic[], datasets?: IDataset[], settings?: IFFGetLogicByDatasetsColumns): IFBLogic[];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLogicByDatasetsColumns = void 0;
|
|
4
|
+
const filterNestedTree_1 = require("../../../general/array/filterNestedTree");
|
|
5
|
+
const isEmpty_1 = require("../../../general/mix/isEmpty");
|
|
6
|
+
const hasProperty_1 = require("../../../general/object/hasProperty");
|
|
7
|
+
/**
|
|
8
|
+
* @todo MODULE NO READY
|
|
9
|
+
* Filters the logic by a datasets array
|
|
10
|
+
* If an qrveyid is not provided in the expression a the filter passes normally
|
|
11
|
+
* @param logic The logic of the filter
|
|
12
|
+
* @param datasets The collection of datasets
|
|
13
|
+
* @returns a new filtered logic
|
|
14
|
+
*/
|
|
15
|
+
function getLogicByDatasetsColumns(logic, datasets = [], settings) {
|
|
16
|
+
if ((0, isEmpty_1.isEmpty)(logic))
|
|
17
|
+
return;
|
|
18
|
+
if ((0, isEmpty_1.isEmpty)(datasets))
|
|
19
|
+
return logic;
|
|
20
|
+
settings = getGetLogicByDatasetsSettings(settings);
|
|
21
|
+
return logic.map(_l => (Object.assign(Object.assign({}, _l), { filters: (0, filterNestedTree_1.filterNestedTree)(_l.filters, 'expressions', (expression) => {
|
|
22
|
+
const letQrveyidPass = settings.letPassUndefinedProperties.qrveyid || (0, hasProperty_1._hasProperty)(expression, 'qrveyid');
|
|
23
|
+
let letQuestionidPass = settings.letPassUndefinedProperties.questionid || (0, hasProperty_1._hasProperty)(expression, 'questionid');
|
|
24
|
+
const dataset = letQrveyidPass ? datasets.find(_data => _data.qrveyid === expression.qrveyid) : undefined;
|
|
25
|
+
if (!(0, isEmpty_1.isEmpty)(dataset)) {
|
|
26
|
+
const column = letQuestionidPass ? (dataset.options || []).find(option => option.id === expression.questionid) : undefined;
|
|
27
|
+
letQuestionidPass = letQuestionidPass || !(0, isEmpty_1.isEmpty)(column);
|
|
28
|
+
}
|
|
29
|
+
return (letQrveyidPass && !(0, isEmpty_1.isEmpty)(dataset)) && letQuestionidPass;
|
|
30
|
+
}) })));
|
|
31
|
+
}
|
|
32
|
+
exports.getLogicByDatasetsColumns = getLogicByDatasetsColumns;
|
|
33
|
+
/**
|
|
34
|
+
* Gets the default settings for the getLogicByDatasetsColumn function
|
|
35
|
+
* @param settings the settings given by the implementer
|
|
36
|
+
* @returns an object with all properties set
|
|
37
|
+
*/
|
|
38
|
+
function getGetLogicByDatasetsSettings(settings) {
|
|
39
|
+
var _a, _b, _c, _d, _e;
|
|
40
|
+
return {
|
|
41
|
+
filterEmptyArrays: (_a = settings === null || settings === void 0 ? void 0 : settings.filterEmptyArrays) !== null && _a !== void 0 ? _a : true,
|
|
42
|
+
letPassUndefinedProperties: {
|
|
43
|
+
qrveyid: (_c = (_b = settings === null || settings === void 0 ? void 0 : settings.letPassUndefinedProperties) === null || _b === void 0 ? void 0 : _b.qrveyid) !== null && _c !== void 0 ? _c : true,
|
|
44
|
+
questionid: (_e = (_d = settings === null || settings === void 0 ? void 0 : settings.letPassUndefinedProperties) === null || _d === void 0 ? void 0 : _d.questionid) !== null && _e !== void 0 ? _e : true
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -6,5 +6,7 @@ export * from './getBackendGroupValue';
|
|
|
6
6
|
export * from './getBackendProperty';
|
|
7
7
|
export * from './getBackendValidator';
|
|
8
8
|
export * from './getBackendValues';
|
|
9
|
+
export * from './getLogicByDatasets';
|
|
10
|
+
export * from './getLogicByDatasetsColumns';
|
|
9
11
|
export * from './getLogicByScopes';
|
|
10
12
|
export * from './getLogicByScopesHierarchy';
|
|
@@ -22,6 +22,8 @@ __exportStar(require("./getBackendGroupValue"), exports);
|
|
|
22
22
|
__exportStar(require("./getBackendProperty"), exports);
|
|
23
23
|
__exportStar(require("./getBackendValidator"), exports);
|
|
24
24
|
__exportStar(require("./getBackendValues"), exports);
|
|
25
|
+
__exportStar(require("./getLogicByDatasets"), exports);
|
|
26
|
+
__exportStar(require("./getLogicByDatasetsColumns"), exports);
|
|
25
27
|
__exportStar(require("./getLogicByScopes"), exports);
|
|
26
28
|
__exportStar(require("./getLogicByScopesHierarchy"), exports);
|
|
27
29
|
// export * from './hasDatasetRelatedFilters';
|
|
@@ -14,6 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./IFFGetLogicByDatasets"), exports);
|
|
18
|
+
__exportStar(require("./IFFGetLogicByDatasetsColumns"), exports);
|
|
17
19
|
__exportStar(require("./IFFiltersGetData"), exports);
|
|
18
20
|
__exportStar(require("./IFFiltersGetValuesFromDataset"), exports);
|
|
19
21
|
__exportStar(require("./IFFiltersGetValuesFromModel"), exports);
|
|
@@ -32,6 +32,7 @@ const areStaticColumnValues_1 = require("../../qrvey/helpers/areStaticColumnValu
|
|
|
32
32
|
const getValuesFromDataset_1 = require("../helpers/common/getValuesFromDataset");
|
|
33
33
|
const getFiltersByDatasetsColumns_1 = require("../helpers/common/getFiltersByDatasetsColumns");
|
|
34
34
|
const getDatasetByColumn_1 = require("../../qrvey/helpers/getDatasetByColumn");
|
|
35
|
+
const getLogicByDatasets_1 = require("../helpers/backend/getLogicByDatasets");
|
|
35
36
|
class FiltersApi {
|
|
36
37
|
constructor(cfg) {
|
|
37
38
|
this.setConfig(cfg);
|
|
@@ -107,7 +108,7 @@ class FiltersApi {
|
|
|
107
108
|
const hierarchyLogic = (0, getLogicByScopesHierarchy_1.getLogicByScopesHierarchy)(logics, scopes, (_a = config.filter) === null || _a === void 0 ? void 0 : _a.extras.scope);
|
|
108
109
|
return [
|
|
109
110
|
...hierarchyLogic,
|
|
110
|
-
...(0, buildUserFilters_1.buildUserFilters)(config.userFilters) || [],
|
|
111
|
+
...(0, getLogicByDatasets_1.getLogicByDatasets)((0, buildUserFilters_1.buildUserFilters)(config.userFilters), (0, isEmpty_1.isEmpty)(dataset) ? [] : [dataset.qrveyid]) || [],
|
|
111
112
|
];
|
|
112
113
|
}
|
|
113
114
|
getFilter(config) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IFBLogic } from "../../interfaces/backend/IFBLogic";
|
|
2
|
+
import { IFFGetLogicByDatasets } from "../../interfaces/functions/IFFGetLogicByDatasets";
|
|
3
|
+
/**
|
|
4
|
+
* [TODO: Add filterEmptyArrays to the filterNestedTree filter condition. Firstly, that function should accept this argument]
|
|
5
|
+
* Filters the logic by a qrveyids array
|
|
6
|
+
* If an qrveyid is not provided in the expression the filter passes normally
|
|
7
|
+
* @param logic The logic of the filter
|
|
8
|
+
* @param datasets The collection of qrveyids
|
|
9
|
+
* @returns a new filtered logic
|
|
10
|
+
*/
|
|
11
|
+
export declare function getLogicByDatasets(logic: IFBLogic[], datasets?: string[], settings?: IFFGetLogicByDatasets): IFBLogic[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { filterNestedTree, _hasProperty } from "../../../general";
|
|
2
|
+
import { isEmpty } from "../../../general/mix/isEmpty";
|
|
3
|
+
/**
|
|
4
|
+
* [TODO: Add filterEmptyArrays to the filterNestedTree filter condition. Firstly, that function should accept this argument]
|
|
5
|
+
* Filters the logic by a qrveyids array
|
|
6
|
+
* If an qrveyid is not provided in the expression the filter passes normally
|
|
7
|
+
* @param logic The logic of the filter
|
|
8
|
+
* @param datasets The collection of qrveyids
|
|
9
|
+
* @returns a new filtered logic
|
|
10
|
+
*/
|
|
11
|
+
export function getLogicByDatasets(logic, datasets = [], settings) {
|
|
12
|
+
if (isEmpty(logic))
|
|
13
|
+
return;
|
|
14
|
+
if (isEmpty(datasets))
|
|
15
|
+
return logic;
|
|
16
|
+
settings = getGetLogicByDatasetsSettings(settings);
|
|
17
|
+
return logic.map(_l => (Object.assign(Object.assign({}, _l), { filters: filterNestedTree(_l.filters, 'expressions', (expression) => {
|
|
18
|
+
const dataset = datasets.find(_data => _data === expression.qrveyid);
|
|
19
|
+
return (settings.letPassUndefinedProperties.qrveyid && !_hasProperty(expression, 'qrveyid')) || !isEmpty(dataset);
|
|
20
|
+
}) })));
|
|
21
|
+
}
|
|
22
|
+
function getGetLogicByDatasetsSettings(settings) {
|
|
23
|
+
var _a, _b, _c;
|
|
24
|
+
return {
|
|
25
|
+
filterEmptyArrays: (_a = settings === null || settings === void 0 ? void 0 : settings.filterEmptyArrays) !== null && _a !== void 0 ? _a : true,
|
|
26
|
+
letPassUndefinedProperties: {
|
|
27
|
+
qrveyid: (_c = (_b = settings === null || settings === void 0 ? void 0 : settings.letPassUndefinedProperties) === null || _b === void 0 ? void 0 : _b.qrveyid) !== null && _c !== void 0 ? _c : true
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IDataset } from "../../../qrvey/interfaces/IDataset";
|
|
2
|
+
import { IFBLogic } from "../../interfaces/backend/IFBLogic";
|
|
3
|
+
import { IFFGetLogicByDatasetsColumns } from "../../interfaces/functions/IFFGetLogicByDatasetsColumns";
|
|
4
|
+
/**
|
|
5
|
+
* @todo MODULE NO READY
|
|
6
|
+
* Filters the logic by a datasets array
|
|
7
|
+
* If an qrveyid is not provided in the expression a the filter passes normally
|
|
8
|
+
* @param logic The logic of the filter
|
|
9
|
+
* @param datasets The collection of datasets
|
|
10
|
+
* @returns a new filtered logic
|
|
11
|
+
*/
|
|
12
|
+
export declare function getLogicByDatasetsColumns(logic: IFBLogic[], datasets?: IDataset[], settings?: IFFGetLogicByDatasetsColumns): IFBLogic[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { filterNestedTree } from "../../../general/array/filterNestedTree";
|
|
2
|
+
import { isEmpty } from "../../../general/mix/isEmpty";
|
|
3
|
+
import { _hasProperty } from "../../../general/object/hasProperty";
|
|
4
|
+
/**
|
|
5
|
+
* @todo MODULE NO READY
|
|
6
|
+
* Filters the logic by a datasets array
|
|
7
|
+
* If an qrveyid is not provided in the expression a the filter passes normally
|
|
8
|
+
* @param logic The logic of the filter
|
|
9
|
+
* @param datasets The collection of datasets
|
|
10
|
+
* @returns a new filtered logic
|
|
11
|
+
*/
|
|
12
|
+
export function getLogicByDatasetsColumns(logic, datasets = [], settings) {
|
|
13
|
+
if (isEmpty(logic))
|
|
14
|
+
return;
|
|
15
|
+
if (isEmpty(datasets))
|
|
16
|
+
return logic;
|
|
17
|
+
settings = getGetLogicByDatasetsSettings(settings);
|
|
18
|
+
return logic.map(_l => (Object.assign(Object.assign({}, _l), { filters: filterNestedTree(_l.filters, 'expressions', (expression) => {
|
|
19
|
+
const letQrveyidPass = settings.letPassUndefinedProperties.qrveyid || _hasProperty(expression, 'qrveyid');
|
|
20
|
+
let letQuestionidPass = settings.letPassUndefinedProperties.questionid || _hasProperty(expression, 'questionid');
|
|
21
|
+
const dataset = letQrveyidPass ? datasets.find(_data => _data.qrveyid === expression.qrveyid) : undefined;
|
|
22
|
+
if (!isEmpty(dataset)) {
|
|
23
|
+
const column = letQuestionidPass ? (dataset.options || []).find(option => option.id === expression.questionid) : undefined;
|
|
24
|
+
letQuestionidPass = letQuestionidPass || !isEmpty(column);
|
|
25
|
+
}
|
|
26
|
+
return (letQrveyidPass && !isEmpty(dataset)) && letQuestionidPass;
|
|
27
|
+
}) })));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Gets the default settings for the getLogicByDatasetsColumn function
|
|
31
|
+
* @param settings the settings given by the implementer
|
|
32
|
+
* @returns an object with all properties set
|
|
33
|
+
*/
|
|
34
|
+
function getGetLogicByDatasetsSettings(settings) {
|
|
35
|
+
var _a, _b, _c, _d, _e;
|
|
36
|
+
return {
|
|
37
|
+
filterEmptyArrays: (_a = settings === null || settings === void 0 ? void 0 : settings.filterEmptyArrays) !== null && _a !== void 0 ? _a : true,
|
|
38
|
+
letPassUndefinedProperties: {
|
|
39
|
+
qrveyid: (_c = (_b = settings === null || settings === void 0 ? void 0 : settings.letPassUndefinedProperties) === null || _b === void 0 ? void 0 : _b.qrveyid) !== null && _c !== void 0 ? _c : true,
|
|
40
|
+
questionid: (_e = (_d = settings === null || settings === void 0 ? void 0 : settings.letPassUndefinedProperties) === null || _d === void 0 ? void 0 : _d.questionid) !== null && _e !== void 0 ? _e : true
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -6,5 +6,7 @@ export * from './getBackendGroupValue';
|
|
|
6
6
|
export * from './getBackendProperty';
|
|
7
7
|
export * from './getBackendValidator';
|
|
8
8
|
export * from './getBackendValues';
|
|
9
|
+
export * from './getLogicByDatasets';
|
|
10
|
+
export * from './getLogicByDatasetsColumns';
|
|
9
11
|
export * from './getLogicByScopes';
|
|
10
12
|
export * from './getLogicByScopesHierarchy';
|
|
@@ -6,6 +6,8 @@ export * from './getBackendGroupValue';
|
|
|
6
6
|
export * from './getBackendProperty';
|
|
7
7
|
export * from './getBackendValidator';
|
|
8
8
|
export * from './getBackendValues';
|
|
9
|
+
export * from './getLogicByDatasets';
|
|
10
|
+
export * from './getLogicByDatasetsColumns';
|
|
9
11
|
export * from './getLogicByScopes';
|
|
10
12
|
export * from './getLogicByScopesHierarchy';
|
|
11
13
|
// export * from './hasDatasetRelatedFilters';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -26,6 +26,7 @@ import { areStaticColumnValues } from '../../qrvey/helpers/areStaticColumnValues
|
|
|
26
26
|
import { getValuesFromDataset } from '../helpers/common/getValuesFromDataset';
|
|
27
27
|
import { getFiltersByDatasetsColumns } from '../helpers/common/getFiltersByDatasetsColumns';
|
|
28
28
|
import { getDatasetByColumn } from '../../qrvey/helpers/getDatasetByColumn';
|
|
29
|
+
import { getLogicByDatasets } from '../helpers/backend/getLogicByDatasets';
|
|
29
30
|
export class FiltersApi {
|
|
30
31
|
constructor(cfg) {
|
|
31
32
|
this.setConfig(cfg);
|
|
@@ -101,7 +102,7 @@ export class FiltersApi {
|
|
|
101
102
|
const hierarchyLogic = getLogicByScopesHierarchy(logics, scopes, (_a = config.filter) === null || _a === void 0 ? void 0 : _a.extras.scope);
|
|
102
103
|
return [
|
|
103
104
|
...hierarchyLogic,
|
|
104
|
-
...buildUserFilters(config.userFilters) || [],
|
|
105
|
+
...getLogicByDatasets(buildUserFilters(config.userFilters), isEmpty(dataset) ? [] : [dataset.qrveyid]) || [],
|
|
105
106
|
];
|
|
106
107
|
}
|
|
107
108
|
getFilter(config) {
|
package/package.json
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { filterNestedTree, _hasProperty } from "../../../general";
|
|
2
|
+
import { isEmpty } from "../../../general/mix/isEmpty";
|
|
3
|
+
import { IFBExpression } from "../../interfaces/backend/IFBExpression";
|
|
4
|
+
import { IFBLogic } from "../../interfaces/backend/IFBLogic";
|
|
5
|
+
import { IFFGetLogicByDatasets } from "../../interfaces/functions/IFFGetLogicByDatasets";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* [TODO: Add filterEmptyArrays to the filterNestedTree filter condition. Firstly, that function should accept this argument]
|
|
9
|
+
* Filters the logic by a qrveyids array
|
|
10
|
+
* If an qrveyid is not provided in the expression the filter passes normally
|
|
11
|
+
* @param logic The logic of the filter
|
|
12
|
+
* @param datasets The collection of qrveyids
|
|
13
|
+
* @returns a new filtered logic
|
|
14
|
+
*/
|
|
15
|
+
export function getLogicByDatasets(logic: IFBLogic[], datasets: string[] = [], settings?: IFFGetLogicByDatasets): IFBLogic[] {
|
|
16
|
+
if (isEmpty(logic)) return;
|
|
17
|
+
if (isEmpty(datasets)) return logic;
|
|
18
|
+
|
|
19
|
+
settings = getGetLogicByDatasetsSettings(settings);
|
|
20
|
+
|
|
21
|
+
return logic.map(_l => ({
|
|
22
|
+
..._l,
|
|
23
|
+
filters: filterNestedTree(_l.filters, 'expressions', (expression: IFBExpression) => {
|
|
24
|
+
const dataset = datasets.find(_data => _data === expression.qrveyid);
|
|
25
|
+
return (settings.letPassUndefinedProperties.qrveyid && !_hasProperty(expression, 'qrveyid')) || !isEmpty(dataset);
|
|
26
|
+
})
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getGetLogicByDatasetsSettings(settings?: IFFGetLogicByDatasets): IFFGetLogicByDatasets {
|
|
31
|
+
return {
|
|
32
|
+
filterEmptyArrays: settings?.filterEmptyArrays ?? true,
|
|
33
|
+
letPassUndefinedProperties: {
|
|
34
|
+
qrveyid: settings?.letPassUndefinedProperties?.qrveyid ?? true
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { filterNestedTree } from "../../../general/array/filterNestedTree";
|
|
2
|
+
import { isEmpty } from "../../../general/mix/isEmpty";
|
|
3
|
+
import { _hasProperty } from "../../../general/object/hasProperty";
|
|
4
|
+
import { IDataset } from "../../../qrvey/interfaces/IDataset";
|
|
5
|
+
import { IFBExpression } from "../../interfaces/backend/IFBExpression";
|
|
6
|
+
import { IFBLogic } from "../../interfaces/backend/IFBLogic";
|
|
7
|
+
import { IFFGetLogicByDatasetsColumns } from "../../interfaces/functions/IFFGetLogicByDatasetsColumns";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @todo MODULE NO READY
|
|
11
|
+
* Filters the logic by a datasets array
|
|
12
|
+
* If an qrveyid is not provided in the expression a the filter passes normally
|
|
13
|
+
* @param logic The logic of the filter
|
|
14
|
+
* @param datasets The collection of datasets
|
|
15
|
+
* @returns a new filtered logic
|
|
16
|
+
*/
|
|
17
|
+
export function getLogicByDatasetsColumns(logic: IFBLogic[], datasets: IDataset[] = [], settings?: IFFGetLogicByDatasetsColumns): IFBLogic[] {
|
|
18
|
+
if (isEmpty(logic)) return;
|
|
19
|
+
if (isEmpty(datasets)) return logic;
|
|
20
|
+
|
|
21
|
+
settings = getGetLogicByDatasetsSettings(settings);
|
|
22
|
+
|
|
23
|
+
return logic.map(_l => ({
|
|
24
|
+
..._l,
|
|
25
|
+
filters: filterNestedTree(_l.filters, 'expressions', (expression: IFBExpression) => {
|
|
26
|
+
const letQrveyidPass = settings.letPassUndefinedProperties.qrveyid || _hasProperty(expression, 'qrveyid');
|
|
27
|
+
let letQuestionidPass = settings.letPassUndefinedProperties.questionid || _hasProperty(expression, 'questionid');
|
|
28
|
+
const dataset = letQrveyidPass ? datasets.find(_data => _data.qrveyid === expression.qrveyid) : undefined;
|
|
29
|
+
if (!isEmpty(dataset)) {
|
|
30
|
+
const column = letQuestionidPass ? (dataset.options || []).find(option => option.id === expression.questionid) : undefined;
|
|
31
|
+
letQuestionidPass = letQuestionidPass || !isEmpty(column);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return (letQrveyidPass && !isEmpty(dataset)) && letQuestionidPass;
|
|
35
|
+
})
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Gets the default settings for the getLogicByDatasetsColumn function
|
|
41
|
+
* @param settings the settings given by the implementer
|
|
42
|
+
* @returns an object with all properties set
|
|
43
|
+
*/
|
|
44
|
+
function getGetLogicByDatasetsSettings(settings?: IFFGetLogicByDatasetsColumns): IFFGetLogicByDatasetsColumns {
|
|
45
|
+
return {
|
|
46
|
+
filterEmptyArrays: settings?.filterEmptyArrays ?? true,
|
|
47
|
+
letPassUndefinedProperties: {
|
|
48
|
+
qrveyid: settings?.letPassUndefinedProperties?.qrveyid ?? true,
|
|
49
|
+
questionid: settings?.letPassUndefinedProperties?.questionid ?? true
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -6,6 +6,8 @@ export * from './getBackendGroupValue';
|
|
|
6
6
|
export * from './getBackendProperty';
|
|
7
7
|
export * from './getBackendValidator';
|
|
8
8
|
export * from './getBackendValues';
|
|
9
|
+
export * from './getLogicByDatasets';
|
|
10
|
+
export * from './getLogicByDatasetsColumns';
|
|
9
11
|
export * from './getLogicByScopes';
|
|
10
12
|
export * from './getLogicByScopesHierarchy';
|
|
11
13
|
// export * from './hasDatasetRelatedFilters';
|
|
@@ -8,6 +8,7 @@ import { IFProperty } from "../IFProperty";
|
|
|
8
8
|
export interface IFBExpression {
|
|
9
9
|
enabled?: boolean; // True: The filter expression is applied; False: The filter expression is not applied.
|
|
10
10
|
groupValue?: IFProperty; // Date grouping for Date column filters
|
|
11
|
+
qrveyid?: string; // The Qrvey ID used in the expression
|
|
11
12
|
questionid?: string; // The Question/Column ID
|
|
12
13
|
questionType?: string; // The type of the Question/Column. Require if it is FORMULA OR BUCKET, otherwise is optional.
|
|
13
14
|
property?: IFProperty; // Properties for Complex Data types
|
|
@@ -28,6 +28,7 @@ import { IFFiltersGetData } from '../interfaces/functions/IFFiltersGetData';
|
|
|
28
28
|
import { getFiltersByDatasetsColumns } from '../helpers/common/getFiltersByDatasetsColumns';
|
|
29
29
|
import { IFUData } from '../interfaces/ui/IFUData';
|
|
30
30
|
import { getDatasetByColumn } from '../../qrvey/helpers/getDatasetByColumn';
|
|
31
|
+
import { getLogicByDatasets } from '../helpers/backend/getLogicByDatasets';
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
interface IFilterApiConfig extends IFilterConfig {
|
|
@@ -117,7 +118,7 @@ export class FiltersApi {
|
|
|
117
118
|
|
|
118
119
|
return [
|
|
119
120
|
...hierarchyLogic,
|
|
120
|
-
...buildUserFilters(config.userFilters) || [],
|
|
121
|
+
...getLogicByDatasets(buildUserFilters(config.userFilters), isEmpty(dataset) ? [] : [dataset.qrveyid]) || [],
|
|
121
122
|
];
|
|
122
123
|
}
|
|
123
124
|
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
// const { buildUserFilters, getLogicByDatasetsColumns } = require('../../../dist/cjs');
|
|
2
|
+
|
|
3
|
+
// // 1- Buen questionid y qrveyid
|
|
4
|
+
// const userFilters = {
|
|
5
|
+
// filters: [
|
|
6
|
+
// {
|
|
7
|
+
// operator: "AND",
|
|
8
|
+
// expressions: [
|
|
9
|
+
// {
|
|
10
|
+
// questionid: "OTCK9KZe2",
|
|
11
|
+
// qrveyid: "mSdv9Qjm5",
|
|
12
|
+
// validationType: "BETWEEN",
|
|
13
|
+
// value: [
|
|
14
|
+
// {
|
|
15
|
+
// lte: "15",
|
|
16
|
+
// gte: "10"
|
|
17
|
+
// },
|
|
18
|
+
// {
|
|
19
|
+
// lte: "30",
|
|
20
|
+
// gte: "20"
|
|
21
|
+
// }
|
|
22
|
+
// ]
|
|
23
|
+
// }
|
|
24
|
+
// ]
|
|
25
|
+
// }
|
|
26
|
+
// ]
|
|
27
|
+
// };
|
|
28
|
+
|
|
29
|
+
// // 2 - Buen questionid sin qrveyid
|
|
30
|
+
// const userFilters2 = {
|
|
31
|
+
// filters: [
|
|
32
|
+
// {
|
|
33
|
+
// operator: "AND",
|
|
34
|
+
// expressions: [
|
|
35
|
+
// {
|
|
36
|
+
// questionid: "OTCK9KZe2",
|
|
37
|
+
// validationType: "BETWEEN",
|
|
38
|
+
// value: [
|
|
39
|
+
// {
|
|
40
|
+
// lte: "15",
|
|
41
|
+
// gte: "10"
|
|
42
|
+
// },
|
|
43
|
+
// {
|
|
44
|
+
// lte: "30",
|
|
45
|
+
// gte: "20"
|
|
46
|
+
// }
|
|
47
|
+
// ]
|
|
48
|
+
// }
|
|
49
|
+
// ]
|
|
50
|
+
// }
|
|
51
|
+
// ]
|
|
52
|
+
// };
|
|
53
|
+
|
|
54
|
+
// // 3 - Buen questionid con mal qrveyid
|
|
55
|
+
// const userFilters3 = {
|
|
56
|
+
// filters: [
|
|
57
|
+
// {
|
|
58
|
+
// operator: "AND",
|
|
59
|
+
// expressions: [
|
|
60
|
+
// {
|
|
61
|
+
// questionid: "OTCK9KZe2",
|
|
62
|
+
// qrveyid: "mSdv9Qjm55",
|
|
63
|
+
// validationType: "BETWEEN",
|
|
64
|
+
// value: [
|
|
65
|
+
// {
|
|
66
|
+
// lte: "15",
|
|
67
|
+
// gte: "10"
|
|
68
|
+
// },
|
|
69
|
+
// {
|
|
70
|
+
// lte: "30",
|
|
71
|
+
// gte: "20"
|
|
72
|
+
// }
|
|
73
|
+
// ]
|
|
74
|
+
// }
|
|
75
|
+
// ]
|
|
76
|
+
// }
|
|
77
|
+
// ]
|
|
78
|
+
// };
|
|
79
|
+
|
|
80
|
+
// // 4 - Mal questionid con buen qrveyid
|
|
81
|
+
// const userFilters4 = {
|
|
82
|
+
// filters: [
|
|
83
|
+
// {
|
|
84
|
+
// operator: "AND",
|
|
85
|
+
// expressions: [
|
|
86
|
+
// {
|
|
87
|
+
// questionid: "OTCK9KZe22",
|
|
88
|
+
// qrveyid: "mSdv9Qjm5",
|
|
89
|
+
// validationType: "BETWEEN",
|
|
90
|
+
// value: [
|
|
91
|
+
// {
|
|
92
|
+
// lte: "15",
|
|
93
|
+
// gte: "10"
|
|
94
|
+
// },
|
|
95
|
+
// {
|
|
96
|
+
// lte: "30",
|
|
97
|
+
// gte: "20"
|
|
98
|
+
// }
|
|
99
|
+
// ]
|
|
100
|
+
// }
|
|
101
|
+
// ]
|
|
102
|
+
// }
|
|
103
|
+
// ]
|
|
104
|
+
// };
|
|
105
|
+
|
|
106
|
+
// // 5 - Mal questionid sin qrveyid
|
|
107
|
+
// const userFilters5 = {
|
|
108
|
+
// filters: [
|
|
109
|
+
// {
|
|
110
|
+
// operator: "AND",
|
|
111
|
+
// expressions: [
|
|
112
|
+
// {
|
|
113
|
+
// questionid: "OTCK9KZe22",
|
|
114
|
+
// validationType: "BETWEEN",
|
|
115
|
+
// value: [
|
|
116
|
+
// {
|
|
117
|
+
// lte: "15",
|
|
118
|
+
// gte: "10"
|
|
119
|
+
// },
|
|
120
|
+
// {
|
|
121
|
+
// lte: "30",
|
|
122
|
+
// gte: "20"
|
|
123
|
+
// }
|
|
124
|
+
// ]
|
|
125
|
+
// }
|
|
126
|
+
// ]
|
|
127
|
+
// }
|
|
128
|
+
// ]
|
|
129
|
+
// };
|
|
130
|
+
|
|
131
|
+
// // 6 - Mal questionid con mal qrveyid
|
|
132
|
+
// const userFilters6 = {
|
|
133
|
+
// filters: [
|
|
134
|
+
// {
|
|
135
|
+
// operator: "AND",
|
|
136
|
+
// expressions: [
|
|
137
|
+
// {
|
|
138
|
+
// questionid: "OTCK9KZe22",
|
|
139
|
+
// qrveyid: "mSdv9Qjm55",
|
|
140
|
+
// validationType: "BETWEEN",
|
|
141
|
+
// value: [
|
|
142
|
+
// {
|
|
143
|
+
// lte: "15",
|
|
144
|
+
// gte: "10"
|
|
145
|
+
// },
|
|
146
|
+
// {
|
|
147
|
+
// lte: "30",
|
|
148
|
+
// gte: "20"
|
|
149
|
+
// }
|
|
150
|
+
// ]
|
|
151
|
+
// }
|
|
152
|
+
// ]
|
|
153
|
+
// }
|
|
154
|
+
// ]
|
|
155
|
+
// };
|
|
156
|
+
|
|
157
|
+
// // 7 - Sin questionid con buen qrveyid
|
|
158
|
+
// const userFilters7 = {
|
|
159
|
+
// filters: [
|
|
160
|
+
// {
|
|
161
|
+
// operator: "AND",
|
|
162
|
+
// expressions: [
|
|
163
|
+
// {
|
|
164
|
+
// qrveyid: "mSdv9Qjm5",
|
|
165
|
+
// validationType: "BETWEEN",
|
|
166
|
+
// value: [
|
|
167
|
+
// {
|
|
168
|
+
// lte: "15",
|
|
169
|
+
// gte: "10"
|
|
170
|
+
// },
|
|
171
|
+
// {
|
|
172
|
+
// lte: "30",
|
|
173
|
+
// gte: "20"
|
|
174
|
+
// }
|
|
175
|
+
// ]
|
|
176
|
+
// }
|
|
177
|
+
// ]
|
|
178
|
+
// }
|
|
179
|
+
// ]
|
|
180
|
+
// };
|
|
181
|
+
|
|
182
|
+
// // 8 - Sin questionid y sin qrveyid
|
|
183
|
+
// const userFilters8 = {
|
|
184
|
+
// filters: [
|
|
185
|
+
// {
|
|
186
|
+
// operator: "AND",
|
|
187
|
+
// expressions: [
|
|
188
|
+
// {
|
|
189
|
+
// validationType: "BETWEEN",
|
|
190
|
+
// value: [
|
|
191
|
+
// {
|
|
192
|
+
// lte: "15",
|
|
193
|
+
// gte: "10"
|
|
194
|
+
// },
|
|
195
|
+
// {
|
|
196
|
+
// lte: "30",
|
|
197
|
+
// gte: "20"
|
|
198
|
+
// }
|
|
199
|
+
// ]
|
|
200
|
+
// }
|
|
201
|
+
// ]
|
|
202
|
+
// }
|
|
203
|
+
// ]
|
|
204
|
+
// };
|
|
205
|
+
|
|
206
|
+
// // 9 - Sin questionid con mal qrveyid
|
|
207
|
+
// const userFilters9 = {
|
|
208
|
+
// filters: [
|
|
209
|
+
// {
|
|
210
|
+
// operator: "AND",
|
|
211
|
+
// expressions: [
|
|
212
|
+
// {
|
|
213
|
+
// qrveyid: "mSdv9Qjm55",
|
|
214
|
+
// validationType: "BETWEEN",
|
|
215
|
+
// value: [
|
|
216
|
+
// {
|
|
217
|
+
// lte: "15",
|
|
218
|
+
// gte: "10"
|
|
219
|
+
// },
|
|
220
|
+
// {
|
|
221
|
+
// lte: "30",
|
|
222
|
+
// gte: "20"
|
|
223
|
+
// }
|
|
224
|
+
// ]
|
|
225
|
+
// }
|
|
226
|
+
// ]
|
|
227
|
+
// }
|
|
228
|
+
// ]
|
|
229
|
+
// };
|
|
230
|
+
|
|
231
|
+
// const datasets = [
|
|
232
|
+
// {
|
|
233
|
+
// "qrveyid": "mSdv9Qjm5",
|
|
234
|
+
// "label": "SQL SELECT ALL - NewView SELECT ALL",
|
|
235
|
+
// "options": [
|
|
236
|
+
// {
|
|
237
|
+
// "id": "OTCK9KZe2",
|
|
238
|
+
// "label": "id",
|
|
239
|
+
// "outputFormat": {
|
|
240
|
+
// "format": "Numeric",
|
|
241
|
+
// "numericType": "INTEGER",
|
|
242
|
+
// "type": "NUMERIC",
|
|
243
|
+
// "decimals": "0"
|
|
244
|
+
// },
|
|
245
|
+
// "qrveyid": "mSdv9Qjm5",
|
|
246
|
+
// "type": "NUMERIC"
|
|
247
|
+
// },
|
|
248
|
+
// {
|
|
249
|
+
// "id": "pL4N25I67",
|
|
250
|
+
// "label": "date_1",
|
|
251
|
+
// "outputFormat": {
|
|
252
|
+
// "type": "DATE",
|
|
253
|
+
// "format": "MM/DD/YYYY"
|
|
254
|
+
// },
|
|
255
|
+
// "qrveyid": "mSdv9Qjm5",
|
|
256
|
+
// "type": "DATE"
|
|
257
|
+
// },
|
|
258
|
+
// {
|
|
259
|
+
// "id": "VvHNwFfjQ",
|
|
260
|
+
// "label": "date_2_dt",
|
|
261
|
+
// "outputFormat": {
|
|
262
|
+
// "type": "DATE",
|
|
263
|
+
// "format": "MM/DD/YYYY"
|
|
264
|
+
// },
|
|
265
|
+
// "qrveyid": "mSdv9Qjm5",
|
|
266
|
+
// "type": "DATE"
|
|
267
|
+
// },
|
|
268
|
+
// {
|
|
269
|
+
// "id": "Em6zxp2Ch",
|
|
270
|
+
// "label": "country",
|
|
271
|
+
// "qrveyid": "mSdv9Qjm5",
|
|
272
|
+
// "type": "TEXT_LABEL"
|
|
273
|
+
// },
|
|
274
|
+
// {
|
|
275
|
+
// "id": "J6Oq48t8F",
|
|
276
|
+
// "label": "epoch",
|
|
277
|
+
// "outputFormat": {
|
|
278
|
+
// "type": "DATE",
|
|
279
|
+
// "format": "MM/DD/YYYY"
|
|
280
|
+
// },
|
|
281
|
+
// "qrveyid": "mSdv9Qjm5",
|
|
282
|
+
// "type": "DATE"
|
|
283
|
+
// }
|
|
284
|
+
// ]
|
|
285
|
+
// }
|
|
286
|
+
// ];
|
|
287
|
+
|
|
288
|
+
// console.log('1 - Buen questionid y buen qrveyid');
|
|
289
|
+
// getLogicByDatasetsColumns(buildUserFilters(userFilters), datasets);
|
|
290
|
+
// console.log('2 - Buen questionid sin qrveyid');
|
|
291
|
+
// getLogicByDatasetsColumns(buildUserFilters(userFilters2), datasets);
|
|
292
|
+
// console.log('3 - Buen questionid con mal qrveyid');
|
|
293
|
+
// getLogicByDatasetsColumns(buildUserFilters(userFilters3), datasets);
|
|
294
|
+
// console.log('4 - Mal questionid con buen qrveyid');
|
|
295
|
+
// getLogicByDatasetsColumns(buildUserFilters(userFilters4), datasets);
|
|
296
|
+
// console.log('5 - Mal questionid sin qrveyid');
|
|
297
|
+
// getLogicByDatasetsColumns(buildUserFilters(userFilters5), datasets);
|
|
298
|
+
// console.log('6 - Mal questionid y mal qrveyid');
|
|
299
|
+
// getLogicByDatasetsColumns(buildUserFilters(userFilters6), datasets);
|
|
300
|
+
// console.log('7 - Sin questionid con buen qrveyid');
|
|
301
|
+
// getLogicByDatasetsColumns(buildUserFilters(userFilters7), datasets);
|
|
302
|
+
// console.log('8 - Sin questionid y sin qrveyid');
|
|
303
|
+
// getLogicByDatasetsColumns(buildUserFilters(userFilters8), datasets);
|
|
304
|
+
// console.log('9 - Sin questionid con mal qrveyid');
|
|
305
|
+
// getLogicByDatasetsColumns(buildUserFilters(userFilters9), datasets);
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
describe('Dummy test', function () {
|
|
309
|
+
test('Dummy test #1', function () {
|
|
310
|
+
expect([]).toEqual([]);
|
|
311
|
+
});
|
|
312
|
+
});
|