From 7e9636e076acda1ed81b861e5b8d3bd6c5327a7c Mon Sep 17 00:00:00 2001 From: micheledic Date: Thu, 4 Jul 2024 15:09:25 +0200 Subject: [PATCH] [FIX][17.0] date_range : error opening conditional on studio --- date_range/static/src/js/tree_editor.esm.js | 126 ++++++++++---------- 1 file changed, 65 insertions(+), 61 deletions(-) diff --git a/date_range/static/src/js/tree_editor.esm.js b/date_range/static/src/js/tree_editor.esm.js index 9c9e689ac2..c5a294eecf 100644 --- a/date_range/static/src/js/tree_editor.esm.js +++ b/date_range/static/src/js/tree_editor.esm.js @@ -46,58 +46,60 @@ patch(TreeEditor.prototype, { ) { info.component = Select; } - let dateRanges = this.env.domain.dateRanges; - if (this.update_operator && this.update_operator.split("daterange_")[1]) { - dateRanges = this.env.domain.dateRanges.filter( - (range) => - range.type_id[0] === - Number(this.update_operator.split("daterange_")[1]) - ); - } - patch(info, { - extractProps({value, update}) { - const props = super.extractProps.apply(this, arguments); - if ( - fieldDef && - (fieldDef.type === "date" || fieldDef.type === "datetime") && - node.operator.includes("daterange") - ) { - let selected = dateRanges.find( - (range) => - range.date_start === - fromDateTime(value[1], fieldDef.type) && - range.date_end === fromDateTime(value[0], fieldDef.type) - ); - if (!selected) { - selected = dateRanges[0]; - update([ - toDateTime(selected.date_end, fieldDef.type), - toDateTime(selected.date_start, fieldDef.type, true), - ]); - } - - return { - options: dateRanges.map((dt) => [dt.id, dt.name]), - update: (v) => { - const range = dateRanges.find((r) => r.id === v); + if (typeof this.env.domain !== "undefined") { + let dateRanges = this.env.domain.dateRanges; + if (this.update_operator && this.update_operator.split("daterange_")[1]) { + dateRanges = this.env.domain.dateRanges.filter( + (range) => + range.type_id[0] === + Number(this.update_operator.split("daterange_")[1]) + ); + } + patch(info, { + extractProps({value, update}) { + const props = super.extractProps.apply(this, arguments); + if ( + fieldDef && + (fieldDef.type === "date" || fieldDef.type === "datetime") && + node.operator.includes("daterange") + ) { + let selected = dateRanges.find( + (range) => + range.date_start === + fromDateTime(value[1], fieldDef.type) && + range.date_end === fromDateTime(value[0], fieldDef.type) + ); + if (!selected) { + selected = dateRanges[0]; update([ - toDateTime(range.date_end, fieldDef.type), - toDateTime(range.date_start, fieldDef.type, true), + toDateTime(selected.date_end, fieldDef.type), + toDateTime(selected.date_start, fieldDef.type, true), ]); - }, - value: selected.id, - }; - } + } - return props; - }, - isSupported(value) { - if (node.operator.includes("daterange")) { - return Array.isArray(value) && value.length === 2; - } - return super.isSupported.apply(this, arguments); - }, - }); + return { + options: dateRanges.map((dt) => [dt.id, dt.name]), + update: (v) => { + const range = dateRanges.find((r) => r.id === v); + update([ + toDateTime(range.date_end, fieldDef.type), + toDateTime(range.date_start, fieldDef.type, true), + ]); + }, + value: selected.id, + }; + } + + return props; + }, + isSupported(value) { + if (node.operator.includes("daterange")) { + return Array.isArray(value) && value.length === 2; + } + return super.isSupported.apply(this, arguments); + }, + }); + } return info; }, @@ -105,18 +107,20 @@ patch(TreeEditor.prototype, { super.updateLeafOperator.apply(this, arguments); this.update_operator = operator; const fieldDef = this.getFieldDef(node.path); - let dateRanges = this.env.domain.dateRanges.filter( - (range) => range.type_id[0] === Number(operator.split("daterange_")[1]) - ); - if (!dateRanges.length) { - dateRanges = this.env.domain.dateRanges; - } - if (operator.includes("daterange") && dateRanges) { - node.value = [ - toDateTime(dateRanges[0].date_end, fieldDef.type), - toDateTime(dateRanges[0].date_start, fieldDef.type, true), - ]; - this.notifyChanges(); + if (typeof this.env.domain !== "undefined") { + let dateRanges = this.env.domain.dateRanges.filter( + (range) => range.type_id[0] === Number(operator.split("daterange_")[1]) + ); + if (!dateRanges.length) { + dateRanges = this.env.domain.dateRanges; + } + if (operator.includes("daterange") && dateRanges) { + node.value = [ + toDateTime(dateRanges[0].date_end, fieldDef.type), + toDateTime(dateRanges[0].date_start, fieldDef.type, true), + ]; + this.notifyChanges(); + } } }, });