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): move between integration tour steps without reloading the page (#44944)

yyhe3644de74327
diff --git a/web/app/(commonLayout)/integrations/[[...slug]]/page.tsx b/web/app/(commonLayout)/integrations/[[...slug]]/page.tsx
index c81f3cd37a9..fc0a2eda51d 100644
--- a/web/app/(commonLayout)/integrations/[[...slug]]/page.tsx
+++ b/web/app/(commonLayout)/integrations/[[...slug]]/page.tsx
@@ -1,5 +1,4 @@
import type { IntegrationRouteSearchParams } from '@/app/components/integrations/routes'
-import IntegrationsPage from '@/app/components/integrations'
import { getIntegrationRouteTargetBySlug } from '@/app/components/integrations/routes'
import { notFound, redirect } from '@/next/navigation'
@@ -18,7 +17,7 @@ const IntegrationsRoutePage = async ({ params, searchParams }: IntegrationsRoute
if (target.type === 'not-found') notFound()
- return <IntegrationsPage section={target.section} syncDocumentTitle />
+ return null
}
export default IntegrationsRoutePage
diff --git a/web/app/(commonLayout)/integrations/layout.tsx b/web/app/(commonLayout)/integrations/layout.tsx
index 3b1bbe9db75..ee516c335de 100644
--- a/web/app/(commonLayout)/integrations/layout.tsx
+++ b/web/app/(commonLayout)/integrations/layout.tsx
@@ -1,5 +1,12 @@
import type { PropsWithChildren } from 'react'
+import { IntegrationsRoutePage } from '@/app/components/integrations/route-page'
+// Rendered here so the page stays mounted across sections; the route segment only validates the slug.
export default function IntegrationsLayout({ children }: PropsWithChildren) {
- return children
+ return (
+ <>
+ <IntegrationsRoutePage />
+ {children}
+ </>
+ )
}
diff --git a/web/app/components/integrations/__tests__/page.spec.tsx b/web/app/components/integrations/__tests__/page.spec.tsx
index 45626991cb4..edcf8ca4529 100644
--- a/web/app/components/integrations/__tests__/page.spec.tsx
+++ b/web/app/components/integrations/__tests__/page.spec.tsx
@@ -310,6 +310,18 @@ it('honors a legacy category-only MCP URL and the explicit route section takes p
).toHaveAttribute('href', '/integrations/tools/api')
})
+it('expands tools in the same render that enters a tool section and keeps them expanded after leaving', () => {
+ const view = renderPage({ props: { section: 'provider' } })
+ const tools = screen.getByRole('button', { name: 'navigation.menus.tools' })
+ expect(tools).toHaveAttribute('aria-expanded', 'false')
+
+ view.rerender(<IntegrationsPage section="mcp" />)
+ expect(tools).toHaveAttribute('aria-expanded', 'true')
+
+ view.rerender(<IntegrationsPage section="data-source" />)
+ expect(tools).toHaveAttribute('aria-expanded', 'true')
+})
+
it('keeps tools expanded while visiting models and changes to tools only when opening the disclosure', async () => {
const user = userEvent.setup()
renderPage({ ui: <SettingsIntegrations /> })
diff --git a/web/app/components/integrations/__tests__/route-page.spec.tsx b/web/app/components/integrations/__tests__/route-page.spec.tsx
new file mode 100644
index 00000000000..83d01680d7d
--- /dev/null
+++ b/web/app/components/integrations/__tests__/route-page.spec.tsx
@@ -0,0 +1,27 @@
+import { render, screen } from '@testing-library/react'
+import { IntegrationsRoutePage } from '../route-page'
+
+let mockPathname = '/integrations/model-provider'
+
+vi.mock('@/next/navigation', () => ({
+ usePathname: () => mockPathname,
+}))
+vi.mock('../index', () => ({
+ default: ({ section }: { section: string }) => <p>{`section: ${section}`}</p>,
+}))
+
+describe('IntegrationsRoutePage', () => {
+ it('renders the section of the current integrations path', () => {
+ mockPathname = '/integrations/tools/mcp'
+ render(<IntegrationsRoutePage />)
+
+ expect(screen.getByText('section: mcp')).toBeInTheDocument()
+ })
+
+ it('renders nothing for a path the route segment redirects', () => {
+ mockPathname = '/integrations/tools'
+ const { container } = render(<IntegrationsRoutePage />)
+
+ expect(container).toBeEmptyDOMElement()
+ })
+})
diff --git a/web/app/components/integrations/index.tsx b/web/app/components/integrations/index.tsx
index 9493cc46c64..c3ada47f424 100644
--- a/web/app/components/integrations/index.tsx
+++ b/web/app/components/integrations/index.tsx
@@ -26,7 +26,7 @@ import {
ScrollAreaThumb,
ScrollAreaViewport,
} from '@langgenius/dify-ui/scroll-area'
-import { useEffect, useId, useRef, useState, useSyncExternalStore } from 'react'
+import { Suspense, useId, useRef, useState, useSyncExternalStore } from 'react'
import { useTranslation } from 'react-i18next'
import { UpdateSettingDialog } from '@/app/components/header/account-setting/update-setting-dialog'
import {
@@ -188,13 +188,11 @@ export default function IntegrationsPage({
const sectionTitle = integrationHeader?.title ?? activeItem?.label ?? integrationsTitle
const isToolSection = Boolean(toolCategoryBySection[section])
const [isToolsExpanded, setIsToolsExpanded] = useState(isToolSection)
- useEffect(() => {
- if (!isToolSection) return undefined
-
- const animationFrame = window.requestAnimationFrame(() => setIsToolsExpanded(true))
-
- return () => window.cancelAnimationFrame(animationFrame)
- }, [isToolSection])
+ const [wasToolSection, setWasToolSection] = useState(isToolSection)
+ if (wasToolSection !== isToolSection) {
+ setWasToolSection(isToolSection)
+ if (isToolSection) setIsToolsExpanded(true)
+ }
const useFillLayout =
section === 'provider' ||
section === 'data-source' ||
@@ -422,21 +420,22 @@ export default function IntegrationsPage({
<section className="flex min-w-0 flex-1 flex-col overflow-hidden max-md:overflow-visible">
{useFillLayout ? (
<div className="flex min-h-0 flex-1 flex-col overflow-hidden max-md:overflow-visible">
- <IntegrationSectionRenderer
- key={section}
- section={section}
- title={integrationHeader?.title ?? activeItem?.label}
- description={headerDescriptionWithLink}
- scrollAreaLabel={scrollAreaLabel}
- providerSearchText={providerSearchText}
- onProviderSearchTextChange={setProviderSearchText}
- onSwitchToMarketplace={handleSwitchToMarketplace}
- canInstallPlugin={canInstallPlugin}
- canDeletePlugin={canDeletePlugin}
- isInstallPermissionLoading={isReferenceSettingLoading}
- canUpdatePlugin={canUpdatePlugin}
- pluginCategoryToolbarAction={pluginSettingAction}
- />
+ <Suspense key={section} fallback={null}>
+ <IntegrationSectionRenderer
+ section={section}
+ title={integrationHeader?.title ?? activeItem?.label}
+ description={headerDescriptionWithLink}
+ scrollAreaLabel={scrollAreaLabel}
+ providerSearchText={providerSearchText}
+ onProviderSearchTextChange={setProviderSearchText}
+ onSwitchToMarketplace={handleSwitchToMarketplace}
+ canInstallPlugin={canInstallPlugin}
+ canDeletePlugin={canDeletePlugin}
+ isInstallPermissionLoading={isReferenceSettingLoading}
+ canUpdatePlugin={canUpdatePlugin}
+ pluginCategoryToolbarAction={pluginSettingAction}
+ />
+ </Suspense>
</div>
) : (
<ScrollArea className="min-h-0 flex-1 overflow-hidden">
@@ -446,20 +445,21 @@ export default function IntegrationsPage({
role={scrollAreaLabel ? 'region' : undefined}
>
<ScrollAreaContent className="min-h-full">
- <IntegrationSectionRenderer
- key={section}
- section={section}
- title={integrationHeader?.title ?? activeItem?.label}
- description={headerDescriptionWithLink}
- providerSearchText={providerSearchText}
- onProviderSearchTextChange={setProviderSearchText}
- onSwitchToMarketplace={handleSwitchToMarketplace}
- canInstallPlugin={canInstallPlugin}
- canDeletePlugin={canDeletePlugin}
- isInstallPermissionLoading={isReferenceSettingLoading}
- canUpdatePlugin={canUpdatePlugin}
- pluginCategoryToolbarAction={pluginSettingAction}
- />
+ <Suspense key={section} fallback={null}>
+ <IntegrationSectionRenderer
+ section={section}
+ title={integrationHeader?.title ?? activeItem?.label}
+ description={headerDescriptionWithLink}
+ providerSearchText={providerSearchText}
+ onProviderSearchTextChange={setProviderSearchText}
+ onSwitchToMarketplace={handleSwitchToMarketplace}
+ canInstallPlugin={canInstallPlugin}
+ canDeletePlugin={canDeletePlugin}
+ isInstallPermissionLoading={isReferenceSettingLoading}
+ canUpdatePlugin={canUpdatePlugin}
+ pluginCategoryToolbarAction={pluginSettingAction}
+ />
+ </Suspense>
</ScrollAreaContent>
</ScrollAreaViewport>
<ScrollAreaScrollbar>
diff --git a/web/app/components/integrations/route-page.tsx b/web/app/components/integrations/route-page.tsx
new file mode 100644
index 00000000000..b7e7ba38ddd
--- /dev/null
+++ b/web/app/components/integrations/route-page.tsx
@@ -0,0 +1,14 @@
+'use client'
+
+import IntegrationsPage from '@/app/components/integrations'
+import { getIntegrationRouteTargetBySlug } from '@/app/components/integrations/routes'
+import { usePathname } from '@/next/navigation'
+
+export function IntegrationsRoutePage() {
+ const pathname = usePathname()
+ const target = getIntegrationRouteTargetBySlug(pathname.split('/').filter(Boolean).slice(1))
+
+ if (target.type !== 'section') return null
+
+ return <IntegrationsPage section={target.section} syncDocumentTitle />
+}
diff --git a/web/app/components/step-by-step-tour/__tests__/mount.spec.tsx b/web/app/components/step-by-step-tour/__tests__/mount.spec.tsx
index 2325a25c27f..e70ea2f9244 100644
--- a/web/app/components/step-by-step-tour/__tests__/mount.spec.tsx
+++ b/web/app/components/step-by-step-tour/__tests__/mount.spec.tsx
@@ -2,13 +2,14 @@ import type { StepByStepTourStatePatchPayload } from '@dify/contracts/api/consol
import type { GetWorkspacesCurrentSummaryResponse } from '@dify/contracts/api/console/workspaces/types.gen'
import type { StepByStepTourSessionState, StepByStepTourTaskId } from '../types'
import { QueryClientProvider } from '@tanstack/react-query'
-import { render, screen, waitFor } from '@testing-library/react'
+import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { createStore, Provider as JotaiProvider } from 'jotai'
import { queryClientAtom } from 'jotai-tanstack-query'
import { createRef } from 'react'
import { consoleQuery } from '@/service/console'
import { createConsoleQueryWrapper } from '@/test/console/query-data'
+import { seedWorkspacePermissionsQuery } from '@/test/console/workspace-permissions'
import { createDeferred } from '@/test/deferred'
import { createStepByStepTourService } from '@/test/fixtures/onboarding'
import { createNuqsTestWrapper } from '@/test/nuqs-testing'
@@ -31,7 +32,8 @@ type StepByStepTourFixtureState = StepByStepTourSessionState & {
const mockRouterPush = vi.fn()
const mockTrackEvent = vi.hoisted(() => vi.fn())
-let mockPathname = '/apps'
+const mockRouterReplace = vi.fn()
+const setPathname = (pathname: string) => window.history.replaceState(null, '', pathname)
const mockWorkspacePermissionKeys = vi.hoisted(() => ({
value: [
'app.create_and_management',
@@ -80,8 +82,8 @@ vi.mock('@/context/modal-context', () => ({
}))
vi.mock('@/next/navigation', () => ({
- usePathname: () => mockPathname,
- useRouter: () => ({ push: mockRouterPush }),
+ usePathname: () => window.location.pathname,
+ useRouter: () => ({ push: mockRouterPush, replace: mockRouterReplace }),
}))
vi.mock('@/service/console', async (importOriginal) => {
@@ -326,7 +328,7 @@ const renderStepByStepTourMount = (searchParams = '') => {
jotaiStore.set(stepByStepTourChecklistMinimizedAtom, checklistMinimized)
const { wrapper } = createNuqsTestWrapper({ searchParams })
- return render(
+ const view = render(
<JotaiProvider store={jotaiStore}>
<QueryClientProvider client={queryClient}>
<div>
@@ -339,6 +341,7 @@ const renderStepByStepTourMount = (searchParams = '') => {
</JotaiProvider>,
{ wrapper },
)
+ return { ...view, queryClient }
}
const expectStepByStepTourPatch = async (body: StepByStepTourStatePatchPayload) => {
@@ -370,7 +373,7 @@ describe('StepByStepTourMount', () => {
mockEnableStepByStepTour.value = true
mockHasBlockingModalOpen.value = false
mockEducationExpireNotice.value = false
- mockPathname = '/apps'
+ setPathname('/apps')
localStorage.clear()
mockStepByStepTour.reset()
tourSession = {}
@@ -816,7 +819,7 @@ describe('StepByStepTourMount', () => {
})
it('does not block the tour outside the Apps route for an unmounted Education notice', async () => {
- mockPathname = '/datasets'
+ setPathname('/datasets')
mockEducationExpireNotice.value = true
setStepByStepTourTestState({
manuallyEnabledWorkspaceIds: ['workspace-1'],
@@ -868,6 +871,37 @@ describe('StepByStepTourMount', () => {
})
})
+ it('adds the Update Settings guide once plugin preference permission loads after the task starts', async () => {
+ setPathname('/integrations/model-provider')
+ mockWorkspacePermissionKeys.value = mockWorkspacePermissionKeys.value.filter(
+ (key) => key !== 'plugin.plugin_preferences',
+ )
+ setStepByStepTourTestState({
+ manuallyEnabledWorkspaceIds: ['workspace-1'],
+ manuallyDisabledWorkspaceIds: [],
+ minimized: false,
+ completedTaskIds: ['home', 'studio', 'knowledge'],
+ skipped: false,
+ })
+ const target = createTourTarget(STEP_BY_STEP_TOUR_TARGETS.integrationModelProviderNav)
+
+ try {
+ const { queryClient } = renderStepByStepTourMount()
+
+ await user.click(await screen.findByRole('button', { name: 'Take a look' }))
+ expect(await screen.findByText('1 of 5')).toBeInTheDocument()
+
+ seedWorkspacePermissionsQuery(queryClient, [
+ ...mockWorkspacePermissionKeys.value,
+ 'plugin.plugin_preferences',
+ ])
+
+ expect(await screen.findByText('1 of 6')).toBeInTheDocument()
+ } finally {
+ target.remove()
+ }
+ })
+
it('uses limited access integration guides when the workspace cannot manage integrations', async () => {
mockCurrentWorkspaceRole.value = 'normal'
mockWorkspacePermissionKeys.value = [
@@ -941,7 +975,7 @@ describe('StepByStepTourMount', () => {
).toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'Mark Knowledge needs permission complete' }),
- ).toBeDisabled()
+ ).toHaveAttribute('aria-disabled', 'true')
expect(mockTrackEvent).toHaveBeenCalledWith('step_tour', {
action: 'permission_fallback_shown',
permission_variant: 'no_knowledge_permission',
@@ -992,6 +1026,52 @@ describe('StepByStepTourMount', () => {
}
})
+ it('opens the coachmark once its target scrolls into view and then follows it', async () => {
+ setStepByStepTourTestState({
+ manuallyEnabledWorkspaceIds: ['workspace-1'],
+ manuallyDisabledWorkspaceIds: [],
+ minimized: false,
+ completedTaskIds: [],
+ skipped: false,
+ })
+ const rect = { height: 180, left: 40, top: 900, width: 360 }
+ const target = createTourTarget(STEP_BY_STEP_TOUR_TARGETS.home, rect.top, rect)
+ target.getBoundingClientRect = () => DOMRect.fromRect({ ...rect, x: rect.left, y: rect.top })
+ const scrollIntoView = vi.fn()
+ target.scrollIntoView = scrollIntoView
+
+ try {
+ renderStepByStepTourMount()
+
+ await user.click(await screen.findByRole('button', { name: 'Show me' }))
+
+ await waitFor(() => expect(scrollIntoView).toHaveBeenCalled())
+ expect(
+ screen.queryByRole('dialog', { name: 'Pick a lesson to see how it works.' }),
+ ).not.toBeInTheDocument()
+
+ rect.top = 120
+ fireEvent.scroll(window)
+
+ const coachmark = await screen.findByRole('dialog', {
+ name: 'Pick a lesson to see how it works.',
+ })
+ await waitFor(() => expect(coachmark).toHaveFocus())
+
+ rect.top = 900
+ fireEvent.scroll(window)
+
+ await waitFor(() =>
+ expect(document.querySelector('[data-step-by-step-tour-highlight]')).toHaveStyle({
+ top: '896px',
+ }),
+ )
+ expect(coachmark).toBeInTheDocument()
+ } finally {
+ target.remove()
+ }
+ })
+
it('uses no-create Learn Dify copy when the workspace cannot create apps', async () => {
mockWorkspacePermissionKeys.value = []
setStepByStepTourTestState({
@@ -1050,7 +1130,7 @@ describe('StepByStepTourMount', () => {
const completeStudioButton = await screen.findByRole('button', {
name: 'Mark Manage your apps in Studio complete',
})
- expect(completeStudioButton).toBeDisabled()
+ expect(completeStudioButton).toHaveAttribute('aria-disabled', 'true')
await user.click(completeStudioButton)
@@ -1064,9 +1144,12 @@ describe('StepByStepTourMount', () => {
await waitFor(() =>
expect(screen.getByRole('progressbar')).toHaveAttribute('aria-valuenow', '0'),
)
- expect(
- screen.getByRole('button', { name: 'Mark Try a Learn Dify lesson complete' }),
- ).toBeDisabled()
+ const reopenedHomeButton = screen.getByRole('button', {
+ name: 'Mark Try a Learn Dify lesson complete',
+ })
+ expect(reopenedHomeButton).toHaveAttribute('aria-disabled', 'true')
+ expect(reopenedHomeButton).toBeEnabled()
+ expect(reopenedHomeButton).toHaveFocus()
})
it('does not allow manually completing externally completed tasks from the checklist', async () => {
@@ -1083,7 +1166,7 @@ describe('StepByStepTourMount', () => {
const completeHomeButton = await screen.findByRole('button', {
name: 'Mark Try a Learn Dify lesson complete',
})
- expect(completeHomeButton).toBeDisabled()
+ expect(completeHomeButton).toHaveAttribute('aria-disabled', 'true')
await user.click(completeHomeButton)
@@ -1091,7 +1174,7 @@ describe('StepByStepTourMount', () => {
})
it('walks through Integration guides and syncs the Integrations section route', async () => {
- mockPathname = '/integrations/model-provider'
+ setPathname('/integrations/model-provider')
setStepByStepTourTestState({
activeTaskId: 'integration',
activeGuideIndex: 0,
@@ -1133,7 +1216,9 @@ describe('StepByStepTourMount', () => {
await user.click(screen.getByRole('button', { name: 'Got it' }))
expect(await screen.findByRole('dialog', { name: 'Tool Plugin' })).toBeInTheDocument()
expect(screen.getByText('2 of 6')).toBeInTheDocument()
- expect(mockRouterPush).toHaveBeenLastCalledWith('/integrations/tools/built-in')
+ expect(window.location.pathname).toBe('/integrations/tools/built-in')
+ expect(mockRouterPush).not.toHaveBeenCalled()
+ expect(mockRouterReplace).not.toHaveBeenCalled()
expect(mockTrackEvent).toHaveBeenCalledWith('step_tour', {
action: 'guide_completed',
guide_id: 'integration.model_provider',
@@ -1143,24 +1228,24 @@ describe('StepByStepTourMount', () => {
await user.click(screen.getByRole('button', { name: 'Got it' }))
expect(await screen.findByRole('dialog', { name: 'MCP' })).toBeInTheDocument()
expect(screen.getByText('3 of 6')).toBeInTheDocument()
- expect(mockRouterPush).toHaveBeenLastCalledWith('/integrations/tools/mcp')
+ expect(window.location.pathname).toBe('/integrations/tools/mcp')
await user.click(screen.getByRole('button', { name: 'Got it' }))
expect(await screen.findByRole('dialog', { name: 'Data Source' })).toBeInTheDocument()
expect(screen.getByText('4 of 6')).toBeInTheDocument()
expect(screen.queryByRole('link', { name: 'Learn more' })).not.toBeInTheDocument()
- expect(mockRouterPush).toHaveBeenLastCalledWith('/integrations/data-source')
+ expect(window.location.pathname).toBe('/integrations/data-source')
await user.click(screen.getByRole('button', { name: 'Got it' }))
expect(await screen.findByRole('dialog', { name: 'Trigger' })).toBeInTheDocument()
expect(screen.getByText('5 of 6')).toBeInTheDocument()
expect(screen.queryByRole('link', { name: 'Learn more' })).not.toBeInTheDocument()
- expect(mockRouterPush).toHaveBeenLastCalledWith('/integrations/trigger')
+ expect(window.location.pathname).toBe('/integrations/trigger')
await user.click(screen.getByRole('button', { name: 'Got it' }))
expect(await screen.findByRole('dialog', { name: 'Update Settings' })).toBeInTheDocument()
expect(screen.getByText('6 of 6')).toBeInTheDocument()
- expect(mockRouterPush).toHaveBeenLastCalledWith('/integrations/tools/built-in')
+ expect(window.location.pathname).toBe('/integrations/tools/built-in')
await user.click(screen.getByRole('button', { name: 'Got it' }))
@@ -1175,7 +1260,7 @@ describe('StepByStepTourMount', () => {
})
it('keeps the Integration update settings guide in the plan until its section target is rendered', async () => {
- mockPathname = '/integrations/model-provider'
+ setPathname('/integrations/model-provider')
setStepByStepTourTestState({
activeTaskId: 'integration',
activeGuideIndex: 0,
@@ -1199,6 +1284,7 @@ describe('StepByStepTourMount', () => {
expect(await screen.findByRole('dialog', { name: 'Model Provider' })).toBeInTheDocument()
expect(screen.getByText('1 of 6')).toBeInTheDocument()
+ // The Tool Plugin section renders the Update Settings target later than its nav item.
await user.click(screen.getByRole('button', { name: 'Got it' }))
expect(await screen.findByRole('dialog', { name: 'Tool Plugin' })).toBeInTheDocument()
expect(screen.getByText('2 of 6')).toBeInTheDocument()
@@ -1215,13 +1301,7 @@ describe('StepByStepTourMount', () => {
expect(await screen.findByRole('dialog', { name: 'Trigger' })).toBeInTheDocument()
expect(screen.getByText('5 of 6')).toBeInTheDocument()
- const updateSettingsTarget = createTourTarget(
- STEP_BY_STEP_TOUR_TARGETS.integrationUpdateSettings,
- 144,
- )
- targets.push(updateSettingsTarget)
- mockPathname = '/integrations/tools/built-in'
-
+ targets.push(createTourTarget(STEP_BY_STEP_TOUR_TARGETS.integrationUpdateSettings, 144))
await user.click(screen.getByRole('button', { name: 'Got it' }))
expect(await screen.findByRole('dialog', { name: 'Update Settings' })).toBeInTheDocument()
expect(screen.getByText('6 of 6')).toBeInTheDocument()
@@ -1231,7 +1311,7 @@ describe('StepByStepTourMount', () => {
})
it('skips the optional Integration update settings guide when plugin preferences permission is unavailable', async () => {
- mockPathname = '/integrations/model-provider'
+ setPathname('/integrations/model-provider')
mockWorkspacePermissionKeys.value = [
'app.create_and_management',
'dataset.create_and_management',
@@ -1293,7 +1373,7 @@ describe('StepByStepTourMount', () => {
})
it('skips the optional Learn Dify guide when the Studio empty section is not rendered', async () => {
- mockPathname = '/apps'
+ setPathname('/apps')
setStepByStepTourTestState({
activeTaskId: 'studio',
activeGuideIndex: 2,
@@ -1314,7 +1394,8 @@ describe('StepByStepTourMount', () => {
renderStepByStepTourMount()
expect(await screen.findByRole('dialog', { name: 'Import a DSL file' })).toBeInTheDocument()
- expect(screen.getByText('3 of 3')).toBeInTheDocument()
+ // An optional guide counts until the tour reaches it and finds no target.
+ expect(screen.getByText('3 of 4')).toBeInTheDocument()
await user.click(screen.getByRole('button', { name: 'Got it' }))
@@ -1325,7 +1406,7 @@ describe('StepByStepTourMount', () => {
})
it('skips the optional app card action guide when no app card action target is rendered', async () => {
- mockPathname = '/apps'
+ setPathname('/apps')
setStepByStepTourTestState({
activeTaskId: 'studio',
activeGuideIndex: 0,
@@ -1351,7 +1432,7 @@ describe('StepByStepTourMount', () => {
renderStepByStepTourMount()
expect(await screen.findByRole('dialog', { name: 'Create a new app' })).toBeInTheDocument()
- expect(screen.getByText('1 of 1')).toBeInTheDocument()
+ expect(screen.getByText('1 of 2')).toBeInTheDocument()
await user.click(screen.getByRole('button', { name: 'Got it' }))
await expectStepByStepTourPatch({ action: 'complete_task', task_id: 'studio' })
@@ -1362,7 +1443,7 @@ describe('StepByStepTourMount', () => {
})
it('skips the active walkthrough without completing the task', async () => {
- mockPathname = '/integrations/model-provider'
+ setPathname('/integrations/model-provider')
setStepByStepTourTestState({
activeTaskId: 'integration',
activeGuideIndex: 1,
@@ -1407,7 +1488,7 @@ describe('StepByStepTourMount', () => {
})
it('focuses the primary action and skips the active walkthrough with Escape', async () => {
- mockPathname = '/integrations/model-provider'
+ setPathname('/integrations/model-provider')
setStepByStepTourTestState({
activeTaskId: 'integration',
activeGuideIndex: 1,
@@ -1488,7 +1569,7 @@ describe('StepByStepTourMount', () => {
})
it('closes the coachmark while its target is missing and opens it once the target renders', async () => {
- mockPathname = '/integrations/model-provider'
+ setPathname('/integrations/model-provider')
setStepByStepTourTestState({
activeTaskId: 'integration',
activeGuideIndex: 1,
@@ -1522,7 +1603,7 @@ describe('StepByStepTourMount', () => {
})
it('keeps the minimized tour control visible when an active guide target is unavailable', async () => {
- mockPathname = '/app/test-app/overview'
+ setPathname('/app/test-app/overview')
setStepByStepTourTestState({
activeTaskId: 'integration',
manuallyEnabledWorkspaceIds: ['workspace-1'],
diff --git a/web/app/components/step-by-step-tour/__tests__/state.spec.ts b/web/app/components/step-by-step-tour/__tests__/state.spec.ts
index df0cf138c84..0b6232f4399 100644
--- a/web/app/components/step-by-step-tour/__tests__/state.spec.ts
+++ b/web/app/components/step-by-step-tour/__tests__/state.spec.ts
@@ -182,14 +182,13 @@ describe('step-by-step tour state', () => {
store.set(startStepByStepTourTaskAtom, {
taskId: 'studio',
guideGroup: 'studioWithApps',
- guideIndexes: [0, 2],
})
expect(store.get(completedStepByStepTourTaskIdsAtom)).toEqual(['home'])
expect(store.get(activeStepByStepTourTaskIdAtom)).toBe('studio')
expect(store.get(activeStepByStepTourGuideIndexAtom)).toBe(0)
expect(store.get(activeStepByStepTourGuideGroupAtom)).toBe('studioWithApps')
- expect(store.get(activeStepByStepTourGuideIndexesAtom)).toEqual([0, 2])
+ expect(store.get(activeStepByStepTourGuideIndexesAtom)).toBeUndefined()
expect(
queryClient.getQueryData<StepByStepTourStateResponse>(stepByStepTourStateQueryKey)
?.completed_task_ids,
diff --git a/web/app/components/step-by-step-tour/coachmark.tsx b/web/app/components/step-by-step-tour/coachmark.tsx
index c310360922e..36034975386 100644
--- a/web/app/components/step-by-step-tour/coachmark.tsx
+++ b/web/app/components/step-by-step-tour/coachmark.tsx
@@ -63,6 +63,9 @@ const getTargetOnlyClipPath = ({ height, left, top, width }: StepByStepTourTarge
return `polygon(evenodd,0% 0%,100% 0%,100% 100%,0% 100%,0% 0%,${left}px ${top}px,${left}px ${bottom}px,${right}px ${bottom}px,${right}px ${top}px,${left}px ${top}px)`
}
+const isRectInViewport = ({ height, left, top, width }: StepByStepTourTargetRect) =>
+ top < window.innerHeight && top + height > 0 && left < window.innerWidth && left + width > 0
+
const useStepGliding = (stepKey: string | undefined) => {
const [glide, setGlide] = useState({ gliding: false, stepKey })
if (glide.stepKey !== stepKey) setGlide({ gliding: Boolean(glide.stepKey && stepKey), stepKey })
@@ -144,16 +147,17 @@ export function StepByStepTourCoachmark({
}
: undefined
- const [awaitingTarget, setAwaitingTarget] = useState(!targetElement)
+ const [awaitingTarget, setAwaitingTarget] = useState(true)
if (!targetElement && !awaitingTarget) setAwaitingTarget(true)
- if (currentOverlay && awaitingTarget) setAwaitingTarget(false)
+ if (currentOverlay && awaitingTarget && isRectInViewport(currentOverlay.highlightRect))
+ setAwaitingTarget(false)
useLayoutEffect(() => {
if (currentOverlay) lastOverlayRef.current = currentOverlay
})
const overlay = currentOverlay ?? lastOverlayRef.current
- const open = Boolean(targetElement && !awaitingTarget && overlay)
+ const open = Boolean(!awaitingTarget && overlay)
const gliding = useStepGliding(open ? overlay?.guide.id : undefined)
const isActionGuide = overlay ? getStepByStepTourGuideKind(overlay.guide) === 'action' : false
const overlayPlacement = overlay?.placement
@@ -277,7 +281,7 @@ export function StepByStepTourCoachmark({
initialFocus={() => primaryActionRef.current ?? popupRef.current}
finalFocus={false}
className={cn(
- 'relative flex w-88 max-w-[calc(100vw-16px)] flex-col rounded-2xl border-[0.5px] border-state-accent-hover-alt bg-state-accent-hover p-4 shadow-[0_20px_24px_-4px_var(--color-shadow-shadow-5),0_8px_8px_-4px_var(--color-shadow-shadow-1)] backdrop-blur-[5px]',
+ 'relative flex w-88 max-w-[calc(100vw-16px)] flex-col rounded-2xl border-[0.5px] border-state-accent-hover-alt bg-state-accent-hover p-4 shadow-[0_20px_24px_-4px_var(--color-shadow-shadow-5),0_8px_8px_-4px_var(--color-shadow-shadow-1)] backdrop-blur-[5px] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-state-accent-solid focus-visible:outline-solid',
isActionGuide ? 'min-h-29.5' : 'min-h-39.5',
)}
>
diff --git a/web/app/components/step-by-step-tour/floating-widget.tsx b/web/app/components/step-by-step-tour/floating-widget.tsx
index f68d0e3790f..ab0b5495637 100644
--- a/web/app/components/step-by-step-tour/floating-widget.tsx
+++ b/web/app/components/step-by-step-tour/floating-widget.tsx
@@ -32,7 +32,6 @@ export type FloatingChecklistProps = {
getTaskIncompleteLabel: (taskTitle: string) => string
onMinimize: () => void
onSkip: () => void
- onCompleteTask: (taskId: StepByStepTourTaskId) => void
onStartTask: (taskId: StepByStepTourTaskId) => void
onUncompleteTask: (taskId: StepByStepTourTaskId) => void
}
@@ -51,7 +50,6 @@ export function FloatingChecklist({
getTaskIncompleteLabel,
onMinimize,
onSkip,
- onCompleteTask,
onStartTask,
onUncompleteTask,
}: FloatingChecklistProps) {
@@ -103,7 +101,6 @@ export function FloatingChecklist({
<TourTaskRow
key={task.id}
task={task}
- onCompleteTask={onCompleteTask}
getTaskCompleteLabel={getTaskCompleteLabel}
getTaskIncompleteLabel={getTaskIncompleteLabel}
onStartTask={onStartTask}
@@ -226,14 +223,12 @@ function TourProgress({
function TourTaskRow({
task,
- onCompleteTask,
getTaskCompleteLabel,
getTaskIncompleteLabel,
onStartTask,
onUncompleteTask,
}: {
task: StepByStepTourTaskView
- onCompleteTask: (taskId: StepByStepTourTaskId) => void
getTaskCompleteLabel: (taskTitle: string) => string
getTaskIncompleteLabel: (taskTitle: string) => string
onStartTask: (taskId: StepByStepTourTaskId) => void
@@ -242,8 +237,6 @@ function TourTaskRow({
const completed = task.status === 'completed'
const current = task.status === 'current'
const disabled = task.status === 'disabled'
- const completionToggleDisabled = disabled || task.canToggleCompletion === false
- const statusIndicatorDisabled = completed ? disabled : completionToggleDisabled
return (
<div
@@ -293,10 +286,8 @@ function TourTaskRow({
</div>
<TaskStatusIndicator
completed={completed}
- disabled={statusIndicatorDisabled}
completeLabel={getTaskCompleteLabel(task.title)}
incompleteLabel={getTaskIncompleteLabel(task.title)}
- onComplete={() => onCompleteTask(task.id)}
onUncomplete={() => onUncompleteTask(task.id)}
/>
</div>
@@ -305,40 +296,25 @@ function TourTaskRow({
function TaskStatusIndicator({
completed,
- disabled,
completeLabel,
incompleteLabel,
- onComplete,
onUncomplete,
}: {
completed: boolean
- disabled: boolean
completeLabel: string
incompleteLabel: string
- onComplete: () => void
onUncomplete: () => void
}) {
- if (completed) {
- return (
- <button
- type="button"
- aria-label={incompleteLabel}
- disabled={disabled}
- className="flex size-4.5 shrink-0 items-center justify-center rounded-full bg-saas-dify-blue-accessible text-text-primary-on-surface outline-state-accent-solid hover:bg-saas-dify-blue-inverted focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-saas-dify-blue-accessible"
- onClick={onUncomplete}
- >
- <span aria-hidden className="i-ri-check-line size-3" />
- </button>
- )
- }
-
return (
<button
type="button"
- aria-label={completeLabel}
- disabled={disabled}
- className="flex size-4.5 shrink-0 items-center justify-center rounded-full border border-components-checkbox-border bg-components-checkbox-bg-unchecked outline-state-accent-solid hover:border-state-accent-solid focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:hover:border-components-checkbox-border"
- onClick={onComplete}
- />
+ aria-label={completed ? incompleteLabel : completeLabel}
+ aria-disabled={!completed || undefined}
+ data-completed={completed ? '' : undefined}
+ className="flex size-4.5 shrink-0 items-center justify-center rounded-full border border-components-checkbox-border bg-components-checkbox-bg-unchecked outline-state-accent-solid focus-visible:outline-2 focus-visible:outline-offset-2 aria-disabled:cursor-not-allowed data-completed:border-transparent data-completed:bg-saas-dify-blue-accessible data-completed:text-text-primary-on-surface"
+ onClick={completed ? onUncomplete : undefined}
+ >
+ {completed && <span aria-hidden className="i-ri-check-line size-3" />}
+ </button>
)
}
diff --git a/web/app/components/step-by-step-tour/mount.tsx b/web/app/components/step-by-step-tour/mount.tsx
index 3ac0f85e3fb..bfb480a4a64 100644
--- a/web/app/components/step-by-step-tour/mount.tsx
+++ b/web/app/components/step-by-step-tour/mount.tsx
@@ -42,6 +42,7 @@ import { currentWorkspaceAtom, isCurrentWorkspaceManagerAtom } from '@/context/w
import { systemFeaturesQueryOptions } from '@/features/system-features/client'
import { usePathname, useRouter } from '@/next/navigation'
import { hasPermission } from '@/utils/permission'
+import { basePath } from '@/utils/var'
import { getStepByStepTourPermissionVariant, trackStepByStepTourEvent } from './analytics'
import { StepByStepTourCoachmark } from './coachmark'
import { FloatingChecklist, MinimizedTourPill } from './floating-widget'
@@ -65,7 +66,6 @@ import {
} from './state'
import {
getStepByStepTourGuideInteractionPolicy,
- getStepByStepTourGuideKind,
getStepByStepTourGuides,
getStepByStepTourTargetSelector,
STEP_BY_STEP_TOUR_TARGETS,
@@ -227,9 +227,9 @@ export default function StepByStepTourMount({
const minimized = Boolean(activeTask) || checklistMinimized
const activeGuideIndexes =
activeGuides.length > 0
- ? getActiveGuideIndexes(activeGuides, sessionGuideIndexes)
- .filter((index) => isGuideEligibleForPlan(activeGuides[index]!, canSetPluginPreferences))
- .filter((index) => isOptionalGuideTargetAvailable(activeGuides[index]!, pathname))
+ ? getActiveGuideIndexes(activeGuides, sessionGuideIndexes).filter((index) =>
+ isGuideEligibleForPlan(activeGuides[index]!, canSetPluginPreferences),
+ )
: []
const activeGuidePlanIndex = activeGuideIndexes.findIndex((index) => index === activeGuideIndex)
const activeStepIndex =
@@ -320,7 +320,7 @@ export default function StepByStepTourMount({
if (lastRequestedIntegrationRouteRef.current === activeGuideRoute) return
lastRequestedIntegrationRouteRef.current = activeGuideRoute
- router.push(activeGuideRoute)
+ router.replace(activeGuideRoute)
}, [activeGuide?.integrationSection, activeTask?.id, pathname, router])
useEffect(() => {
@@ -513,7 +513,6 @@ export default function StepByStepTourMount({
id: task.id,
iconClassName: knowledgeUnavailable ? 'i-ri-lock-line' : task.iconClassName,
status: completed ? 'completed' : task.id === currentTask?.id ? 'current' : 'pending',
- canToggleCompletion: false,
}
})
@@ -599,6 +598,16 @@ export default function StepByStepTourMount({
return
}
+ const nextGuideSection =
+ activeTask.id === 'integration'
+ ? activeGuides[nextActiveGuide.activeGuideIndex]?.integrationSection
+ : undefined
+ const nextGuideRoute = nextGuideSection && buildIntegrationPath(nextGuideSection)
+ // The Integrations page stays mounted across sections, so the step only needs the URL.
+ if (nextGuideRoute && nextGuideRoute !== pathname) {
+ lastRequestedIntegrationRouteRef.current = nextGuideRoute
+ window.history.replaceState(null, '', `${basePath}${nextGuideRoute}`)
+ }
advanceGuide({
guideIndex: nextActiveGuide.activeGuideIndex,
guideIndexes: nextActiveGuide.activeGuideIndexes,
@@ -671,18 +680,6 @@ export default function StepByStepTourMount({
setChecklistMinimized(true)
}}
onSkip={skipTour}
- onCompleteTask={(taskId) => {
- const guides = getStepByStepTourGuides(taskId, sessionGuideGroup)
- const hasExternalCompletionGuide = guides.some(
- (guide) => getStepByStepTourGuideKind(guide) === 'action',
- )
- if (hasExternalCompletionGuide) return
-
- completeTask({
- taskId,
- onSuccess: (completedTaskIds) => trackTaskCompleted(completedTaskIds, taskId),
- })
- }}
onStartTask={(taskId) => {
const task = availableTasks.find((item) => item.id === taskId)
@@ -710,15 +707,7 @@ export default function StepByStepTourMount({
return
}
- const guides = getStepByStepTourGuides(taskId, guideGroup)
- const guideIndexes = createGuideIndexes(guides).filter((index) =>
- isGuideEligibleForPlan(guides[index]!, canSetPluginPreferences),
- )
- startTask({
- taskId,
- guideGroup,
- guideIndexes: guideIndexes.length > 0 ? guideIndexes : undefined,
- })
+ startTask({ taskId, guideGroup })
router.push(task.route)
}}
onUncompleteTask={(taskId) => {
diff --git a/web/app/components/step-by-step-tour/state.ts b/web/app/components/step-by-step-tour/state.ts
index d9aba27e9a8..c5c3e0d9a33 100644
--- a/web/app/components/step-by-step-tour/state.ts
+++ b/web/app/components/step-by-step-tour/state.ts
@@ -188,21 +188,12 @@ export const startStepByStepTourTaskAtom = atom(
(
_get,
set,
- {
- taskId,
- guideGroup,
- guideIndexes,
- }: {
- taskId: StepByStepTourTaskId
- guideGroup?: StepByStepTourGuideGroup
- guideIndexes?: number[]
- },
+ { taskId, guideGroup }: { taskId: StepByStepTourTaskId; guideGroup?: StepByStepTourGuideGroup },
) => {
set(stepByStepTourSessionAtom, {
activeTaskId: taskId,
activeGuideIndex: 0,
activeGuideGroup: guideGroup,
- activeGuideIndexes: guideIndexes,
})
},
)
diff --git a/web/app/components/step-by-step-tour/types.ts b/web/app/components/step-by-step-tour/types.ts
index 4c196463493..50f5ce97154 100644
--- a/web/app/components/step-by-step-tour/types.ts
+++ b/web/app/components/step-by-step-tour/types.ts
@@ -45,7 +45,6 @@ export type StepByStepTourTaskView = {
status: StepByStepTourTaskStatus
primaryActionLabel: string
disabledReason?: string
- canToggleCompletion?: boolean
learnMoreLabel?: string
learnMoreHref?: string
}