Skip to content
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

standardize validator functions to all Object props #8903

Open
indirectlylit opened this issue Dec 13, 2021 · 40 comments
Open

standardize validator functions to all Object props #8903

indirectlylit opened this issue Dec 13, 2021 · 40 comments
Assignees
Labels
help wanted Open source contributors welcome

Comments

@indirectlylit
Copy link
Contributor

Observed behavior

Following up from: #8640, #8878, and #8902 which added validation functions.

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 sometimes validator. The keys of Object 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:

device: {
type: Object,
required: true,
validator(val) {
return val.name && val.id && val.baseurl;
},
},

device: {
type: Object,
required: true,
validator(val) {
return isString(val.name) && isString(val.id) && isString(val.baseurl);
},
},

value: {
type: Object,
required: true,
validator(value) {
const inputKeys = ['channels', 'accessibility_labels', 'languages', 'grade_levels'];
return inputKeys.every(k => Object.prototype.hasOwnProperty.call(value, k));
},
},

Expected behavior

Component object props should have a validator and fill in default values which should simplify internal logic of components using these props

@nikkuAg
Copy link
Contributor

nikkuAg commented Feb 9, 2024

Is this issue still open? I would like to work on this

@MisRob
Copy link
Member

MisRob commented Feb 12, 2024

Hi, @nikkuAg, yes, thanks for volunteering

@MisRob
Copy link
Member

MisRob commented Feb 12, 2024

@indirectlylit
Copy link
Contributor Author

This seems to be relevant

yes, that was the intent - thank you

Introduces two new functions, validateObject and objectWithDefaults, which bring Vue prop-like validation and default behavior to nested javascript objects. This can be used with component props, vuex and API validation, and other scenarios

a stopgap for lack of TypeScript, perhaps :)

@rtibbles
Copy link
Member

a stopgap for lack of TypeScript

Except we could use this for runtime validation, which TypeScript does not provide!

@nikkuAg
Copy link
Contributor

nikkuAg commented Mar 1, 2024

Hi,
I am not entirely able to understand what I have to do.

@rtibbles
Copy link
Member

rtibbles commented Mar 4, 2024

The basic idea is to use the Object validation specification work that was done in the referenced PRs, and use it to fully document each of the cases where an Object type is used as a prop.

This allows for better specification of the intended properties and shape of the prop, and to give more semantic error messages when these expectations are violated.

I would start by looking at one of the examples listed in the issue, and replacing the validator function with the Object validation specification.

@MisRob
Copy link
Member

MisRob commented Apr 5, 2024

Hi @nikkuAg, are you still planning to work on this at some point or would it be better to unassign?

@nikkuAg
Copy link
Contributor

nikkuAg commented Apr 7, 2024

Hi @MisRob,
I'm currently occupied with another task, but once I complete it, I'll be able to pick this up. Therefore, I believe it would be best to unassign me for now so that someone else can take over.

@MisRob
Copy link
Member

MisRob commented Apr 8, 2024

Okay @nikkuAg, thank you, let us know any time if you'd like to return to this

@tiffcoding
Copy link

hello, can i be assigned to work on a few of these validators?

@rtibbles
Copy link
Member

rtibbles commented Dec 9, 2024

Hi @tiffcoding - yes, and please do feel free to open a PR with just a few of them, there is no need to do all of these all at once!

@MisRob
Copy link
Member

MisRob commented Dec 17, 2024

@Ammog-Warrier
Copy link

Hello there. Is this still being worked on?Asking since its been 3 weeks. I'm open to working on it if it's open. Thank You

@akolson
Copy link
Member

akolson commented Jan 3, 2025

Great! Thank you! I'll assign it to you shortly!

@nucleogenesis
Copy link
Member

@Ammog-Warrier do you still plan to tackle this issue?

In any case, @tiffcoding 's work in #12921 may be helpful for whoever ends up working on this.

@Ammog-Warrier
Copy link

Ammog-Warrier commented Jan 15, 2025

@Ammog-Warrier do you still plan to tackle this issue?

In any case, @tiffcoding 's work in #12921 may be helpful for whoever ends up working on this.

Yes yes, I'm currently working on it. I just glt sidetracked for few days because of some life stuff. Thank you for the advice. I'll look into it

@akolson
Copy link
Member

akolson commented Jan 15, 2025

Thank you @Ammog-Warrier for your confirmation!

@Ammog-Warrier
Copy link

Hey there! sorry for this, but I was free for a bit but my schedule just got even worse loaded than I expected. I sincerely apologise and request you to assign this issue to someone else.

