diff --git a/web/app/components/workflow/__tests__/panel-contextmenu.spec.tsx b/web/app/components/workflow/__tests__/panel-contextmenu.spec.tsx index 37ee2cf0b30..f22601f82aa 100644 --- a/web/app/components/workflow/__tests__/panel-contextmenu.spec.tsx +++ b/web/app/components/workflow/__tests__/panel-contextmenu.spec.tsx @@ -1,5 +1,6 @@ import { ContextMenu } from '@langgenius/dify-ui/context-menu' import { fireEvent, screen, waitFor } from '@testing-library/react' +import { FlowType } from '@/types/common' import { fullWorkflowAccessControl } from '../hooks-store' import { PanelContextmenu } from '../panel-contextmenu' import { BlockEnum } from '../types' @@ -147,6 +148,24 @@ describe('PanelContextmenu', () => { }) }) + it('should hide import app on snippet canvases', async () => { + renderPanelContextmenu({ + initialStoreState: { + contextMenuTarget: { type: 'panel' }, + }, + hooksStoreProps: { + configsMap: { + flowId: 'snippet-1', + flowType: FlowType.snippet, + fileSettings: {}, + }, + }, + }) + + expect(await screen.findByText('export')).toBeInTheDocument() + expect(screen.queryByText('importApp')).not.toBeInTheDocument() + }) + it('should render preview action in chat mode', async () => { mockUseIsChatMode.mockReturnValue(true) diff --git a/web/app/components/workflow/panel-contextmenu.tsx b/web/app/components/workflow/panel-contextmenu.tsx index 2e620e26909..d46d6f2628e 100644 --- a/web/app/components/workflow/panel-contextmenu.tsx +++ b/web/app/components/workflow/panel-contextmenu.tsx @@ -9,6 +9,7 @@ import { useCallback, } from 'react' import { useTranslation } from 'react-i18next' +import { FlowType } from '@/types/common' import { TEST_RUN_MENU_HOTKEY } from './header/shortcuts' import { useDSL, @@ -18,6 +19,7 @@ import { useWorkflowStartRun, } from './hooks' import { useHooksStore } from './hooks-store' +import { isSnippetCanvas } from './nodes/_base/hooks/snippet-input-field-vars' import AddBlock from './operator/add-block' import { useOperator } from './operator/hooks' import { ShortcutKbd } from './shortcuts/shortcut-kbd' @@ -48,6 +50,7 @@ export function PanelContextmenu({ const { isCommentModeAvailable } = useWorkflowMoveMode() const { exportCheck } = useDSL() const accessControl = useHooksStore(s => s.accessControl) + const flowType = useHooksStore(s => s.configsMap?.flowType) const isChatMode = useIsChatMode() const workflowOperationReadOnly = !!( workflowRunningData?.result.status === WorkflowRunningStatus.Running @@ -57,6 +60,7 @@ export function PanelContextmenu({ ) const canEditWorkflow = accessControl.canEdit && !workflowOperationReadOnly const canCommentWorkflow = accessControl.canComment && !workflowOperationReadOnly + const shouldHideImportApp = flowType === FlowType.snippet || isSnippetCanvas() const renderAddBlockTrigger = useCallback(() => { return ( @@ -177,12 +181,14 @@ export function PanelContextmenu({ > {t('export', { ns: 'app' })} - setShowImportDSLModal(true)} - > - {t('importApp', { ns: 'app' })} - + {!shouldHideImportApp && ( + setShowImportDSLModal(true)} + > + {t('importApp', { ns: 'app' })} + + )} )}