-
Notifications
You must be signed in to change notification settings - Fork 405
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
#7585: refactor of the Print plugin as a plugins container #7596
#7585: refactor of the Print plugin as a plugins container #7596
Conversation
5a5aa97
to
4dfd8db
Compare
4dfd8db
to
8d579a5
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.
It's a little scary to me to have too many plugins by default. We already had some doubts with timeline + playback.
Can I suggest to use plugin injection as replacement for defaults components when you have a specific target.
E.g. when a plugin as a target like the following in the containers
:
{ target: "TextInput"
| "Layout"
| "LegendOptions"
| "Resolution"
| "MapPreview"
| "Option"
The (documented) convention of the plugin is that these target are replacements for default components.
I think this solution is more maintainable on the core.
What do you think?
@offtherailz how would you add a custom plugin in a specific position? For example between title and description in the current printing dialog? |
In this case I should replace the whole panel (TextInput??). If some panels may accept more options, maybe we can define a target for the panel content.I Don't know if it is a requirement I think you can be able to:
Moreover I read on mailing list they was asking for adding a button to save on cloud the pdf. So future we may also allow to add some buttons here and there.
Now I think they are decoupled so every panel is idependent and I think it makes sense, Maybe injecting an null component for the target may work? |
@offtherailz to summarize the changes you suggest should be:
Is it correct? |
Yes @mbarto , correct. Hope it makes the plugin more flexible and maintainable. |
…iner, restored standard components
…iner, implemented override and removal of standard plugins
…iner, fix in Option to correctly use properties with path
@offtherailz I have updated the PR. The build is currently failing due to webpack/nodejs issues (I guess) |
…iner, fix for the build
web/client/product/plugins.js
Outdated
PrintTextInputPlugin: require('../plugins/print/TextInput').default, | ||
PrintLayoutPlugin: require('../plugins/print/Layout').default, | ||
PrintLegendOptionsPlugin: require('../plugins/print/LegendOptions').default, | ||
PrintResolutionPlugin: require('../plugins/print/Resolution').default, | ||
PrintMapPreviewPlugin: require('../plugins/print/MapPreview').default, | ||
PrintOptionPlugin: require('../plugins/print/Option').default |
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.
My idea was not to include any plugin, but only allow to override by plugin injection, on demand. Having this big set of plugin to configure or customize a single plugin is a problem. Potentially makes the size of the plugins list explode.
I asked to have a plugin like :
{
"name": "PluginCustomization",
"containers": {
"Print": {
target: "left-panel-accordion", // I suggested to have specific targets to replace specific components.
position: ""
Component: MyCustomization
}
}
}
…iner, moved the Null plugin in plugins/print, removed print subplugins from product plugins.js, updated docs
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.
It's ok, now I understood what you did.
- Please look ad my comments, I think that applying the changes everything will seems easier to configure and maintain
- You can avoid to use
createPlugin
for every single panel inprint
folder, using directly the component (that is optionally connected to the state). - For targets use names with dashes for everything, for constiency, as you did for
left-panel
e.g.printoptions
-->print-options
,defaultbackgroundignore
->default-background-ignore
web/client/plugins/Print.jsx
Outdated
* // Custom plugin added to the left-panel target | ||
* { | ||
* "name": "PrintTextInput", | ||
* "id", "ExtraParam", | ||
* "override": { | ||
* "Print": { | ||
* "target": "left-panel", | ||
* "position": 1.5 | ||
* } | ||
* }, | ||
* "cfg": { | ||
* "property": "extra", | ||
* "label": "Extra stuff", | ||
* "placeholder": "Inserisci cose..." | ||
* } | ||
* } | ||
* | ||
* @example | ||
* // Custom plugin replacing an existing target | ||
* { | ||
* "name": "PrintTextInput", | ||
* "id", "ExtraParam", | ||
* "override": { | ||
* "Print": { | ||
* "target": "name", | ||
* "position": 1 | ||
* } | ||
* }, | ||
* "cfg": { | ||
* "property": "extra", | ||
* "label": "Extra stuff", | ||
* "placeholder": "Inserisci cose..." | ||
* } | ||
* } | ||
* | ||
* @example | ||
* // Removal of an existing target | ||
* { | ||
* "name": "Null", | ||
* "override": { | ||
* "Print": { | ||
* "target": "name", | ||
* "position": 1 | ||
* } | ||
* }, | ||
* "cfg": { | ||
* } | ||
* } |
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.
Instead of having 3 examples and a lot of configurations and code, I suggest to use one single plugin, with no component, using the multi-target support.
Please try it.
* // Custom plugin added to the left-panel target | |
* { | |
* "name": "PrintTextInput", | |
* "id", "ExtraParam", | |
* "override": { | |
* "Print": { | |
* "target": "left-panel", | |
* "position": 1.5 | |
* } | |
* }, | |
* "cfg": { | |
* "property": "extra", | |
* "label": "Extra stuff", | |
* "placeholder": "Inserisci cose..." | |
* } | |
* } | |
* | |
* @example | |
* // Custom plugin replacing an existing target | |
* { | |
* "name": "PrintTextInput", | |
* "id", "ExtraParam", | |
* "override": { | |
* "Print": { | |
* "target": "name", | |
* "position": 1 | |
* } | |
* }, | |
* "cfg": { | |
* "property": "extra", | |
* "label": "Extra stuff", | |
* "placeholder": "Inserisci cose..." | |
* } | |
* } | |
* | |
* @example | |
* // Removal of an existing target | |
* { | |
* "name": "Null", | |
* "override": { | |
* "Print": { | |
* "target": "name", | |
* "position": 1 | |
* } | |
* }, | |
* "cfg": { | |
* } | |
* } | |
// PrintCustomizations.js | |
const MyCustomPanel = () => <div>Hello, I am a custom component</div> | |
const MyCustomLayout = connect(mapStateToProps, dispatchToProps)(CustomLayoutSelector); | |
export default createPlugin('PrintCustomizations', | |
containers: [ | |
// this entry allows to add a new panel between text input and accordion panel | |
{ | |
Print: [{ // this entry add a panel | |
target: "left-panel", | |
position: 1.5, | |
Component: MyCustomPanel | |
}, | |
// this entry allows to | |
{ | |
target: "layout", | |
Component: MyCustomLayout | |
}, { | |
target: "map-preview", // To remove one component, simply create a component that returns null. | |
Component: () => null | |
}]); | |
* To remove a widget, you have to include a Null plugin with the desired target. | ||
* You can use the position to sort existing and custom items. |
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 can customize Print
plugin by creating one custom plugin (or more) that modifies the existing components with your ones. You can configure this plugin in localConfig.json as usual.
Co-authored-by: Lorenzo Natali <offtherailz@gmail.com>
Co-authored-by: Lorenzo Natali <offtherailz@gmail.com>
This PR has been merged without an approval @mbarto. @offtherailz please check it as soon as you can. |
My review was on 2 points:
These are missing:
These changes are not mandatory for the functionality itself, but simplify a lot the current solution, that is very tricky. |
If you look at the code you will see that each panel exports both a component and a plugin (as a default).
I didn't commit your suggestion directly, but if you look again at the example, if has been replaced by something very similar to yours, but verified and tested.
That said, feel free to remove my admin commit rights from the project if you prefer. |
So all that Or there is some reason to keep them?
Great, I was confused by the double export (I said it was only confusing).
Please don't misunderstand me, I mean you may ask to me if you was in a hurry or what else. We would find a way to clarify and maybe split this clean up in 2. |
Description
This PR is a refactor of the Print plugin, to allow for custom UI plugins to be included from projects.
Most of the printing dialog widgets have been refactored as subplugins of the Print plugin.
Some ancillary work has been included to improve usability:
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (check one with "x", remove the others)
Issue
#7585
What is the current behavior?
#7585
What is the new behavior?
Breaking change
Does this PR introduce a breaking change? (check one with "x", remove the other)
Other useful information