From da85977e8357fe1f0f31d1fad007e613b0a875cc Mon Sep 17 00:00:00 2001 From: "Michael (mcm)" Date: Fri, 2 Jun 2023 10:28:15 +0000 Subject: [PATCH] [FIX] web: fix domain selector double click Before this commit, we needed to double click on "add a rule/group" to execute the action if focused an input. This commit fixes this issue, we can now click once to execute the action of the buttons. task id: 3346327 closes odoo/odoo#125756 X-original-commit: 0db23b5a7e29f8714a63375c5d86f5d1b2220bda Signed-off-by: Mathieu Duckerts-Antoine --- .../core/domain_selector/domain_selector.js | 6 +++- .../domain_selector/domain_selector_nodes.js | 33 ++++++++++++------- .../static/src/core/domain_selector/utils.js | 2 +- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/addons/web/static/src/core/domain_selector/domain_selector.js b/addons/web/static/src/core/domain_selector/domain_selector.js index ebbff2d4439..f45d43f8f3a 100644 --- a/addons/web/static/src/core/domain_selector/domain_selector.js +++ b/addons/web/static/src/core/domain_selector/domain_selector.js @@ -101,7 +101,11 @@ export class DomainSelector extends Component { this.tree.isSupported = true; - const options = { defaultConnector: p.defaultConnector, distributeNot: !p.isDebugMode }; + const options = { + defaultConnector: p.defaultConnector, + distributeNot: !p.isDebugMode, + previousTree: this.tree.root, + }; this.tree.root = buildDomainSelectorTree(domain, pathsInfo, options); this.defaultLeaf = buildDomainSelectorTree( defaultLeafDomain, diff --git a/addons/web/static/src/core/domain_selector/domain_selector_nodes.js b/addons/web/static/src/core/domain_selector/domain_selector_nodes.js index 9f8cdb6dc92..b4a50a321f4 100644 --- a/addons/web/static/src/core/domain_selector/domain_selector_nodes.js +++ b/addons/web/static/src/core/domain_selector/domain_selector_nodes.js @@ -16,10 +16,10 @@ export class DomainValueExpr { class DomainNode { static nextId = 0; - constructor(type, negate) { - this.id = ++DomainNode.nextId; + constructor(type, options = {}) { + this.id = options.id ?? ++DomainNode.nextId; this.type = type; - this.negate = negate; + this.negate = options.negate ?? false; } toDomain() { @@ -41,8 +41,8 @@ const TITLES = { }; export class BranchDomainNode extends DomainNode { - constructor(connector, children = [], negate = false) { - super("branch", negate); + constructor(connector, children, options = {}) { + super("branch", options); this.connector = connector; this.children = children; } @@ -80,8 +80,8 @@ export class BranchDomainNode extends DomainNode { // ---------------------------------------------------------------------------- export class LeafDomainNode extends DomainNode { - constructor(pathInfo, operatorInfo, value, negate = false) { - super("leaf", negate); + constructor(pathInfo, operatorInfo, value, options = {}) { + super("leaf", options); this.pathInfo = pathInfo; this.operatorInfo = operatorInfo; this.value = value; @@ -109,7 +109,9 @@ export class LeafDomainNode extends DomainNode { } clone() { - return new LeafDomainNode(this.pathInfo, this.operatorInfo, this.value, this.negate); + return new LeafDomainNode(this.pathInfo, this.operatorInfo, this.value, { + negate: this.negate, + }); } } @@ -173,19 +175,26 @@ export function getLeafOperatorInfo(tree, fieldDef) { /** * @param {import("@web/core/domain_tree").Tree} tree * @param {Object} pathsInfo + * @param {LeafDomainNode|BranchDomainNode} [previousTree] * @returns {LeafDomainNode|BranchDomainNode} */ -export function toDomainSelectorTree(tree, pathsInfo) { +export function toDomainSelectorTree(tree, pathsInfo, previousTree = null) { if (tree.type === "condition") { const path = tree.path; const negate = tree.negate; const pathInfo = pathsInfo[path]; const operatorInfo = getLeafOperatorInfo(tree, pathInfo.fieldDef); const value = getValue(tree.valueAST); - return new LeafDomainNode(pathInfo, operatorInfo, value, negate); + const id = previousTree instanceof LeafDomainNode ? previousTree.id : null; + return new LeafDomainNode(pathInfo, operatorInfo, value, { negate, id }); } const connector = tree.value === "&" ? "AND" : "OR"; const negate = tree.negate; - const children = tree.children.map((child) => toDomainSelectorTree(child, pathsInfo)); - return new BranchDomainNode(connector, children, negate); + const children = tree.children.map((child, index) => { + const subTree = + previousTree instanceof BranchDomainNode ? previousTree.children[index] : null; + return toDomainSelectorTree(child, pathsInfo, subTree); + }); + const id = previousTree instanceof BranchDomainNode ? previousTree.id : null; + return new BranchDomainNode(connector, children, { negate, id }); } diff --git a/addons/web/static/src/core/domain_selector/utils.js b/addons/web/static/src/core/domain_selector/utils.js index f82d9a15afa..cf3cfa17847 100644 --- a/addons/web/static/src/core/domain_selector/utils.js +++ b/addons/web/static/src/core/domain_selector/utils.js @@ -23,7 +23,7 @@ export function buildDomain(domainSelectorTree) { */ export function buildDomainSelectorTree(domain, pathsInfo, options = {}) { const tree = toTree(domain, options); - return toDomainSelectorTree(tree, pathsInfo); + return toDomainSelectorTree(tree, pathsInfo, options.previousTree); } /**