Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

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

yyh9fd153ad9937
diff --git a/web/app/components/app/app-publisher/__tests__/index.spec.tsx b/web/app/components/app/app-publisher/__tests__/index.spec.tsx
index f5b800ee40b..0fe3770645b 100644
--- a/web/app/components/app/app-publisher/__tests__/index.spec.tsx
+++ b/web/app/components/app/app-publisher/__tests__/index.spec.tsx
@@ -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(() => {
diff --git a/web/app/components/app/app-publisher/index.tsx b/web/app/components/app/app-publisher/index.tsx
index f3e65682a8f..e0713ecdd74 100644
--- a/web/app/components/app/app-publisher/index.tsx
+++ b/web/app/components/app/app-publisher/index.tsx
@@ -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