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

Standardizing Validator Functions for Object props #12921

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,20 @@
device: {
type: Object,
required: true,
validator(val) {
return val.name && val.id && val.baseurl;
},
validator: objectValidator({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is objectValidator coming from here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#8878 Hello, I was following the structure mentioned in this PR!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what @nucleogenesis means is that you will need to import this function from somewhere.

These are the functions available for import, for example:

import { validateObject, objectWithDefaults } from 'kolibri/utils/objectSpecs';

name: {
type: String,
required: true,
},
id: {
type: String,
required: true,
},
baseurl: {
type: String,
required: true,
},
}),
},
facility: {
type: Object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,16 @@
notification: {
type: Object,
required: true,
validator(notification) {
return (
Object.values(NotificationEvents).includes(notification.event) &&
Object.values(NotificationObjects).includes(notification.object)
);
},
validator: objectValidator({
event: {
required: true,
validator: value => Object.values(NotificationEvents).includes(value),
},
object: {
required: true,
validator: value => Object.values(NotificationObjects).includes(value),
},
}),
},
lastQuery: {
type: Object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,18 @@
group: {
type: Object,
required: true,
validator(group) {
return group.name && group.users;
},
validator: objectValidator({
name: {
type: String,
required: true,
validator: value => value !== null && value !== '',
},
users: {
type: Array,
required: true,
validator: value => Array.isArray(value) && value.length > 0,
},
}),
},
},
computed: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,24 @@
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));
},
validator: objectValidator({
channels: {
type: Array,
required: true,
},
accessibility_labels: {
type: Array,
required: true,
},
languages: {
type: Array,
required: true,
},
grade_levels: {
type: Array,
required: true,
},
}),
},
showChannels: {
type: Boolean,
Expand Down
Loading