Skip to content
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

feat: add ⌥+⏎ as a shortcut for the verb form #3546

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
30 changes: 30 additions & 0 deletions frontend/console/e2e/cron.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,33 @@ test('send cron request', async ({ page }) => {

expect(responseJson).toEqual({})
})

test('submit cron form using ⌥+⏎ shortcut', async ({ page }) => {
bradleydwyer marked this conversation as resolved.
Show resolved Hide resolved
await navigateToDecl(page, 'cron', 'thirtySeconds')

await page.locator('input#request-path').focus()

await page.keyboard.press('Alt+Enter')

const responseEditor = page.locator('#response-editor .cm-content[role="textbox"]')
await expect(responseEditor).toBeVisible()

const responseText = await responseEditor.textContent()
const responseJson = JSON.parse(responseText?.trim() || '{}')

expect(responseJson).toEqual({})
})

test('submit cron form using ⌥+⏎ shortcut without focusing first', async ({ page }) => {
await navigateToDecl(page, 'cron', 'thirtySeconds')

await page.keyboard.press('Alt+Enter')
bradleydwyer marked this conversation as resolved.
Show resolved Hide resolved

const responseEditor = page.locator('#response-editor .cm-content[role="textbox"]')
await expect(responseEditor).toBeVisible()

const responseText = await responseEditor.textContent()
const responseJson = JSON.parse(responseText?.trim() || '{}')

expect(responseJson).toEqual({})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Copy01Icon } from 'hugeicons-react'
import { useEffect, useRef } from 'react'
import { Button } from '../../../../components/Button'

export const VerbFormInput = ({
Expand All @@ -18,13 +19,29 @@ export const VerbFormInput = ({
onSubmit: (path: string) => void
handleCopyButton?: () => void
}) => {
const formRef = useRef<HTMLFormElement>(null)

const handleSubmit: React.FormEventHandler<HTMLFormElement> = async (event) => {
event.preventDefault()
onSubmit(path)
}

useEffect(() => {
const handleGlobalKeyDown = (event: KeyboardEvent) => {
if (event.altKey && event.key === 'Enter') {
event.preventDefault()
formRef.current?.dispatchEvent(new Event('submit', { cancelable: true, bubbles: true }))
}
}

document.addEventListener('keydown', handleGlobalKeyDown)
return () => {
document.removeEventListener('keydown', handleGlobalKeyDown)
}
}, [path, readOnly, onSubmit])
bradleydwyer marked this conversation as resolved.
Show resolved Hide resolved

return (
<form onSubmit={handleSubmit} className='rounded-lg'>
<form ref={formRef} onSubmit={handleSubmit} className='rounded-lg'>
<div className='flex rounded-md'>
<span id='call-type' className='inline-flex items-center rounded-l-md border border-r-0 border-gray-300 dark:border-gray-500 px-3 ml-4 sm:text-sm'>
{requestType}
Expand All @@ -38,7 +55,7 @@ export const VerbFormInput = ({
readOnly={readOnly}
onChange={(event) => setPath(event.target.value)}
/>
<Button variant='primary' size='md' type='submit' title='Send' className='mx-2'>
<Button variant='primary' size='md' type='submit' title='Send (⌥+⏎)' className='mx-2'>
Send
</Button>
<Button variant='secondary' size='md' type='button' title='Copy' onClick={handleCopyButton} className='mr-2'>
Expand Down
Loading