Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin of the invisible elements #3574

Draft
wants to merge 2 commits into
base: master-mysterious-egg
Choose a base branch
from

Conversation

loco-odoo
Copy link

No description provided.

@robodoo
Copy link

robodoo commented Nov 25, 2024

This PR targets the un-managed branch odoo-dev/odoo:master-mysterious-egg, it needs to be retargeted before it can be merged.

@loco-odoo loco-odoo force-pushed the master-mysterious-egg-loco-1 branch 9 times, most recently from 9c4544a to fa9f7b0 Compare November 27, 2024 12:43
Steps to reproduce:
- Enter in edit mode.
- Select the "Customize" tab.

-> Error.
Comment on lines +97 to +99
for (const handler of this.getResource("on_snippet_dropped")) {
handler();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use this.dispatchTo("on_snippet_dropped")

}
}

function isSnippetVisible(snippetEl) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isVisible(el) ?

return snippetEl.dataset.invisible !== "1";
}

function setSnippetVisibility(invisibleEntry, show) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setVisibility(el, visible)

Comment on lines +97 to +99
for (const handler of this.getResource("on_snippet_dropped")) {
handler();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the editor config onChange instead of a new signal on_snippet_dropped, otherwise undo/redo will not be taken into consideration.

@@ -78,6 +78,7 @@ export class SnippetModel extends Reactive {
isCustom: false,
imagePreviewSrc: snippetEl.dataset.oImagePreview,
};
snippetEl.children[0].dataset["name"] = snippet.title;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. that is strange to mutate the dom in a method called "compute", if necessary I would create another method.
  2. Why do need to duplicate the information in the same node? Either
    2.1 We change the xml to change the key data-snippet to data-name or data-snippet-name
    2.2 The code that reads for the name read data-name || data-snippet

If I had to chose, I'd take 2.1, because it makes more sense to have the data only once with a consistent key. Except if there is a difference in meaning with the 2 keys (data-snippet and data-name).

@@ -86,6 +92,7 @@ export class SnippetsMenu extends Component {
this.state.currentOptionsContainers = currentOptionsContainers;
this.setTab("customize");
},
on_snippet_dropped: this.updateInvisibleEls.bind(this),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use the editor config onChange to take the history in consideration.

@@ -22,3 +22,48 @@
background-color: #3e3e46;
}

.o_we_invisible_el_panel {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of the refactoring is to remove css that should be converted to bootstrap classes so you should add the bootsrap classes directly in the component xml template whenever possible.

For precise position & size, we haven't concluded anything yet, I'm not sure of the current team vision on that. cc @FrancoisGe

import { Component, onWillStart, onWillUpdateProps, useState } from "@odoo/owl";
import { WithSubEnv } from "../builder_helpers";
import { getSnippetName } from "../../utils";
export class InvisibleElementsTab extends Component {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not mention the concept of "Tab" in the name as it is not a Tab.
InvisibleElements ?

@@ -235,6 +248,12 @@ export class SnippetsMenu extends Component {
}
return true;
}

updateInvisibleEls() {
this.state.invisibleEls = [
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invisibleElements to avoid abbreviation

};

setup() {
this.state = useState({ invisibleEls: null });
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invisibleEntries ?

this.state.invisibleEls = createInvisibleElements(rootInvisibleSnippetEls, false);
}

onInvisibleEntryClick(invisibleEntry) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toggleElementVisibility(element)?

Invisible Elements
</div>
<t t-foreach="state.invisibleEls" t-as="invisibleEntry" t-key="invisibleEntry_index">
<t t-call="html_builder.invisibleSnippetEntry" t-call-context="{'entry': invisibleEntry, 'invisibleElTab': this}"/>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of 'invisibleElTab': this, what about 'toggleElementVisibility': toggleElementVisibility

}

function getBasicSection(content) {
function getBasicSection(content, name, processed = false) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Another reason why not to have some processing changing the template, so we don't have "convoluted" checks.
  2. If it is really necessary, you could always return the "processed" to avoid to having to write getBasicSection(..., false) and getBasicSection(..., true).
  3. Just a side note and detail, I would always avoid boolean arguments and have it wrapped in an object instead. Some arguments can be found here: https://alexkondov.com/should-you-pass-boolean-to-functions/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants