fix(web): derive publish shortcut display from hotkey (#37758)

This commit is contained in:
yyh 2026-06-22 18:26:54 +08:00 committed by GitHub
parent 76e587f78a
commit 9fd153ad99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View File

@ -30,6 +30,7 @@ const sectionProps = vi.hoisted(() => ({
actions: null as null | Record<string, any>,
}))
const hotkeyMocks = vi.hoisted(() => ({
hotkeys: [] as string[],
handlers: [] as Array<(event: { preventDefault: () => void }) => void>,
}))
@ -44,7 +45,8 @@ vi.mock('react-i18next', () => ({
}))
vi.mock('@tanstack/react-hotkeys', () => ({
useHotkey: (_hotkey: string, handler: (event: { preventDefault: () => void }) => void) => {
useHotkey: (hotkey: string, handler: (event: { preventDefault: () => void }) => void) => {
hotkeyMocks.hotkeys.push(hotkey)
hotkeyMocks.handlers.push(handler)
},
}))
@ -190,6 +192,7 @@ vi.mock('../sections', () => ({
describe('AppPublisher', () => {
beforeEach(() => {
vi.clearAllMocks()
hotkeyMocks.hotkeys.length = 0
hotkeyMocks.handlers.length = 0
sectionProps.summary = null
sectionProps.access = null
@ -240,6 +243,7 @@ describe('AppPublisher', () => {
enabled: true,
})
})
expect(sectionProps.summary?.publishShortcut).toEqual(['Mod', 'Shift', 'P'])
expect(mockRefetch).not.toHaveBeenCalled()
})
@ -477,6 +481,7 @@ describe('AppPublisher', () => {
/>,
)
expect(hotkeyMocks.hotkeys).toContain('Mod+Shift+P')
hotkeyMocks.handlers[0]!({ preventDefault })
await waitFor(() => {

View File

@ -1,3 +1,4 @@
import type { RegisterableHotkey } from '@tanstack/react-hotkeys'
import type { FormEvent } from 'react'
import type { ModelAndParameter } from '../configuration/debug/types'
import type { WorkflowHiddenStartVariable, WorkflowLaunchInputValue } from '@/app/components/app/overview/app-card-utils'
@ -82,7 +83,8 @@ export type AppPublisherProps = {
hasHumanInputNode?: boolean
}
const PUBLISH_SHORTCUT = ['ctrl', '⇧', 'P']
const PUBLISH_HOTKEY = 'Mod+Shift+P' satisfies RegisterableHotkey
const PUBLISH_SHORTCUT = PUBLISH_HOTKEY.split('+')
export type AppPublisherPublishParams = ModelAndParameter | PublishWorkflowParams
@ -290,7 +292,7 @@ export function AppPublisher({
}
}
useHotkey('Mod+Shift+P', (e) => {
useHotkey(PUBLISH_HOTKEY, (e) => {
e.preventDefault()
if (publishDisabled || published)
return