The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(tui): /connectors row shortcuts dispatch through a table
Siddharth Balyan4265ddb8e13d
diff --git a/ui-tui/src/__tests__/connectorAccounts.test.ts b/ui-tui/src/__tests__/connectorAccounts.test.tsindex d9569baf7eb..b5419805ea6 100644--- a/ui-tui/src/__tests__/connectorAccounts.test.ts+++ b/ui-tui/src/__tests__/connectorAccounts.test.ts@@ -7,7 +7,15 @@ import {resetConnectionOperationsForTests} from '../app/connectionOperationStore.js'import { getOverlayState, hasPromptOpen, patchOverlayState, resetOverlayState } from '../app/overlayStore.js'-import { accountRowText, accountView, nameProblem, needsRepair, panelShortcut } from '../domain/connectorAccounts.js'+import {+ accountRowText,+ accountView,+ nameProblem,+ needsRepair,+ offersReconnect,+ panelShortcut,+ reconnectRefusal+} from '../domain/connectorAccounts.js'const row = (over: Partial<ConnectorAccountRow> & { disabled?: boolean }): ConnectorAccountRow =>({@@ -55,7 +63,13 @@ describe('reconnect is offered only as a repair', () => {for (const status of ['failed', 'expired', 'revoked', 'inactive'] as const) {expect(needsRepair(row({ active: false, status }))).toBe(true)+ expect(reconnectRefusal(row({ active: false, status }))).toBeNull()}++ expect(reconnectRefusal(row({ status: 'active' }))).toBe('healthy')+ expect(reconnectRefusal(row({ disabled: true, status: 'inactive' }))).toBe('retired')+ expect(offersReconnect(row({ status: 'active' }))).toBe(false)+ expect(offersReconnect(undefined)).toBe(true)})})diff --git a/ui-tui/src/components/connectorsOverlay.tsx b/ui-tui/src/components/connectorsOverlay.tsxindex 15811dda186..d724ad58a05 100644--- a/ui-tui/src/components/connectorsOverlay.tsx+++ b/ui-tui/src/components/connectorsOverlay.tsx@@ -19,8 +19,10 @@ import {isRetired,nameProblem,type NameProblem,- needsRepair,- panelShortcut+ offersReconnect,+ type PanelShortcut,+ panelShortcut,+ reconnectRefusal} from '../domain/connectorAccounts.js'import type { GatewayClient } from '../gatewayClient.js'import type { Translations } from '../i18n/types.js'@@ -81,6 +83,12 @@ const errorText = (T: Translations, error: unknown): string =>? T.connectors.notice.nameTaken: rpcErrorMessage(error)+/** The open link's operation, app, name and deadline; empty outside the link view. */+const linkFields = (stage: Stage) =>+ stage.kind === 'link'+ ? { linkApp: stage.app, linkDeadline: stage.deadlineAt, linkName: stage.name, linkOp: stage.opId }+ : { linkApp: '', linkDeadline: 0, linkName: '', linkOp: '' }+export function ConnectorsOverlay({ gw, maxWidth, onClose, t }: ConnectorsOverlayProps) {const T = useT()const [rows, setRows] = useState<ConnectorAccountRow[]>([])@@ -170,10 +178,7 @@ export function ConnectorsOverlay({ gw, maxWidth, onClose, t }: ConnectorsOverla}// Poll the account operation while its link is open; Esc leaves the link valid until it expires.- const linkOp = stage.kind === 'link' ? stage.opId : ''- const linkApp = stage.kind === 'link' ? stage.app : ''- const linkName = stage.kind === 'link' ? stage.name : ''- const linkDeadline = stage.kind === 'link' ? stage.deadlineAt : 0+ const { linkApp, linkDeadline, linkName, linkOp } = linkFields(stage)useEffect(() => {if (!linkOp) {@@ -293,17 +298,38 @@ export function ConnectorsOverlay({ gw, maxWidth, onClose, t }: ConnectorsOverla})+ // A healthy account has nothing to repair; signing it in again would only replace a working link.const reconnect = (row: ConnectorAccountRow) => {- if (isRetired(row)) {- return setNotice(T.connectors.notice.retiredNoReconnect)- }+ const refusal = reconnectRefusal(row)- // A healthy account has nothing to repair; signing it in again would only replace a working link.- if (!needsRepair(row)) {- return setNotice(T.connectors.notice.connected(row.connector, accountName(row)))- }+ refusal+ ? setNotice(+ refusal === 'retired'+ ? T.connectors.notice.retiredNoReconnect+ : T.connectors.notice.connected(row.connector, accountName(row))+ )+ : startConnect(row.connector, { connection_id: row.connection_id }, accountName(row))+ }- startConnect(row.connector, { connection_id: row.connection_id }, accountName(row))+ const startRename = (row: ConnectorAccountRow) => {+ setErr('')+ setStage({ draft: row.alias ?? '', kind: 'rename', row })+ }++ const confirmRemove = (row: ConnectorAccountRow) =>+ patchOverlayState({+ confirm: {+ danger: true,+ onConfirm: () => remove(row),+ title: T.connectors.remove.confirm(row.connector, accountName(row))+ }+ })++ // The letter shortcuts that act on the selected row.+ const rowActions: Partial<Record<PanelShortcut, (row: ConnectorAccountRow) => void>> = {+ reconnect,+ remove: confirmRemove,+ rename: startRename}const listKey = (ch: string, key: KeyLike) => {@@ -329,30 +355,10 @@ export function ConnectorsOverlay({ gw, maxWidth, onClose, t }: ConnectorsOverlareturn openAddApp()}- if (!selected) {- return- }-- if (shortcut === 'rename') {- setErr('')-- return setStage({ draft: selected.alias ?? '', kind: 'rename', row: selected })- }-- if (shortcut === 'remove') {- const row = selected-- return patchOverlayState({- confirm: {- danger: true,- onConfirm: () => remove(row),- title: T.connectors.remove.confirm(row.connector, accountName(row))- }- })- }+ const act = shortcut ? rowActions[shortcut] : undefined- if (shortcut === 'reconnect') {- return reconnect(selected)+ if (act && selected) {+ act(selected)}}@@ -510,9 +516,7 @@ export function ConnectorsOverlay({ gw, maxWidth, onClose, t }: ConnectorsOverla</Text>) : null}{footer}- <OverlayHint t={t}>- {selected && !needsRepair(selected) ? T.connectors.hintHealthy : T.connectors.hint}- </OverlayHint>+ <OverlayHint t={t}>{offersReconnect(selected) ? T.connectors.hint : T.connectors.hintHealthy}</OverlayHint></Box>)}diff --git a/ui-tui/src/domain/connectorAccounts.ts b/ui-tui/src/domain/connectorAccounts.tsindex 2480ea7468a..6806aabf744 100644--- a/ui-tui/src/domain/connectorAccounts.ts+++ b/ui-tui/src/domain/connectorAccounts.ts@@ -12,6 +12,14 @@ export const isRetired = (row: ConnectorAccountRow): boolean => Boolean(row.disa* would only be signed in again, so the panel answers that it is connected instead. */export const needsRepair = (row: ConnectorAccountRow): boolean => !isRetired(row) && row.status !== 'active'+/** Why the panel will not start a reconnect on `row`, or null when it should. */+export function reconnectRefusal(row: ConnectorAccountRow): 'healthy' | 'retired' | null {+ return isRetired(row) ? 'retired' : needsRepair(row) ? null : 'healthy'+}++/** Whether the panel's hint offers `c`: only for a selected row that needs repair (or no selection). */+export const offersReconnect = (row: ConnectorAccountRow | undefined): boolean => !row || needsRepair(row)+/** The name a row is addressed by: its alias, else the app's own account label. */export const accountName = (row: ConnectorAccountRow): string => row.alias || row.label