🙌 OpenHands: AI-Driven Development
fix: prevent deletion of the active LLM profile (#1127)
Tim O'Farrella89aac89f6aa
diff --git a/__tests__/components/settings/llm-profiles/llm-profiles-manager.test.tsx b/__tests__/components/settings/llm-profiles/llm-profiles-manager.test.tsxindex c1e73ad45e..267c150606 100644--- a/__tests__/components/settings/llm-profiles/llm-profiles-manager.test.tsx+++ b/__tests__/components/settings/llm-profiles/llm-profiles-manager.test.tsx@@ -225,15 +225,16 @@ describe("LlmProfilesManager", () => {renderManager();- await screen.findByText("gpt-4-profile");+ await screen.findByText("claude-profile");+ // Use the second profile (claude-profile) — the active profile's Delete is disabledconst menuTriggers = screen.getAllByTestId("profile-menu-trigger");- await user.click(menuTriggers[0]);+ await user.click(menuTriggers[1]);await user.click(screen.getByText("Delete"));// Delete modal should appear with confirmation messageexpect(- screen.getByText('Are you sure you want to delete "gpt-4-profile"?'),+ screen.getByText('Are you sure you want to delete "claude-profile"?'),).toBeInTheDocument();});@@ -269,15 +270,15 @@ describe("LlmProfilesManager", () => {renderManager();- await screen.findByText("gpt-4-profile");+ await screen.findByText("claude-profile");- // Open delete modal+ // Open delete modal — use the second profile (claude-profile); active profile's Delete is disabledconst menuTriggers = screen.getAllByTestId("profile-menu-trigger");- await user.click(menuTriggers[0]);+ await user.click(menuTriggers[1]);await user.click(screen.getByText("Delete"));expect(- screen.getByText('Are you sure you want to delete "gpt-4-profile"?'),+ screen.getByText('Are you sure you want to delete "claude-profile"?'),).toBeInTheDocument();// Click Cancel@@ -285,7 +286,7 @@ describe("LlmProfilesManager", () => {// Modal should be closedexpect(- screen.queryByText('Are you sure you want to delete "gpt-4-profile"?'),+ screen.queryByText('Are you sure you want to delete "claude-profile"?'),).not.toBeInTheDocument();});});diff --git a/__tests__/components/settings/llm-profiles/profile-actions-menu.test.tsx b/__tests__/components/settings/llm-profiles/profile-actions-menu.test.tsxindex 453d7320f0..21bc151fd9 100644--- a/__tests__/components/settings/llm-profiles/profile-actions-menu.test.tsx+++ b/__tests__/components/settings/llm-profiles/profile-actions-menu.test.tsx@@ -11,6 +11,7 @@ vi.mock("react-i18next", () => ({"BUTTON$RENAME": "Rename","SETTINGS$PROFILE_SET_ACTIVE": "Set as active","BUTTON$DELETE": "Delete",+ "SETTINGS$PROFILE_CANNOT_DELETE_ACTIVE": "Cannot delete the active profile",};return translations[key] || key;},@@ -108,6 +109,18 @@ describe("ProfileActionsMenu", () => {expect(setActiveButton).toBeDisabled();});+ it("disables Delete button when isActive is true", () => {+ render(<ProfileActionsMenu {...defaultProps} isActive />);++ expect(screen.getByTestId("profile-delete")).toBeDisabled();+ });++ it("enables Delete button when isActive is false", () => {+ render(<ProfileActionsMenu {...defaultProps} isActive={false} />);++ expect(screen.getByTestId("profile-delete")).not.toBeDisabled();+ });+it("calls onDelete and onClose when Delete is clicked", async () => {const user = userEvent.setup();const handleDelete = vi.fn();diff --git a/src/components/features/settings/llm-profiles/profile-actions-menu.tsx b/src/components/features/settings/llm-profiles/profile-actions-menu.tsxindex aad0012bfc..bd6016b049 100644--- a/src/components/features/settings/llm-profiles/profile-actions-menu.tsx+++ b/src/components/features/settings/llm-profiles/profile-actions-menu.tsx@@ -12,6 +12,7 @@ import { cn } from "#/utils/utils";import { dropdownMenuListClassName } from "#/utils/dropdown-classes";import { I18nKey } from "#/i18n/declaration";import { ConversationNameContextMenuIconText } from "#/components/features/conversation/conversation-name-context-menu-icon-text";+import { StyledTooltip } from "#/components/shared/buttons/styled-tooltip";import EditIcon from "#/icons/u-edit.svg?react";import CheckCircleIcon from "#/icons/u-check-circle.svg?react";import DeleteIcon from "#/icons/u-delete.svg?react";@@ -216,15 +217,30 @@ export function ProfileActionsMenu({disabled={setActiveDisabled}testId="profile-set-active"/>- <MenuItem- index={3}- icon={<DeleteIcon width={16} height={16} />}- label={t(I18nKey.BUTTON$DELETE)}- onClick={() => handleAction(onDelete)}- onKeyDown={handleKeyDown}- menuItemsRef={menuItemsRef}- testId="profile-delete"- />+ {(() => {+ const deleteItem = (+ <MenuItem+ index={3}+ icon={<DeleteIcon width={16} height={16} />}+ label={t(I18nKey.BUTTON$DELETE)}+ onClick={() => handleAction(onDelete)}+ onKeyDown={handleKeyDown}+ menuItemsRef={menuItemsRef}+ disabled={isActive}+ testId="profile-delete"+ />+ );+ if (!isActive) return deleteItem;+ return (+ <StyledTooltip+ content={t(I18nKey.SETTINGS$PROFILE_CANNOT_DELETE_ACTIVE)}+ placement="left"+ >+ {/* span needed so pointer events reach the tooltip trigger on a disabled button */}+ <span className="inline-flex w-full">{deleteItem}</span>+ </StyledTooltip>+ );+ })()}</div>);diff --git a/src/i18n/translation.json b/src/i18n/translation.jsonindex e48a11be92..0f091ab62f 100644--- a/src/i18n/translation.json+++ b/src/i18n/translation.json@@ -28508,6 +28508,23 @@"uk": "Видалити","ca": "Suprimeix"},+ "SETTINGS$PROFILE_CANNOT_DELETE_ACTIVE": {+ "en": "Cannot delete the active profile",+ "ja": "アクティブなプロファイルは削除できません",+ "zh-CN": "无法删除活动配置文件",+ "zh-TW": "無法刪除使用中的設定檔",+ "ko-KR": "활성 프로필은 삭제할 수 없습니다",+ "no": "Kan ikke slette den aktive profilen",+ "it": "Impossibile eliminare il profilo attivo",+ "pt": "Não é possível excluir o perfil ativo",+ "es": "No se puede eliminar el perfil activo",+ "ar": "لا يمكن حذف الملف الشخصي النشط",+ "fr": "Impossible de supprimer le profil actif",+ "tr": "Etkin profil silinemez",+ "de": "Das aktive Profil kann nicht gelöscht werden",+ "uk": "Неможливо видалити активний профіль",+ "ca": "No es pot suprimir el perfil actiu"+ },"CHAT_INTERFACE$FETCHING_OLDER_MESSAGES": {"en": "Fetching older messages…","ja": "古いメッセージを取得中…",