-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Widget types error message #1131
Conversation
Deploy preview for netlify-cms-www ready! Built with commit ef599b2 |
Deploy preview for cms-demo ready! Built with commit ef599b2 |
Thanks for this @solpark! First I'll port some relevant comments from Gitter:
I misread your first comment a bit and assumed you meant throwing a descriptive error in the console, not sure where I got that from. The approach you took here is the ideal approach, but it's going to require more work to implement because widgets need to provide their own validation rules. For example, there's a rule that says It's also not a small thing to extend the widget API so that individual widgets can provide it's own config validation. I'm wondering if this is the right time to take our global error component further and allow various areas of the codebase to trigger it in a controlled manner, or else trigger error components with smaller scopes so that the entire app doesn't shut down (although that's often ideal since most errors are showstoppers). Thoughts? cc/ @tech4him1 @talves |
Hey @solpark, is this still something you're able to work on? |
@erquhart Hi! Yes, I am still interested to continue to work on this. I was waiting to hear thoughts from the others tagged :) How should I proceed? |
@solpark so sorry, I thought I responded already! So this is getting into API stuff, but I'm thinking (very loosely):
I'm imagining this function being provided in an options object to function validateConfig(field) {...}
registerWidget('string', StringControl, StringPreview, { validateConfig } What do you think? |
@erquhart Interesting! I would love to take a stab at this. |
Found a problem with my last comment: developers implementing the CMS usually won't be writing those config validation functions - they'll be provided by the widget authors. Having developers retrieve and register that function with each widget that provides it is just a bad idea. The issue here is sort of built in to Netlify CMS API's - extensions are generally just a registered entity that does one thing, which is intentional and makes things straightforward, but also disallows expected norms for "plugins", like the ability to register additional functionality from with the plugin itself. Example: Widget registration right now: registerWidget(name, ControlComponent, PreviewComponent) Widget registration as it probably should be: registerWidget(Widget)
We're now talking about a major 2.0 initiative, redesign of the widget registration API. My example shows what I think 90% of folks will probably do, no need for custom naming of the registered widget in most cases, and we would also accept an expanded signature for tighter control, probably: registerWidget({
name: 'widgetName',
widget: Widget,
}) Everything could be explicitly registered with that approach, including specific control and preview components as is possible currently. Thoughts? If you'd like to play around with any of this while considering, registration happens in |
Closing as stale. |
- Summary
User sees specific error message when widget fields are of wrong data type.
Closes #1074
- Test plan
These are three of the many types of errors.
It should catch wrong data types of widget fields no matter how nested the fields are.
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)