@Abhishek-Punhani
Copy link
Contributor

@MisRob Can i work on this issue?

@MisRob
Copy link
Member

MisRob commented Jan 20, 2025

Hi @Ammog-Warrier, no problem at all, thank you for letting us know.

Hi @Abhishek-Punhani, yes I will assign you. Thanks!

@MisRob
Copy link
Member

MisRob commented Jan 20, 2025

@Abhishek-Punhani I'd recommend you study #12921 and @nucleogenesis's review - it has helpful information for this task

@Abhishek-Punhani
Copy link
Contributor

Abhishek-Punhani commented Jan 20, 2025

@MisRob I was looking into this issue and I found that changes could be done ContentPage.vue,SelectGroup.vue and FacilityAdminCredentialsForm.vue
I didnt find any validator used in kolibri/plugins/setup_wizard/assets/src/views/importFacility/SelectFacilityForm.vue

Image

Is this what I am supposed to do?

@MisRob
Copy link
Member

MisRob commented Jan 21, 2025

Hi @Abhishek-Punhani, I think there's many many places to update in Kolibri, basically any time there's an Object prop. I'd definitely recommend your start with just a very small number of files for your first pull request. After we confirm it's all good, you can continue with more places if you wish to. Your screenshot looks like a good direction to me.

@MisRob
Copy link
Member

MisRob commented Jan 21, 2025

@Abhishek-Punhani We don't only want to update existing validators but also to validate objects that don't have any validators yet. But as said, in smaller chunks ideally :) Thanks!

@Abhishek-Punhani
Copy link
Contributor

@MisRob Thank you for your feedback. I’ve raised a PR where I modified the validators function in three Vue files to incorporate the validateObject function. Please review it at your convenience. I believe I can implement the validateObject and objectWithDefaults functions in upcoming PRs, but I would greatly appreciate your guidance to ensure they are implemented effectively.

@MisRob
Copy link
Member

MisRob commented Feb 12, 2025

Hi @Abhishek-Punhani, thank you! I think you can feel free to continue working on this issue.

@Abhishek-Punhani
Copy link
Contributor

@MisRob Thanks! Since this approach has been applied to a few files in the merged PR, should I continue making similar changes across other relevant files, or would you prefer a different approach? Let me know how you'd like me to proceed!

@MisRob
Copy link
Member

MisRob commented Feb 12, 2025

Yes @Abhishek-Punhani, feel free to gradually work through this as you wish. The only thing I'd recommend opening pull requests of reasonable size since reviews will be easier and faster than having a huge PR, and that's all. However you can definitely do a bit more than in the first one, perhaps around 10 files in a single PR? That's just my opinionated recommendation, you're welcome to choose.

@Abhishek-Punhani
Copy link
Contributor

Got it . Thanks @MisRob . I will try to raise a PR soon

@Abhishek-Punhani
Copy link
Contributor

Hi @MisRob I think we can begin by resolving all the files in the Learn App. I have raised a PR modifying 10 files—please review it at your convenience.

@MisRob
Copy link
Member

MisRob commented Feb 17, 2025

Sure, thanks @Abhishek-Punhani

@EshaanAgg
Copy link
Contributor

Hi! Since the scope of this issue is the entire codebase, would it be okay if I, too, joined to help? I can coordinate with @Abhishek-Punhani to work on disjoint directories, so that there is no duplication of efforts and we can work on the issue parallely.

@Abhishek-Punhani
Copy link
Contributor

Abhishek-Punhani commented Feb 20, 2025

Hi @EshaanAgg , I think it would it better if we both collaborate together and coordinate to avoid any conflicts in our PRs. Let me know how you'd like to split things up! I think with this we can close this issue at a faster pace . @MisRob Please let me know how would you like me and @EshaanAgg to proceed with this issue!

@EshaanAgg
Copy link
Contributor

EshaanAgg commented Feb 20, 2025

I was able to jot up a quick script that listed all the files that match the given regex and probably require intervention. One way to open up the issue to multiple contributors would be to treat this message (or we can copy this into the issue description itself) and treat it as the issue tracker. Any contributor can message here to claim a folder that he/she wants to work on, and the maintainers can edit the message to add a WIP @Contributor in front of the folder to indicate the same. Once the folder is done, we can delete it from the markdown or check the checkbox!

How does this approach sound?

Files with Object-Type Props Missing Validators

@MisRob
Copy link
Member

MisRob commented Feb 24, 2025

Hi @EshaanAgg, thanks a lot for helping to coordinate, this would be very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Open source contributors welcome
Projects
None yet
Development

No branches or pull requests