-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
pat-contentbrowser
component registry
#1396
Conversation
86945ac
to
4e5693c
Compare
915762f
to
1594b8b
Compare
This solution provides a general approach to override components with |
Can you please explain a bit more how this was done with pattern_options? |
So if we combine the lookup from the registry, with pattern_options for each component we want to make customizable, we can change anything, even on per field level. For example, if we want this for SelectedItem, the default name for the component is |
Historical: you could provide either a I like the idea of providing custom registry keys to the pattern options. I could think of a dictionary, since there could be more overridable components in the future:
|
@petschki this is an interesting approach. But I think this misses the use case a bit. With the previous pat-relateditems approach you could change the selected item template per related items widget instance. Now you can only change the component for all reference browser instances. What I think would be really useful is to use a different selected item component based on the context. As equivalent in Plone: a different browser view based on the implemented interface of the context. It looks like that the @plone/registry does support this via the https://plone-registry.readthedocs.io/how-to-guides/register-and-retrieve-components.html |
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.
See my comment here: #1396 (comment)
@@ -85,6 +92,10 @@ | |||
selectedItemsNode.dispatchEvent(events.change_event()); | |||
} | |||
|
|||
function LoadSelectedItemComponent(node, props) { | |||
const component = new RegisteredSelectedItem.component({target: node, props: props}); |
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.
const component = new RegisteredSelectedItem.component({target: node, props: props}); | |
const component = plone_registry.getComponent({ | |
name: "pat-contentbrowser.SelectedItem", | |
dependencies: [props.item["@type"]] | |
}).component; | |
return component({target: node, props: props}); |
NOTE: untested pseudo code
// get selectedItem component from registry | ||
const RegisteredSelectedItem = plone_registry.getComponent("pat-contentbrowser.SelectedItem"); | ||
|
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.
// get selectedItem component from registry | |
const RegisteredSelectedItem = plone_registry.getComponent("pat-contentbrowser.SelectedItem"); |
Replaced by below...
According to the @plone/registry docs the I'd be OK having a per-type lookup - as long as it doesn't add a significant performance impact. It would be another improvement over the previous situation. That way you could for example render the selected items for different content types differently - an image has different layout requirements than a news item or a location venue or a event. |
I prefer the version where we control it in the widget, then we can have multiple veriantion in the same content type for different fields. @thet the registry like we use it now is globally. But if we allow chnaging the name of the component to use via patterns_options and push this into the svelte app via props, we are very flexible on per widget level. |
So to register a new variant we use plone/registry, this variant can be registered under one of the default component names and will override them. Or it can be registered as a new component under a different name and can then be used on per widget level per patterns_options. If the dependency function works like you thing, we can implement this too. So by registering a new component under default name, but with a pendency on a content type, all relation fields would use this implementation. But still allowing it to be overridden by pattern_options per widget. |
I followed the idea of @MrTango and added a new parameter This parameter (a dictionary to make other components also customizable in the future) can be customized with Custom Component: collective/collective.behavior.relatedmedia@8ddfaae And it works 🎉 @thet the |
5cf4a2d
to
2dcea4d
Compare
abcf5d3
to
7c6eca4
Compare
registry dependencies is not the right approach in this case... solved it with custom registry keys.
class="pat-contentbrowser" | ||
data-pat-contentbrowser='{ | ||
"customComponentKeys": { | ||
"SelectedItem": "pat-contentbrowser.myfield.MySelectedItemComponent", |
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.
@petschki @MrTango Regarding the custom component keys - isn't selectedItem
the only component key which is supported yet?
I'm a bit restrained to use JSON structures as pattern options - especially JSON objects. Until now I had the impression that JSON objects prevent us from using the Patterns options parser and thus prevent us currently from using the BasePattern (that can be fixed).
But your PR here shows that this is not entirely true - You're using both the Patterns Parser and BasePattern here. However, at least the customComponentKeys
is currently not formally defined in the Patterns Parser.
I'd have maybe made a flat single option out for the selectedItem component. Something like selectedItemComponent
. Then we can use Patternslib CSS style Pattern option definition like data-pat-contentbrowser="selectedItemComponent: my-component;"
.
But since this seems to work fine, all is good!
This registers
SelectedItem
component with@plone/registry
to make it overridable.