(
projectPath: string,
subProjectPath: string,
buttonElement?: HTMLElement
)
| 1357 | ); |
| 1358 | |
| 1359 | const handleRemoveSection = async ( |
| 1360 | projectPath: string, |
| 1361 | subProjectPath: string, |
| 1362 | buttonElement?: HTMLElement |
| 1363 | ) => { |
| 1364 | // Capture the anchor location up front because the sub-project action menu unmounts its |
| 1365 | // button immediately after click; failures still need stable error placement. |
| 1366 | const anchor = |
| 1367 | buttonElement != null |
| 1368 | ? (() => { |
| 1369 | const buttonRect = buttonElement.getBoundingClientRect(); |
| 1370 | return { |
| 1371 | top: buttonRect.top + window.scrollY, |
| 1372 | left: buttonRect.right + 10, |
| 1373 | }; |
| 1374 | })() |
| 1375 | : undefined; |
| 1376 | |
| 1377 | // Removing a sub-project unregisters it and clears the cwd pointer from its workspaces. |
| 1378 | const workspacesInSection = (userProjects.get(projectPath)?.workspaces ?? []).filter( |
| 1379 | (workspace) => workspace.subProjectPath === subProjectPath |
| 1380 | ); |
| 1381 | |
| 1382 | if (workspacesInSection.length > 0) { |
| 1383 | const ok = await confirmDialog({ |
| 1384 | title: "Remove sub-project?", |
| 1385 | description: `${workspacesInSection.length} workspace(s) in this sub-project will move back to the parent project.`, |
| 1386 | confirmLabel: "Remove", |
| 1387 | confirmVariant: "destructive", |
| 1388 | }); |
| 1389 | if (!ok) { |
| 1390 | return; |
| 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | const result = await onRemoveProject(subProjectPath); |
| 1395 | if (!result.success) { |
| 1396 | const error = getErrorMessage(result.error) || "Failed to remove sub-project"; |
| 1397 | sectionRemoveError.showError(subProjectPath, error, anchor); |
| 1398 | } |
| 1399 | }; |
| 1400 | |
| 1401 | const handleOpenSecrets = useCallback( |
| 1402 | (projectPath: string) => { |
no test coverage detected