-
Notifications
You must be signed in to change notification settings - Fork 788
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
add core validator generator for Object-type props #8640
Comments
is this issue still open? Can I contribute to this issue? |
Yes, please do! |
Can you assign it to me and provide me any other relevant information/tips? |
Yes, I have assigned you. There is an example of a function that does some of what is described above here: https://github.com/learningequality/kolibri-design-system/blob/main/lib/content/mixin.js#L50, however, this does not do full checking against the Vue js prop specification, so to meet the specs layed out above, it would need to be extended. Worth looking at the VueJS source code for how they handle validation there, as essentially the spec is just asking for prop validation to be done in a nested way inside objects: https://github.com/vuejs/vue/blob/2.6/src/core/util/props.js#L21 |
A few simplifying assumptions can be made:
|
Working on it and soon I will make a PR for it |
Thank you. Please target the |
Still working on it, should be ready by tomorrow. Sorry for the delay |
Thanks for keeping us updated! |
Observed behavior
There are a large number of
Object
-type props with no validator function. (Search the codebase using a multi-line regex to help find them:{[^}]*type: Object[^}]*}
)Normal component props are well-documented using
type
,required
, and sometimesvalidator
. The keys ofObject
props are as much a part of the component API as the other ones, but they are often under-documented.Even when validation of
Object
props is done in Kolibri, it is performed in an ad-hoc manner with little consistency and the logging is less useful because usually Vue will simply say the validator failed without specifying why. Some examples:kolibri/kolibri/core/assets/src/views/sync/FacilityAdminCredentialsForm.vue
Lines 54 to 60 in c3238a8
kolibri/kolibri/plugins/setup_wizard/assets/src/views/importFacility/SelectFacilityForm.vue
Lines 67 to 73 in c3238a8
kolibri/kolibri/plugins/learn/assets/src/views/EmbeddedSidePanel/SelectGroup.vue
Lines 72 to 79 in c3238a8
Expected behavior
Object
props should be documented and enforced similar to other props. This includes the ability to specifytype
,required
, andvalidator
for object propertiesObject
-type props have a validator functionUser-facing consequences
Object
-based props in new components do not have sufficient support from our built-in tooling for quickly writing effective and useful validatorsObject
-based props do not have as much insight and assurance into what data might exist in the object without looking at parent components that pass the data inProposal
Add a new core function
objectValidator
tokolibri.utils.validators
.props
object, where each key is the name of an expected property, and each value may contain information about thetype
,required
, andvalidator
for that property.true
orfalse
depending on whether the object conforms to the schema. Additionally, when the value isfalse
the function should log a helpful error message specific to the mode of failure.Then this can be used to define validators on
Object
-type properties. For example:Context
0.15
The text was updated successfully, but these errors were encountered: