Skip to content

Commit 2b94b6b

Browse files
Improved Object Validations with New ValidateObject
1 parent 277ab0e commit 2b94b6b

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

kolibri/plugins/learn/assets/src/views/HybridLearningLessonCard.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,18 @@
5353
},
5454
mixins: [commonLearnStrings, commonCoreStrings],
5555
props: {
56-
content: {
56+
content: {
5757
type: Object,
5858
required: true,
59+
validator: function (content) {
60+
return validateObject(content, {
61+
id: { type: String, required: true },
62+
title: { type: String, required: true },
63+
thumbnail: { type: String, required: false, default: '' },
64+
description: { type: String, required: false, default: '' },
65+
num_coach_contents: { type: Number, required: false, default: 0 },
66+
});
67+
},
5968
},
6069
link: {
6170
type: Object,

kolibri/plugins/learn/assets/src/views/LibraryAndChannelBrowserMainContent.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import HybridLearningContentCard from './HybridLearningContentCard';
4040
import HybridLearningFooter from './HybridLearningContentCard/HybridLearningFooter';
4141
import CardList from './CardList';
42+
import { validateObject } from 'kolibri/utils/objectSpecs';
4243
4344
export default {
4445
name: 'LibraryAndChannelBrowserMainContent',
@@ -66,14 +67,21 @@
6667
contents: {
6768
type: Array,
6869
required: true,
70+
validator: function (contents) {
71+
return contents.every(content =>
72+
validateObject(content, {
73+
id: { type: String, required: true },
74+
title: { type: String, required: true },
75+
is_leaf: { type: Boolean, required: true },
76+
copies: { type: Array, required: false, default: () => [] },
77+
}),
78+
);
79+
},
6980
},
7081
currentCardViewStyle: {
7182
type: String,
7283
required: true,
7384
default: 'card',
74-
validator(value) {
75-
return ['card', 'list'].includes(value);
76-
},
7785
},
7886
keepCurrentBackLink: {
7987
type: Boolean,

packages/kolibri/components/DownloadButton.vue

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import useUser from 'kolibri/composables/useUser';
2525
import { getRenderableFiles } from './internal/ContentRenderer/utils';
2626
import { getFilePresetString } from './internal/filePresetStrings';
27-
27+
import { validateObject } from 'kolibri/utils/objectSpecs';
2828
export default {
2929
name: 'DownloadButton',
3030
setup() {
@@ -38,6 +38,26 @@
3838
files: {
3939
type: Array,
4040
default: () => [],
41+
validator: function (files) {
42+
return files.every(file =>
43+
validateObject(file, {
44+
checksum: { type: String, required: true },
45+
extension: { type: String, required: true },
46+
preset: { type: String, required: true },
47+
lang: {
48+
type: Object,
49+
required: false,
50+
default: () => ({}),
51+
validator: function (lang) {
52+
return validateObject(lang, {
53+
lang_name: { type: String, required: true },
54+
});
55+
},
56+
},
57+
storage_url: { type: String, required: true },
58+
}),
59+
);
60+
},
4161
},
4262
nodeTitle: {
4363
type: String,

0 commit comments

Comments
 (0)