Commit 106557f3 by Ari Rizzitano

convert course/library listing to use reactrenderer

parent 292848cf
...@@ -5,7 +5,7 @@ import PropTypes from 'prop-types'; ...@@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
function CourseOrLibraryListing(props) { export function CourseOrLibraryListing(props) {
const allowReruns = props.allowReruns; const allowReruns = props.allowReruns;
const linkClass = props.linkClass; const linkClass = props.linkClass;
const idBase = props.idBase; const idBase = props.idBase;
...@@ -75,57 +75,3 @@ CourseOrLibraryListing.propTypes = { ...@@ -75,57 +75,3 @@ CourseOrLibraryListing.propTypes = {
items: PropTypes.arrayOf(PropTypes.object).isRequired, items: PropTypes.arrayOf(PropTypes.object).isRequired,
linkClass: PropTypes.string.isRequired, linkClass: PropTypes.string.isRequired,
}; };
export class StudioCourseIndex {
constructor(selector, context, allowReruns) {
// The HTML element is only conditionally shown, based on number of courses.
const element = document.querySelector(selector);
if (element) {
ReactDOM.render(
<CourseOrLibraryListing
items={context}
linkClass="course-link"
idBase="course"
allowReruns={allowReruns}
/>,
element,
);
}
}
}
export class StudioArchivedIndex {
constructor(selector, context, allowReruns) {
// The HTML element is only conditionally shown, based on number of archived courses.
const element = document.querySelector(selector);
if (element) {
ReactDOM.render(
<CourseOrLibraryListing
items={context}
linkClass="course-link"
idBase="archived"
allowReruns={allowReruns}
/>,
element,
);
}
}
}
export class StudioLibraryIndex {
constructor(selector, context) {
// The HTML element is only conditionally shown, based on number of libraries.
const element = document.querySelector(selector);
if (element) {
ReactDOM.render(
<CourseOrLibraryListing
items={context}
linkClass="library-link"
idBase="library"
allowReruns={false}
/>,
document.querySelector(selector),
);
}
}
}
...@@ -324,7 +324,18 @@ from openedx.core.djangolib.js_utils import ( ...@@ -324,7 +324,18 @@ from openedx.core.djangolib.js_utils import (
% endif % endif
%if len(courses) > 0 or optimization_enabled: %if len(courses) > 0 or optimization_enabled:
<div class="courses courses-tab react-course-listing active"></div> <div class="courses courses-tab react-course-listing active">
${static.renderReact(
component="CourseOrLibraryListing",
id="react-course-listing",
props={
'items': sorted(courses, key=lambda s: s['display_name'].lower() if s['display_name'] is not None else ''),
'linkClass': 'course-link',
'idBase': 'course',
'allowReruns': allow_course_reruns and rerun_creator_status and course_creator_status=='granted'
}
)}
</div>
%else: %else:
<div class="notice notice-incontext notice-instruction notice-instruction-nocourses list-notices courses-tab active"> <div class="notice notice-incontext notice-instruction notice-instruction-nocourses list-notices courses-tab active">
...@@ -442,11 +453,33 @@ from openedx.core.djangolib.js_utils import ( ...@@ -442,11 +453,33 @@ from openedx.core.djangolib.js_utils import (
% endif % endif
%if archived_courses: %if archived_courses:
<div class="archived-courses react-archived-course-listing archived-courses-tab"></div> <div class="archived-courses react-archived-course-listing archived-courses-tab">
${static.renderReact(
component="CourseOrLibraryListing",
id="react-archived-course-listing",
props={
'items': sorted(archived_courses, key=lambda s: s['display_name'].lower() if s['display_name'] is not None else ''),
'linkClass': 'course-link',
'idBase': 'archived',
'allowReruns': allow_course_reruns and rerun_creator_status and course_creator_status=='granted'
}
)}
</div>
%endif %endif
%if len(libraries) > 0 or optimization_enabled: %if len(libraries) > 0 or optimization_enabled:
<div class="libraries react-library-listing libraries-tab"></div> <div class="libraries react-library-listing libraries-tab">
${static.renderReact(
component="CourseOrLibraryListing",
id="react-library-listing",
props={
'items': sorted(libraries, key=lambda s: s['display_name'].lower() if s['display_name'] is not None else ''),
'linkClass': 'library-link',
'idBase': 'library',
'allowReruns': allow_course_reruns and rerun_creator_status and course_creator_status=='granted'
}
)}
</div>
%else: %else:
<div class="notice notice-incontext notice-instruction notice-instruction-nocourses list-notices libraries-tab"> <div class="notice notice-incontext notice-instruction notice-instruction-nocourses list-notices libraries-tab">
...@@ -552,22 +585,4 @@ from openedx.core.djangolib.js_utils import ( ...@@ -552,22 +585,4 @@ from openedx.core.djangolib.js_utils import (
%endif %endif
</div> </div>
<%static:webpack entry="StudioIndex">
var enableReruns = ${allow_course_reruns and rerun_creator_status and course_creator_status=='granted' | n, dump_js_escaped_json};
new StudioCourseIndex(
".react-course-listing",
${sorted(courses, key=lambda s: s['display_name'].lower() if s['display_name'] is not None else '') | n, dump_js_escaped_json},
enableReruns
);
new StudioArchivedIndex(
".react-archived-course-listing",
${sorted(archived_courses, key=lambda s: s['display_name'].lower() if s['display_name'] is not None else '') | n, dump_js_escaped_json},
enableReruns
);
new StudioLibraryIndex(
".react-library-listing",
${sorted(libraries, key=lambda s: s['display_name'].lower() if s['display_name'] is not None else '') | n, dump_js_escaped_json}
);
</%static:webpack>
</%block> </%block>
...@@ -19,7 +19,7 @@ module.exports = { ...@@ -19,7 +19,7 @@ module.exports = {
// Studio // Studio
AssetsPage: './node_modules/@edx/studio-frontend/src/index.jsx', AssetsPage: './node_modules/@edx/studio-frontend/src/index.jsx',
Import: './cms/static/js/features/import/factories/import.js', Import: './cms/static/js/features/import/factories/import.js',
StudioIndex: './cms/static/js/features_jsx/studio/index.jsx', CourseOrLibraryListing: './cms/static/js/features_jsx/studio/CourseOrLibraryListing.jsx',
AccessibilityPage: './node_modules/@edx/studio-frontend/src/accessibilityIndex.jsx', AccessibilityPage: './node_modules/@edx/studio-frontend/src/accessibilityIndex.jsx',
// LMS // LMS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment