Path: blob/master/src/packages/frontend/course/compute/modal.tsx
1503 views
import { Alert, Button, Divider, Modal, Space } from "antd";1import { useEffect, useState } from "react";2import SelectServer from "@cocalc/frontend/compute/select-server";3import { useFrameContext } from "@cocalc/frontend/frame-editors/frame-tree/frame-context";4import type { CourseActions } from "../actions";5import Students from "./students";6import type { Unit } from "../store";7import { getUnitId } from "./util";89interface Props {10onClose: () => void;11actions: CourseActions;12unit: Unit;13}1415export default function ComputeServerModal({ onClose, actions, unit }: Props) {16const { project_id } = useFrameContext();17const config = unit?.get("compute_server");18const [server_id, setServerId] = useState<number | undefined>(19config?.get("server_id"),20);21const [showHelp, setShowHelp] = useState<boolean>(false);22useEffect(() => {23setServerId(config?.get("server_id"));24}, [config]);2526return (27<Modal28width={"90%"}29open30title={31<>32Compute Server Configuration{" "}33<Button34type="link"35onClick={() => {36setShowHelp(!showHelp);37}}38>39{showHelp ? "Hide " : ""} Help40</Button>41</>42}43onOk={onClose}44onCancel={onClose}45>46{showHelp && (47<Alert48style={{ margin: "15px 0 25px 0" }}49type="info"50message="Student Compute Servers"51showIcon52closable53onClose={() => {54setShowHelp(false);55}}56description={57<>58Select a compute server from this instructor project. You can then59easily create and control identically configured compute servers60in each student project.61<ul>62<li>63The compute server in the student project does not have a copy64of the underlying data and installed files of your compute65server; it just has the same configuration (e.g., cpu, RAM,66disk size).67</li>68<li>69If you select the same compute server for multiple70assignments, it is only created in the student's project once.71</li>72<li>73The person (probably you) who creates the compute server owns74it and pays all costs.75</li>76</ul>77</>78}79/>80)}81<Space direction="vertical" style={{ width: "100%" }}>82<div style={{ textAlign: "center" }}>83<Space style={{ alignItems: "center" }}>84<div style={{ marginRight: "30px" }}>85{server_id ? "" : "Select "}Compute Server86{server_id ? "" : " (not Home Base)"}:87</div>88<SelectServer89title="A compute server with identical configuration to the selected one will be created in each student project."90fullLabel91style={{ borderRadius: "5px" }}92project_id={project_id}93value={server_id}94setValue={(server_id) => {95setServerId(server_id);96actions.compute.setComputeServerConfig({97unit_id: getUnitId(unit),98compute_server: {99server_id,100},101});102}}103/>104</Space>105</div>106{!!server_id && (107<>108<Divider orientation="left">Student Compute Servers</Divider>109<Students actions={actions} unit={unit} onClose={onClose} />110</>111)}112</Space>113</Modal>114);115}116117118