Skip to content

Commit 7f03167

Browse files
Improved Object Validations with New ValidateObject
1 parent 277ab0e commit 7f03167

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<script>
3939
4040
import { validateLinkObject } from 'kolibri/utils/validators';
41+
import { validateObject } from 'kolibri/utils/objectSpecs';
4142
import commonCoreStrings from 'kolibri/uiText/commonCoreStrings';
4243
import ProgressBar from './ProgressBar';
4344
import LearningActivityLabel from './LearningActivityLabel';
@@ -56,6 +57,15 @@
5657
content: {
5758
type: Object,
5859
required: true,
60+
validator: function (content) {
61+
return validateObject(content, {
62+
id: { type: String, required: true },
63+
title: { type: String, required: true },
64+
thumbnail: { type: String, required: false, default: '' },
65+
description: { type: String, required: false, default: '' },
66+
num_coach_contents: { type: Number, required: false, default: 0 },
67+
});
68+
},
5969
},
6070
link: {
6171
type: Object,

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<script>
3434
3535
import useKResponsiveWindow from 'kolibri-design-system/lib/composables/useKResponsiveWindow';
36+
import { validateObject } from 'kolibri/utils/objectSpecs';
3637
import useContentLink from '../composables/useContentLink';
3738
import CardGrid from './cards/CardGrid';
3839
import ResourceCard from './cards/ResourceCard';
@@ -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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<script>
2323
2424
import useUser from 'kolibri/composables/useUser';
25+
import { validateObject } from 'kolibri/utils/objectSpecs';
2526
import { getRenderableFiles } from './internal/ContentRenderer/utils';
2627
import { getFilePresetString } from './internal/filePresetStrings';
2728
@@ -38,6 +39,26 @@
3839
files: {
3940
type: Array,
4041
default: () => [],
42+
validator: function (files) {
43+
return files.every(file =>
44+
validateObject(file, {
45+
checksum: { type: String, required: true },
46+
extension: { type: String, required: true },
47+
preset: { type: String, required: true },
48+
lang: {
49+
type: Object,
50+
required: false,
51+
default: () => ({}),
52+
validator: function (lang) {
53+
return validateObject(lang, {
54+
lang_name: { type: String, required: true },
55+
});
56+
},
57+
},
58+
storage_url: { type: String, required: true },
59+
}),
60+
);
61+
},
4162
},
4263
nodeTitle: {
4364
type: String,

0 commit comments

Comments
 (0)