@elliemae/ds-query-builder 3.11.0-rc.0 → 3.11.0-rc.1
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/components/helpers/adapter.js +138 -0
- package/dist/cjs/components/helpers/adapter.js.map +7 -0
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/components/helpers/adapter.js +112 -0
- package/dist/esm/components/helpers/adapter.js.map +7 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +2 -2
- package/package.json +12 -12
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var adapter_exports = {};
|
|
26
|
+
__export(adapter_exports, {
|
|
27
|
+
adapterV1toV2: () => adapterV1toV2,
|
|
28
|
+
adapterV2toV1: () => adapterV2toV1
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(adapter_exports);
|
|
31
|
+
var React = __toESM(require("react"));
|
|
32
|
+
const translateCondition = (logical) => {
|
|
33
|
+
console.log("logical", logical);
|
|
34
|
+
if (logical === "and")
|
|
35
|
+
return true;
|
|
36
|
+
if (logical === "or")
|
|
37
|
+
return false;
|
|
38
|
+
throw Error("invalid logical: " + logical);
|
|
39
|
+
};
|
|
40
|
+
const isGroup = (item) => item.logical === "and" || item.logical === "or";
|
|
41
|
+
const createFieldId = (item) => `filter_${new Date().getTime()}_${Math.random().toString(36).substring(7)}`;
|
|
42
|
+
const createGroupId = (item) => `group_${new Date().getTime()}_${Math.random().toString(36).substring(7)}`;
|
|
43
|
+
const getType = (item) => isGroup(item) ? "group" : "filter";
|
|
44
|
+
const adapterV2toV1 = (value) => {
|
|
45
|
+
const main = value[0];
|
|
46
|
+
const parseField = (currenNode, parentIdGroup, mapFilters2, mapGroups2, items2) => {
|
|
47
|
+
currenNode.fields.forEach((element) => {
|
|
48
|
+
const isItGroup = isGroup(element);
|
|
49
|
+
const id = isItGroup ? createGroupId(element) : createFieldId(element);
|
|
50
|
+
const translation = {
|
|
51
|
+
id,
|
|
52
|
+
element: {
|
|
53
|
+
parentIdGroup: isItGroup ? parentIdGroup : void 0,
|
|
54
|
+
idGroup: isItGroup ? id : parentIdGroup,
|
|
55
|
+
idFilter: isItGroup ? void 0 : id,
|
|
56
|
+
field: isItGroup ? void 0 : element.column,
|
|
57
|
+
condition: isItGroup ? translateCondition(element.logical) : "",
|
|
58
|
+
value: isItGroup ? void 0 : element.value,
|
|
59
|
+
type: getType(element),
|
|
60
|
+
operator: isItGroup ? void 0 : element.operator
|
|
61
|
+
},
|
|
62
|
+
children: []
|
|
63
|
+
};
|
|
64
|
+
const mapGroupsTranslation = isItGroup ? {
|
|
65
|
+
condition: translateCondition(element.logical),
|
|
66
|
+
idGroup: id,
|
|
67
|
+
parentIdGroup,
|
|
68
|
+
type: getType(element)
|
|
69
|
+
} : void 0;
|
|
70
|
+
const mapFiltersTranslation = !isItGroup ? {
|
|
71
|
+
parentIdGroup: isItGroup ? parentIdGroup : void 0,
|
|
72
|
+
idGroup: isItGroup ? id : parentIdGroup,
|
|
73
|
+
idFilter: isItGroup ? void 0 : id,
|
|
74
|
+
field: isItGroup ? void 0 : element.column,
|
|
75
|
+
condition: isItGroup ? translateCondition(element.logical) : void 0,
|
|
76
|
+
value: isItGroup ? void 0 : element.value,
|
|
77
|
+
type: getType(element),
|
|
78
|
+
operator: isItGroup ? void 0 : element.operator,
|
|
79
|
+
target: "value"
|
|
80
|
+
} : void 0;
|
|
81
|
+
if (isItGroup) {
|
|
82
|
+
mapGroups2[id] = mapGroupsTranslation;
|
|
83
|
+
} else
|
|
84
|
+
mapFilters2[id] = mapFiltersTranslation;
|
|
85
|
+
items2.push(translation);
|
|
86
|
+
if (isItGroup && element.fields.length > 0) {
|
|
87
|
+
parseField(element, id, mapFilters2, mapGroups2, translation.children);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
const mainGroup = createGroupId({});
|
|
92
|
+
const mapFilters = {};
|
|
93
|
+
const mapGroups = {
|
|
94
|
+
[mainGroup]: {
|
|
95
|
+
parentIdGroup: "main",
|
|
96
|
+
idGroup: mainGroup,
|
|
97
|
+
condition: translateCondition(main.logical),
|
|
98
|
+
type: "group"
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const items = [];
|
|
102
|
+
parseField(main, mainGroup, mapFilters, mapGroups, items);
|
|
103
|
+
return {
|
|
104
|
+
step: Math.round(Math.random() * 100) + 1,
|
|
105
|
+
mapFilters,
|
|
106
|
+
mapGroups,
|
|
107
|
+
main: mainGroup,
|
|
108
|
+
items
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
const getConditionToLogical = (condition) => condition ? "and" : "or";
|
|
112
|
+
const adapterV1toV2 = (data) => {
|
|
113
|
+
const result = [];
|
|
114
|
+
const mainGroup = data.main;
|
|
115
|
+
const init = {
|
|
116
|
+
logical: getConditionToLogical(data.mapGroups[mainGroup].condition),
|
|
117
|
+
fields: []
|
|
118
|
+
};
|
|
119
|
+
const parseItemsToFields = (items, result2) => {
|
|
120
|
+
items.forEach((item) => {
|
|
121
|
+
const { element, children } = item;
|
|
122
|
+
if (element.type === "filter") {
|
|
123
|
+
result2.push({ column: element.field, operator: element.operator, value: element.value });
|
|
124
|
+
} else {
|
|
125
|
+
const group = {
|
|
126
|
+
logical: getConditionToLogical(element.condition),
|
|
127
|
+
fields: []
|
|
128
|
+
};
|
|
129
|
+
parseItemsToFields(children, group.fields);
|
|
130
|
+
result2.push(group);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
parseItemsToFields(data.items, init.fields);
|
|
135
|
+
result.push(init);
|
|
136
|
+
return result;
|
|
137
|
+
};
|
|
138
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/components/helpers/adapter.ts", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["const translateCondition = (logical: string) => {\n console.log('logical', logical)\n if (logical === 'and') return true;\n if (logical === 'or') return false;\n throw Error('invalid logical: '+logical)\n}\nconst isGroup = (item: { logical: string; }) => item.logical === 'and' || item.logical === 'or';\nconst createFieldId = (item: any) => `filter_${new Date().getTime()}_${Math.random().toString(36).substring(7)}`;\nconst createGroupId = (item: {}) => `group_${new Date().getTime()}_${Math.random().toString(36).substring(7)}`;\nconst getType = (item: any) => (isGroup(item) ? 'group' : 'filter');\n\n\nexport const adapterV2toV1 = (value: any[]) => {\n const main = value[0]; // QB1 only support a group as level 0\n const parseField = (currenNode: { fields: any[]; }, parentIdGroup: string, mapFilters: { [x: string]: { parentIdGroup: any; idGroup: any; idFilter: string | undefined; field: any; condition: boolean | undefined; value: any; type: string; operator: any; target: string; } | undefined; }, mapGroups: { [x: string]: { condition: boolean; idGroup: string; parentIdGroup: any; type: string; } | { parentIdGroup: string; idGroup: string; condition: boolean; type: string; } | undefined; }, items: { id: string; element: { parentIdGroup: any; idGroup: any; idFilter: string | undefined; field: any; condition: string | boolean; value: any; type: string; operator: any; }; children: never[]; }[]) => {\n currenNode.fields.forEach((element: { column: any; logical: string; value: any; operator: any; fields: string | any[]; }) => {\n const isItGroup = isGroup(element);\n const id = isItGroup ? createGroupId(element) : createFieldId(element);\n const translation = {\n id,\n element: {\n parentIdGroup: isItGroup ? parentIdGroup : undefined,\n idGroup: isItGroup ? id : parentIdGroup,\n idFilter: isItGroup ? undefined : id,\n field: isItGroup ? undefined : element.column,\n condition: isItGroup ? translateCondition(element.logical) : '',\n value: isItGroup ? undefined : element.value,\n type: getType(element),\n operator: isItGroup ? undefined : element.operator,\n },\n children: [],\n };\n\n const mapGroupsTranslation = isItGroup\n ? {\n condition: translateCondition(element.logical),\n idGroup: id,\n parentIdGroup,\n type: getType(element),\n }\n : undefined;\n const mapFiltersTranslation = !isItGroup\n ? {\n parentIdGroup: isItGroup ? parentIdGroup : undefined,\n idGroup: isItGroup ? id : parentIdGroup,\n idFilter: isItGroup ? undefined : id,\n field: isItGroup ? undefined : element.column,\n condition: isItGroup ? translateCondition(element.logical) : undefined,\n value: isItGroup ? undefined : element.value,\n type: getType(element),\n operator: isItGroup ? undefined : element.operator,\n target: 'value',\n }\n : undefined;\n\n if (isItGroup) {\n mapGroups[id] = mapGroupsTranslation;\n } else mapFilters[id] = mapFiltersTranslation;\n items.push(translation);\n\n if (isItGroup && element.fields.length > 0) {\n parseField(element as any, id, mapFilters, mapGroups, translation.children);\n }\n });\n };\n\n const mainGroup = createGroupId({});\n const mapFilters = {};\n const mapGroups = {\n [mainGroup]: {\n parentIdGroup: 'main',\n idGroup: mainGroup,\n condition: translateCondition(main.logical),\n type: 'group',\n },\n };\n const items: any = [];\n parseField(main, mainGroup, mapFilters, mapGroups, items);\n return {\n step: Math.round(Math.random() * 100) + 1,\n mapFilters,\n mapGroups,\n main: mainGroup,\n items,\n };\n};\n\nconst getConditionToLogical = (condition: any) => (condition ? 'and' : 'or');\n\nexport const adapterV1toV2 = (data: { main: any; mapGroups: { [x: string]: { condition: any; }; }; items: any; }) => {\n const result = [];\n const mainGroup = data.main;\n const init = {\n logical: getConditionToLogical(data.mapGroups[mainGroup].condition),\n fields: []\n };\n const parseItemsToFields = (items: any[], result: { column?: any; operator?: any; value?: any; logical?: string; fields?: never[]; }[]) => {\n items.forEach((item: { element: any; children: any; }) => {\n const { element, children } = item;\n if (element.type === 'filter') {\n result.push({ column: element.field, operator: element.operator, value: element.value });\n } else {\n const group = {\n logical: getConditionToLogical(element.condition),\n fields: [],\n };\n parseItemsToFields(children, group.fields);\n result.push(group);\n }\n });\n };\n\n parseItemsToFields(data.items, init.fields);\n result.push(init);\n return result;\n};", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,MAAM,qBAAqB,CAAC,YAAoB;AAC9C,UAAQ,IAAI,WAAW,OAAO;AAC9B,MAAI,YAAY;AAAO,WAAO;AAC9B,MAAI,YAAY;AAAM,WAAO;AAC7B,QAAM,MAAM,sBAAoB,OAAO;AACzC;AACA,MAAM,UAAU,CAAC,SAA+B,KAAK,YAAY,SAAS,KAAK,YAAY;AAC3F,MAAM,gBAAgB,CAAC,SAAc,UAAU,IAAI,KAAK,EAAE,QAAQ,KAAK,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,CAAC;AAC7G,MAAM,gBAAgB,CAAC,SAAa,SAAS,IAAI,KAAK,EAAE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,SAAS;AAAA,UAChD,QAAQ,CAAC;AAAA,QACX;AACA,2BAAmB,UAAU,MAAM,MAAM;AACzC,QAAAA,QAAO,KAAK,KAAK;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,EACH;AAEA,qBAAmB,KAAK,OAAO,KAAK,MAAM;AAC1C,SAAO,KAAK,IAAI;AAChB,SAAO;AACT;",
|
|
6
|
+
"names": ["mapFilters", "mapGroups", "items", "result"]
|
|
7
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -25,10 +25,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
26
|
var src_exports = {};
|
|
27
27
|
__export(src_exports, {
|
|
28
|
+
adapterV1toV2: () => import_adapter.adapterV1toV2,
|
|
29
|
+
adapterV2toV1: () => import_adapter.adapterV2toV1,
|
|
28
30
|
default: () => import_DSQueryBuilder.default
|
|
29
31
|
});
|
|
30
32
|
module.exports = __toCommonJS(src_exports);
|
|
31
33
|
var React = __toESM(require("react"));
|
|
32
34
|
var import_DSQueryBuilder = __toESM(require("./DSQueryBuilder"));
|
|
33
35
|
__reExport(src_exports, require("./DSQueryBuilder"), module.exports);
|
|
36
|
+
var import_adapter = require("./components/helpers/adapter");
|
|
34
37
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.tsx", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["export { default } from './DSQueryBuilder';\nexport * from './DSQueryBuilder';\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,4BAAwB;AACxB,wBAAc,6BADd;",
|
|
4
|
+
"sourcesContent": ["export { default } from './DSQueryBuilder';\nexport * from './DSQueryBuilder';\nexport { adapterV2toV1, adapterV1toV2 } from './components/helpers/adapter'", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,4BAAwB;AACxB,wBAAc,6BADd;AAEA,qBAA6C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
const translateCondition = (logical) => {
|
|
3
|
+
console.log("logical", logical);
|
|
4
|
+
if (logical === "and")
|
|
5
|
+
return true;
|
|
6
|
+
if (logical === "or")
|
|
7
|
+
return false;
|
|
8
|
+
throw Error("invalid logical: " + logical);
|
|
9
|
+
};
|
|
10
|
+
const isGroup = (item) => item.logical === "and" || item.logical === "or";
|
|
11
|
+
const createFieldId = (item) => `filter_${new Date().getTime()}_${Math.random().toString(36).substring(7)}`;
|
|
12
|
+
const createGroupId = (item) => `group_${new Date().getTime()}_${Math.random().toString(36).substring(7)}`;
|
|
13
|
+
const getType = (item) => isGroup(item) ? "group" : "filter";
|
|
14
|
+
const adapterV2toV1 = (value) => {
|
|
15
|
+
const main = value[0];
|
|
16
|
+
const parseField = (currenNode, parentIdGroup, mapFilters2, mapGroups2, items2) => {
|
|
17
|
+
currenNode.fields.forEach((element) => {
|
|
18
|
+
const isItGroup = isGroup(element);
|
|
19
|
+
const id = isItGroup ? createGroupId(element) : createFieldId(element);
|
|
20
|
+
const translation = {
|
|
21
|
+
id,
|
|
22
|
+
element: {
|
|
23
|
+
parentIdGroup: isItGroup ? parentIdGroup : void 0,
|
|
24
|
+
idGroup: isItGroup ? id : parentIdGroup,
|
|
25
|
+
idFilter: isItGroup ? void 0 : id,
|
|
26
|
+
field: isItGroup ? void 0 : element.column,
|
|
27
|
+
condition: isItGroup ? translateCondition(element.logical) : "",
|
|
28
|
+
value: isItGroup ? void 0 : element.value,
|
|
29
|
+
type: getType(element),
|
|
30
|
+
operator: isItGroup ? void 0 : element.operator
|
|
31
|
+
},
|
|
32
|
+
children: []
|
|
33
|
+
};
|
|
34
|
+
const mapGroupsTranslation = isItGroup ? {
|
|
35
|
+
condition: translateCondition(element.logical),
|
|
36
|
+
idGroup: id,
|
|
37
|
+
parentIdGroup,
|
|
38
|
+
type: getType(element)
|
|
39
|
+
} : void 0;
|
|
40
|
+
const mapFiltersTranslation = !isItGroup ? {
|
|
41
|
+
parentIdGroup: isItGroup ? parentIdGroup : void 0,
|
|
42
|
+
idGroup: isItGroup ? id : parentIdGroup,
|
|
43
|
+
idFilter: isItGroup ? void 0 : id,
|
|
44
|
+
field: isItGroup ? void 0 : element.column,
|
|
45
|
+
condition: isItGroup ? translateCondition(element.logical) : void 0,
|
|
46
|
+
value: isItGroup ? void 0 : element.value,
|
|
47
|
+
type: getType(element),
|
|
48
|
+
operator: isItGroup ? void 0 : element.operator,
|
|
49
|
+
target: "value"
|
|
50
|
+
} : void 0;
|
|
51
|
+
if (isItGroup) {
|
|
52
|
+
mapGroups2[id] = mapGroupsTranslation;
|
|
53
|
+
} else
|
|
54
|
+
mapFilters2[id] = mapFiltersTranslation;
|
|
55
|
+
items2.push(translation);
|
|
56
|
+
if (isItGroup && element.fields.length > 0) {
|
|
57
|
+
parseField(element, id, mapFilters2, mapGroups2, translation.children);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
const mainGroup = createGroupId({});
|
|
62
|
+
const mapFilters = {};
|
|
63
|
+
const mapGroups = {
|
|
64
|
+
[mainGroup]: {
|
|
65
|
+
parentIdGroup: "main",
|
|
66
|
+
idGroup: mainGroup,
|
|
67
|
+
condition: translateCondition(main.logical),
|
|
68
|
+
type: "group"
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const items = [];
|
|
72
|
+
parseField(main, mainGroup, mapFilters, mapGroups, items);
|
|
73
|
+
return {
|
|
74
|
+
step: Math.round(Math.random() * 100) + 1,
|
|
75
|
+
mapFilters,
|
|
76
|
+
mapGroups,
|
|
77
|
+
main: mainGroup,
|
|
78
|
+
items
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
const getConditionToLogical = (condition) => condition ? "and" : "or";
|
|
82
|
+
const adapterV1toV2 = (data) => {
|
|
83
|
+
const result = [];
|
|
84
|
+
const mainGroup = data.main;
|
|
85
|
+
const init = {
|
|
86
|
+
logical: getConditionToLogical(data.mapGroups[mainGroup].condition),
|
|
87
|
+
fields: []
|
|
88
|
+
};
|
|
89
|
+
const parseItemsToFields = (items, result2) => {
|
|
90
|
+
items.forEach((item) => {
|
|
91
|
+
const { element, children } = item;
|
|
92
|
+
if (element.type === "filter") {
|
|
93
|
+
result2.push({ column: element.field, operator: element.operator, value: element.value });
|
|
94
|
+
} else {
|
|
95
|
+
const group = {
|
|
96
|
+
logical: getConditionToLogical(element.condition),
|
|
97
|
+
fields: []
|
|
98
|
+
};
|
|
99
|
+
parseItemsToFields(children, group.fields);
|
|
100
|
+
result2.push(group);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
parseItemsToFields(data.items, init.fields);
|
|
105
|
+
result.push(init);
|
|
106
|
+
return result;
|
|
107
|
+
};
|
|
108
|
+
export {
|
|
109
|
+
adapterV1toV2,
|
|
110
|
+
adapterV2toV1
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/components/helpers/adapter.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "const translateCondition = (logical: string) => {\n console.log('logical', logical)\n if (logical === 'and') return true;\n if (logical === 'or') return false;\n throw Error('invalid logical: '+logical)\n}\nconst isGroup = (item: { logical: string; }) => item.logical === 'and' || item.logical === 'or';\nconst createFieldId = (item: any) => `filter_${new Date().getTime()}_${Math.random().toString(36).substring(7)}`;\nconst createGroupId = (item: {}) => `group_${new Date().getTime()}_${Math.random().toString(36).substring(7)}`;\nconst getType = (item: any) => (isGroup(item) ? 'group' : 'filter');\n\n\nexport const adapterV2toV1 = (value: any[]) => {\n const main = value[0]; // QB1 only support a group as level 0\n const parseField = (currenNode: { fields: any[]; }, parentIdGroup: string, mapFilters: { [x: string]: { parentIdGroup: any; idGroup: any; idFilter: string | undefined; field: any; condition: boolean | undefined; value: any; type: string; operator: any; target: string; } | undefined; }, mapGroups: { [x: string]: { condition: boolean; idGroup: string; parentIdGroup: any; type: string; } | { parentIdGroup: string; idGroup: string; condition: boolean; type: string; } | undefined; }, items: { id: string; element: { parentIdGroup: any; idGroup: any; idFilter: string | undefined; field: any; condition: string | boolean; value: any; type: string; operator: any; }; children: never[]; }[]) => {\n currenNode.fields.forEach((element: { column: any; logical: string; value: any; operator: any; fields: string | any[]; }) => {\n const isItGroup = isGroup(element);\n const id = isItGroup ? createGroupId(element) : createFieldId(element);\n const translation = {\n id,\n element: {\n parentIdGroup: isItGroup ? parentIdGroup : undefined,\n idGroup: isItGroup ? id : parentIdGroup,\n idFilter: isItGroup ? undefined : id,\n field: isItGroup ? undefined : element.column,\n condition: isItGroup ? translateCondition(element.logical) : '',\n value: isItGroup ? undefined : element.value,\n type: getType(element),\n operator: isItGroup ? undefined : element.operator,\n },\n children: [],\n };\n\n const mapGroupsTranslation = isItGroup\n ? {\n condition: translateCondition(element.logical),\n idGroup: id,\n parentIdGroup,\n type: getType(element),\n }\n : undefined;\n const mapFiltersTranslation = !isItGroup\n ? {\n parentIdGroup: isItGroup ? parentIdGroup : undefined,\n idGroup: isItGroup ? id : parentIdGroup,\n idFilter: isItGroup ? undefined : id,\n field: isItGroup ? undefined : element.column,\n condition: isItGroup ? translateCondition(element.logical) : undefined,\n value: isItGroup ? undefined : element.value,\n type: getType(element),\n operator: isItGroup ? undefined : element.operator,\n target: 'value',\n }\n : undefined;\n\n if (isItGroup) {\n mapGroups[id] = mapGroupsTranslation;\n } else mapFilters[id] = mapFiltersTranslation;\n items.push(translation);\n\n if (isItGroup && element.fields.length > 0) {\n parseField(element as any, id, mapFilters, mapGroups, translation.children);\n }\n });\n };\n\n const mainGroup = createGroupId({});\n const mapFilters = {};\n const mapGroups = {\n [mainGroup]: {\n parentIdGroup: 'main',\n idGroup: mainGroup,\n condition: translateCondition(main.logical),\n type: 'group',\n },\n };\n const items: any = [];\n parseField(main, mainGroup, mapFilters, mapGroups, items);\n return {\n step: Math.round(Math.random() * 100) + 1,\n mapFilters,\n mapGroups,\n main: mainGroup,\n items,\n };\n};\n\nconst getConditionToLogical = (condition: any) => (condition ? 'and' : 'or');\n\nexport const adapterV1toV2 = (data: { main: any; mapGroups: { [x: string]: { condition: any; }; }; items: any; }) => {\n const result = [];\n const mainGroup = data.main;\n const init = {\n logical: getConditionToLogical(data.mapGroups[mainGroup].condition),\n fields: []\n };\n const parseItemsToFields = (items: any[], result: { column?: any; operator?: any; value?: any; logical?: string; fields?: never[]; }[]) => {\n items.forEach((item: { element: any; children: any; }) => {\n const { element, children } = item;\n if (element.type === 'filter') {\n result.push({ column: element.field, operator: element.operator, value: element.value });\n } else {\n const group = {\n logical: getConditionToLogical(element.condition),\n fields: [],\n };\n parseItemsToFields(children, group.fields);\n result.push(group);\n }\n });\n };\n\n parseItemsToFields(data.items, init.fields);\n result.push(init);\n return result;\n};"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,MAAM,qBAAqB,CAAC,YAAoB;AAC9C,UAAQ,IAAI,WAAW,OAAO;AAC9B,MAAI,YAAY;AAAO,WAAO;AAC9B,MAAI,YAAY;AAAM,WAAO;AAC7B,QAAM,MAAM,sBAAoB,OAAO;AACzC;AACA,MAAM,UAAU,CAAC,SAA+B,KAAK,YAAY,SAAS,KAAK,YAAY;AAC3F,MAAM,gBAAgB,CAAC,SAAc,UAAU,IAAI,KAAK,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AQ,OAAO,UAAU,QAAQ,UAAU,OAAO,QAAQ,MAAM,CAAC;AAAA,MACzF,OAAO;AACL,cAAM,QAAQ;AAAA,UACZ,SAAS,sBAAsB,QAAQ,SAAS;AAAA,UAChD,QAAQ,CAAC;AAAA,QACX;AACA,2BAAmB,UAAU,MAAM,MAAM;AACzC,QAAAA,QAAO,KAAK,KAAK;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,EACH;AAEA,qBAAmB,KAAK,OAAO,KAAK,MAAM;AAC1C,SAAO,KAAK,IAAI;AAChB,SAAO;AACT;",
|
|
6
|
+
"names": ["mapFilters", "mapGroups", "items", "result"]
|
|
7
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { default as default2 } from "./DSQueryBuilder";
|
|
3
3
|
export * from "./DSQueryBuilder";
|
|
4
|
+
import { adapterV2toV1, adapterV1toV2 } from "./components/helpers/adapter";
|
|
4
5
|
export {
|
|
6
|
+
adapterV1toV2,
|
|
7
|
+
adapterV2toV1,
|
|
5
8
|
default2 as default
|
|
6
9
|
};
|
|
7
10
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export { default } from './DSQueryBuilder';\nexport * from './DSQueryBuilder';\
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,WAAAA,gBAAe;AACxB,cAAc;",
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export { default } from './DSQueryBuilder';\nexport * from './DSQueryBuilder';\nexport { adapterV2toV1, adapterV1toV2 } from './components/helpers/adapter'"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,WAAAA,gBAAe;AACxB,cAAc;AACd,SAAS,eAAe,qBAAqB;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-query-builder",
|
|
3
|
-
"version": "3.11.0-rc.
|
|
3
|
+
"version": "3.11.0-rc.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Query Builder",
|
|
6
6
|
"files": [
|
|
@@ -171,17 +171,17 @@
|
|
|
171
171
|
"indent": 4
|
|
172
172
|
},
|
|
173
173
|
"dependencies": {
|
|
174
|
-
"@elliemae/ds-accordion": "3.11.0-rc.
|
|
175
|
-
"@elliemae/ds-button": "3.11.0-rc.
|
|
176
|
-
"@elliemae/ds-classnames": "3.11.0-rc.
|
|
177
|
-
"@elliemae/ds-form": "3.11.0-rc.
|
|
178
|
-
"@elliemae/ds-grid": "3.11.0-rc.
|
|
179
|
-
"@elliemae/ds-icon": "3.11.0-rc.
|
|
180
|
-
"@elliemae/ds-icons": "3.11.0-rc.
|
|
181
|
-
"@elliemae/ds-popper": "3.11.0-rc.
|
|
182
|
-
"@elliemae/ds-shared": "3.11.0-rc.
|
|
183
|
-
"@elliemae/ds-tooltip": "3.11.0-rc.
|
|
184
|
-
"@elliemae/ds-utilities": "3.11.0-rc.
|
|
174
|
+
"@elliemae/ds-accordion": "3.11.0-rc.1",
|
|
175
|
+
"@elliemae/ds-button": "3.11.0-rc.1",
|
|
176
|
+
"@elliemae/ds-classnames": "3.11.0-rc.1",
|
|
177
|
+
"@elliemae/ds-form": "3.11.0-rc.1",
|
|
178
|
+
"@elliemae/ds-grid": "3.11.0-rc.1",
|
|
179
|
+
"@elliemae/ds-icon": "3.11.0-rc.1",
|
|
180
|
+
"@elliemae/ds-icons": "3.11.0-rc.1",
|
|
181
|
+
"@elliemae/ds-popper": "3.11.0-rc.1",
|
|
182
|
+
"@elliemae/ds-shared": "3.11.0-rc.1",
|
|
183
|
+
"@elliemae/ds-tooltip": "3.11.0-rc.1",
|
|
184
|
+
"@elliemae/ds-utilities": "3.11.0-rc.1",
|
|
185
185
|
"classnames": "~2.3.1",
|
|
186
186
|
"prop-types": "~15.8.1",
|
|
187
187
|
"react-addons-update": "~15.6.3"
|