CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/course/modals.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2024 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Alert, Modal } from "antd";
7
import { useIntl } from "react-intl";
8
9
import { AppRedux } from "@cocalc/frontend/app-framework";
10
import { Icon } from "@cocalc/frontend/components/icon";
11
import { AddAssignments } from "@cocalc/frontend/course/assignments/assignments-panel";
12
import { COMMANDS } from "@cocalc/frontend/course/commands";
13
import { DeleteAllStudentProjects } from "@cocalc/frontend/course/configuration//delete-all-student-projects";
14
import { DeleteAllStudents } from "@cocalc/frontend/course/configuration//delete-all-students";
15
import {
16
CopyMissingHandoutsAndAssignments,
17
ExportGrades,
18
ReconfigureAllProjects,
19
ResendInvites,
20
StartAllProjects,
21
} from "@cocalc/frontend/course/configuration/actions-panel";
22
import ConfigurationCopying from "@cocalc/frontend/course/configuration/configuration-copying";
23
import {
24
CollaboratorPolicy,
25
ConfigureSoftwareEnvironment,
26
EmailInvitation,
27
EnvVariables,
28
NetworkFilesystem,
29
RestrictStudentProjects,
30
TitleAndDescription,
31
UpgradeConfiguration,
32
} from "@cocalc/frontend/course/configuration/configuration-panel";
33
import EmptyTrash from "@cocalc/frontend/course/configuration/empty-trash";
34
import { Nbgrader } from "@cocalc/frontend/course/configuration/nbgrader";
35
import { Parallel } from "@cocalc/frontend/course/configuration/parallel";
36
import { TerminalCommandPanel } from "@cocalc/frontend/course/configuration/terminal-command";
37
import { AddHandouts } from "@cocalc/frontend/course/handouts/handouts-panel";
38
import { DeleteSharedProjectPanel } from "@cocalc/frontend/course/shared-project/delete-shared-project";
39
import { SharedProjectPanel } from "@cocalc/frontend/course/shared-project/shared-project-panel";
40
import AddStudents from "@cocalc/frontend/course/students/add-students";
41
import { course, isIntlMessage } from "@cocalc/frontend/i18n";
42
import type { ProjectMap, UserMap } from "@cocalc/frontend/todo-types";
43
import { CourseEditorActions } from "../frame-editors/course-editor/actions";
44
import { CourseActions } from "./actions";
45
import type { CourseSettingsRecord, StudentsMap } from "./store";
46
47
interface Props {
48
frameActions: CourseEditorActions;
49
actions: CourseActions;
50
modal?: string;
51
name: string;
52
students?: StudentsMap;
53
user_map?: UserMap;
54
project_map?: ProjectMap;
55
project_id: string;
56
path: string;
57
configuring_projects?: boolean;
58
reinviting_students?: boolean;
59
settings?: CourseSettingsRecord;
60
redux: AppRedux;
61
}
62
63
export default function Modals(props: Props) {
64
const intl = useIntl();
65
const { students, user_map, project_map, modal } = props;
66
if (students == null || user_map == null || project_map == null || !modal) {
67
return null;
68
}
69
const close = () => {
70
props.frameActions.setState({ modal: "" });
71
};
72
const { title, Body, icon } = getModal(modal);
73
74
return (
75
<Modal
76
onCancel={close}
77
onOk={close}
78
cancelButtonProps={{ style: { display: "none" } }}
79
okText="Close"
80
open
81
title={
82
title ? (
83
<>
84
{icon && <Icon name={icon} />}{" "}
85
{isIntlMessage(title) ? intl.formatMessage(title) : title}
86
</>
87
) : undefined
88
}
89
width={800}
90
>
91
<br />
92
<Body
93
{...props}
94
students={students}
95
user_map={user_map}
96
project_map={project_map}
97
close={close}
98
/>
99
</Modal>
100
);
101
}
102
103
function getModal(modal: string) {
104
const { label: title, icon } = COMMANDS[modal] ?? {};
105
switch (modal) {
106
case "add-students":
107
return { Body: AddStudents, title, icon };
108
case "add-assignments":
109
return {
110
Body: AddAssignments,
111
title: course.add_assignments,
112
icon: "share-square",
113
};
114
case "add-handouts":
115
return { Body: AddHandouts, title, icon };
116
117
case "start-all-projects":
118
return {
119
Body: StartAllProjects,
120
};
121
122
case "terminal-command":
123
return { Body: TerminalCommandPanel };
124
125
case "reconfigure-all-projects":
126
return {
127
Body: ReconfigureAllProjects,
128
};
129
130
case "export-grades":
131
return { Body: ExportGrades };
132
133
case "resend-invites":
134
return { Body: ResendInvites };
135
136
case "copy-missing-handouts-and-assignments":
137
return { Body: CopyMissingHandoutsAndAssignments };
138
139
case "empty-trash":
140
return { Body: EmptyTrash };
141
142
case "delete-student-projects":
143
return { Body: DeleteAllStudentProjects };
144
145
case "delete-students":
146
return { Body: DeleteAllStudents };
147
148
case "delete-shared-project":
149
return { Body: DeleteSharedProjectPanel };
150
151
case "create-shared-project":
152
return { Body: SharedProjectPanel };
153
154
case "title-and-description":
155
return { Body: TitleAndDescription };
156
157
case "email-invitation":
158
return { Body: EmailInvitation };
159
case "copy-limit":
160
return { Body: Parallel };
161
case "collaborator-policy":
162
return { Body: CollaboratorPolicy };
163
case "restrict-student-projects":
164
return { Body: RestrictStudentProjects };
165
case "nbgrader":
166
return { Body: Nbgrader };
167
case "network-file-systems":
168
return { Body: NetworkFilesystem };
169
case "env-variables":
170
return { Body: EnvVariables };
171
case "upgrades":
172
return { Body: UpgradeConfiguration };
173
case "software-environment":
174
return { Body: ConfigureSoftwareEnvironment };
175
case "configuration-copying":
176
return { Body: ConfigurationCopying };
177
178
default:
179
return {
180
Body: () => (
181
<Alert type="warning" message={<>BUG -- Unknown modal: {modal}</>} />
182
),
183
title: "Error",
184
icon: "bug",
185
};
186
}
187
}
188
189