Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 13166ab

Browse files
committedJun 4, 2025·
frontend/projects/compute image: refactor selector instead
1 parent 1d57055 commit 13166ab

File tree

3 files changed

+73
-75
lines changed

3 files changed

+73
-75
lines changed
 

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,17 @@
55

66
// cSpell:ignore descr disp dflt
77

8-
import { Alert, Button, Col, Divider, List, Radio, Row } from "antd";
8+
import {
9+
Alert,
10+
Button,
11+
Col,
12+
Divider,
13+
List,
14+
Radio,
15+
Row,
16+
Space,
17+
Switch,
18+
} from "antd";
919
import { join } from "path";
1020
import { FormattedMessage, useIntl } from "react-intl";
1121

@@ -21,6 +31,7 @@ import {
2131
A,
2232
Gap,
2333
Icon,
34+
HelpIcon,
2435
Markdown,
2536
Paragraph,
2637
SearchInput,
@@ -123,6 +134,7 @@ export const SoftwareEnvironment: React.FC<Props> = (props: Props) => {
123134
[customize_software],
124135
);
125136

137+
const [selectCustom, setSelectCustom] = useState(false);
126138
const [search_img, set_search_img] = useState<string>("");
127139
const [image_selected, set_image_selected] = useState<string | undefined>(
128140
undefined,
@@ -272,6 +284,22 @@ export const SoftwareEnvironment: React.FC<Props> = (props: Props) => {
272284
);
273285
}
274286

287+
function render_switch_custom() {
288+
if (!onCoCalcCom) return null;
289+
return (
290+
<Space style={{ marginLeft: "20px" }}>
291+
<Switch
292+
value={selectCustom}
293+
onChange={setSelectCustom}
294+
title={"Switch to select a custom software environment"}
295+
checkedChildren={"Custom"}
296+
unCheckedChildren={"Standard"}
297+
/>
298+
<HelpIcon title="Software Environment">Help</HelpIcon>
299+
</Space>
300+
);
301+
}
302+
275303
function render_selected_custom_image_info() {
276304
if (image_type !== "custom" || image_selected == null || images == null) {
277305
return;
@@ -568,6 +596,7 @@ export const SoftwareEnvironment: React.FC<Props> = (props: Props) => {
568596
<>
569597
{render_divider()}
570598
{render_standard_image_selector()}
599+
{render_switch_custom()}
571600
<Col sm={12}>{render_custom_images()}</Col>
572601
<Col sm={12}>{render_selected_custom_image_info()}</Col>
573602
<Col sm={24}>{render_custom_images_info()}</Col>

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

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const img_sorter = (a, b): number => {
6969

7070
interface ComputeImageSelectorProps {
7171
current_image: string;
72-
layout: "horizontal" | "compact" | "dialog" | "dropdown";
72+
layout: "horizontal" | "compact" | "dialog";
7373
onSelect: (img: string) => void;
7474
disabled?: boolean;
7575
size?: SizeType;
@@ -92,7 +92,6 @@ export function ComputeImageSelector({
9292
const disabled = propsDisabled ?? false;
9393
const size = propsSize ?? "small";
9494
const label = propsLabel ?? capitalize(intl.formatMessage(labels.select));
95-
const [dropdownCustom, setDropdownCustom] = useState(false);
9695

9796
// initialize with the given default
9897
const [nextImg, setNextImg] = useState<string>(current_image);
@@ -199,21 +198,7 @@ export function ComputeImageSelector({
199198
);
200199
}
201200

202-
function render_dropdown_custom() {
203-
if (!isCoCalcCom) return null;
204-
return (
205-
<Space style={{ marginLeft: "20px" }}>
206-
<Switch
207-
value={dropdownCustom}
208-
onChange={setDropdownCustom}
209-
title={"Switch to select a custom software environment"}
210-
checkedChildren={"Custom"}
211-
unCheckedChildren={"Standard"}
212-
/>
213-
<HelpIcon title="Software Environment">help</HelpIcon>
214-
</Space>
215-
);
216-
}
201+
217202

218203
function render_doubt() {
219204
return (
@@ -402,23 +387,29 @@ export function ComputeImageSelector({
402387
</Col>
403388
</Row>
404389
);
405-
// used in projects → create new project
406-
case "dropdown":
407-
return (
408-
<Row gutter={[10, 10]}>
409-
<Col xs={24}>
410-
<Icon name={SOFTWARE_ENVIRONMENT_ICON} />
411-
<Gap />
412-
{render_selector()}
413-
<Gap />
414-
{render_dropdown_custom()}
415-
</Col>
416-
<Col xs={24}>
417-
<Paragraph>{render_info(nextImg)}</Paragraph>
418-
{/* <pre>{JSON.stringify(images?.toJS(), null, 2)}</pre> */}
419-
</Col>
420-
</Row>
421-
);
390+
// // used in projects → create new project
391+
// case "dropdown":
392+
// return (
393+
// <Row gutter={[10, 10]}>
394+
// <Col xs={24}>
395+
// <Icon name={SOFTWARE_ENVIRONMENT_ICON} />
396+
// <Gap />
397+
// {render_selector()}
398+
// <Gap />
399+
// {render_switch_custom()}
400+
// </Col>
401+
402+
// <Col xs={24}>
403+
// {" "}
404+
// {selectCustom ? (
405+
// <Paragraph>custom</Paragraph>
406+
// ) : (
407+
// <Paragraph>{render_info(nextImg)}</Paragraph>
408+
// )}
409+
// {/* <pre>{JSON.stringify(images?.toJS(), null, 2)}</pre> */}
410+
// </Col>
411+
// </Row>
412+
// );
422413
// successor of "vertical", where there is a dialog with a clear indication to click a button
423414
case "dialog":
424415
return (

‎src/packages/frontend/projects/create-project.tsx

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { useIntl } from "react-intl";
1414
import { Alert, Well } from "@cocalc/frontend/antd-bootstrap";
1515
import {
1616
CSS,
17-
React,
1817
redux,
1918
useEffect,
2019
useIsMountedRef,
@@ -30,11 +29,11 @@ import {
3029
SoftwareEnvironmentState,
3130
} from "@cocalc/frontend/custom-software/selector";
3231
import { labels } from "@cocalc/frontend/i18n";
33-
import { ComputeImageSelector } from "@cocalc/frontend/project/settings/compute-image-selector";
32+
// import { ComputeImageSelector } from "@cocalc/frontend/project/settings/compute-image-selector";
3433
import { SiteLicenseInput } from "@cocalc/frontend/site-licenses/input";
3534
import { BuyLicenseForProject } from "@cocalc/frontend/site-licenses/purchase/buy-license-for-project";
3635
import track from "@cocalc/frontend/user-tracking";
37-
import { DEFAULT_COMPUTE_IMAGE } from "@cocalc/util/db-schema";
36+
// import { DEFAULT_COMPUTE_IMAGE } from "@cocalc/util/db-schema";
3837
import {
3938
KUCALC_COCALC_COM,
4039
KUCALC_ON_PREMISES,
@@ -53,10 +52,10 @@ interface Props {
5352

5453
type EditState = "edit" | "view" | "saving";
5554

56-
export const NewProjectCreator: React.FC<Props> = ({
55+
export function NewProjectCreator({
5756
start_in_edit_mode,
5857
default_value,
59-
}: Props) => {
58+
}: Props) {
6059
const intl = useIntl();
6160
// view --> edit --> saving --> view
6261
const [state, set_state] = useState<EditState>(
@@ -85,13 +84,13 @@ export const NewProjectCreator: React.FC<Props> = ({
8584
);
8685

8786
const customize_software = useTypedRedux("customize", "software");
88-
const [default_software_img, software_images] = useMemo(
89-
() => [
90-
customize_software.get("default"),
91-
customize_software.get("environments"),
92-
],
93-
[customize_software],
94-
);
87+
// const [default_software_img, software_images] = useMemo(
88+
// () => [
89+
// customize_software.get("default"),
90+
// customize_software.get("environments"),
91+
// ],
92+
// [customize_software],
93+
// );
9594

9695
const [form] = Form.useForm();
9796

@@ -277,33 +276,12 @@ export const NewProjectCreator: React.FC<Props> = ({
277276
set_custom_software(obj);
278277
}
279278

280-
function render_customize_software_env() {
279+
function render_select_software_env() {
281280
return (
282-
<>
283-
<Form.Item label="Software environment">
284-
<ComputeImageSelector
285-
current_image={default_software_img ?? DEFAULT_COMPUTE_IMAGE}
286-
layout={"dropdown"}
287-
onSelect={(img) => {
288-
const display = software_images.get(img)?.get("title");
289-
custom_software_on_change({
290-
image_selected: img,
291-
title_text: display,
292-
image_type: "standard",
293-
});
294-
}}
295-
changing={false}
296-
label={"set"}
297-
/>
298-
</Form.Item>
299-
300-
<Card size="small" title="Software environment" style={CARD_STYLE}>
301-
<SoftwareEnvironment
302-
onChange={custom_software_on_change}
303-
showTitle={false}
304-
/>
305-
</Card>
306-
</>
281+
<SoftwareEnvironment
282+
onChange={custom_software_on_change}
283+
showTitle={false}
284+
/>
307285
);
308286
}
309287

@@ -426,7 +404,7 @@ export const NewProjectCreator: React.FC<Props> = ({
426404
</div>
427405
</Col>
428406
</Row>
429-
{render_customize_software_env()}
407+
{render_select_software_env()}
430408
{render_add_license()}
431409
{render_license()}
432410
<Row>
@@ -482,4 +460,4 @@ export const NewProjectCreator: React.FC<Props> = ({
482460
{render_project_creation()}
483461
</div>
484462
);
485-
};
463+
}

0 commit comments

Comments
 (0)
Please sign in to comment.