Path: blob/master/src/packages/next/components/store/run-limit.tsx
6028 views
/*1* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Divider, Form } from "antd";6import { useRouter } from "next/router";78import { unreachable } from "@cocalc/util/misc";9import A from "components/misc/A";10import IntegerSlider from "components/misc/integer-slider";1112import type { LicenseSource } from "@cocalc/util/upgrades/shopping";1314export const MAX_ALLOWED_RUN_LIMIT = 10000;1516interface RunLimitProps {17showExplanations: boolean;18form: any;19onChange: () => void;20disabled?: boolean;21boost?: boolean;22source: LicenseSource;23}2425export function RunLimit({26showExplanations,27form,28onChange,29disabled = false,30boost = false,31source,32}: RunLimitProps) {33const router = useRouter();3435function extra() {36if (!showExplanations) return;3738switch (source) {39case "site-license":40return (41<div style={{ marginTop: "5px" }}>42{boost ? (43<div style={{ fontWeight: "bold" }}>44It's not necessary to match the run limit of the license you45want to boost!46</div>47) : undefined}48Simultaneously run this many projects using this license. You, and49anyone you share the license code with, can apply the license to an50unlimited number of projects, but it will only be used up to the run51limit. When{" "}52<A href="https://doc.cocalc.com/teaching-instructors.html">53teaching a course54</A>55,{" "}56<b>57<i>58the run limit is typically 2 more than the number of students59(one for each student, one for the shared project and one for60the instructor project)61</i>62</b>63.64</div>65);66case "course":67return (68<div style={{ marginTop: "5px" }}>69If you consider creating a shared project for your course, you70should select one more seat than the number of students. One for71each student, and one for the shared project. Regarding your72instructor project, you need one additional seat or purchase a73regular{" "}74<a onClick={() => router.push("/store/site-license")}>75site license76</a>{" "}77to cover it.78</div>79);8081default:82unreachable(source);83}84}8586switch (source) {87case "site-license":88return (89<>90<Divider plain>Simultaneous Project Upgrades</Divider>91<Form.Item92label="Run Limit"93name="run_limit"94initialValue={1}95extra={extra()}96>97<EditRunLimit98source={source}99disabled={disabled}100onChange={(run_limit) => {101form.setFieldsValue({ run_limit });102onChange();103}}104/>105</Form.Item>106</>107);108109case "course":110return (111<>112<Divider plain>Size of Course</Divider>113<Form.Item114label="Students"115name="run_limit"116initialValue={25}117extra={extra()}118>119<EditRunLimit120source={source}121disabled={disabled}122onChange={(run_limit) => {123form.setFieldsValue({ run_limit });124onChange();125}}126/>127</Form.Item>128</>129);130131default:132unreachable(source);133}134}135136function EditRunLimit({137value,138onChange,139disabled,140source,141}: {142value?: number;143onChange: (run_limit: number) => void;144disabled?: boolean;145source: LicenseSource;146}) {147return (148<IntegerSlider149value={value}150min={1}151disabled={disabled}152max={300}153maxText={MAX_ALLOWED_RUN_LIMIT}154onChange={onChange}155units={source === "course" ? "students" : "projects"}156presets={157source === "course"158? [10, 25, 50, 75, 100, 125, 150, 200]159: [1, 2, 10, 50, 100, 250, 500]160}161/>162);163}164165166