mirror of
https://github.com/langgenius/dify.git
synced 2026-06-23 20:41:17 +08:00
fix(web): derive publish shortcut display from hotkey (#37758)
This commit is contained in:
parent
76e587f78a
commit
9fd153ad99
@ -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(() => {
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user