Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 2613x 201x 201x 117x 50x 201x 201x 201x 201x 93x 4x 4x 2x 4x 4x 201x 2x 28x | import React, { useEffect, useState } from "react";
import { useBackend } from "main/utils/useBackend";
import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import { useCurrentUser } from "main/utils/currentUser";
import { useNavigate, useParams, useSearchParams } from "react-router";
import Modal from "react-bootstrap/Modal";
import { Button, Tab, Tabs, OverlayTrigger, Tooltip } from "react-bootstrap";
import AssignmentTabComponent from "main/components/TabComponent/AssignmentTabComponent";
import NewAssignmentsTabComponent from "main/components/TabComponent/NewAssignmentsTabComponent";
import EnrollmentTabComponent from "main/components/TabComponent/EnrollmentTabComponent";
import StaffTabComponent from "main/components/TabComponent/StaffTabComponent";
import GithubSettingIcon from "main/components/Common/GithubSettingIcon";
import TeamsTabComponent from "main/components/TabComponent/TeamsTabComponent";
import { CourseWarningBanner } from "main/components/Courses/CourseWarningBanner";
import SettingsTabComponent from "main/components/TabComponent/SettingsTabComponent";
import JobTabComponent from "main/components/TabComponent/JobTabComponent";
import { hasRole } from "main/utils/currentUser";
import DownloadsTabComponent from "main/components/TabComponent/DownloadsTabComponent";
import SectionsTabComponent from "main/components/TabComponent/SectionsTabComponent";
import { useCourseOptions } from "main/utils/courseOptionsUtils";
import SlackTabComponent from "main/components/TabComponent/SlackTabComponent";
import DokkuTabComponent from "main/components/TabComponent/DokkuTabComponent";
import ApiKeysTabComponent from "main/components/TabComponent/ApiKeysTabComponent";
import EduDoraTabComponent from "main/components/TabComponent/EduDoraTabComponent";
import { slackInfoQueryKey } from "main/utils/slackUtils";
import {
COURSE_TABS,
chooseCourseTab,
getStoredCourseTab,
storeCourseTab,
} from "main/utils/courseTabUtils";
export default function InstructorCourseShowPage({
testId = "InstructorCourseShowPage",
showSettingsTab = true,
staffTabIsInstructor = true,
courseViewPath = "instructor",
canEditStudents,
canManageTeams,
}) {
const currentUser = useCurrentUser();
const courseId = useParams().id;
const [showErrorModal, setShowErrorModal] = useState(false);
const {
data: course,
error: _errorCourse,
status: _statusCourse,
failureCount: courseBackendFailureCount,
} = useBackend(
[`/api/courses/${courseId}`],
// Stryker disable next-line StringLiteral : GET and empty string are equivalent
{ method: "GET", url: `/api/courses/${courseId}` },
null,
true,
);
// Which tabs there are depends on the course options, which anyone who can
// manage the course can read. Staff (the view with no Settings tab) only get
// the New Assignments tab so far, so for them every other option is treated
// as off.
const { data: allCourseOptions } = useCourseOptions(courseId);
const courseOptions = showSettingsTab
? allCourseOptions
: { NEW_ASSIGNMENT_FEATURES: allCourseOptions.NEW_ASSIGNMENT_FEATURES };
// The Sections tab is only shown when the TRANSLATE_SECTIONS course option
// is enabled.
const showSectionsTab = courseOptions.TRANSLATE_SECTIONS === true;
// The New Assignments tab is only shown when the NEW_ASSIGNMENT_FEATURES
// course option is enabled.
const showNewAssignmentsTab = courseOptions.NEW_ASSIGNMENT_FEATURES === true;
// The Dokku tab is only shown when the DOKKU_MANAGER course option is enabled.
const showDokkuTab = courseOptions.DOKKU_MANAGER === true;
// The API Keys tab is only shown when the ENABLE_API_KEYS course option is
// enabled (the backend refuses to create or accept keys otherwise).
const showApiKeysTab = courseOptions.ENABLE_API_KEYS === true;
// The EduDora tab is only shown when the ENABLE_EDUDORA course option is
// enabled.
const showEduDoraTab = courseOptions.ENABLE_EDUDORA === true;
// The Slack tab is only shown when the SLACK_INTEGRATION course option is
// enabled and a Slack token has been saved. The query key is shared with the
// Slack card on the Settings tab, so saving a token there shows the tab.
const slackIntegrationEnabled = courseOptions.SLACK_INTEGRATION === true;
const { data: slackInfo } = useBackend(
[slackInfoQueryKey(courseId)],
// Stryker disable next-line StringLiteral : GET and empty string are equivalent
{ method: "GET", url: slackInfoQueryKey(courseId) },
{},
true,
{ enabled: slackIntegrationEnabled },
);
const showSlackTab =
slackIntegrationEnabled && Boolean(slackInfo.slackBotToken);
// Which tab is showing is kept in the URL as ?tab=<name>, so that a tab can be
// linked to and survives a refresh; see main/utils/courseTabUtils
const [searchParams, setSearchParams] = useSearchParams();
const requestedTab = searchParams.get("tab");
const visibleTabs = COURSE_TABS.filter(
(tab) =>
(tab !== "sections" || showSectionsTab) &&
(tab !== "new-assignments" || showNewAssignmentsTab) &&
(tab !== "dokku" || showDokkuTab) &&
(tab !== "slack" || showSlackTab) &&
(tab !== "api-keys" || showApiKeysTab) &&
(tab !== "edudora" || showEduDoraTab) &&
(tab !== "settings" || showSettingsTab),
);
const activeTab = chooseCourseTab({
requestedTab,
storedTab: getStoredCourseTab(courseId),
visibleTabs,
});
// Remember the tab for the next time this course is opened without ?tab=
useEffect(() => {
if (COURSE_TABS.includes(requestedTab)) {
storeCourseTab(courseId, requestedTab);
}
}, [courseId, requestedTab]);
// Stryker disable OptionalChaining -- course?.instructorEmail is more readable than course && course.instructorEmail
const getCourseFailed = courseBackendFailureCount > 0;
const canEditCourseOptions =
hasRole(currentUser, "ROLE_ADMIN") ||
currentUser?.root?.user?.email === course?.instructorEmail;
// Stryker enable OptionalChaining
const navigate = useNavigate();
useEffect(() => {
if (getCourseFailed) {
setShowErrorModal(true);
const timer = setTimeout(() => {
navigate("/", { replace: true });
}, 3000);
// Stryker disable next-line BlockStatement
return () => {
clearTimeout(timer);
};
}
}, [getCourseFailed, navigate]);
return (
<BasicLayout>
<Modal show={showErrorModal}>
<Modal.Header>
<Modal.Title>Course Not Found</Modal.Title>
</Modal.Header>
<Modal.Body>
Course not found. You will be returned to the course list in 3
seconds.
</Modal.Body>
<Modal.Footer>
<Button onClick={() => setShowErrorModal(false)} variant={"primary"}>
Close
</Button>
</Modal.Footer>
</Modal>
<CourseWarningBanner
courseId={courseId}
orgName={course?.orgName}
hideBasePermissionWarning={course?.hideBasePermissionWarning ?? false}
hideFreePlanWarning={course?.hideFreePlanWarning ?? false}
/>
{!course ? (
<div data-testid={`${testId}-loading`}>Course: Loading...</div>
) : (
<div className="border rounded-3 p-4 mb-4">
<div className="d-flex align-items-center gap-3">
{course.orgName && (
<img
src={`https://github.com/${course.orgName}.png?size=64`}
alt={course.orgName}
data-testid={`${testId}-github-org-image`}
className="rounded-circle border"
style={{ width: 48, height: 48 }}
/>
)}
<div>
<div className="d-flex align-items-center gap-2">
<h1
data-testid={`${testId}-title`}
className="h3 mb-0 fw-semibold"
>
{course.courseName}
</h1>
<span className="badge bg-primary-subtle text-primary-emphasis rounded-pill">
{course.term}
</span>
</div>
{course.orgName && (
<div className="d-flex align-items-center gap-2">
<a
href={`https://github.com/${course.orgName}`}
target="_blank"
rel="noopener noreferrer"
className="text-primary text-decoration-none fs-5"
data-testid={`${testId}-github-org-link`}
>
{course.orgName}
</a>
{course.installationId && (
<OverlayTrigger
placement="right"
overlay={
<Tooltip id={`${testId}-tooltip-github-settings`}>
Manage settings for association between your GitHub
organization and this web application.
</Tooltip>
}
>
<a
href={`https://github.com/organizations/${course.orgName}/settings/installations/${course.installationId}`}
target="_blank"
rel="noopener noreferrer"
data-testid={`${testId}-github-settings-link`}
>
<GithubSettingIcon
size={20}
data-testid={`${testId}-github-settings-icon`}
/>
</a>
</OverlayTrigger>
)}
</div>
)}
</div>
</div>
</div>
)}
<Tabs
activeKey={activeTab}
onSelect={(tab) => setSearchParams({ tab }, { replace: true })}
>
<Tab eventKey={"students"} title={"Students"} className="pt-2">
<EnrollmentTabComponent
courseId={courseId}
testIdPrefix={testId}
currentUser={currentUser}
canEditStudents={canEditStudents}
translateSections={showSectionsTab}
canvasEnabled={courseOptions.ENABLE_CANVAS === true}
/>
</Tab>
<Tab eventKey={"staff"} title={"Staff"} className="pt-2">
<StaffTabComponent
courseId={courseId}
testIdPrefix={testId}
currentUser={currentUser}
isInstructor={staffTabIsInstructor}
/>
</Tab>
<Tab eventKey={"teams"} title={"Teams"} className="pt-2">
<TeamsTabComponent
courseId={courseId}
testIdPrefix={testId}
currentUser={currentUser}
canManageTeams={canManageTeams}
/>
</Tab>
{showSectionsTab && (
<Tab eventKey={"sections"} title={"Sections"} className="pt-2">
<SectionsTabComponent courseId={courseId} testIdPrefix={testId} />
</Tab>
)}
<Tab eventKey={"assignments"} title={"Assignments"} className="pt-2">
<AssignmentTabComponent
courseId={courseId}
testIdPrefix={testId}
currentUser={currentUser}
/>
</Tab>
{showNewAssignmentsTab && (
<Tab
eventKey={"new-assignments"}
title={"New Assignments"}
className="pt-2"
>
<NewAssignmentsTabComponent
courseId={courseId}
courseViewPath={courseViewPath}
testIdPrefix={testId}
/>
</Tab>
)}
<Tab eventKey={"jobs"} title={"Jobs"} className="pt-2">
<JobTabComponent courseId={courseId} testIdPrefix={testId} />
</Tab>
<Tab eventKey={"downloads"} title={"Downloads"} className="pt-2">
<DownloadsTabComponent courseId={courseId} testIdPrefix={testId} />
</Tab>
{showDokkuTab && (
<Tab eventKey={"dokku"} title={"Dokku"} className="pt-2">
<DokkuTabComponent courseId={courseId} testIdPrefix={testId} />
</Tab>
)}
{showSlackTab && (
<Tab
eventKey={"slack"}
title={"Slack"}
className="pt-2"
mountOnEnter={true}
>
<SlackTabComponent
courseId={courseId}
testIdPrefix={testId}
slackTeamName={slackInfo.slackTeamName}
slackTeamUrl={slackInfo.slackTeamUrl}
showSectionChannels={showSectionsTab}
/>
</Tab>
)}
{showApiKeysTab && (
<Tab eventKey={"api-keys"} title={"API Keys"} className="pt-2">
<ApiKeysTabComponent courseId={courseId} testIdPrefix={testId} />
</Tab>
)}
{showEduDoraTab && (
<Tab eventKey={"edudora"} title={"EduDora"} className="pt-2">
<EduDoraTabComponent testIdPrefix={testId} />
</Tab>
)}
{showSettingsTab && (
<Tab eventKey={"settings"} title={"Settings"} className="pt-2">
<SettingsTabComponent
courseId={courseId}
testIdPrefix={testId}
canEditCourseOptions={canEditCourseOptions}
/>
</Tab>
)}
</Tabs>
</BasicLayout>
);
}
|