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

Consolidate content node utilities into kolibri-common. #12699

Merged
Merged
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
19 changes: 0 additions & 19 deletions kolibri/core/assets/src/utils/contentNodeUtils.js

This file was deleted.

2 changes: 1 addition & 1 deletion kolibri/core/assets/src/views/ExamReport/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import has from 'lodash/has';
import logger from 'kolibri.lib.logging';
import { masteryModelValidator } from '../../utils/contentNodeUtils';
import { masteryModelValidator } from 'kolibri-common/utils/contentNode';

export const logging = logger.getLogger(__filename);

Expand Down
2 changes: 1 addition & 1 deletion kolibri/core/assets/src/views/MasteryModel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script>

import { MasteryModelTypes } from 'kolibri.coreVue.vuex.constants';
import { masteryModelValidator } from '../utils/contentNodeUtils';
import { masteryModelValidator } from 'kolibri-common/utils/contentNode';

export default {
name: 'MasteryModel',
Expand Down
19 changes: 19 additions & 0 deletions packages/kolibri-common/utils/contentNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import groupBy from 'lodash/groupBy';
import sortBy from 'lodash/sortBy';
import { MasteryModelTypes } from 'kolibri.coreVue.vuex.constants';
import { getContentLangActive } from 'kolibri.utils.i18n';

export function deduplicateResources(contentNodes) {
Expand Down Expand Up @@ -30,3 +31,21 @@ export function deduplicateResources(contentNodes) {
return primaryNode;
});
}

export function masteryModelValidator({ type, m, n }) {
let isValid = true;
const typeIsValid = Object.values(MasteryModelTypes).includes(type);
if (!typeIsValid) {
// eslint-disable-next-line no-console
console.error(`Invalid mastery model type: ${type}`);
isValid = false;
}
if (type === MasteryModelTypes.m_of_n) {
if (typeof n !== 'number' || typeof m !== 'number') {
// eslint-disable-next-line no-console
console.error(`Invalid value of m and/or n. m: ${m}, n: ${n}`);
isValid = false;
}
}
return isValid;
}