Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/course/modals.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2024 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Alert, Modal } from "antd";6import { useIntl } from "react-intl";78import { AppRedux } from "@cocalc/frontend/app-framework";9import { Icon } from "@cocalc/frontend/components/icon";10import { AddAssignments } from "@cocalc/frontend/course/assignments/assignments-panel";11import { COMMANDS } from "@cocalc/frontend/course/commands";12import { DeleteAllStudentProjects } from "@cocalc/frontend/course/configuration//delete-all-student-projects";13import { DeleteAllStudents } from "@cocalc/frontend/course/configuration//delete-all-students";14import {15CopyMissingHandoutsAndAssignments,16ExportGrades,17ReconfigureAllProjects,18ResendInvites,19StartAllProjects,20} from "@cocalc/frontend/course/configuration/actions-panel";21import ConfigurationCopying from "@cocalc/frontend/course/configuration/configuration-copying";22import {23CollaboratorPolicy,24ConfigureSoftwareEnvironment,25EmailInvitation,26EnvVariables,27NetworkFilesystem,28RestrictStudentProjects,29TitleAndDescription,30UpgradeConfiguration,31} from "@cocalc/frontend/course/configuration/configuration-panel";32import EmptyTrash from "@cocalc/frontend/course/configuration/empty-trash";33import { Nbgrader } from "@cocalc/frontend/course/configuration/nbgrader";34import { Parallel } from "@cocalc/frontend/course/configuration/parallel";35import { TerminalCommandPanel } from "@cocalc/frontend/course/configuration/terminal-command";36import { AddHandouts } from "@cocalc/frontend/course/handouts/handouts-panel";37import { DeleteSharedProjectPanel } from "@cocalc/frontend/course/shared-project/delete-shared-project";38import { SharedProjectPanel } from "@cocalc/frontend/course/shared-project/shared-project-panel";39import AddStudents from "@cocalc/frontend/course/students/add-students";40import { course, isIntlMessage } from "@cocalc/frontend/i18n";41import type { ProjectMap, UserMap } from "@cocalc/frontend/todo-types";42import { CourseEditorActions } from "../frame-editors/course-editor/actions";43import { CourseActions } from "./actions";44import type { CourseSettingsRecord, StudentsMap } from "./store";4546interface Props {47frameActions: CourseEditorActions;48actions: CourseActions;49modal?: string;50name: string;51students?: StudentsMap;52user_map?: UserMap;53project_map?: ProjectMap;54project_id: string;55path: string;56configuring_projects?: boolean;57reinviting_students?: boolean;58settings?: CourseSettingsRecord;59redux: AppRedux;60}6162export default function Modals(props: Props) {63const intl = useIntl();64const { students, user_map, project_map, modal } = props;65if (students == null || user_map == null || project_map == null || !modal) {66return null;67}68const close = () => {69props.frameActions.setState({ modal: "" });70};71const { title, Body, icon } = getModal(modal);7273return (74<Modal75onCancel={close}76onOk={close}77cancelButtonProps={{ style: { display: "none" } }}78okText="Close"79open80title={81title ? (82<>83{icon && <Icon name={icon} />}{" "}84{isIntlMessage(title) ? intl.formatMessage(title) : title}85</>86) : undefined87}88width={800}89>90<br />91<Body92{...props}93students={students}94user_map={user_map}95project_map={project_map}96close={close}97/>98</Modal>99);100}101102function getModal(modal: string) {103const { label: title, icon } = COMMANDS[modal] ?? {};104switch (modal) {105case "add-students":106return { Body: AddStudents, title, icon };107case "add-assignments":108return {109Body: AddAssignments,110title: course.add_assignments,111icon: "share-square",112};113case "add-handouts":114return { Body: AddHandouts, title, icon };115116case "start-all-projects":117return {118Body: StartAllProjects,119};120121case "terminal-command":122return { Body: TerminalCommandPanel };123124case "reconfigure-all-projects":125return {126Body: ReconfigureAllProjects,127};128129case "export-grades":130return { Body: ExportGrades };131132case "resend-invites":133return { Body: ResendInvites };134135case "copy-missing-handouts-and-assignments":136return { Body: CopyMissingHandoutsAndAssignments };137138case "empty-trash":139return { Body: EmptyTrash };140141case "delete-student-projects":142return { Body: DeleteAllStudentProjects };143144case "delete-students":145return { Body: DeleteAllStudents };146147case "delete-shared-project":148return { Body: DeleteSharedProjectPanel };149150case "create-shared-project":151return { Body: SharedProjectPanel };152153case "title-and-description":154return { Body: TitleAndDescription };155156case "email-invitation":157return { Body: EmailInvitation };158case "copy-limit":159return { Body: Parallel };160case "collaborator-policy":161return { Body: CollaboratorPolicy };162case "restrict-student-projects":163return { Body: RestrictStudentProjects };164case "nbgrader":165return { Body: Nbgrader };166case "network-file-systems":167return { Body: NetworkFilesystem };168case "env-variables":169return { Body: EnvVariables };170case "upgrades":171return { Body: UpgradeConfiguration };172case "software-environment":173return { Body: ConfigureSoftwareEnvironment };174case "configuration-copying":175return { Body: ConfigurationCopying };176177default:178return {179Body: () => (180<Alert type="warning" message={<>BUG -- Unknown modal: {modal}</>} />181),182title: "Error",183icon: "bug",184};185}186}187188189