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.

refactor(web): simplify local preview dialog ownership (#43510)

yyhf434c148b9a1
diff --git a/web/app/components/app/access-point/__tests__/environment-access-point-cards.spec.tsx b/web/app/components/app/access-point/__tests__/environment-access-point-cards.spec.tsx
index 29b0829ce01..824e92d1f7c 100644
--- a/web/app/components/app/access-point/__tests__/environment-access-point-cards.spec.tsx
+++ b/web/app/components/app/access-point/__tests__/environment-access-point-cards.spec.tsx
@@ -62,15 +62,6 @@ vi.mock('@/app/components/app/access-point/shared/use-access-point-actions', ()
}),
}))
-vi.mock('@/app/components/app/overview/customize', () => ({
- default: ({ api_base_url, isShow }: { api_base_url: string; isShow: boolean }) =>
- isShow ? (
- <div role="dialog" aria-label="environment customize">
- {api_base_url}
- </div>
- ) : null,
-}))
-
vi.mock('@/app/components/app/overview/settings', () => ({
default: ({ isShow }: { isShow: boolean }) =>
isShow ? <div role="dialog" aria-label="environment settings" /> : null,
@@ -409,9 +400,12 @@ describe('environment access point cards', () => {
expect(screen.getByRole('button', { name: /customize\.entry/ })).toBeEnabled(),
)
await user.click(screen.getByRole('button', { name: /customize\.entry/ }))
- expect(screen.getByRole('dialog', { name: 'environment customize' })).toHaveTextContent(
- 'https://api.example.test/v1',
- )
+ expect(
+ screen.getByRole('dialog', { name: 'appOverview.overview.appInfo.customize.title' }),
+ ).toHaveTextContent('https://api.example.test/v1')
+
+ await user.click(screen.getByRole('button', { name: 'common.operation.close' }))
+ await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
await user.click(screen.getByRole('button', { name: /settings\.settings/ }))
expect(screen.getByRole('dialog', { name: 'environment settings' })).toBeInTheDocument()
diff --git a/web/app/components/app/access-point/__tests__/web-app-card.spec.tsx b/web/app/components/app/access-point/__tests__/web-app-card.spec.tsx
index 22068a2aa9d..d4b61cf917e 100644
--- a/web/app/components/app/access-point/__tests__/web-app-card.spec.tsx
+++ b/web/app/components/app/access-point/__tests__/web-app-card.spec.tsx
@@ -88,8 +88,8 @@ vi.mock('@/app/components/app/app-access-control', () => ({
),
}))
-vi.mock('@/app/components/app/overview/customize', () => ({
- default: () => null,
+vi.mock('@/context/i18n', () => ({
+ useDocLink: () => (path: string) => `https://docs.example.test/en${path}`,
}))
vi.mock('@/app/components/app/overview/settings', () => ({
diff --git a/web/app/components/app/access-point/built-in-access-points/web-app-card.tsx b/web/app/components/app/access-point/built-in-access-points/web-app-card.tsx
index 9b44cbb610b..790b91aac06 100644
--- a/web/app/components/app/access-point/built-in-access-points/web-app-card.tsx
+++ b/web/app/components/app/access-point/built-in-access-points/web-app-card.tsx
@@ -21,7 +21,7 @@ import { useMutation } from '@tanstack/react-query'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import AccessControl from '@/app/components/app/app-access-control'
-import CustomizeModal from '@/app/components/app/overview/customize'
+import { CustomizeDialog } from '@/app/components/app/overview/customize'
import EmbeddedModal from '@/app/components/app/overview/embedded'
import SettingsModal from '@/app/components/app/overview/settings'
import { WorkflowLaunchDialog } from '@/app/components/app/overview/workflow-launch-dialog'
@@ -93,7 +93,6 @@ export function WebAppAccessPointCard({
const setAppDetail = useAppStore((state) => state.setAppDetail)
const [showSettings, setShowSettings] = useState(false)
const [showEmbedded, setShowEmbedded] = useState(false)
- const [showCustomize, setShowCustomize] = useState(false)
const [showAccess, setShowAccess] = useState(false)
const [showRegenerate, setShowRegenerate] = useState(false)
const [showWorkflowLaunch, setShowWorkflowLaunch] = useState(false)
@@ -229,17 +228,12 @@ export function WebAppAccessPointCard({
{t(($) => $['studio.accessPoint.embedIntoSite'], { ns: 'deployments' })}
</Button>
)}
- <Button
- className="flex items-center gap-1 px-3"
- variant="secondary"
+ <CustomizeDialog
+ appId={appInfo.id}
+ api_base_url={appInfo.api_base_url}
+ mode={appInfo.mode}
disabled={!actionsAvailable || !canManageAccessPoint}
- onClick={() => setShowCustomize(true)}
- >
- <span aria-hidden className="i-custom-vender-deploy-code-block size-4" />
- {t(($) => $['overview.appInfo.customize.entry'], {
- ns: 'appOverview',
- })}
- </Button>
+ />
<Button
className="flex items-center gap-1 px-3"
variant="secondary"
@@ -310,13 +304,6 @@ export function WebAppAccessPointCard({
hiddenInputs={hiddenLaunchVariables}
/>
)}
- <CustomizeModal
- isShow={showCustomize}
- onClose={() => setShowCustomize(false)}
- appId={appInfo.id}
- api_base_url={appInfo.api_base_url}
- mode={appInfo.mode}
- />
{showAccess && (
<AccessControl
app={appInfo}
diff --git a/web/app/components/app/access-point/deployed-environment-access-points/environment-web-app-card.tsx b/web/app/components/app/access-point/deployed-environment-access-points/environment-web-app-card.tsx
index 7530ff6fcd8..f39bad4d4f9 100644
--- a/web/app/components/app/access-point/deployed-environment-access-points/environment-web-app-card.tsx
+++ b/web/app/components/app/access-point/deployed-environment-access-points/environment-web-app-card.tsx
@@ -13,7 +13,7 @@ import { Button } from '@langgenius/dify-ui/button'
import { useMutation, useQuery, useQueryClient, useSuspenseQuery } from '@tanstack/react-query'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
-import CustomizeModal from '@/app/components/app/overview/customize'
+import { CustomizeDialog } from '@/app/components/app/overview/customize'
import SettingsModal from '@/app/components/app/overview/settings'
import { useStore as useAppStore } from '@/app/components/app/store'
import { AccessPointCard } from '@/app/components/base/access-point/card'
@@ -65,7 +65,6 @@ export function EnvironmentWebAppCard({
const { data: systemFeatures } = useSuspenseQuery(systemFeaturesQueryOptions())
const actions = useAccessPointActions(appId, canManageAccessPoint)
const [showSettings, setShowSettings] = useState(false)
- const [showCustomize, setShowCustomize] = useState(false)
const [showAccess, setShowAccess] = useState(false)
const [showRegenerate, setShowRegenerate] = useState(false)
const params = {
@@ -189,17 +188,12 @@ export function EnvironmentWebAppCard({
onEnabledChange={siteQuery.isSuccess ? handleEnabledChange : undefined}
actions={
<>
- <Button
- className="flex items-center gap-1 px-3"
- variant="secondary"
+ <CustomizeDialog
+ appId={appId}
+ api_base_url={apiQuery.data?.base_url ?? ''}
+ mode={appInfo?.mode}
disabled={!actionsAvailable || !apiQuery.isSuccess || !canManageAccessPoint}
- onClick={() => setShowCustomize(true)}
- >
- <span aria-hidden className="i-custom-vender-deploy-code-block size-4" />
- {t(($) => $['overview.appInfo.customize.entry'], {
- ns: 'appOverview',
- })}
- </Button>
+ />
<Button
className="flex items-center gap-1 px-3"
variant="secondary"
@@ -257,13 +251,6 @@ export function EnvironmentWebAppCard({
onSave={actions.saveSiteConfig}
/>
)}
- <CustomizeModal
- isShow={showCustomize}
- onClose={() => setShowCustomize(false)}
- appId={appId}
- api_base_url={apiQuery.data?.base_url ?? ''}
- mode={appInfo?.mode}
- />
{showAccess && (
<EnvironmentAccessControl
appId={appId}
diff --git a/web/app/components/app/overview/customize/index.tsx b/web/app/components/app/overview/customize/index.tsx
index 0a8d90b0525..7cafdf686ea 100644
--- a/web/app/components/app/overview/customize/index.tsx
+++ b/web/app/components/app/overview/customize/index.tsx
@@ -1,7 +1,7 @@
'use client'
import type { AppMode } from '@dify/contracts/api/console/apps/types.gen'
-import type { FC } from 'react'
-import { buttonVariants } from '@langgenius/dify-ui/button'
+import type { ReactNode } from 'react'
+import { Button, buttonVariants } from '@langgenius/dify-ui/button'
import { cn } from '@langgenius/dify-ui/cn'
import {
Dialog,
@@ -9,23 +9,23 @@ import {
DialogContent,
DialogDescription,
DialogTitle,
+ DialogTrigger,
} from '@langgenius/dify-ui/dialog'
import { IconButton } from '@langgenius/dify-ui/icon-button'
-import * as React from 'react'
import { useTranslation } from 'react-i18next'
import { useDocLink } from '@/context/i18n'
import { AppModeEnum } from '@/types/app'
-type IShareLinkProps = {
- isShow: boolean
- onClose: () => void
+type CustomizeDialogProps = {
+ disabled?: boolean
+ triggerLabel?: string
api_base_url: string
appId: string
mode?: AppMode
sourceCodeRepository?: 'webapp-conversation' | 'webapp-text-generator'
}
-const StepNum: FC<{ children: React.ReactNode }> = ({ children }) => (
+const StepNum = ({ children }: { children: ReactNode }) => (
<div className="mr-3 flex size-7 shrink-0 items-center justify-center rounded-2xl bg-util-colors-blue-blue-50 text-text-accent">
{children}
</div>
@@ -52,14 +52,14 @@ const GithubIcon = ({ className }: { className: string }) => {
const prefixCustomize = 'overview.appInfo.customize'
-const CustomizeModal: FC<IShareLinkProps> = ({
- isShow,
- onClose,
+export function CustomizeDialog({
+ disabled,
+ triggerLabel,
appId,
api_base_url,
mode,
sourceCodeRepository,
-}) => {
+}: CustomizeDialogProps) {
const { t } = useTranslation(['appOverview', 'common'])
const docLink = useDocLink()
const isChatApp = mode === AppModeEnum.CHAT || mode === AppModeEnum.ADVANCED_CHAT
@@ -68,7 +68,14 @@ const CustomizeModal: FC<IShareLinkProps> = ({
const apiDocLink = docLink('/api-reference/guides/get-started')
return (
- <Dialog open={isShow} onOpenChange={(open) => !open && onClose()}>
+ <Dialog>
+ <DialogTrigger
+ disabled={disabled}
+ render={<Button variant="secondary" className="flex items-center gap-1 px-3" />}
+ >
+ <span aria-hidden className="i-custom-vender-deploy-code-block size-4" />
+ {triggerLabel ?? t(($) => $['overview.appInfo.customize.entry'], { ns: 'appOverview' })}
+ </DialogTrigger>
<DialogContent className="flex max-h-[calc(100dvh-2rem)] w-160 flex-col overflow-hidden!">
<DialogTitle className="shrink-0 title-2xl-semi-bold text-text-primary">
{t(($) => $[`${prefixCustomize}.title`], { ns: 'appOverview' })}
@@ -184,5 +191,3 @@ const CustomizeModal: FC<IShareLinkProps> = ({
</Dialog>
)
}
-
-export default CustomizeModal
diff --git a/web/app/components/datasets/create-from-pipeline/list/template-card/__tests__/focus.browser.spec.tsx b/web/app/components/datasets/create-from-pipeline/list/template-card/__tests__/focus.browser.spec.tsx
index 2897ee75f41..060d339521f 100644
--- a/web/app/components/datasets/create-from-pipeline/list/template-card/__tests__/focus.browser.spec.tsx
+++ b/web/app/components/datasets/create-from-pipeline/list/template-card/__tests__/focus.browser.spec.tsx
@@ -1,11 +1,22 @@
import type { PipelineTemplate } from '@/models/pipeline'
import { Button } from '@langgenius/dify-ui/button'
-import { DialogTitle } from '@langgenius/dify-ui/dialog'
+import {
+ QueryClient,
+ QueryClientProvider,
+ queryOptions,
+ skipToken,
+ useQuery,
+} from '@tanstack/react-query'
import { userEvent } from 'vite-plus/test/browser'
import { render } from 'vitest-browser-react'
import { ChunkingMode } from '@/models/datasets'
import TemplateCard from '../index'
+const templateQueryOptions = queryOptions({
+ queryKey: ['pipeline-template'],
+ queryFn: skipToken,
+})
+
vi.mock('@/next/navigation', () => ({ useRouter: () => ({ push: vi.fn() }) }))
vi.mock('@/app/components/base/amplitude', () => ({ trackEvent: vi.fn() }))
vi.mock('@/app/components/workflow/plugin-dependency/hooks', () => ({
@@ -16,20 +27,14 @@ vi.mock('@/service/knowledge/use-create-dataset', () => ({
}))
vi.mock('@/service/knowledge/use-dataset', () => ({ useInvalidDatasetList: () => vi.fn() }))
vi.mock('@/service/use-pipeline', () => ({
- usePipelineTemplateById: () => ({ refetch: vi.fn() }),
+ usePipelineTemplateById: () => useQuery(templateQueryOptions),
useDeleteTemplate: () => ({ mutateAsync: vi.fn() }),
useExportTemplateDSL: () => ({ mutateAsync: vi.fn(), isPending: false }),
useInvalidCustomizedTemplateList: () => vi.fn(),
}))
-// The workflow preview and edit form do not own the card's dialog or trigger.
-vi.mock('../details', () => ({
- default: ({ onClose }: { onClose: () => void }) => (
- <div className="flex h-full flex-col items-end justify-end">
- <DialogTitle>Template details</DialogTitle>
- <Button onClick={onClose}>Close details</Button>
- </div>
- ),
+vi.mock('@/app/components/workflow/workflow-preview', () => ({
+ default: () => <div>Workflow preview</div>,
}))
vi.mock('../edit-pipeline-info', () => ({ default: () => null }))
@@ -42,18 +47,32 @@ const pipeline: PipelineTemplate = {
position: 1,
}
+const templateInfo = {
+ name: 'Document pipeline',
+ description: 'Process documents',
+ icon_info: { icon_type: 'emoji', icon: '📊', icon_background: '#FFF4ED', icon_url: '' },
+ chunk_structure: 'text',
+ graph: { nodes: [], edges: [], viewport: { x: 0, y: 0, zoom: 1 } },
+}
+
+function TemplateCardFixture({ queryClient }: { queryClient: QueryClient }) {
+ return (
+ <QueryClientProvider client={queryClient}>
+ <Button>Before template</Button>
+ <div className="w-80">
+ <TemplateCard pipeline={pipeline} type="built-in" showMoreOperations={false} />
+ </div>
+ </QueryClientProvider>
+ )
+}
+
describe('Template card focus', () => {
it('reveals keyboard actions and restores visible focus after details closes away from the card', async () => {
// Browser mode is required: display:none prevents native focus restoration,
// and CSS hover/focus-within decides whether the returned button is visible.
- const screen = await render(
- <>
- <Button>Before template</Button>
- <div className="w-80">
- <TemplateCard pipeline={pipeline} type="built-in" showMoreOperations={false} />
- </div>
- </>,
- )
+ const queryClient = new QueryClient()
+ queryClient.setQueryData(templateQueryOptions.queryKey, templateInfo)
+ const screen = await render(<TemplateCardFixture queryClient={queryClient} />)
await screen.getByRole('button', { name: 'Before template' }).click()
await userEvent.tab()
const choose = screen.getByRole('button', { name: 'datasetPipeline.operations.choose' })
@@ -63,9 +82,9 @@ describe('Template card focus', () => {
const details = screen.getByRole('button', { name: 'datasetPipeline.operations.details' })
await expect.element(details).toHaveFocus()
await userEvent.keyboard('{Enter}')
- const dialog = screen.getByRole('dialog', { name: 'Template details' })
+ const dialog = screen.getByRole('dialog', { name: 'Document pipeline' })
await expect.element(dialog).toBeVisible()
- await dialog.getByRole('button', { name: 'Close details' }).click()
+ await dialog.getByRole('button', { name: 'common.operation.close' }).click()
await expect.element(dialog).not.toBeInTheDocument()
await expect.element(details).toHaveFocus()
expect(details.element().checkVisibility({ checkOpacity: true })).toBe(true)
@@ -76,4 +95,32 @@ describe('Template card focus', () => {
await expect.element(details).toHaveFocus()
expect(details.element().checkVisibility({ checkOpacity: true })).toBe(true)
})
+
+ it('keeps close focused when template details finish loading and returns focus to the trigger', async () => {
+ const queryClient = new QueryClient()
+ const screen = await render(<TemplateCardFixture queryClient={queryClient} />)
+ await screen.getByRole('button', { name: 'Before template' }).click()
+ await userEvent.tab()
+ await userEvent.tab()
+ const details = screen.getByRole('button', { name: 'datasetPipeline.operations.details' })
+ await expect.element(details).toHaveFocus()
+ await userEvent.keyboard('{Enter}')
+ const dialog = screen.getByRole('dialog', { name: pipeline.name })
+ await expect.element(dialog).toBeVisible()
+ const close = dialog.getByRole('button', { name: 'common.operation.close' })
+ await expect.element(close).toHaveFocus()
+ await expect
+ .element(dialog.getByRole('button', { name: 'datasetPipeline.operations.useTemplate' }))
+ .not.toBeInTheDocument()
+
+ queryClient.setQueryData(templateQueryOptions.queryKey, templateInfo)
+ await expect
+ .element(dialog.getByRole('button', { name: 'datasetPipeline.operations.useTemplate' }))
+ .toBeVisible()
+ await expect.element(close).toHaveFocus()
+ await userEvent.keyboard('{Enter}')
+ await expect.element(dialog).not.toBeInTheDocument()
+ await expect.element(details).toHaveFocus()
+ expect(details.element().checkVisibility({ checkOpacity: true })).toBe(true)
+ })
})
diff --git a/web/app/components/datasets/create-from-pipeline/list/template-card/__tests__/index.spec.tsx b/web/app/components/datasets/create-from-pipeline/list/template-card/__tests__/index.spec.tsx
index 631d1e49b6f..7a15e480d01 100644
--- a/web/app/components/datasets/create-from-pipeline/list/template-card/__tests__/index.spec.tsx
+++ b/web/app/components/datasets/create-from-pipeline/list/template-card/__tests__/index.spec.tsx
@@ -95,18 +95,8 @@ vi.mock('../edit-pipeline-info', () => ({
),
}))
-// Mock Details component
-vi.mock('../details', () => ({
- default: ({ onClose, onApplyTemplate }: { onClose: () => void; onApplyTemplate: () => void }) => (
- <div data-testid="details-component">
- <button data-testid="details-close" onClick={onClose}>
- Close
- </button>
- <button data-testid="details-apply" onClick={onApplyTemplate}>
- Apply
- </button>
- </div>
- ),
+vi.mock('@/app/components/workflow/workflow-preview', () => ({
+ default: () => <div>Workflow preview</div>,
}))
const mockCreateDataset = vi.fn()
@@ -132,6 +122,13 @@ vi.mock('@/service/knowledge/use-dataset', () => ({
vi.mock('@/service/use-pipeline', () => ({
usePipelineTemplateById: () => ({
+ data: {
+ name: 'Test Pipeline',
+ description: 'Test pipeline description',
+ icon_info: { icon_type: 'emoji', icon: '📊', icon_background: '#FFF4ED', icon_url: '' },
+ chunk_structure: 'text',
+ graph: { nodes: [], edges: [], viewport: { x: 0, y: 0, zoom: 1 } },
+ },
refetch: mockGetPipelineTemplateInfo,
}),
useDeleteTemplate: () => ({
@@ -321,7 +318,7 @@ describe('TemplateCard', () => {
fireEvent.click(detailsButton)
await waitFor(() => {
- expect(screen.getByTestId('details-component')).toBeInTheDocument()
+ expect(screen.getByRole('dialog', { name: 'Test Pipeline' })).toBeInTheDocument()
})
})
@@ -331,14 +328,14 @@ describe('TemplateCard', () => {
fireEvent.click(detailsButton)
await waitFor(() => {
- expect(screen.getByTestId('details-component')).toBeInTheDocument()
+ expect(screen.getByRole('dialog', { name: 'Test Pipeline' })).toBeInTheDocument()
})
- const closeButton = screen.getByTestId('details-close')
+ const closeButton = screen.getByRole('button', { name: 'common.operation.close' })
fireEvent.click(closeButton)
await waitFor(() => {
- expect(screen.queryByTestId('details-component')).not.toBeInTheDocument()
+ expect(screen.queryByRole('dialog', { name: 'Test Pipeline' })).not.toBeInTheDocument()
})
})
@@ -347,13 +344,13 @@ describe('TemplateCard', () => {
fireEvent.click(screen.getByTestId('action-details'))
await waitFor(() => {
- expect(screen.getByTestId('details-component')).toBeInTheDocument()
+ expect(screen.getByRole('dialog', { name: 'Test Pipeline' })).toBeInTheDocument()
})
fireEvent.keyDown(document, { key: 'Escape', code: 'Escape' })
await waitFor(() => {
- expect(screen.queryByTestId('details-component')).not.toBeInTheDocument()
+ expect(screen.queryByRole('dialog', { name: 'Test Pipeline' })).not.toBeInTheDocument()
})
})
@@ -368,10 +365,12 @@ describe('TemplateCard', () => {
fireEvent.click(detailsButton)
await waitFor(() => {
- expect(screen.getByTestId('details-component')).toBeInTheDocument()
+ expect(screen.getByRole('dialog', { name: 'Test Pipeline' })).toBeInTheDocument()
})
- const applyButton = screen.getByTestId('details-apply')
+ const applyButton = screen.getByRole('button', {
+ name: 'datasetPipeline.operations.useTemplate',
+ })
fireEvent.click(applyButton)
await waitFor(() => {
diff --git a/web/app/components/datasets/create-from-pipeline/list/template-card/details/__tests__/index.spec.tsx b/web/app/components/datasets/create-from-pipeline/list/template-card/details/__tests__/index.spec.tsx
index 5949fc63478..979196d1e94 100644
--- a/web/app/components/datasets/create-from-pipeline/list/template-card/details/__tests__/index.spec.tsx
+++ b/web/app/components/datasets/create-from-pipeline/list/template-card/details/__tests__/index.spec.tsx
@@ -1,4 +1,7 @@
-import { fireEvent, render, screen } from '@testing-library/react'
+import type { ReactElement, ReactNode } from 'react'
+import { Dialog, DialogContent } from '@langgenius/dify-ui/dialog'
+import { fireEvent, render, screen, waitFor } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
import { beforeEach, describe, expect, it, vi } from 'vite-plus/test'
import Details from '../index'
@@ -46,6 +49,16 @@ const createImageIconPipelineInfo = () => ({
},
})
+function DetailsDialog({ children }: { children: ReactNode }) {
+ return (
+ <Dialog defaultOpen>
+ <DialogContent>{children}</DialogContent>
+ </Dialog>
+ )
+}
+
+const renderDetails = (element: ReactElement) => render(element, { wrapper: DetailsDialog })
+
// Details Component Tests
describe('Details', () => {
@@ -53,7 +66,7 @@ describe('Details', () => {
id: 'pipeline-1',
type: 'customized' as const,
onApplyTemplate: vi.fn(),
- onClose: vi.fn(),
+ name: 'Loading Pipeline',
}
beforeEach(() => {
@@ -62,14 +75,17 @@ describe('Details', () => {
// Loading State Tests
describe('Loading State', () => {
- it('should show loading when data is not available', () => {
+ it('keeps the dialog named and closable while the template is loading', async () => {
+ const user = userEvent.setup()
mockUsePipelineTemplateById.mockReturnValue({
data: null,
})
- render(<Details {...defaultProps} />)
- // Loading component should be rendered
+ renderDetails(<Details {...defaultProps} />)
+ expect(screen.getByRole('dialog', { name: 'Loading Pipeline' })).toBeInTheDocument()
expect(screen.queryByText('Test Pipeline')).not.toBeInTheDocument()
+ await user.click(screen.getByRole('button', { name: 'common.operation.close' }))
+ await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
})
})
@@ -79,7 +95,7 @@ describe('Details', () => {
data: createPipelineTemplateInfo(),
})
- render(<Details {...defaultProps} />)
+ renderDetails(<Details {...defaultProps} />)
expect(screen.getByText('Test Pipeline')).toBeInTheDocument()
})
@@ -88,7 +104,7 @@ describe('Details', () => {
data: createPipelineTemplateInfo(),
})
- render(<Details {...defaultProps} />)
+ renderDetails(<Details {...defaultProps} />)
expect(screen.getByText('This is a test pipeline')).toBeInTheDocument()
})
@@ -97,7 +113,7 @@ describe('Details', () => {
data: createPipelineTemplateInfo(),
})
- render(<Details {...defaultProps} />)
+ renderDetails(<Details {...defaultProps} />)
expect(screen.getByText(/details\.createdBy/i)).toBeInTheDocument()
})
@@ -106,7 +122,7 @@ describe('Details', () => {
data: createPipelineTemplateInfo({ created_by: '' }),
})
- render(<Details {...defaultProps} />)
+ renderDetails(<Details {...defaultProps} />)
expect(screen.queryByText(/details\.createdBy/i)).not.toBeInTheDocument()
})
@@ -115,7 +131,7 @@ describe('Details', () => {
data: createPipelineTemplateInfo(),
})
- render(<Details {...defaultProps} />)
+ renderDetails(<Details {...defaultProps} />)
expect(screen.getByText(/operations\.useTemplate/i)).toBeInTheDocument()
})
@@ -124,7 +140,7 @@ describe('Details', () => {
data: createPipelineTemplateInfo(),
})
- render(<Details {...defaultProps} />)
+ renderDetails(<Details {...defaultProps} />)
expect(screen.getByText(/details\.structure/i)).toBeInTheDocument()
})
@@ -133,9 +149,8 @@ describe('Details', () => {
data: createPipelineTemplateInfo(),
})
- const { container } = render(<Details {...defaultProps} />)
- const closeButton = container.querySelector('button[type="button"]')
- expect(closeButton).toBeInTheDocument()
+ renderDetails(<Details {...defaultProps} />)
+ expect(screen.getByRole('button', { name: 'common.operation.close' })).toBeInTheDocument()
})
it('should render workflow preview', () => {
@@ -143,7 +158,7 @@ describe('Details', () => {
data: createPipelineTemplateInfo(),
})
- render(<Details {...defaultProps} />)
+ renderDetails(<Details {...defaultProps} />)
expect(screen.getByTestId('workflow-preview')).toBeInTheDocument()
})
@@ -152,23 +167,23 @@ describe('Details', () => {
data: createPipelineTemplateInfo(),
})
- render(<Details {...defaultProps} />)
+ renderDetails(<Details {...defaultProps} />)
// Tooltip component should be present
expect(screen.getByText(/details\.structure/i)).toBeInTheDocument()
})
})
describe('User Interactions', () => {
- it('should call onClose when close button is clicked', () => {
+ it('closes the dialog when the close button is clicked', async () => {
+ const user = userEvent.setup()
mockUsePipelineTemplateById.mockReturnValue({
data: createPipelineTemplateInfo(),
})
- const { container } = render(<Details {...defaultProps} />)
- const closeButton = container.querySelector('button[type="button"]')
- fireEvent.click(closeButton!)
-
- expect(defaultProps.onClose).toHaveBeenCalledTimes(1)
+ renderDetails(<Details {...defaultProps} />)
+ expect(screen.getByRole('dialog', { name: 'Test Pipeline' })).toBeInTheDocument()
+ await user.click(screen.getByRole('button', { name: 'common.operation.close' }))
+ await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
})
it('should call onApplyTemplate when use template button is clicked', () => {
@@ -176,7 +191,7 @@ describe('Details', () => {
data: createPipelineTemplateInfo(),
})
- render(<Details {...defaultProps} />)
+ renderDetails(<Details {...defaultProps} />)
const useButton = screen.getByText(/operations\.useTemplate/i).closest('button')
fireEvent.click(useButton!)
@@ -191,7 +206,7 @@ describe('Details', () => {
data: createPipelineTemplateInfo(),
})
- render(<Details {...defaultProps} />)
+ renderDetails(<Details {...defaultProps} />)
expect(screen.getByText('Test Pipeline')).toBeInTheDocument()
})
@@ -200,7 +215,7 @@ describe('Details', () => {
data: createImageIconPipelineInfo(),
})
- render(<Details {...defaultProps} />)
+ renderDetails(<Details {...defaultProps} />)
expect(screen.getByText('Test Pipeline')).toBeInTheDocument()
})
@@ -209,7 +224,7 @@ describe('Details', () => {
data: null,
})
- render(<Details {...defaultProps} />)
+ renderDetails(<Details {...defaultProps} />)
expect(screen.queryByText('Test Pipeline')).not.toBeInTheDocument()
})
@@ -222,7 +237,7 @@ describe('Details', () => {
data: createPipelineTemplateInfo(),
})
- render(<Details {...defaultProps} />)
+ renderDetails(<Details {...defaultProps} />)
expect(mockUsePipelineTemplateById).toHaveBeenCalledWith(
{ template_id: 'pipeline-1', type: 'customized' },
@@ -235,7 +250,7 @@ describe('Details', () => {
data: createPipelineTemplateInfo(),
})
- render(<Details {...defaultProps} type="built-in" />)
+ renderDetails(<Details {...defaultProps} type="built-in" />)
expect(mockUsePipelineTemplateById).toHaveBeenCalledWith(
{ template_id: 'pipeline-1', type: 'built-in' },
@@ -251,7 +266,7 @@ describe('Details', () => {
data: createPipelineTemplateInfo({ chunk_structure: 'text' }),
})
- render(<Details {...defaultProps} />)
+ renderDetails(<Details {...defaultProps} />)
expect(screen.getByText(/details\.structure/i)).toBeInTheDocument()
})
@@ -260,7 +275,7 @@ describe('Details', () => {
data: createPipelineTemplateInfo({ chunk_structure: 'hierarchical' }),
})
- render(<Details {...defaultProps} />)
+ renderDetails(<Details {...defaultProps} />)
expect(screen.getByText(/details\.structure/i)).toBeInTheDocument()
})
@@ -269,7 +284,7 @@ describe('Details', () => {
data: createPipelineTemplateInfo({ chunk_structure: 'qa' }),
})
- render(<Details {...defaultProps} />)
+ renderDetails(<Details {...defaultProps} />)
expect(screen.getByText(/details\.structure/i)).toBeInTheDocument()
})
})
@@ -280,7 +295,7 @@ describe('Details', () => {
data: createPipelineTemplateInfo(),
})
- const { container } = render(<Details {...defaultProps} />)
+ const { baseElement: container } = renderDetails(<Details {...defaultProps} />)
const sidebar = container.querySelector('.w-90')
expect(sidebar).toBeInTheDocument()
})
@@ -290,7 +305,7 @@ describe('Details', () => {
data: createPipelineTemplateInfo(),
})
- const { container } = render(<Details {...defaultProps} />)
+ const { baseElement: container } = renderDetails(<Details {...defaultProps} />)
const previewContainer = container.querySelector('[class*="grow"]')
expect(previewContainer).toBeInTheDocument()
})
diff --git a/web/app/components/datasets/create-from-pipeline/list/template-card/details/index.tsx b/web/app/components/datasets/create-from-pipeline/list/template-card/details/index.tsx
index ceed68023a9..08f361c71a3 100644
--- a/web/app/components/datasets/create-from-pipeline/list/template-card/details/index.tsx
+++ b/web/app/components/datasets/create-from-pipeline/list/template-card/details/index.tsx
@@ -1,7 +1,9 @@
import type { AppIconType } from '@/types/app'
import { Button } from '@langgenius/dify-ui/button'
+import { DialogClose, DialogTitle } from '@langgenius/dify-ui/dialog'
+import { IconButton } from '@langgenius/dify-ui/icon-button'
import { Infotip, InfotipContent, InfotipTrigger } from '@langgenius/dify-ui/infotip'
-import { RiAddLine, RiCloseLine } from '@remixicon/react'
+import { RiAddLine } from '@remixicon/react'
import * as React from 'react'
import { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
@@ -16,13 +18,13 @@ type DetailsProps = {
id: string
type: 'customized' | 'built-in'
onApplyTemplate: () => void
- onClose: () => void
+ name: string
}
-const Details = ({ id, type, onApplyTemplate, onClose }: DetailsProps) => {
+const Details = ({ id, type, name, onApplyTemplate }: DetailsProps) => {
const structureLabelId = React.useId()
- const { t } = useTranslation(['datasetPipeline'])
+ const { t } = useTranslation(['datasetPipeline', 'common'])
const { data: pipelineTemplateInfo } = usePipelineTemplateById(
{
template_id: id,
@@ -41,79 +43,91 @@ const Details = ({ id, type, onApplyTemplate, onClose }: DetailsProps) => {
const chunkStructureConfig = useChunkStructureConfig()
- if (!pipelineTemplateInfo) {
- return <LoadingPlaceholder className="h-full" />
- }
-
return (
- <div className="flex h-full">
- <div className="flex grow items-center justify-center p-3 pr-0">
- <WorkflowPreview {...pipelineTemplateInfo.graph} className="overflow-hidden rounded-2xl" />
- </div>
- <div className="relative flex w-90 shrink-0 flex-col">
- <button
- type="button"
- className="absolute top-4 right-4 z-10 flex size-8 items-center justify-center"
- onClick={onClose}
- >
- <RiCloseLine className="size-4 text-text-tertiary" />
- </button>
- <div className="flex items-start gap-x-3 pt-6 pr-12 pb-2 pl-4">
- <AppIcon
- size="large"
- iconType={appIcon.type as AppIconType}
- icon={appIcon.type === 'image' ? appIcon.fileId : appIcon.icon}
- background={appIcon.type === 'image' ? undefined : appIcon.background}
- imageUrl={appIcon.type === 'image' ? appIcon.url : undefined}
- />
- <div className="flex grow flex-col gap-y-1 overflow-hidden py-px">
- <div
- className="truncate system-md-semibold text-text-secondary"
- title={pipelineTemplateInfo.name}
- >
- {pipelineTemplateInfo.name}
+ <>
+ <DialogClose
+ render={
+ <IconButton
+ aria-label={t(($) => $['operation.close'], { ns: 'common' })}
+ size="lg"
+ className="absolute top-4 right-4 z-10"
+ >
+ <span className="i-ri-close-line size-4 text-text-tertiary" aria-hidden />
+ </IconButton>
+ }
+ />
+ {pipelineTemplateInfo ? (
+ <div className="flex h-full">
+ <div className="flex grow items-center justify-center p-3 pr-0">
+ <WorkflowPreview
+ {...pipelineTemplateInfo.graph}
+ className="overflow-hidden rounded-2xl"
+ />
+ </div>
+ <div className="relative flex w-90 shrink-0 flex-col">
+ <div className="flex items-start gap-x-3 pt-6 pr-12 pb-2 pl-4">
+ <AppIcon
+ size="large"
+ iconType={appIcon.type as AppIconType}
+ icon={appIcon.type === 'image' ? appIcon.fileId : appIcon.icon}
+ background={appIcon.type === 'image' ? undefined : appIcon.background}
+ imageUrl={appIcon.type === 'image' ? appIcon.url : undefined}
+ />
+ <div className="flex grow flex-col gap-y-1 overflow-hidden py-px">
+ <DialogTitle
+ className="truncate system-md-semibold text-text-secondary"
+ title={pipelineTemplateInfo.name}
+ >
+ {pipelineTemplateInfo.name}
+ </DialogTitle>
+ {pipelineTemplateInfo.created_by && (
+ <div
+ className="truncate system-2xs-medium-uppercase text-text-tertiary"
+ title={pipelineTemplateInfo.created_by}
+ >
+ {t(($) => $['details.createdBy'], {
+ ns: 'datasetPipeline',
+ author: pipelineTemplateInfo.created_by,
+ })}
+ </div>
+ )}
+ </div>
+ </div>
+ <p className="px-4 pt-1 pb-2 system-sm-regular text-text-secondary">
+ {pipelineTemplateInfo.description}
+ </p>
+ <div className="p-3">
+ <Button variant="primary" onClick={onApplyTemplate} className="w-full">
+ <RiAddLine className="size-4" />
+ <span>{t(($) => $['operations.useTemplate'], { ns: 'datasetPipeline' })}</span>
+ </Button>
</div>
- {pipelineTemplateInfo.created_by && (
- <div
- className="truncate system-2xs-medium-uppercase text-text-tertiary"
- title={pipelineTemplateInfo.created_by}
- >
- {t(($) => $['details.createdBy'], {
- ns: 'datasetPipeline',
- author: pipelineTemplateInfo.created_by,
- })}
+ <div className="flex flex-col gap-y-1 px-4 py-2">
+ <div className="flex h-6 items-center gap-x-0.5">
+ <span
+ id={structureLabelId}
+ className="system-sm-semibold-uppercase text-text-secondary"
+ >
+ {t(($) => $['details.structure'], { ns: 'datasetPipeline' })}
+ </span>
+ <Infotip>
+ <InfotipTrigger aria-labelledby={structureLabelId} />
+ <InfotipContent aria-labelledby={structureLabelId} className="max-w-60">
+ {t(($) => $['details.structureTooltip'], { ns: 'datasetPipeline' })}
+ </InfotipContent>
+ </Infotip>
</div>
- )}
- </div>
- </div>
- <p className="px-4 pt-1 pb-2 system-sm-regular text-text-secondary">
- {pipelineTemplateInfo.description}
- </p>
- <div className="p-3">
- <Button variant="primary" onClick={onApplyTemplate} className="w-full">
- <RiAddLine className="size-4" />
- <span>{t(($) => $['operations.useTemplate'], { ns: 'datasetPipeline' })}</span>
- </Button>
- </div>
- <div className="flex flex-col gap-y-1 px-4 py-2">
- <div className="flex h-6 items-center gap-x-0.5">
- <span
- id={structureLabelId}
- className="system-sm-semibold-uppercase text-text-secondary"
- >
- {t(($) => $['details.structure'], { ns: 'datasetPipeline' })}
- </span>
- <Infotip>
- <InfotipTrigger aria-labelledby={structureLabelId} />
- <InfotipContent aria-labelledby={structureLabelId} className="max-w-60">
- {t(($) => $['details.structureTooltip'], { ns: 'datasetPipeline' })}
- </InfotipContent>
- </Infotip>
+ <ChunkStructureCard {...chunkStructureConfig[pipelineTemplateInfo.chunk_structure]} />
+ </div>
</div>
- <ChunkStructureCard {...chunkStructureConfig[pipelineTemplateInfo.chunk_structure]} />
</div>
- </div>
- </div>
+ ) : (
+ <>
+ <DialogTitle className="sr-only">{name}</DialogTitle>
+ <LoadingPlaceholder className="h-full" />
+ </>
+ )}
+ </>
)
}
diff --git a/web/app/components/datasets/create-from-pipeline/list/template-card/index.tsx b/web/app/components/datasets/create-from-pipeline/list/template-card/index.tsx
index 62d6e87b4ea..8cb084d0732 100644
--- a/web/app/components/datasets/create-from-pipeline/list/template-card/index.tsx
+++ b/web/app/components/datasets/create-from-pipeline/list/template-card/index.tsx
@@ -41,7 +41,6 @@ const TemplateCard = ({ pipeline, showMoreOperations = true, type }: TemplateCar
const { push } = useRouter()
const [showEditModal, setShowEditModal] = useState(false)
const [showDeleteConfirm, setShowConfirmDelete] = useState(false)
- const [showDetailModal, setShowDetailModal] = useState(false)
const { refetch: getPipelineTemplateInfo } = usePipelineTemplateById(
{
@@ -100,10 +99,6 @@ const TemplateCard = ({ pipeline, showMoreOperations = true, type }: TemplateCar
setShowEditModal(false)
}, [])
- const closeDetailsModal = useCallback(() => {
- setShowDetailModal(false)
- }, [])
-
const { mutateAsync: exportPipelineDSL, isPending: isExporting } = useExportTemplateDSL()
const handleExportDSL = useCallback(async () => {
@@ -148,7 +143,7 @@ const TemplateCard = ({ pipeline, showMoreOperations = true, type }: TemplateCar
iconInfo={pipeline.icon}
chunkStructure={pipeline.chunk_structure}
/>
- <Dialog open={showDetailModal} onOpenChange={setShowDetailModal}>
+ <Dialog>
<Actions
onApplyTemplate={handleUseTemplate}
showMoreOperations={showMoreOperations}
@@ -160,7 +155,7 @@ const TemplateCard = ({ pipeline, showMoreOperations = true, type }: TemplateCar
<Details
id={pipeline.id}
type={type}
- onClose={closeDetailsModal}
+ name={pipeline.name}
onApplyTemplate={handleUseTemplate}
/>
</DialogContent>
diff --git a/web/features/agent-v2/agent-detail/access/components/__tests__/access-surface-cards.spec.tsx b/web/features/agent-v2/agent-detail/access/components/__tests__/access-surface-cards.spec.tsx
index e7225289d6b..65a1d971677 100644
--- a/web/features/agent-v2/agent-detail/access/components/__tests__/access-surface-cards.spec.tsx
+++ b/web/features/agent-v2/agent-detail/access/components/__tests__/access-surface-cards.spec.tsx
@@ -671,6 +671,21 @@ describe('Agent access surface cards', () => {
name: /appOverview\.overview\.appInfo\.customize\.way1\.step1Operation/,
}),
).toHaveAttribute('href', 'https://github.com/langgenius/webapp-conversation')
+ await user.click(within(dialog).getByRole('button', { name: 'common.operation.close' }))
+ await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
+ const trigger = screen.getByRole('button', {
+ name: 'agentV2.agentDetail.access.webApp.actions.customFrontend',
+ })
+ await waitFor(() => expect(trigger).toHaveFocus())
+ await user.keyboard('{Enter}')
+ expect(
+ await screen.findByRole('dialog', {
+ name: 'appOverview.overview.appInfo.customize.title',
+ }),
+ ).toBeInTheDocument()
+ await user.keyboard('{Escape}')
+ await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
+ await waitFor(() => expect(trigger).toHaveFocus())
})
it('should open the embedded dialog with the Agent web app route', async () => {
diff --git a/web/features/agent-v2/agent-detail/access/components/web-app-access-card.tsx b/web/features/agent-v2/agent-detail/access/components/web-app-access-card.tsx
index ae7081a221e..255b262cbc7 100644
--- a/web/features/agent-v2/agent-detail/access/components/web-app-access-card.tsx
+++ b/web/features/agent-v2/agent-detail/access/components/web-app-access-card.tsx
@@ -13,7 +13,7 @@ import {
WebAppAccessControlEntry,
WebAppAccessControlEntrySkeleton,
} from '@/app/components/app/access-point/shared/web-app-access-control'
-import CustomizeModal from '@/app/components/app/overview/customize'
+import { CustomizeDialog } from '@/app/components/app/overview/customize'
import EmbeddedModal from '@/app/components/app/overview/embedded'
import SettingsModal from '@/app/components/app/overview/settings'
import { AccessPointCard } from '@/app/components/base/access-point/card'
@@ -73,7 +73,6 @@ export function WebAppAccessCard({
appId,
}
: null
- const [showCustomizeModal, setShowCustomizeModal] = useState(false)
const [showEmbeddedModal, setShowEmbeddedModal] = useState(false)
const [showSettingsModal, setShowSettingsModal] = useState(false)
const [showAccessControl, setShowAccessControl] = useState(false)
@@ -242,15 +241,20 @@ export function WebAppAccessCard({
<span aria-hidden className="i-ri-window-line size-4" />
{t(($) => $['agentDetail.access.webApp.actions.embedIntoSite'])}
</Button>
- <Button
- variant="secondary"
- disabled={!canUseIntegrationActions || !customizeConfig}
- onClick={() => setShowCustomizeModal(true)}
- className="flex items-center gap-1 px-3"
- >
- <span aria-hidden className="i-custom-vender-deploy-code-block size-4" />
- {t(($) => $['agentDetail.access.webApp.actions.customFrontend'])}
- </Button>
+ {canManageWebApp && customizeConfig ? (
+ <CustomizeDialog
+ appId={customizeConfig.appId}
+ api_base_url={customizeConfig.apiBaseUrl}
+ sourceCodeRepository="webapp-conversation"
+ disabled={!canUseIntegrationActions}
+ triggerLabel={t(($) => $['agentDetail.access.webApp.actions.customFrontend'])}
+ />
+ ) : (
+ <Button variant="secondary" disabled className="flex items-center gap-1 px-3">
+ <span aria-hidden className="i-custom-vender-deploy-code-block size-4" />
+ {t(($) => $['agentDetail.access.webApp.actions.customFrontend'])}
+ </Button>
+ )}
<Button
variant="secondary"
disabled={!canManageWebApp || !settingsAppInfo || updateSiteMutation.isPending}
@@ -313,15 +317,6 @@ export function WebAppAccessCard({
onSave={handleSaveSettings}
/>
)}
- {canManageWebApp && customizeConfig && (
- <CustomizeModal
- isShow={showCustomizeModal}
- onClose={() => setShowCustomizeModal(false)}
- appId={customizeConfig.appId}
- api_base_url={customizeConfig.apiBaseUrl}
- sourceCodeRepository="webapp-conversation"
- />
- )}
{canManageWebApp && embeddedConfig && (
<EmbeddedModal
isShow={showEmbeddedModal}