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/next/components/licenses/select-license.tsx
Views: 687
/* Select component to choose from one of the licenses that you manage */12import { CSSProperties, ReactNode } from "react";3import useAPI from "lib/hooks/api";4import Loading from "components/share/loading";5import { Quota } from "./license";6import { Alert, Select } from "antd";7const { Option } = Select;8import { search_split, search_match } from "@cocalc/util/misc";910interface Props {11onSelect: (license_id: string) => void;12license?: string;13style?: CSSProperties;14disabled?: boolean;15}1617export default function SelectLicense({18onSelect,19license,20style,21disabled,22}: Props) {23let { result, error } = useAPI("licenses/get-managed");24if (error) {25return <Alert type="error" message={error} />;26}27if (!result) {28return <Loading style={{ fontSize: "16pt", margin: "auto" }} />;29}3031const v: ReactNode[] = [];32for (const x of result) {33v.push(34<Option35value={x.id}36key={x.id}37search={`${x.id} ${x.title} ${x.description} ${JSON.stringify(38x.quota,39)}`.toLowerCase()}40>41{x.title?.trim() ? `${x.title} - ` : ""}42<span style={{ fontFamily: "monospace" }}>{x.id}</span>43<br />44<Quota quota={x.quota} />45</Option>,46);47}4849return (50<Select51style={{ ...style, ...(license ? { height: "80px" } : undefined) }}52disabled={disabled}53showSearch54allowClear55placeholder="Select a license"56optionFilterProp="children"57value={58license ? license : undefined /* no empty string so placeholder works */59}60onChange={onSelect}61filterOption={(input, option) => {62if (!input.trim()) return true;63return search_match(option?.search ?? "", search_split(input));64}}65>66{v}67</Select>68);69}707172