From 00cedbad65c765e12741ec1b5280459e4e228de1 Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Fri, 16 Jun 2023 08:22:04 +0000 Subject: [PATCH] [REF] web: Settings, labels search This commit, removes from the compiler all the code made to collect all the labels of the setting for the search. Now, the labels are collected at mounted time, by the setting itself. This commit prepares and is part of the task that aim to refactor the relational model and migrate it to owl. part-of task-id 3179751 closes odoo/odoo#125332 Signed-off-by: Pierre Rousseau (pro) --- .../static/src/views/form/form_renderer.js | 11 +------ .../highlight_text/highlight_text.xml | 10 ++++--- .../highlight_text/settings_radio_field.js | 4 --- .../settings/searchable_setting.js | 17 +++++++---- .../settings/searchable_setting.xml | 1 + .../settings_form_compiler.js | 30 ++----------------- .../settings_form_renderer.js | 30 ------------------- .../settings_form_view_tests.js | 2 +- 8 files changed, 22 insertions(+), 83 deletions(-) diff --git a/addons/web/static/src/views/form/form_renderer.js b/addons/web/static/src/views/form/form_renderer.js index b1f58ce66f3..bcb68d6564a 100644 --- a/addons/web/static/src/views/form/form_renderer.js +++ b/addons/web/static/src/views/form/form_renderer.js @@ -34,12 +34,7 @@ export class FormRenderer extends Component { const { arch, xmlDoc } = archInfo; const templates = { FormRenderer: xmlDoc }; this.state = useState({}); // Used by Form Compiler - this.templates = useViewCompiler( - Compiler || FormCompiler, - arch, - templates, - this.compileParams - ); + this.templates = useViewCompiler(Compiler || FormCompiler, arch, templates); useSubEnv({ model: record.model }); useBounceButton(useRef("compiled_view_root"), (target) => { return !record.isInEdition && !!target.closest(".oe_title, .o_inner_group"); @@ -88,10 +83,6 @@ export class FormRenderer extends Component { evalDomainFromRecord(record, expr) { return evalDomain(expr, record.evalContext); } - - get compileParams() { - return {}; - } } FormRenderer.template = xml``; diff --git a/addons/web/static/src/webclient/settings_form_view/highlight_text/highlight_text.xml b/addons/web/static/src/webclient/settings_form_view/highlight_text/highlight_text.xml index cd2e16ad107..c609e6a9f6a 100644 --- a/addons/web/static/src/webclient/settings_form_view/highlight_text/highlight_text.xml +++ b/addons/web/static/src/webclient/settings_form_view/highlight_text/highlight_text.xml @@ -1,9 +1,11 @@ - - - - + + + + + + diff --git a/addons/web/static/src/webclient/settings_form_view/highlight_text/settings_radio_field.js b/addons/web/static/src/webclient/settings_form_view/highlight_text/settings_radio_field.js index 17aaf665d52..e59f9ee4fc4 100644 --- a/addons/web/static/src/webclient/settings_form_view/highlight_text/settings_radio_field.js +++ b/addons/web/static/src/webclient/settings_form_view/highlight_text/settings_radio_field.js @@ -12,10 +12,6 @@ export class SettingsRadioField extends RadioField { export const settingsRadioField = { ...radioField, component: SettingsRadioField, - extractStringExpr(fieldName, record) { - const radioItems = SettingsRadioField.getItems(fieldName, record); - return radioItems.map((r) => r[1]); - }, }; registry.category("fields").add("base_settings.radio", settingsRadioField); diff --git a/addons/web/static/src/webclient/settings_form_view/settings/searchable_setting.js b/addons/web/static/src/webclient/settings_form_view/settings/searchable_setting.js index 5cfc48589ae..1db2c809f71 100644 --- a/addons/web/static/src/webclient/settings_form_view/settings/searchable_setting.js +++ b/addons/web/static/src/webclient/settings_form_view/settings/searchable_setting.js @@ -2,19 +2,28 @@ import { escapeRegExp } from "@web/core/utils/strings"; import { Setting } from "@web/views/form/setting/setting"; -import { useState } from "@odoo/owl"; +import { onMounted, useRef, useState } from "@odoo/owl"; import { FormLabelHighlightText } from "../highlight_text/form_label_highlight_text"; import { HighlightText } from "../highlight_text/highlight_text"; export class SearchableSetting extends Setting { setup() { + this.settingRef = useRef("setting"); this.state = useState({ search: this.env.searchState, showAllContainer: this.env.showAllContainer, }); - this.labels = this.props.labels || []; + this.labels = []; this.labels.push(this.labelString, this.props.help); super.setup(); + onMounted(() => { + if (this.settingRef.el) { + const searchableTexts = this.settingRef.el.querySelectorAll("span[searchableText]"); + searchableTexts.forEach((st) => { + this.labels.push(st.getAttribute("searchableText")); + }); + } + }); } get classNames() { @@ -43,7 +52,3 @@ SearchableSetting.components = { FormLabel: FormLabelHighlightText, HighlightText, }; -SearchableSetting.props = { - ...Setting.props, - labels: { type: Array, optional: 1 }, -}; diff --git a/addons/web/static/src/webclient/settings_form_view/settings/searchable_setting.xml b/addons/web/static/src/webclient/settings_form_view/settings/searchable_setting.xml index 741079baa2e..611b48449c8 100644 --- a/addons/web/static/src/webclient/settings_form_view/settings/searchable_setting.xml +++ b/addons/web/static/src/webclient/settings_form_view/settings/searchable_setting.xml @@ -2,6 +2,7 @@
+ setting visible()
diff --git a/addons/web/static/src/webclient/settings_form_view/settings_form_compiler.js b/addons/web/static/src/webclient/settings_form_view/settings_form_compiler.js index f1bda03a608..1ac1a1acb9c 100644 --- a/addons/web/static/src/webclient/settings_form_view/settings_form_compiler.js +++ b/addons/web/static/src/webclient/settings_form_view/settings_form_compiler.js @@ -89,30 +89,13 @@ export class SettingsFormCompiler extends FormCompiler { compileSetting(el, params) { params.componentName = el.getAttribute("type") === "header" ? "SettingHeader" : "SearchableSetting"; - params.labels = []; const res = super.compileSetting(el, params); - if (params.componentName === "SearchableSetting") { - res.setAttribute("labels", JSON.stringify(params.labels)); - } - delete params.labels; - return res; - } - - compileField(el, params) { - const res = super.compileField(el, params); - if (params.labels && el.hasAttribute("widget")) { - const label = params.getFieldExpr(el.getAttribute("name"), el.getAttribute("widget")); - if (label) { - params.labels.push(label); - } - } return res; } compileNode(node, params, evalInvisible) { if (isTextNode(node)) { - if (params.labels && node.textContent.trim()) { - params.labels.push(node.textContent.trim()); + if (node.textContent.trim()) { return createElement("HighlightText", { originalText: toStringExpression(node.textContent), }); @@ -121,18 +104,9 @@ export class SettingsFormCompiler extends FormCompiler { return super.compileNode(node, params, evalInvisible); } - createLabelFromField(fieldId, fieldName, fieldString, label, params) { - const res = super.createLabelFromField(fieldId, fieldName, fieldString, label, params); - if (res.hasAttribute("string") && params.labels) { - params.labels.push(res.getAttribute("string")); - } - return res; - } - compileButton(el, params) { const res = super.compileButton(el, params); - if (res.hasAttribute("string") && params.labels && res.children.length === 0) { - params.labels.push(res.getAttribute("string")); + if (res.hasAttribute("string") && res.children.length === 0) { const contentSlot = createElement("t"); contentSlot.setAttribute("t-set-slot", "contents"); const content = createElement("HighlightText", { diff --git a/addons/web/static/src/webclient/settings_form_view/settings_form_renderer.js b/addons/web/static/src/webclient/settings_form_view/settings_form_renderer.js index 267c57d8a81..bc3fb8a3afb 100644 --- a/addons/web/static/src/webclient/settings_form_view/settings_form_renderer.js +++ b/addons/web/static/src/webclient/settings_form_view/settings_form_renderer.js @@ -1,6 +1,5 @@ /** @odoo-module **/ -import { registry } from "@web/core/registry"; import { FormRenderer } from "@web/views/form/form_renderer"; import { FormLabelHighlightText } from "./highlight_text/form_label_highlight_text"; import { HighlightText } from "./highlight_text/highlight_text"; @@ -12,15 +11,8 @@ import { SettingsPage } from "./settings/settings_page"; import { useState } from "@odoo/owl"; -const fieldRegistry = registry.category("fields"); - -const labels = Object.create(null); - export class SettingsFormRenderer extends FormRenderer { setup() { - if (!labels[this.props.archInfo.arch]) { - labels[this.props.archInfo.arch] = []; - } super.setup(); this.searchState = useState(this.env.searchState); } @@ -28,28 +20,6 @@ export class SettingsFormRenderer extends FormRenderer { get shouldAutoFocus() { return false; } - - get compileParams() { - return { - ...super.compileParams, - labels: labels[this.props.archInfo.arch], - getFieldExpr: this.getFieldExpr, - record: this.props.record, - }; - } - - getFieldExpr(fieldName, fieldWidget) { - const name = `base_settings.${fieldWidget}`; - let fieldClass; - if (fieldRegistry.contains(name)) { - fieldClass = fieldRegistry.get(name); - } - if (fieldClass && fieldClass.extractStringExpr) { - return fieldClass.extractStringExpr(fieldName, this.record); - } else { - return ""; - } - } } SettingsFormRenderer.components = { ...FormRenderer.components, diff --git a/addons/web/static/tests/webclient/settings_form_view/settings_form_view_tests.js b/addons/web/static/tests/webclient/settings_form_view/settings_form_view_tests.js index 2b968b2951a..d450afb4faa 100644 --- a/addons/web/static/tests/webclient/settings_form_view/settings_form_view_tests.js +++ b/addons/web/static/tests/webclient/settings_form_view/settings_form_view_tests.js @@ -1528,7 +1528,7 @@ QUnit.module("SettingsFormView", (hooks) => { const expectedCompiled = ` - +