Skip to content

The agent that grows with you

fix(desktop): Try again is disabled while its start is in flight

Siddharth Balyane22e4517ade5
diff --git a/apps/desktop/src/app/capabilities/connectors/connect-element.test.tsx b/apps/desktop/src/app/capabilities/connectors/connect-element.test.tsx
new file mode 100644
index 00000000000..4dde1a89b72
--- /dev/null
+++ b/apps/desktop/src/app/capabilities/connectors/connect-element.test.tsx
@@ -0,0 +1,57 @@
+import { cleanup, render, screen } from '@testing-library/react'
+import { afterEach, describe, expect, it } from 'vitest'
+
+import { I18nProvider } from '@/i18n'
+
+import { ConnectElement } from './connect-element'
+import type { AccountOperation } from './data/account-operations'
+
+const failed: AccountOperation = {
+ connectors: ['gmail'],
+ deadlineAt: 1_800_000_000,
+ opId: 'op_1',
+ request: { connectionId: 'ca_work', reconnect: true },
+ scope: 'default',
+ seq: 1,
+ settled: false,
+ settledBy: null,
+ targets: [
+ {
+ action: 'reconnect',
+ connectUrl: 'https://example.com/old',
+ connectionId: 'ca_new',
+ detail: '',
+ discoveryError: null,
+ instructions: null,
+ kind: 'connector',
+ name: 'gmail',
+ requiredEnv: [],
+ state: 'failed',
+ tools: []
+ }
+ ]
+}
+
+afterEach(cleanup)
+
+describe('ConnectElement Try again', () => {
+ it('stays disabled while its start is in flight, so two clicks cannot mint two sign-ins', () => {
+ const view = (retrying: boolean) => (
+ <I18nProvider>
+ <ConnectElement
+ onRetry={() => undefined}
+ onStopWaiting={() => undefined}
+ operation={failed}
+ retrying={retrying}
+ />
+ </I18nProvider>
+ )
+
+ const { rerender } = render(view(true))
+
+ expect((screen.getByRole('button', { name: 'Try again' }) as HTMLButtonElement).disabled).toBe(true)
+
+ rerender(view(false))
+ expect((screen.getByRole('button', { name: 'Try again' }) as HTMLButtonElement).disabled).toBe(false)
+ })
+})
diff --git a/apps/desktop/src/app/capabilities/connectors/connect-element.tsx b/apps/desktop/src/app/capabilities/connectors/connect-element.tsx
index 89f039e9e19..dacd11488ff 100644
--- a/apps/desktop/src/app/capabilities/connectors/connect-element.tsx
+++ b/apps/desktop/src/app/capabilities/connectors/connect-element.tsx
@@ -11,9 +11,11 @@ export interface ConnectElementProps {
/** Restarts the failed sign-in of the account the operation is for; absent while one is still waiting. */
onRetry?: () => void
onStopWaiting: () => void
+ /** A start for this app is in flight; a second Try again would mint a second replacement sign-in. */
+ retrying?: boolean
}
-export function ConnectElement({ operation, onRetry, onStopWaiting }: ConnectElementProps) {
+export function ConnectElement({ operation, onRetry, onStopWaiting, retrying = false }: ConnectElementProps) {
const { t } = useI18n()
const copy = t.connectorsPage
const link = operation.targets.find(target => target.connectUrl)?.connectUrl ?? null
@@ -43,7 +45,7 @@ export function ConnectElement({ operation, onRetry, onStopWaiting }: ConnectEle
) : null}
{onRetry ? (
- <Button onClick={onRetry} size="xs" variant="secondary">
+ <Button disabled={retrying} onClick={onRetry} size="xs" variant="secondary">
{copy.card.verb.tryAgain}
</Button>
) : null}
diff --git a/apps/desktop/src/app/capabilities/connectors/hosted-dialog.tsx b/apps/desktop/src/app/capabilities/connectors/hosted-dialog.tsx
index d6317b433bf..0de65c242d5 100644
--- a/apps/desktop/src/app/capabilities/connectors/hosted-dialog.tsx
+++ b/apps/desktop/src/app/capabilities/connectors/hosted-dialog.tsx
@@ -130,6 +130,7 @@ export function HostedConnectorDialog({
onRetry={retryable(operation) ? () => accountActions.retry(operation) : undefined}
onStopWaiting={() => onGiveUp(operation.opId)}
operation={operation}
+ retrying={accountActions.reconnecting}
/>
) : undefined