Skip to content

Commit f6d7f4f

Browse files
committed
[REF] web: condition_tree: split file
The file condition_tree.js has become quite big. We split it in several files so that the role of various parts are clearer. Along the way, we have reworked a bit some functions, notably toAST. Part-of: odoo#216038 Related: odoo/enterprise#88759 Signed-off-by: Michaël Mattiello (mcm) <[email protected]>
1 parent d72aaba commit f6d7f4f

32 files changed

+1748
-1809
lines changed

addons/web/static/src/core/domain_selector/domain_selector.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
import { Component, onWillStart, onWillUpdateProps } from "@odoo/owl";
2-
import { Domain } from "@web/core/domain";
3-
import { TreeEditor } from "@web/core/tree_editor/tree_editor";
4-
import {
5-
domainFromTree,
6-
treeFromDomain,
7-
formatValue,
8-
condition,
9-
constructTree,
10-
} from "@web/core/tree_editor/condition_tree";
112
import { CheckBox } from "@web/core/checkbox/checkbox";
12-
import { deepEqual } from "@web/core/utils/objects";
3+
import { Domain } from "@web/core/domain";
134
import { getDomainDisplayedOperators } from "@web/core/domain_selector/domain_selector_operator_editor";
14-
import { getOperatorEditorInfo } from "@web/core/tree_editor/tree_editor_operator_editor";
155
import { _t } from "@web/core/l10n/translation";
166
import { ModelFieldSelector } from "@web/core/model_field_selector/model_field_selector";
17-
import { useService } from "@web/core/utils/hooks";
7+
import { condition, formatValue } from "@web/core/tree_editor/condition_tree";
8+
import { constructTreeFromDomain } from "@web/core/tree_editor/construct_tree_from_domain";
9+
import { domainFromTree } from "@web/core/tree_editor/domain_from_tree";
10+
import { TreeEditor } from "@web/core/tree_editor/tree_editor";
11+
import { getOperatorEditorInfo } from "@web/core/tree_editor/tree_editor_operator_editor";
12+
import { treeFromDomain } from "@web/core/tree_editor/tree_from_domain";
1813
import { useMakeGetFieldDef } from "@web/core/tree_editor/utils";
14+
import { useService } from "@web/core/utils/hooks";
15+
import { deepEqual } from "@web/core/utils/objects";
1916
import { getDefaultCondition } from "./utils";
2017

2118
const ARCHIVED_CONDITION = condition("active", "in", [true, false]);
@@ -69,9 +66,11 @@ export class DomainSelector extends Component {
6966
return;
7067
}
7168

72-
const getFieldDef = await this.makeGetFieldDef(p.resModel, constructTree(domain), [
73-
"active",
74-
]);
69+
const getFieldDef = await this.makeGetFieldDef(
70+
p.resModel,
71+
constructTreeFromDomain(domain),
72+
["active"]
73+
);
7574

7675
this.tree = treeFromDomain(domain, {
7776
getFieldDef,

addons/web/static/src/core/domain_selector/utils.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { getDefaultValue } from "@web/core/tree_editor/tree_editor_value_editors";
21
import { getDomainDisplayedOperators } from "@web/core/domain_selector/domain_selector_operator_editor";
3-
import { useService } from "@web/core/utils/hooks";
4-
import { domainFromTree, condition } from "@web/core/tree_editor/condition_tree";
2+
import { condition } from "@web/core/tree_editor/condition_tree";
3+
import { domainFromTree } from "@web/core/tree_editor/domain_from_tree";
4+
import { getDefaultValue } from "@web/core/tree_editor/tree_editor_value_editors";
55
import { getDefaultPath } from "@web/core/tree_editor/utils";
6+
import { useService } from "@web/core/utils/hooks";
67

78
export function getDefaultCondition(fieldDefs) {
89
const defaultPath = getDefaultPath(fieldDefs);

addons/web/static/src/core/expression_editor/expression_editor.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import { Component, onWillStart, onWillUpdateProps } from "@odoo/owl";
22
import { getExpressionDisplayedOperators } from "@web/core/expression_editor/expression_editor_operator_editor";
3-
import {
4-
condition,
5-
expressionFromTree,
6-
treeFromExpression,
7-
} from "@web/core/tree_editor/condition_tree";
3+
import { _t } from "@web/core/l10n/translation";
4+
import { ModelFieldSelector } from "@web/core/model_field_selector/model_field_selector";
5+
import { condition } from "@web/core/tree_editor/condition_tree";
6+
import { expressionFromTree } from "@web/core/tree_editor/expression_from_tree";
87
import { TreeEditor } from "@web/core/tree_editor/tree_editor";
98
import { getOperatorEditorInfo } from "@web/core/tree_editor/tree_editor_operator_editor";
109
import { getDefaultValue } from "@web/core/tree_editor/tree_editor_value_editors";
10+
import { treeFromExpression } from "@web/core/tree_editor/tree_from_expression";
1111
import { getDefaultPath } from "@web/core/tree_editor/utils";
12-
import { ModelFieldSelector } from "@web/core/model_field_selector/model_field_selector";
13-
import { _t } from "@web/core/l10n/translation";
1412

1513
export class ExpressionEditor extends Component {
1614
static template = "web.ExpressionEditor";
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { COMPARATORS, TERM_OPERATORS_NEGATION_EXTENDED } from "./operators";
2+
3+
export function isBool(ast) {
4+
return ast.type === 8 && ast.fn.type === 5 && ast.fn.value === "bool" && ast.args.length === 1;
5+
}
6+
7+
export function isNot(ast) {
8+
return ast.type === 6 && ast.op === "not";
9+
}
10+
11+
export function not(ast) {
12+
if (isNot(ast)) {
13+
return ast.right;
14+
}
15+
if (ast.type === 2) {
16+
return { ...ast, value: !ast.value };
17+
}
18+
if (ast.type === 7 && COMPARATORS.includes(ast.op)) {
19+
return { ...ast, op: TERM_OPERATORS_NEGATION_EXTENDED[ast.op] }; // do not use this if ast is within a domain context!
20+
}
21+
return { type: 6, op: "not", right: isBool(ast) ? ast.args[0] : ast };
22+
}
23+
24+
export function isValidPath(ast, options) {
25+
const getFieldDef = options.getFieldDef || (() => null);
26+
if (ast.type === 5) {
27+
return getFieldDef(ast.value) !== null;
28+
}
29+
return false;
30+
}

0 commit comments

Comments
 (0)