Skip to content

Commit 3b1cc67

Browse files
authored
Fixed import from JsonLogic when like op is used inside group with some group op (#1225)
1 parent dfb464c commit 3b1cc67

File tree

9 files changed

+78
-3
lines changed

9 files changed

+78
-3
lines changed

packages/core/modules/import/jsonLogic.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,10 @@ const convertOp = (op, vals, conv, config, not, meta, parentField = null, _isOne
874874
match.jlArgs.forEach(arg => havingVals.push(arg));
875875
// We reset op to new op that represents multiple jsonlogic operators
876876
conj = match.newOp;
877+
if (jlDualMeaningOps.includes(match.newOp)) {
878+
// use original order of args
879+
havingVals = match.vals;
880+
}
877881
}
878882
}
879883

packages/examples/src/demo/config/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,11 @@ export default (skin: string) => {
439439
max: 2021,
440440
},
441441
valueSources: ["value"],
442-
}
442+
},
443+
model: {
444+
type: "text",
445+
valueSources: ["value"],
446+
},
443447
}
444448
},
445449
prox1: {

packages/examples/src/demo/init_data/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import initLogicWithNot from "./logic/with_not";
55
import initLogicAutocomplete from "./logic/autocomplete";
66
import initLogicWithNotInSome from "./logic/with_not_in_some";
77
import initLogicWithFuncInLhs from "./logic/with_func_in_lhs";
8+
import initLogicGroupSomeInAny from "./logic/with_group_some_in_any";
9+
import initLogicGroupSomeInLike from "./logic/with_group_some_in_like";
810

911
import {
1012
Utils, JsonTree,
@@ -26,6 +28,8 @@ export const initFiles: Record<string, any> = {
2628
"logic/with_not_in_some": initLogicWithNotInSome,
2729
"logic/with_func_in_lhs": initLogicWithFuncInLhs,
2830
"logic/autocomplete": initLogicAutocomplete,
31+
"logic/with_group_some_in_any": initLogicGroupSomeInAny,
32+
"logic/with_group_some_in_like": initLogicGroupSomeInLike,
2933

3034
"tree/complex": initTreeComplex,
3135
"tree/empty": emptyTree,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export default
2+
{
3+
"and": [
4+
{
5+
"some": [
6+
{
7+
"var": "cars"
8+
},
9+
{
10+
"in": [
11+
{
12+
"var": "vendor"
13+
},
14+
[
15+
"Ford"
16+
]
17+
]
18+
}
19+
]
20+
}
21+
]
22+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default
2+
{
3+
"and": [
4+
{
5+
"some": [
6+
{
7+
"var": "cars"
8+
},
9+
{
10+
"in": [
11+
"toyo",
12+
{
13+
"var": "model"
14+
}
15+
]
16+
}
17+
]
18+
}
19+
]
20+
};

packages/examples/src/demo/utils.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const initTreeWithValidation = (initFileKey: string, config: Config, vali
6969
let errors: string[];
7070
// eslint-disable-next-line prefer-const
7171
({tree, errors} = importFromInitFile(initFileKey, config));
72+
console.log("Loaded tree: ", tree?.toJS?.());
7273
const {fixedTree, fixedErrors, nonFixedErrors} = Utils.sanitizeTree(tree, config, {
7374
...(validationOptions ?? {}),
7475
removeEmptyGroups: false,

packages/tests/specs/QueryWithGroupsAndStructs.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,20 @@ describe("query with !struct and !group", () => {
116116
});
117117
});
118118

119-
describe("should handle some-in when it's not related to multiselect_contains op", () => {
119+
describe("should handle some-in when it's not related to multiselect_contains op and means select_any_in", () => {
120120
export_checks(configs.with_group_inside_struct, inits.with_nested_and_select_any_in_in_some, "JsonLogic", {
121121
"query": "vehicles.cars.vendor IN (\"Ford\", \"Toyota\")",
122122
logic: inits.with_nested_and_select_any_in_in_some,
123123
});
124124
});
125125

126+
describe("should handle some-in when it's not related to multiselect_contains op and means like", () => {
127+
export_checks(configs.with_group_inside_struct, inits.with_nested_and_like_in_some, "JsonLogic", {
128+
"query": "vehicles.cars.model Contains \"coro\"",
129+
logic: inits.with_nested_and_like_in_some,
130+
});
131+
});
132+
126133
});
127134

128135
//////////////////////////////////////////////////////////////////////////////////////////

packages/tests/support/configs.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,11 @@ export const with_group_inside_struct = (BasicConfig) => ({
537537
max: 2021,
538538
},
539539
valueSources: ["value"],
540-
}
540+
},
541+
model: {
542+
type: "text",
543+
valueSources: ["value"],
544+
},
541545
}
542546
},
543547
bikes: {

packages/tests/support/inits.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,15 @@ export const with_nested_and_select_any_in_in_some = {
370370
]
371371
};
372372

373+
export const with_nested_and_like_in_some = {
374+
"and": [
375+
{ "some": [
376+
{ "var": "vehicles.cars" },
377+
{ "in": [ "coro", { "var": "model" } ] }
378+
] }
379+
]
380+
};
381+
373382
export const with_select_not_any_in_in_some = {
374383
"and": [
375384
{ "some": [

0 commit comments

Comments
 (0)