mirror of
https://github.com/langgenius/dify.git
synced 2026-09-08 11:04:27 +08:00
fix(web): fix selection menu hide
This commit is contained in:
parent
b6fbec066d
commit
8e2d507e5c
@ -25,7 +25,7 @@ vi.mock('@/next/navigation', () => ({
|
|||||||
}),
|
}),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
vi.mock('@/app/components/base/ui/toast', () => ({
|
vi.mock('@langgenius/dify-ui/toast', () => ({
|
||||||
toast: {
|
toast: {
|
||||||
success: (...args: unknown[]) => mockToastSuccess(...args),
|
success: (...args: unknown[]) => mockToastSuccess(...args),
|
||||||
error: (...args: unknown[]) => mockToastError(...args),
|
error: (...args: unknown[]) => mockToastError(...args),
|
||||||
@ -39,13 +39,19 @@ vi.mock('@/service/use-snippets', () => ({
|
|||||||
}),
|
}),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
vi.mock('@/service/client', () => ({
|
vi.mock('@/service/client', async (importOriginal) => {
|
||||||
|
const actual = await importOriginal<typeof import('@/service/client')>()
|
||||||
|
return {
|
||||||
|
...actual,
|
||||||
consoleClient: {
|
consoleClient: {
|
||||||
|
...actual.consoleClient,
|
||||||
snippets: {
|
snippets: {
|
||||||
|
...actual.consoleClient.snippets,
|
||||||
syncDraftWorkflow: (...args: unknown[]) => mockSyncDraftWorkflow(...args),
|
syncDraftWorkflow: (...args: unknown[]) => mockSyncDraftWorkflow(...args),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}))
|
}
|
||||||
|
})
|
||||||
|
|
||||||
vi.mock('../hooks', async () => {
|
vi.mock('../hooks', async () => {
|
||||||
const actual = await vi.importActual<typeof import('../hooks')>('../hooks')
|
const actual = await vi.importActual<typeof import('../hooks')>('../hooks')
|
||||||
@ -301,6 +307,8 @@ describe('SelectionContextmenu', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
fireEvent.click(screen.getByTestId('selection-contextmenu-item-createSnippet'))
|
fireEvent.click(screen.getByTestId('selection-contextmenu-item-createSnippet'))
|
||||||
|
expect(store.getState().selectionMenu).toBeUndefined()
|
||||||
|
expect(screen.queryByTestId('selection-contextmenu-item-createSnippet')).not.toBeInTheDocument()
|
||||||
fireEvent.change(screen.getByPlaceholderText('workflow.snippet.namePlaceholder'), {
|
fireEvent.change(screen.getByPlaceholderText('workflow.snippet.namePlaceholder'), {
|
||||||
target: { value: 'My snippet' },
|
target: { value: 'My snippet' },
|
||||||
})
|
})
|
||||||
|
|||||||
@ -335,6 +335,7 @@ const SelectionContextmenu = () => {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}, [selectionMenu])
|
}, [selectionMenu])
|
||||||
|
const isMenuOpen = Boolean(selectionMenu && anchor)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectionMenu && selectedNodes.length <= 1)
|
if (selectionMenu && selectedNodes.length <= 1)
|
||||||
@ -561,14 +562,15 @@ const SelectionContextmenu = () => {
|
|||||||
return (
|
return (
|
||||||
<div data-testid="selection-contextmenu">
|
<div data-testid="selection-contextmenu">
|
||||||
<ContextMenu
|
<ContextMenu
|
||||||
open
|
open={isMenuOpen}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (!open)
|
if (!open)
|
||||||
handleSelectionContextmenuCancel()
|
handleSelectionContextmenuCancel()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
{isMenuOpen && (
|
||||||
<ContextMenuContent
|
<ContextMenuContent
|
||||||
positionerProps={anchor ? { anchor } : undefined}
|
positionerProps={{ anchor }}
|
||||||
popupClassName="w-[240px] py-0"
|
popupClassName="w-[240px] py-0"
|
||||||
>
|
>
|
||||||
<div className="p-1">
|
<div className="p-1">
|
||||||
@ -612,6 +614,7 @@ const SelectionContextmenu = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ContextMenuContent>
|
</ContextMenuContent>
|
||||||
|
)}
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
{isCreateSnippetDialogOpen && (
|
{isCreateSnippetDialogOpen && (
|
||||||
<CreateSnippetDialog
|
<CreateSnippetDialog
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user