Skip to content

Commit

Permalink
refactor: fix jsdoc types
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Dec 11, 2023
1 parent 8d16909 commit eb30b06
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 22 deletions.
20 changes: 10 additions & 10 deletions src/course-outline/constants.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
export const SECTION_BADGE_STATUTES = {
export const SECTION_BADGE_STATUTES = /** @type {const} */ ({
live: 'live',
publishedNotLive: 'published_not_live',
staffOnly: 'staff_only',
draft: 'draft',
};
});

export const STAFF_ONLY = 'staff_only';

export const HIGHLIGHTS_FIELD_MAX_LENGTH = 250;

export const CHECKLIST_FILTERS = {
export const CHECKLIST_FILTERS = /** @type {const} */ ({
ALL: 'ALL',
SELF_PACED: 'SELF_PACED',
INSTRUCTOR_PACED: 'INSTRUCTOR_PACED',
};
});

export const DEFAULT_NEW_DISPLAY_NAMES = {
export const DEFAULT_NEW_DISPLAY_NAMES = /** @type {const} */ ({
chapter: 'Section',
subsection: 'Subsection',
};
});

export const LAUNCH_CHECKLIST = {
export const LAUNCH_CHECKLIST = /** @type {const} */ ({
data: [
{
id: 'welcomeMessage',
Expand All @@ -47,9 +47,9 @@ export const LAUNCH_CHECKLIST = {
pacingTypeFilter: CHECKLIST_FILTERS.ALL,
},
],
};
});

export const BEST_PRACTICES_CHECKLIST = {
export const BEST_PRACTICES_CHECKLIST = /** @type {const} */ ({
data: [
{
id: 'videoDuration',
Expand All @@ -72,4 +72,4 @@ export const BEST_PRACTICES_CHECKLIST = {
pacingTypeFilter: CHECKLIST_FILTERS.ALL,
},
],
};
});
85 changes: 74 additions & 11 deletions src/course-outline/data/api.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
import { camelCaseObject, getConfig } from '@edx/frontend-platform';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';

Expand Down Expand Up @@ -28,10 +29,28 @@ export const getXBlockBaseApiUrl = () => `${getApiBaseUrl()}/xblock/`;
export const getUpdateCourseSectionApiUrl = (sectionId) => `${getXBlockBaseApiUrl()}${sectionId}`;
export const getXBlockApiUrl = (blockId) => `${getXBlockBaseApiUrl()}outline/${blockId}`;

/**
* @typedef {Object} courseOutline
* @property {string} courseReleaseDate
* @property {Object} courseStructure
* @property {Object} deprecatedBlocksInfo
* @property {string} discussionsIncontextFeedbackUrl
* @property {string} discussionsIncontextLearnmoreUrl
* @property {Object} initialState
* @property {Object} initialUserClipboard
* @property {string} languageCode
* @property {string} lmsLink
* @property {string} mfeProctoredExamSettingsUrl
* @property {string} notificationDismissUrl
* @property {string[]} proctoringErrors
* @property {string} reindexLink
* @property {null} rerunNotificationId
*/

/**
* Get course outline index.
* @param {string} courseId
* @returns {Promise<Object>}
* @returns {Promise<courseOutline>}
*/
export async function getCourseOutlineIndex(courseId) {
const { data } = await getAuthenticatedHttpClient()
Expand All @@ -42,10 +61,8 @@ export async function getCourseOutlineIndex(courseId) {

/**
* Get course best practices.
* @param {string} courseId
* @param {boolean} excludeGraded
* @param {boolean} all
* @returns {Promise<Object>}
* @param {{courseId: string, excludeGraded: boolean, all: boolean}} options
* @returns {Promise<{isSelfPaced: boolean, sections: any, subsection: any, units: any, videos: any }>}
*/
export async function getCourseBestPractices({
courseId,
Expand All @@ -58,13 +75,21 @@ export async function getCourseBestPractices({
return camelCaseObject(data);
}

/** @typedef {object} courseLaunchData
* @property {boolean} isSelfPaced
* @property {object} dates
* @property {object} assignments
* @property {object} grades
* @property {number} grades.sum_of_weights
* @property {object} certificates
* @property {object} updates
* @property {object} proctoring
*/

/**
* Get course launch.
* @param {string} courseId
* @param {boolean} gradedOnly
* @param {boolean} validateOras
* @param {boolean} all
* @returns {Promise<Object>}
* @param {{courseId: string, gradedOnly: boolean, validateOras: boolean, all: boolean}} options
* @returns {Promise<courseLaunchData>}
*/
export async function getCourseLaunch({
courseId,
Expand Down Expand Up @@ -109,10 +134,48 @@ export async function restartIndexingOnCourse(reindexLink) {
return camelCaseObject(data);
}

/**
* @typedef {Object} section
* @property {string} id
* @property {string} displayName
* @property {string} category
* @property {boolean} hasChildren
* @property {string} editedOn
* @property {boolean} published
* @property {string} publishedOn
* @property {string} studioUrl
* @property {boolean} releasedToStudents
* @property {string} releaseDate
* @property {string} visibilityState
* @property {boolean} hasExplicitStaffLock
* @property {string} start
* @property {boolean} graded
* @property {string} dueDate
* @property {null} due
* @property {null} relativeWeeksDue
* @property {null} format
* @property {string[]} courseGraders
* @property {boolean} hasChanges
* @property {object} actions
* @property {null} explanatoryMessage
* @property {object[]} userPartitions
* @property {string} showCorrectness
* @property {string[]} highlights
* @property {boolean} highlightsEnabled
* @property {boolean} highlightsPreviewOnly
* @property {string} highlightsDocUrl
* @property {object} childInfo
* @property {boolean} ancestorHasStaffLock
* @property {boolean} staffOnlyMessage
* @property {boolean} hasPartitionGroupComponents
* @property {object} userPartitionInfo
* @property {boolean} enableCopyPasteUnits
*/

/**
* Get course section
* @param {string} sectionId
* @returns {Promise<Object>}
* @returns {Promise<section>}
*/
export async function getCourseSection(sectionId) {
const { data } = await getAuthenticatedHttpClient()
Expand Down
2 changes: 1 addition & 1 deletion src/course-outline/utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { SECTION_BADGE_STATUTES, STAFF_ONLY } from './constants';
* @param {bool} visibleToStaffOnly - value from section info
* @param {string} visibilityState - value from section info
* @param {bool} staffOnlyMessage - value from section info
* @returns {typeof SECTION_BADGE_STATUTES}
* @returns {SECTION_BADGE_STATUTES[keyof SECTION_BADGE_STATUTES]}
*/
const getSectionStatus = ({
published,
Expand Down

0 comments on commit eb30b06

Please sign in to comment.