From 5cc608dd03d571d72cfd0cc6d572ff0faf7aaed9 Mon Sep 17 00:00:00 2001 From: Lily Delalande <119957291+lily-de@users.noreply.github.com> Date: Wed, 9 Apr 2025 11:14:56 -0400 Subject: [PATCH] no more esc toasts (#2109) --- .../extensions/ExtensionsSection.tsx | 49 +++++++++++++------ .../extensions/extension-manager.ts | 25 ++++------ ui/desktop/src/toasts.tsx | 11 +---- 3 files changed, 44 insertions(+), 41 deletions(-) diff --git a/ui/desktop/src/components/settings_v2/extensions/ExtensionsSection.tsx b/ui/desktop/src/components/settings_v2/extensions/ExtensionsSection.tsx index afdd7928..86763ff7 100644 --- a/ui/desktop/src/components/settings_v2/extensions/ExtensionsSection.tsx +++ b/ui/desktop/src/components/settings_v2/extensions/ExtensionsSection.tsx @@ -23,6 +23,7 @@ export default function ExtensionsSection() { const [selectedExtension, setSelectedExtension] = useState(null); const [isModalOpen, setIsModalOpen] = useState(false); const [isAddModalOpen, setIsAddModalOpen] = useState(false); + // We don't need errorFormData anymore since we're not reopening modals on failure const fetchExtensions = async () => { setLoading(true); @@ -72,38 +73,54 @@ export default function ExtensionsSection() { }; const handleAddExtension = async (formData: ExtensionFormData) => { + // Close the modal immediately + handleModalClose(); + const extensionConfig = createExtensionConfig(formData); try { await activateExtension({ addToConfig: addExtension, extensionConfig: extensionConfig }); } catch (error) { - // Even if activation fails, the extension is added as disabled, so we want to show it console.error('Failed to activate extension:', error); + // Even if activation fails, we don't reopen the modal } finally { - handleModalClose(); + // Refresh the extensions list regardless of success or failure await fetchExtensions(); } }; const handleUpdateExtension = async (formData: ExtensionFormData) => { - const extensionConfig = createExtensionConfig(formData); - - await updateExtension({ - enabled: formData.enabled, - extensionConfig: extensionConfig, - addToConfig: addExtension, - }); - - // First refresh the extensions list - await fetchExtensions(); - - // Then close the modal after data is refreshed + // Close the modal immediately handleModalClose(); + + const extensionConfig = createExtensionConfig(formData); + try { + await updateExtension({ + enabled: formData.enabled, + extensionConfig: extensionConfig, + addToConfig: addExtension, + }); + } catch (error) { + console.error('Failed to update extension:', error); + // We don't reopen the modal on failure + } finally { + // Refresh the extensions list regardless of success or failure + await fetchExtensions(); + } }; const handleDeleteExtension = async (name: string) => { - await deleteExtension({ name, removeFromConfig: removeExtension }); + // Close the modal immediately handleModalClose(); - await fetchExtensions(); + + try { + await deleteExtension({ name, removeFromConfig: removeExtension }); + } catch (error) { + console.error('Failed to delete extension:', error); + // We don't reopen the modal on failure + } finally { + // Refresh the extensions list regardless of success or failure + await fetchExtensions(); + } }; const handleModalClose = () => { diff --git a/ui/desktop/src/components/settings_v2/extensions/extension-manager.ts b/ui/desktop/src/components/settings_v2/extensions/extension-manager.ts index 45fd461f..e558f89f 100644 --- a/ui/desktop/src/components/settings_v2/extensions/extension-manager.ts +++ b/ui/desktop/src/components/settings_v2/extensions/extension-manager.ts @@ -18,7 +18,7 @@ export async function activateExtension({ }: ActivateExtensionProps): Promise { try { // AddToAgent - await addToAgent(extensionConfig, { silent: false, showEscMessage: true }); + await addToAgent(extensionConfig, { silent: false }); } catch (error) { console.error('Failed to add extension to agent:', error); // add to config with enabled = false @@ -89,18 +89,15 @@ export async function addToAgentOnStartup({ extensionConfig, }: AddToAgentOnStartupProps): Promise { try { - await retryWithBackoff( - () => addToAgent(extensionConfig, { silent: true, showEscMessage: false }), - { - retries: 3, - delayMs: 1000, - shouldRetry: (error: any) => - error.message && - (error.message.includes('428') || - error.message.includes('Precondition Required') || - error.message.includes('Agent is not initialized')), - } - ); + await retryWithBackoff(() => addToAgent(extensionConfig, { silent: true }), { + retries: 3, + delayMs: 1000, + shouldRetry: (error: any) => + error.message && + (error.message.includes('428') || + error.message.includes('Precondition Required') || + error.message.includes('Agent is not initialized')), + }); } catch (finalError) { toastService.configure({ silent: false }); toastService.error({ @@ -190,8 +187,6 @@ export async function toggleExtension({ // add to agent with toast options await addToAgent(extensionConfig, { ...toastOptions, - // For toggle operations, we want to show toast but no ESC message - showEscMessage: false, }); } catch (error) { console.error('Error adding extension to agent. Will try to toggle back off.'); diff --git a/ui/desktop/src/toasts.tsx b/ui/desktop/src/toasts.tsx index 91dec865..fe8672aa 100644 --- a/ui/desktop/src/toasts.tsx +++ b/ui/desktop/src/toasts.tsx @@ -4,13 +4,11 @@ import { Button } from './components/ui/button'; export interface ToastServiceOptions { silent?: boolean; - showEscMessage?: boolean; shouldThrow?: boolean; } export default class ToastService { private silent: boolean = false; - private showEscMessage: boolean = true; private shouldThrow: boolean = false; // Create a singleton instance @@ -27,9 +25,7 @@ export default class ToastService { if (options.silent !== undefined) { this.silent = options.silent; } - if (options.showEscMessage !== undefined) { - this.showEscMessage = options.showEscMessage; - } + if (options.shouldThrow !== undefined) { this.shouldThrow = options.shouldThrow; } @@ -52,11 +48,6 @@ export default class ToastService { const toastId = toastLoading({ title, msg }); - if (this.showEscMessage) { - toast.info( - 'Press the ESC key on your keyboard to continue using goose while extension loads' - ); - } return toastId; }