Skip to content

Commit af00c5d

Browse files
committed
fix #7304 -- course: constantly needless changing the software environment of each course project to itself constantly
- also add "Software Environment" menu item
1 parent 326193c commit af00c5d

File tree

5 files changed

+78
-28
lines changed

5 files changed

+78
-28
lines changed

src/packages/frontend/course/configuration/configuration-panel.tsx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,10 @@ export function ConfigurationPanel({
8585
<br />
8686
<RestrictStudentProjects settings={settings} actions={actions} />
8787
<br />
88-
<StudentProjectSoftwareEnvironment
89-
actions={actions.configuration}
90-
software_image={settings.get("custom_image")}
91-
course_project_id={project_id}
92-
inherit_compute_image={settings.get("inherit_compute_image")}
88+
<ConfigureSoftwareEnvironment
89+
actions={actions}
90+
settings={settings}
91+
project_id={project_id}
9392
/>
9493
<br />
9594
<Parallel name={name} />
@@ -357,3 +356,25 @@ export function EnvVariables({
357356
/>
358357
);
359358
}
359+
360+
export function ConfigureSoftwareEnvironment({
361+
actions,
362+
settings,
363+
project_id,
364+
close,
365+
}: {
366+
actions;
367+
settings;
368+
project_id;
369+
close?;
370+
}) {
371+
return (
372+
<StudentProjectSoftwareEnvironment
373+
actions={actions.configuration}
374+
software_image={settings.get("custom_image")}
375+
course_project_id={project_id}
376+
inherit_compute_image={settings.get("inherit_compute_image")}
377+
close={close}
378+
/>
379+
);
380+
}

src/packages/frontend/course/configuration/student-project-software-environment.tsx

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
KUCALC_COCALC_COM,
2525
KUCALC_ON_PREMISES,
2626
} from "@cocalc/util/db-schema/site-defaults";
27-
import { Alert, Button, Card, Divider, Radio } from "antd";
27+
import { Alert, Button, Card, Divider, Radio, Space } from "antd";
2828
import { ConfigurationActions } from "./actions";
2929

3030
const CSI_HELP =
@@ -35,13 +35,15 @@ interface Props {
3535
course_project_id: string;
3636
software_image?: string;
3737
inherit_compute_image?: boolean;
38+
close?;
3839
}
3940

4041
export function StudentProjectSoftwareEnvironment({
4142
actions,
4243
course_project_id,
4344
software_image,
4445
inherit_compute_image,
46+
close,
4547
}: Props) {
4648
const customize_kucalc = useTypedRedux("customize", "kucalc");
4749
const customize_software = useTypedRedux("customize", "software");
@@ -110,27 +112,36 @@ export function StudentProjectSoftwareEnvironment({
110112
);
111113
} else {
112114
return (
113-
<>
114-
<Button onClick={() => set_changing(false)}>Cancel</Button>
115-
<Button
116-
disabled={
117-
state.image_type === "custom" && state.image_selected == null
118-
}
119-
type="primary"
120-
onClick={async () => {
121-
set_changing(false);
122-
await actions.set_software_environment(state);
123-
}}
124-
>
125-
Save
126-
</Button>
127-
<br />
115+
<div>
128116
<SoftwareEnvironment
129117
onChange={handleChange}
130118
default_image={software_image}
131119
/>
132120
{state.image_type === "custom" && csi_warning()}
133-
</>
121+
<br />
122+
<Space>
123+
<Button
124+
onClick={() => {
125+
set_changing(false);
126+
}}
127+
>
128+
Cancel
129+
</Button>
130+
<Button
131+
disabled={
132+
state.image_type === "custom" && state.image_selected == null
133+
}
134+
type="primary"
135+
onClick={async () => {
136+
set_changing(false);
137+
await actions.set_software_environment(state);
138+
close?.();
139+
}}
140+
>
141+
Save
142+
</Button>
143+
</Space>
144+
</div>
134145
);
135146
}
136147
}
@@ -139,9 +150,7 @@ export function StudentProjectSoftwareEnvironment({
139150
if (inherit) return;
140151
return (
141152
<>
142-
<Divider orientation="left" plain>
143-
Configure
144-
</Divider>
153+
<Divider orientation="left">Configure</Divider>
145154
{render_controls_body()}
146155
</>
147156
);
@@ -226,7 +235,7 @@ export function StudentProjectSoftwareEnvironment({
226235
}
227236
>
228237
<p>
229-
Student projects will be using the software environment:{" "}
238+
Student projects will use the following software environment:{" "}
230239
<em>{current_environment}</em>
231240
</p>
232241
{render_description()}

src/packages/frontend/course/modals.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
RestrictStudentProjects,
2626
TitleAndDescription,
2727
UpgradeConfiguration,
28+
ConfigureSoftwareEnvironment,
2829
} from "@cocalc/frontend/course/configuration/configuration-panel";
2930
import { Parallel } from "@cocalc/frontend/course/configuration/parallel";
3031
import { Nbgrader } from "@cocalc/frontend/course/configuration/nbgrader";
@@ -154,6 +155,8 @@ function getModal(modal: string) {
154155
return { Body: EnvVariables };
155156
case "upgrades":
156157
return { Body: UpgradeConfiguration };
158+
case "software-environment":
159+
return { Body: ConfigureSoftwareEnvironment };
157160

158161
default:
159162
return {

src/packages/frontend/frame-editors/course-editor/editor.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const COURSE_MENUS = {
5757
],
5858
nbgraderConfig: ["course-nbgrader"],
5959
environmentConfig: [
60+
"course-software-environment",
6061
"course-network-file-systems",
6162
"course-env-variables",
6263
],
@@ -182,6 +183,17 @@ const COMMANDS = {
182183
actions.setModal("nbgrader");
183184
},
184185
},
186+
"course-software-environment": {
187+
icon: "laptop",
188+
label: "Software Environment",
189+
button: "Software",
190+
title:
191+
"Configure the software environment that all student projects will use.",
192+
onClick: ({ props }) => {
193+
const { actions } = props;
194+
actions.setModal("software-environment");
195+
},
196+
},
185197
"course-network-file-systems": {
186198
icon: "database",
187199
label: "Cloud Storage & Remote File Systems",

src/packages/frontend/project_actions.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3297,11 +3297,16 @@ export class ProjectActions extends Actions<ProjectStoreState> {
32973297
this.setState({ internet_warning_closed: true });
32983298
}
32993299

3300-
async set_compute_image(compute_image: string): Promise<void> {
3300+
set_compute_image = async (compute_image: string): Promise<void> => {
33013301
const projects_store = this.redux.getStore("projects");
33023302
const previous: string =
33033303
projects_store.getIn(["project_map", this.project_id, "compute_image"]) ??
33043304
"";
3305+
if (previous == compute_image) {
3306+
// it is already set to the goal, so nothing to do.
3307+
// See https://github.com/sagemathinc/cocalc/issues/7304
3308+
return;
3309+
}
33053310

33063311
await client_query({
33073312
query: {
@@ -3319,7 +3324,7 @@ export class ProjectActions extends Actions<ProjectStoreState> {
33193324
next: compute_image,
33203325
};
33213326
this.log(event);
3322-
}
3327+
};
33233328

33243329
async set_environment(env: object): Promise<void> {
33253330
if (typeof env != "object") {

0 commit comments

Comments
 (0)