From ab544b5d2b17f4fa55007e914cbd54210c8e17af Mon Sep 17 00:00:00 2001 From: stvn Date: Fri, 15 May 2020 12:02:06 -0700 Subject: [PATCH] Add new Studio/insights links to InstructorToolbar --- src/courseware/course/InstructorToolbar.jsx | 61 ++++++++++++++++++--- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/src/courseware/course/InstructorToolbar.jsx b/src/courseware/course/InstructorToolbar.jsx index 5b160714..9f440d14 100644 --- a/src/courseware/course/InstructorToolbar.jsx +++ b/src/courseware/course/InstructorToolbar.jsx @@ -3,11 +3,44 @@ import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { Collapsible } from '@edx/paragon'; -function InstructorToolbar(props) { - if (!props.activeUnitLmsWebUrl) { - return null; - } +import { getConfig } from '@edx/frontend-platform'; +function getInsightsUrl(courseId) { + const urlBase = getConfig().INSIGHTS_BASE_URL; + let urlFull; + if (urlBase) { + urlFull = `${urlBase}/courses`; + // This shouldn't actually be missing, at present, + // but we're providing a reasonable fallback, + // in case of either error or extension. + if (courseId) { + urlFull += `/${courseId}`; + } + } + return urlFull; +} + +function getStudioUrl(courseId, unitId) { + const urlBase = getConfig().STUDIO_BASE_URL; + let urlFull; + if (urlBase) { + if (unitId) { + urlFull = `${urlBase}/container/${unitId}`; + } else if (courseId) { + urlFull = `{$urlBase}/course/${courseId}`; + } + } + return urlFull; +} + +function InstructorToolbar(props) { + const { + courseId, + unitId, + } = props; + const urlInsights = getInsightsUrl(courseId); + const urlLms = props.activeUnitLmsWebUrl; + const urlStudio = getStudioUrl(courseId, unitId); return (
@@ -29,9 +62,23 @@ function InstructorToolbar(props) {
-
- View unit in the existing experience -
+ {urlLms && ( +
+ View in the existing experience +
+ )} +   + {urlStudio && ( +
+ View in Studio +
+ )} +   + {urlInsights && ( +
+ View in Insights +
+ )}
);