Skip to content

Commit 0dea0c0

Browse files
committed
init
1 parent 72b7f65 commit 0dea0c0

File tree

1 file changed

+70
-25
lines changed

1 file changed

+70
-25
lines changed

packages/vscode-extension/src/webview/components/AppRootSelect.tsx

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as Select from "@radix-ui/react-select";
22
import "./AppRootSelect.css";
33
import "./shared/Dropdown.css";
44
import _ from "lodash";
5-
import React, { PropsWithChildren, useEffect, useMemo } from "react";
5+
import React, { PropsWithChildren, useEffect, useMemo, useState } from "react";
66
import { use$ } from "@legendapp/state/react";
77
import { useProject } from "../providers/ProjectProvider";
88
import { LaunchConfiguration, LaunchConfigurationKind } from "../../common/LaunchConfig";
@@ -46,6 +46,8 @@ function renderLaunchConfigurations(
4646
prefix: string,
4747
customLaunchConfigurations: LaunchConfiguration[],
4848
selectedValue: string | undefined,
49+
isExpanded: boolean,
50+
onToggleExpand: () => void,
4951
onEditConfig?: (config: LaunchConfiguration, isSelected: boolean) => void
5052
) {
5153
if (customLaunchConfigurations.length === 0) {
@@ -54,33 +56,44 @@ function renderLaunchConfigurations(
5456

5557
return (
5658
<Select.Group>
57-
<Select.Label className="approot-select-label">{groupLabel}</Select.Label>
58-
{customLaunchConfigurations.map((config, idx) => (
59-
<RichSelectItem
60-
value={`${prefix}:${idx}`}
61-
key={idx}
62-
data-testid={`approot-select-item-${config.name || config.appRoot}`}
63-
icon={<span className="codicon codicon-folder" />}
64-
title={displayNameForConfig(config) ?? config.appRoot ?? "./"}
65-
subtitle={displayNameForConfig(config) ? config.appRoot : undefined}
66-
isSelected={selectedValue === `${prefix}:${idx}`}>
67-
{onEditConfig && (
68-
<ConfigureButton
69-
dataTest={`edit-launch-config-button-${config.name || idx}`}
70-
onClick={() =>
71-
onEditConfig(config as LaunchConfiguration, selectedValue === `${prefix}:${idx}`)
72-
}
73-
/>
74-
)}
75-
</RichSelectItem>
76-
))}
59+
<div
60+
className="approot-select-label-collapsible"
61+
onClick={onToggleExpand}
62+
style={{ cursor: "pointer", display: "flex", alignItems: "center", gap: "6px" }}>
63+
<span
64+
className={`codicon ${isExpanded ? "codicon-chevron-down" : "codicon-chevron-right"}`}
65+
/>
66+
<Select.Label className="approot-select-label">{groupLabel}</Select.Label>
67+
</div>
68+
{isExpanded &&
69+
customLaunchConfigurations.map((config, idx) => (
70+
<RichSelectItem
71+
value={`${prefix}:${idx}`}
72+
key={idx}
73+
data-testid={`approot-select-item-${config.name || config.appRoot}`}
74+
icon={<span className="codicon codicon-folder" />}
75+
title={displayNameForConfig(config) ?? config.appRoot ?? "./"}
76+
subtitle={displayNameForConfig(config) ? config.appRoot : undefined}
77+
isSelected={selectedValue === `${prefix}:${idx}`}>
78+
{onEditConfig && (
79+
<ConfigureButton
80+
dataTest={`edit-launch-config-button-${config.name || idx}`}
81+
onClick={() =>
82+
onEditConfig(config as LaunchConfiguration, selectedValue === `${prefix}:${idx}`)
83+
}
84+
/>
85+
)}
86+
</RichSelectItem>
87+
))}
7788
</Select.Group>
7889
);
7990
}
8091

8192
function renderDetectedLaunchConfigurations(
8293
detectedConfigurations: LaunchConfiguration[],
83-
selectedValue: string | undefined
94+
selectedValue: string | undefined,
95+
isExpanded: boolean,
96+
onToggleExpand: () => void
8497
) {
8598
if (detectedConfigurations.length === 0) {
8699
return null;
@@ -90,13 +103,17 @@ function renderDetectedLaunchConfigurations(
90103
"Detected applications",
91104
"detected",
92105
detectedConfigurations,
93-
selectedValue
106+
selectedValue,
107+
isExpanded,
108+
onToggleExpand
94109
);
95110
}
96111

97112
function renderCustomLaunchConfigurations(
98113
customLaunchConfigurations: LaunchConfiguration[],
99114
selectedValue: string | undefined,
115+
isExpanded: boolean,
116+
onToggleExpand: () => void,
100117
onEditConfig: (config: LaunchConfiguration, isSelected: boolean) => void
101118
) {
102119
if (customLaunchConfigurations.length === 0) {
@@ -108,6 +125,8 @@ function renderCustomLaunchConfigurations(
108125
"custom",
109126
customLaunchConfigurations,
110127
selectedValue,
128+
isExpanded,
129+
onToggleExpand,
111130
onEditConfig
112131
);
113132
}
@@ -145,10 +164,17 @@ function AppRootSelect() {
145164
customLaunchConfigurations: customConfigurations,
146165
} = projectState;
147166

167+
console.log("Frytki", selectedConfiguration);
168+
148169
const selectedAppRootPath = projectState.appRootPath;
149170
const selectedAppRoot = applicationRoots.find((root) => root.path === selectedAppRootPath);
150171
const { openModal } = useModal();
151172

173+
const [expandedSections, setExpandedSections] = useState<{ detected: boolean; custom: boolean }>({
174+
detected: false,
175+
custom: false,
176+
});
177+
152178
function onEditConfig(config: LaunchConfiguration, isSelected: boolean) {
153179
openModal(<LaunchConfigurationView launchConfig={config} isCurrentConfig={isSelected} />, {
154180
title: "Launch Configuration",
@@ -199,6 +225,14 @@ function AppRootSelect() {
199225
}
200226
})();
201227

228+
useEffect(() => {
229+
if (!projectInitialized) return;
230+
setExpandedSections({
231+
detected: selectedConfiguration.kind === LaunchConfigurationKind.Detected,
232+
custom: selectedConfiguration.kind === LaunchConfigurationKind.Custom,
233+
});
234+
}, [projectInitialized, selectedConfiguration.kind]);
235+
202236
useUnknownConfigurationAlert(projectInitialized && selectedValue === "unknown");
203237

204238
const configurationsCount = detectedConfigurations.length + customConfigurations.length;
@@ -232,8 +266,19 @@ function AppRootSelect() {
232266
<span className="codicon codicon-chevron-up" />
233267
</Select.ScrollUpButton>
234268
<Select.Viewport className="approot-select-viewport">
235-
{renderDetectedLaunchConfigurations(detectedConfigurations, selectedValue)}
236-
{renderCustomLaunchConfigurations(customConfigurations, selectedValue, onEditConfig)}
269+
{renderDetectedLaunchConfigurations(
270+
detectedConfigurations,
271+
selectedValue,
272+
expandedSections.detected,
273+
() => setExpandedSections((prev) => ({ ...prev, detected: !prev.detected }))
274+
)}
275+
{renderCustomLaunchConfigurations(
276+
customConfigurations,
277+
selectedValue,
278+
expandedSections.custom,
279+
() => setExpandedSections((prev) => ({ ...prev, custom: !prev.custom })),
280+
onEditConfig
281+
)}
237282
{configurationsCount > 0 && <Select.Separator className="approot-select-separator" />}
238283
<SelectItem value="manage" data-testid="add-launch-config-button">
239284
<span className="codicon codicon-add" />

0 commit comments

Comments
 (0)