-
Notifications
You must be signed in to change notification settings - Fork 116
dynamic snippets options #4034
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
dynamic snippets options #4034
Conversation
|
This PR targets the un-managed branch odoo-dev/odoo:master-mysterious-egg, it needs to be retargeted before it can be merged. |
4b2e9bf to
a6b4c92
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be careful, the dynamicsnippetoption component is destroyed and recreated possibly many times (for ex, when switching from custom tab to block tab and back), so we don't want to refetch dynamic snippets everytime. i guess a better solution would be to move that in a plugin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ged-odoo As far as I undestood so far from the answers I received on this topic, there is no async life-cycle entry point in plugins, and their shared functions are not supposed to be async either... and if I keep the info in a Promise in the plugin, I doubt the template rendering allows await.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in a plugin, you don't have to have a async lifecycle. you can just work with promises:
class DynamicSnippetOptionPlugin extends Plugin {
static id = "DynamicSnippetOption";
resources = {
builder_options: [
withSequence(10, {
OptionComponent: DynamicSnippetOption,
props: { loadFilters: () => this.fetchDynamicFilters() },
selector: ".s_dynamic_snippet",
}),
],
builder_actions: this.getActions(),
};
setup() {
this.filters = null;
}
fetchDynamicFilters() {
if (!this.filters) {
this.filters = this._fetchDynamicFilters();
}
return this.filters;
}
async _fetchDynamicFilters() {
const filters = await rpc(...);
....
}
}and in your component:
class DynamicSnippetOption extends Component {
onWillStart() {
this.filters = await this.props.loadFilters();
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I did something similar, but with a cache based on the parameters since the plugin is a singleton. And I also made those shared methods so that the other kinds of dynamic snippet options can also use them.
addons/html_builder/static/src/plugins/dynamic_snippet_option.js
Outdated
Show resolved
Hide resolved
fa174dd to
3e6b990
Compare
|
This PR targets the un-managed branch odoo-dev/odoo:master-mysterious-egg, it needs to be retargeted before it can be merged. |
3e6b990 to
cb54b20
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (unit) {
if(saveUnit) {
actionValue = convertNumericToUnit(...) + saveUnit
} else {
actionValue = actionValue + unit
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also added test
53107df to
0f4332e
Compare
addons/html_builder/static/src/plugins/dynamic_snippet_option.js
Outdated
Show resolved
Hide resolved
addons/html_builder/static/src/plugins/dynamic_snippet_option.js
Outdated
Show resolved
Hide resolved
addons/html_builder/static/src/plugins/dynamic_snippet_option.js
Outdated
Show resolved
Hide resolved
addons/html_builder/static/src/plugins/dynamic_snippet_option.js
Outdated
Show resolved
Hide resolved
addons/html_builder/static/src/plugins/dynamic_snippet_option.xml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don t use template_opt ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used by future xpaths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don t use filter_opt ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used by future xpaths
addons/html_builder/static/src/plugins/dynamic_snippet_option.xml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<BuilderSelectItem t-if=""template.thumb" is supported if you want to remove 2 lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to be able to xpath "inside t-if" in case the image is not just what we want
addons/html_builder/static/src/core/building_blocks/builder_number_input.js
Outdated
Show resolved
Hide resolved
0f4332e to
93d4abc
Compare
No description provided.