From b307e360becb7ff0dda51c24ceb7fc39d77c1064 Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Tue, 11 Apr 2023 12:22:45 +0000 Subject: [PATCH] [IMP] web: DomainSelector improvements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The objective of this commit is twofold: - improve the style of the DomainSelector component, in particular, the style of the control buttons "Add node", "Add branch", and "Delete node". - add the possibility to reset the domain when the current domain is not supported. The debug input is also always visible in that case if the debug mode is active. It is displayed in readonly iff the corresponding DomainSelector prop is set to true. Task ID: 3269923 closes odoo/odoo#118057 Related: odoo/enterprise#39512 Signed-off-by: Géry Debongnie Co-authored-by: Mathieu Duckerts-Antoine Co-authored-by: Michaël Mattiello --- .../core/domain_selector/domain_selector.js | 8 +- .../core/domain_selector/domain_selector.scss | 194 ++++++++++++ .../core/domain_selector/domain_selector.xml | 80 +++-- .../src/legacy/scss/domain_selector.scss | 283 +++++++++--------- addons/web/static/src/legacy/xml/base.xml | 2 +- .../tests/core/domain_selector_tests.js | 76 ++++- .../tests/views/fields/domain_field_tests.js | 2 +- 7 files changed, 448 insertions(+), 197 deletions(-) create mode 100644 addons/web/static/src/core/domain_selector/domain_selector.scss 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 3582e3e5442..fe0349a4bca 100644 --- a/addons/web/static/src/core/domain_selector/domain_selector.js +++ b/addons/web/static/src/core/domain_selector/domain_selector.js @@ -51,6 +51,12 @@ export class DomainSelector extends Component { onWillUpdateProps((np) => this.onPropsUpdated(np)); } + get className() { + return `${this.props.readonly ? "o_read_mode" : "o_edit_mode"} ${ + this.props.className + }`.trim(); + } + async onPropsUpdated(p) { try { // try to parse and execute the domain, if it fails then the domain is not supported. @@ -67,7 +73,7 @@ export class DomainSelector extends Component { this.tree.isSupported = true; } catch { this.tree.isSupported = false; - this.tree.root = null; + this.tree.root = this.treeBuilder.build(new Domain([]), {}); } } diff --git a/addons/web/static/src/core/domain_selector/domain_selector.scss b/addons/web/static/src/core/domain_selector/domain_selector.scss new file mode 100644 index 00000000000..a86f27d1997 --- /dev/null +++ b/addons/web/static/src/core/domain_selector/domain_selector.scss @@ -0,0 +1,194 @@ +.o_domain_selector:not(.o_domain_selector_legacy) { + cursor: default; + + &.o_domain_node, .o_domain_node { + $o-domain-selector-indent: 32px; + $o-domain-selector-panel-space: 60px; + $o-domain-selector-row-height: 35px; // should be greater than a "normal" row so that "header" parts are the same size of rows + $o-domain-animation-bar-height: 15px; + + position: relative; + + // Rows in a domain node (selector) have a minimum height and holds the control panel + .o_domain_selector_row { + display: flex; + align-items: center; + min-height: $o-domain-selector-row-height; + + > * { + flex: 0 0 auto; + } + + > .o_domain_node_control_panel { + @include o-position-absolute($top: 0, $bottom: 0, $right: -$o-domain-selector-panel-space); + + > button { + float: left; + width: $o-domain-selector-panel-space/2; + height: 100%; + padding: 0; + background-color: transparent; + font-size: 16px; + opacity: 0.2; + cursor: pointer; + + &.o_domain_delete_node_button { + font-size: 12px; + padding-left: 5px; + } + } + } + } + + // Rules specific to domain parts which contain sub-domain parts + &.o_domain_tree { + > .o_domain_tree_header { + position: relative; + } + .o_domain_tree_operator_caret::after { + @include o-caret-down; + } + + & .o_domain_node_children_container { + padding-left: $o-domain-selector-indent; + } + + // Rules specific to domain root + &.o_domain_selector { + > .o_domain_tree_header { + min-height: 22px; // prevents "records button" to overflow 1-row domain + } + + > .o_domain_node_children_container { + padding-left: 0; + } + + &.o_edit_mode > .o_domain_node_children_container { + padding-right: $o-domain-selector-panel-space; // delete button is over the row + } + + > .o_domain_debug_container { + display: block; + margin-top: 16px; + padding: 8px 10px 12px; + background: var(--DomainDebugContainer-background-colomap-get, #{$o-gray-900}); + color: rgba(white, 0.5); + font-family: monospace; + font-weight: normal; + + > textarea { + border: none; + padding-top: 8px; + background: transparent; + color: white; + } + } + } + } + + // Rules specific to domain parts which do not contain sub-domain parts + &.o_domain_leaf { + &.o_read_mode { + display: inline-flex; + margin-right: 4px; + } + + > .o_domain_leaf_info { + background: $o-brand-lightsecondary; + border: 1px solid darken($o-brand-lightsecondary, 10%); + padding: 2px 4px; + + > .o_field_selector { + float: left; + margin-right: 4px; + + > .o_field_selector_value > .o_field_selector_chain_part { + border: none; + font-weight: 700; + } + } + .o_domain_leaf_operator { + font-style: italic; + } + .o_domain_leaf_value { + font-weight: 700; + } + } + + > .o_domain_leaf_edition { + display: flex; + width: 100%; + padding: 4px ($o-domain-selector-panel-space/2) 4px 0; + + > * { + width: auto; + background-color: white; + + &.o_field_selector { + flex: 0 1 40%; + width: 40%; + + > .o_field_selector_value > .o_field_selector_chain_part { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } + } + + &:last-child { // field value + flex: 1 1 25%; + } + + + * { + margin-left: 4px; + } + + input, select, .o_datepicker, .o_datepicker_input { + height: 100%; + } + } + + .o_domain_leaf_value_tags { + display: flex; + + > * { + flex: 0 0 auto; + } + > input { + flex: 1 1 auto; + width: 0; + min-width: 50px; + } + .o_domain_leaf_value_remove_tag_button { + cursor: pointer; + } + } + } + } + + // Animation effects + transition: margin-bottom .05s ease .05s; + + &::after { + content: ""; + @include o-position-absolute($left: 0, $right: 0, $top: 100%); + display: block; + height: $o-domain-animation-bar-height; + max-height: 0; + background-image: linear-gradient(45deg, rgba($o-brand-primary, 0.4), rgba($o-brand-primary, 0.1)); + transition: max-height .05s ease .05s; + } + + &.o_hover_btns, &.o_hover_add_node { + .o_domain_node_control_panel > button { + opacity: 0.5; + &:hover { + opacity: 1.0; + &.o_domain_delete_node_button { + color: var(--danger); + } + } + } + } + } +} diff --git a/addons/web/static/src/core/domain_selector/domain_selector.xml b/addons/web/static/src/core/domain_selector/domain_selector.xml index 97e934ac10e..c6770e9e199 100644 --- a/addons/web/static/src/core/domain_selector/domain_selector.xml +++ b/addons/web/static/src/core/domain_selector/domain_selector.xml @@ -2,40 +2,38 @@ - - - - - - -
This domain is not supported.
-
-
- - -
- - Match all records - - +
+ + + + Match all records + + + + + + Match records with the following rule: + + + + Match records with + + of the following rules: + - - Match records with the following rule: - - - Match records with - - of the following rules: - + This domain is not supported. + + + - +