🙌 OpenHands: AI-Driven Development
fix(plugins): point duplicate-install toast at Update or Uninstall (#18110)
fengyue-xvea321062adae6
diff --git a/__tests__/hooks/mutation/use-plugin-mutations.test.ts b/__tests__/hooks/mutation/use-plugin-mutations.test.tsindex 08a9cd84f5..a11f36f45d 100644--- a/__tests__/hooks/mutation/use-plugin-mutations.test.ts+++ b/__tests__/hooks/mutation/use-plugin-mutations.test.ts@@ -153,4 +153,20 @@ describe("plugin mutations", () => {i18n.t(I18nKey.ERROR$CORS_OR_NETWORK),]);});++ it("points to the plugin's dialog when the plugin is already installed", async () => {+ vi.spyOn(PluginsManagementService, "installPlugin").mockRejectedValue(+ new HttpError(+ 409,+ "Plugin already installed. Use force=true to overwrite.",+ ),+ );++ const result = failingMutations[0].run();++ await waitFor(() => expect(result.current.isError).toBe(true));+ expect(errorToastMessages()).toEqual([+ I18nKey.SETTINGS$PLUGINS_ALREADY_INSTALLED,+ ]);+ });});diff --git a/src/hooks/mutation/use-install-plugin.ts b/src/hooks/mutation/use-install-plugin.tsindex 393a7561fe..ab9d84d013 100644--- a/src/hooks/mutation/use-install-plugin.ts+++ b/src/hooks/mutation/use-install-plugin.ts@@ -3,10 +3,12 @@ import { useTranslation } from "react-i18next";import PluginsManagementService, {type InstallPluginRequest,} from "#/api/plugins-management-service";+import { isSdkHttpStatusError } from "#/api/agent-server-compatibility";import { PLUGINS_QUERY_KEYS } from "#/hooks/query/query-keys";import { I18nKey } from "#/i18n/declaration";import {displayApiErrorToast,+ displayErrorToast,displaySuccessToast,} from "#/utils/custom-toast-handlers";@@ -31,6 +33,14 @@ export function useInstallPlugin() {});displaySuccessToast(t(I18nKey.SETTINGS$PLUGINS_INSTALL_SUCCESS));},- onError: (error) => displayApiErrorToast(error, t(I18nKey.ERROR$GENERIC)),+ onError: (error) => {+ // The server's 409 says to retry with `force=true`, which the form+ // cannot do; Update or Uninstall in the plugin's dialog can.+ if (isSdkHttpStatusError(error, 409)) {+ displayErrorToast(t(I18nKey.SETTINGS$PLUGINS_ALREADY_INSTALLED));+ return;+ }+ displayApiErrorToast(error, t(I18nKey.ERROR$GENERIC));+ },});}diff --git a/src/i18n/translation.json b/src/i18n/translation.jsonindex 50d3909f04..0fd523d261 100644--- a/src/i18n/translation.json+++ b/src/i18n/translation.json@@ -35257,6 +35257,23 @@"tr": "Eklenti kuruldu.","uk": "Плагін встановлено."},+ "SETTINGS$PLUGINS_ALREADY_INSTALLED": {+ "en": "This plugin is already installed. Open its card to Update or Uninstall it.",+ "ja": "このプラグインはすでにインストールされています。カードを開いて「更新」または「アンインストール」してください。",+ "zh-CN": "此插件已安装。请打开其卡片进行“更新”或“卸载”。",+ "zh-TW": "此外掛程式已安裝。請開啟其卡片以「更新」或「解除安裝」。",+ "ko-KR": "이 플러그인은 이미 설치되어 있습니다. 카드를 열어 업데이트 또는 제거하세요.",+ "no": "Denne plugin-en er allerede installert. Åpne kortet for å oppdatere eller avinstallere.",+ "ar": "هذه الإضافة مثبتة بالفعل. افتح بطاقتها للتحديث أو إلغاء التثبيت.",+ "de": "Dieses Plugin ist bereits installiert. Öffne seine Karte, um es zu aktualisieren oder zu deinstallieren.",+ "fr": "Ce plugin est déjà installé. Ouvrez sa carte pour le mettre à jour ou le désinstaller.",+ "it": "Questo plugin è già installato. Apri la sua scheda per Aggiornare o Disinstallare.",+ "pt": "Este plugin já está instalado. Abra o cartão dele para Atualizar ou Desinstalar.",+ "es": "Este complemento ya está instalado. Abre su tarjeta para Actualizarlo o Desinstalarlo.",+ "ca": "Aquest connector ja està instal·lat. Obre'n la targeta per actualitzar-lo o desinstal·lar-lo.",+ "tr": "Bu eklenti zaten yüklü. Güncellemek veya kaldırmak için kartını açın.",+ "uk": "Цей плагін уже встановлено. Відкрийте його картку, щоб оновити або видалити."+ },"SETTINGS$PLUGINS_UNINSTALL_SUCCESS": {"en": "Plugin uninstalled.","ja": "プラグインをアンインストールしました。",