Skip to content

Commit e692eda

Browse files
committed
Merge remote-tracking branch 'origin/master' into llm-fix-account-llm
2 parents 5b04f37 + 3ff94e2 commit e692eda

File tree

4 files changed

+105
-32
lines changed

4 files changed

+105
-32
lines changed

src/packages/frontend/custom-software/selector.tsx

Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
44
*/
55

6-
import { Alert, Divider } from "antd";
6+
import { Alert, Button, Divider } from "antd";
77
import { join } from "path";
88
import {
99
Col,
@@ -16,6 +16,7 @@ import {
1616
} from "react-bootstrap";
1717

1818
import {
19+
CSS,
1920
React,
2021
redux,
2122
useMemo,
@@ -27,6 +28,7 @@ import {
2728
Gap,
2829
Icon,
2930
Markdown,
31+
Paragraph,
3032
SearchInput,
3133
} from "@cocalc/frontend/components";
3234
import {
@@ -49,22 +51,22 @@ import {
4951

5052
const BINDER_URL = "https://mybinder.readthedocs.io/en/latest/";
5153

52-
const cs_list_style: Readonly<React.CSSProperties> = Object.freeze({
54+
const CS_LIST_STYLE: CSS = {
5355
height: "250px",
5456
overflowX: "hidden" as "hidden",
5557
overflowY: "scroll" as "scroll",
5658
border: `1px solid ${COLORS.GRAY_LL}`,
5759
borderRadius: "5px",
5860
marginBottom: "0px",
59-
});
61+
} as const;
6062

61-
const entries_item_style: Readonly<React.CSSProperties> = Object.freeze({
63+
const ENTRIES_ITEM_STYLE: CSS = {
6264
width: "100%",
6365
margin: "2px 0px",
6466
padding: "5px",
6567
border: "none",
6668
textAlign: "left" as "left",
67-
});
69+
} as const;
6870

6971
export interface SoftwareEnvironmentState {
7072
image_selected?: string;
@@ -109,7 +111,9 @@ export const SoftwareEnvironment: React.FC<Props> = (props: Props) => {
109111
"compute_images",
110112
"images",
111113
);
114+
112115
const customize_kucalc = useTypedRedux("customize", "kucalc");
116+
const onCoCalcCom = customize_kucalc === KUCALC_COCALC_COM;
113117
const customize_software = useTypedRedux("customize", "software");
114118
const [dflt_software_img, software_images] = useMemo(
115119
() => [
@@ -188,7 +192,7 @@ export const SoftwareEnvironment: React.FC<Props> = (props: Props) => {
188192
key={id}
189193
active={image_selected === id}
190194
onClick={() => set_state(id, display, image_type)}
191-
style={entries_item_style}
195+
style={ENTRIES_ITEM_STYLE}
192196
bsSize={"small"}
193197
>
194198
{display}
@@ -198,7 +202,7 @@ export const SoftwareEnvironment: React.FC<Props> = (props: Props) => {
198202
.toArray();
199203

200204
if (entries.length > 0) {
201-
return <ListGroup style={cs_list_style}>{entries}</ListGroup>;
205+
return <ListGroup style={CS_LIST_STYLE}>{entries}</ListGroup>;
202206
} else {
203207
if (search_img.length > 0) {
204208
return <div>No search hits.</div>;
@@ -322,8 +326,55 @@ export const SoftwareEnvironment: React.FC<Props> = (props: Props) => {
322326
);
323327
}
324328

329+
function render_onprem() {
330+
const selected = image_selected ?? dflt_software_img;
331+
return (
332+
<>
333+
<Paragraph>
334+
Select the software enviornment. Either go with the default
335+
environment, or select one of the more specialized ones. Whatever you
336+
pick, you can change it later in Project Settings → Control → Software
337+
Environment at any time.
338+
</Paragraph>
339+
<Paragraph>
340+
<ComputeImageSelector
341+
size={"middle"}
342+
selected_image={selected}
343+
layout={"horizontal"}
344+
onSelect={(img) => {
345+
const display = software_images.get(img)?.get("title");
346+
set_state(img, display, "standard");
347+
}}
348+
/>
349+
</Paragraph>
350+
<Paragraph>
351+
{selected !== dflt_software_img ? (
352+
<Alert
353+
type="info"
354+
banner
355+
message={
356+
<>
357+
You've selected a non-standard image:{" "}
358+
<Button
359+
size="small"
360+
type="link"
361+
onClick={() => {
362+
set_state(dflt_software_img, undefined, "standard");
363+
}}
364+
>
365+
Reset
366+
</Button>
367+
</>
368+
}
369+
/>
370+
) : undefined}
371+
</Paragraph>
372+
</>
373+
);
374+
}
375+
325376
function render_default_explanation(): JSX.Element {
326-
if (customize_kucalc === KUCALC_COCALC_COM) {
377+
if (onCoCalcCom) {
327378
return (
328379
<>
329380
<b>Default</b>: large repository of software, well tested – maintained
@@ -365,7 +416,7 @@ export const SoftwareEnvironment: React.FC<Props> = (props: Props) => {
365416
}
366417

367418
function render_standard_explanation(): JSX.Element {
368-
if (customize_kucalc === KUCALC_COCALC_COM) {
419+
if (onCoCalcCom) {
369420
return (
370421
<>
371422
<b>Standard</b>: upcoming and archived versions of the "Default"
@@ -466,13 +517,19 @@ export const SoftwareEnvironment: React.FC<Props> = (props: Props) => {
466517
function render_type_selection() {
467518
return (
468519
<>
469-
{showTitle && <ControlLabel>Software environment</ControlLabel>}
470-
471-
<FormGroup>
472-
{render_default()}
473-
{render_standard()}
474-
{render_custom()}
475-
</FormGroup>
520+
{showTitle ? (
521+
<ControlLabel>Software environment</ControlLabel>
522+
) : undefined}
523+
524+
{onCoCalcCom ? (
525+
<FormGroup>
526+
{render_default()}
527+
{render_standard()}
528+
{render_custom()}
529+
</FormGroup>
530+
) : (
531+
render_onprem()
532+
)}
476533
</>
477534
);
478535
}
@@ -492,11 +549,15 @@ export const SoftwareEnvironment: React.FC<Props> = (props: Props) => {
492549
{render_type_selection()}
493550
</Col>
494551

495-
{render_divider()}
496-
{render_standard_image_selector()}
497-
<Col sm={6}>{render_custom_images()}</Col>
498-
<Col sm={6}>{render_selected_custom_image_info()}</Col>
499-
<Col sm={12}>{render_custom_images_info()}</Col>
552+
{onCoCalcCom ? (
553+
<>
554+
{render_divider()}
555+
{render_standard_image_selector()}
556+
<Col sm={6}>{render_custom_images()}</Col>
557+
<Col sm={6}>{render_selected_custom_image_info()}</Col>
558+
<Col sm={12}>{render_custom_images_info()}</Col>
559+
</>
560+
) : undefined}
500561
</Row>
501562
);
502563
};

src/packages/frontend/project/settings/compute-image-selector.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import { DownOutlined } from "@ant-design/icons";
99
import { Button, Col, Dropdown, MenuProps, Row } from "antd";
10+
import { SizeType } from "antd/es/config-provider/SizeContext";
1011
import { fromJS } from "immutable";
1112

1213
import { useTypedRedux } from "@cocalc/frontend/app-framework";
@@ -43,12 +44,21 @@ interface ComputeImageSelectorProps {
4344
onFocus?: () => void;
4445
onSelect: (e) => void;
4546
disabled?: boolean;
47+
size?: SizeType;
4648
}
4749

4850
export const ComputeImageSelector: React.FC<ComputeImageSelectorProps> = (
4951
props: ComputeImageSelectorProps,
5052
) => {
51-
const { selected_image, onFocus, onBlur, onSelect, layout, disabled } = props;
53+
const {
54+
selected_image,
55+
onFocus,
56+
onBlur,
57+
onSelect,
58+
layout,
59+
disabled,
60+
size = "small",
61+
} = props;
5262

5363
const software_envs: SoftwareEnvironments | null = useTypedRedux(
5464
"customize",
@@ -131,7 +141,7 @@ export const ComputeImageSelector: React.FC<ComputeImageSelectorProps> = (
131141
<Button
132142
onBlur={onBlur}
133143
onFocus={onFocus}
134-
size="small"
144+
size={size}
135145
disabled={disabled}
136146
>
137147
{selected_title} <DownOutlined />

src/packages/server/software-envs.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55

66
// This is used by the hub to adjust the "customization" variable for the user visible site, and also by manage in on-prem, to actually get the associated configuration
77

8+
import { constants } from "node:fs";
9+
import { access, readFile } from "node:fs/promises";
10+
import { join } from "node:path";
11+
812
import getLogger from "@cocalc/backend/logger";
913
import {
1014
Purpose,
1115
sanitizeSoftwareEnv,
1216
SoftwareEnvConfig,
1317
} from "@cocalc/util/sanitize-software-envs";
14-
import { constants } from "fs";
15-
import { access, readFile } from "fs/promises";
16-
import { join } from "path";
1718

18-
const logger = getLogger("hub:webapp-config");
19+
const logger = getLogger("hub:software-envs");
1920
const L = logger.debug;
2021
const W = logger.warn;
2122

@@ -28,7 +29,7 @@ const cache: { [key in Purpose]: SoftwareEnvConfig | false | null } = {
2829
* A configuration for available software environments could be stored at the location of $COCALC_SOFTWARE_ENVIRONMENTS.
2930
*/
3031
export async function getSoftwareEnvironments(
31-
purpose: Purpose
32+
purpose: Purpose,
3233
): Promise<SoftwareEnvConfig | null> {
3334
if (cache[purpose] === null) {
3435
cache[purpose] = (await readConfig(purpose)) ?? false;
@@ -46,14 +47,14 @@ async function readConfig(purpose: Purpose): Promise<SoftwareEnvConfig | null> {
4647

4748
if (!(await isReadable(softwareFn))) {
4849
W(
49-
`WARNING: $COCALC_SOFTWARE_ENVIRONMENTS is defined but ${softwareFn} does not exist`
50+
`WARNING: $COCALC_SOFTWARE_ENVIRONMENTS is defined but ${softwareFn} does not exist`,
5051
);
5152
return null;
5253
}
5354

5455
if (!(await isReadable(registryFn))) {
5556
W(
56-
`WARNING: $COCALC_SOFTWARE_ENVIRONMENTS is defined but ${registryFn} does not exist`
57+
`WARNING: $COCALC_SOFTWARE_ENVIRONMENTS is defined but ${registryFn} does not exist`,
5758
);
5859
return null;
5960
}

src/packages/util/sanitize-software-envs.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
44
*/
55

6-
import { ComputeImage } from "@cocalc/util/compute-images";
76
import { isEmpty, isObject, pick } from "lodash";
7+
8+
import { ComputeImage } from "@cocalc/util/compute-images";
89
import { DEFAULT_COMPUTE_IMAGE } from "./db-schema/defaults";
910

1011
// This sanitization routine checks if the "software environment" information
@@ -54,7 +55,7 @@ interface Opts {
5455
*/
5556
export function sanitizeSoftwareEnv(
5657
opts: Opts,
57-
L: (...msg) => void
58+
L: (...msg) => void,
5859
): SoftwareEnvConfig | null {
5960
const { software, registry, purpose } = opts;
6061

0 commit comments

Comments
 (0)