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/frontend/account/licenses/projects-with-licenses.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Alert, Col, Row } from "antd";6import { useEffect, useMemo, useState } from "react";7import { Virtuoso } from "react-virtuoso";89import { redux, useTypedRedux } from "@cocalc/frontend/app-framework";10import { Loading, TimeAgo } from "@cocalc/frontend/components";11import { SiteLicense } from "@cocalc/frontend/project/settings/site-license";12import { SelectProject } from "@cocalc/frontend/projects/select-project";13import { plural, trunc_middle } from "@cocalc/util/misc";14import { LICENSES_STYLE } from "./managed-licenses";15import { projects_with_licenses } from "./util";1617export function ProjectsWithLicenses({}) {18const [project_id, setProjectId] = useState<string | undefined>(undefined);19const project_map = useTypedRedux("projects", "project_map");20const all_projects_have_been_loaded = useTypedRedux(21"projects",22"all_projects_have_been_loaded",23);24const projects = useMemo(25() => projects_with_licenses(project_map),26[project_map],27);2829useEffect(() => {30if (!all_projects_have_been_loaded) {31// Mounted this component, but all projects aren't loaded, so ensure they get loaded.32redux.getActions("projects").load_all_projects();33}34}, []);3536function sanitize(s: any): string {37return typeof s === "string" ? s : "";38}3940function row_renderer({ index }) {41const { project_id, last_edited, num_licenses } = projects[index];42const project_title = sanitize(project_map?.getIn([project_id, "title"]));43return (44<Row45key={projects[index]?.project_id}46style={{ borderBottom: "1px solid lightgrey", cursor: "pointer" }}47onClick={() => {48setProjectId(project_id);49}}50>51<Col span={12} style={{ paddingLeft: "15px" }}>52<a>{trunc_middle(project_title, 80)}</a>53</Col>54<Col span={6}>55{num_licenses} {plural(num_licenses, "License")}56</Col>57<Col span={6}>{last_edited && <TimeAgo date={last_edited} />}</Col>58</Row>59);60}6162function render_projects_with_license() {63if (projects == null || projects.length == 0) {64return (65<span>66You do not have any licensed projects yet. Please purchase a license67or apply a license to one of your projects in Project Settings.68</span>69);70}71return (72<div73style={{ ...LICENSES_STYLE, height: "175px", marginTop: "5px" }}74className={"smc-vfill"}75>76<Virtuoso77totalCount={projects.length}78itemContent={(index) => row_renderer({ index })}79/>80{!all_projects_have_been_loaded && <Loading theme={"medium"} />}81</div>82);83}8485return (86<div>87<h3>Projects</h3>88<Alert89style={{ marginBottom: "15px" }}90banner91type="info"92message={93<>94Select a project below to add or remove a license from that project,95or to buy a license for that project.96</>97}98/>99<SelectProject value={project_id} onChange={setProjectId} />100{project_id && project_map && (101<SiteLicense102project_id={project_id}103site_license={project_map.getIn([project_id, "site_license"]) as any}104/>105)}106<div style={{ marginTop: "10px" }}>107The following {projects.length} {plural(projects.length, "project")}{" "}108have a license:109</div>110{render_projects_with_license()}111</div>112);113}114115116