Repository navigation
fix(web): announce the Safe-mode confirm and Saved Credentials as dialogs; Escape closes Saved Credentials #582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
apps/web/src/frontend/features/connections/components/CredentialManager.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // @vitest-environment jsdom | ||
| import React from 'react'; | ||
| import { fireEvent, render, screen } from '@testing-library/react'; | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| // The editor store loads the theme store, which reads the colour scheme. | ||
| window.matchMedia ??= ((media: string) => ({ | ||
| matches: false, | ||
| media, | ||
| onchange: null, | ||
| addEventListener: () => {}, | ||
| removeEventListener: () => {}, | ||
| addListener: () => {}, | ||
| removeListener: () => {}, | ||
| dispatchEvent: () => false, | ||
| })) as unknown as typeof window.matchMedia; | ||
|
|
||
| // The credential form is its own layer; a stand-in is enough to open it. | ||
| vi.mock('./ConnectionModal', () => ({ | ||
| ConnectionModal: ({ open }: { open: boolean }) => (open ? <div data-testid="connection-form" /> : null), | ||
| })); | ||
|
|
||
| import { CredentialManager } from './CredentialManager'; | ||
|
|
||
| describe('CredentialManager', () => { | ||
| it('is a modal dialog named Saved Credentials, with a named close button', () => { | ||
| render(<CredentialManager open onClose={() => undefined} />); | ||
| const dialog = screen.getByRole('dialog', { name: 'Saved Credentials' }); | ||
| expect(dialog.getAttribute('aria-modal')).toBe('true'); | ||
| expect(screen.getByRole('button', { name: 'Close saved credentials' })).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('closes on Escape', () => { | ||
| const onClose = vi.fn(); | ||
| render(<CredentialManager open onClose={onClose} />); | ||
| fireEvent.keyDown(window, { key: 'Escape' }); | ||
| expect(onClose).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('leaves Escape to the credential form while it is open on top', () => { | ||
| const onClose = vi.fn(); | ||
| render(<CredentialManager open onClose={onClose} />); | ||
| fireEvent.click(screen.getByRole('button', { name: /Add Credential/ })); | ||
| expect(screen.getByTestId('connection-form')).toBeTruthy(); | ||
| fireEvent.keyDown(window, { key: 'Escape' }); | ||
| expect(onClose).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
apps/web/src/frontend/features/sql-editor/components/WriteConfirmDialog.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { WriteConfirmDialog } from './WriteConfirmDialog'; | ||
|
|
||
| describe('WriteConfirmDialog', () => { | ||
| it('is announced as a modal dialog named by its title', () => { | ||
| render( | ||
| <WriteConfirmDialog | ||
| writeStatements={['UPDATE products SET name = name WHERE id = 1']} | ||
| credentialCount={1} | ||
| onCancel={() => undefined} | ||
| onConfirm={() => undefined} | ||
| /> | ||
| ); | ||
| const dialog = screen.getByRole('dialog', { name: 'Safe mode: run UPDATE statements?' }); | ||
| expect(dialog.getAttribute('aria-modal')).toBe('true'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { useEffect, useRef } from 'react'; | ||
|
|
||
| /** | ||
| * Call `onEscape` when Escape is pressed, while `enabled`. A key another | ||
| * handler already claimed (`preventDefault`, for example an open menu inside | ||
| * the dialog) is left alone, and so is everything while `enabled` is false: | ||
| * a dialog with another layer open on top passes false, so Escape closes only | ||
| * the top one. | ||
| * | ||
| * Registered once per enabled state; callers may pass a fresh function on | ||
| * every render. | ||
| */ | ||
| export function useEscapeKey(onEscape: () => void, enabled = true): void { | ||
| const onEscapeRef = useRef(onEscape); | ||
| onEscapeRef.current = onEscape; | ||
| useEffect(() => { | ||
| if (!enabled) return; | ||
| const onKey = (e: KeyboardEvent) => { | ||
| if (e.key === 'Escape' && !e.defaultPrevented) onEscapeRef.current(); | ||
| }; | ||
| window.addEventListener('keydown', onKey); | ||
| return () => window.removeEventListener('keydown', onKey); | ||
| }, [enabled]); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Form layer leaves Escape unhandled
Medium Severity
useEscapeKeyis disabled whileaddingoreditingso Escape can close the credential form on top, butConnectionModalhas no Escape handler. After Add or Edit Credential, Escape dismisses neither layer. Users who just used Escape to close Saved Credentials now get no response.Reviewed by Cursor Bugbot for commit bf24fd4. Configure here.