Files
dify/web/app/components/workflow-app/hooks/use-auto-onboarding.ts
+4
YeuolyGitHubStreamlyzno1zhsamaHarrylyzno1yesseniahjlarrygemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>WTW0313Copilot
b76e17b25d feat: introduce trigger functionality (#27644)
Signed-off-by: lyzno1 <[email protected]>
Co-authored-by: Stream <[email protected]>
Co-authored-by: lyzno1 <[email protected]>
Co-authored-by: zhsama <[email protected]>
Co-authored-by: Harry <[email protected]>
Co-authored-by: lyzno1 <[email protected]>
Co-authored-by: yessenia <[email protected]>
Co-authored-by: hjlarry <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: WTW0313 <[email protected]>
Co-authored-by: Copilot <[email protected]>
2025-11-12 17:59:37 +08:00

69 lines
2.0 KiB
TypeScript

import { useCallback, useEffect } from 'react'
import { useStoreApi } from 'reactflow'
import { useWorkflowStore } from '@/app/components/workflow/store'
export const useAutoOnboarding = () => {
const store = useStoreApi()
const workflowStore = useWorkflowStore()
const checkAndShowOnboarding = useCallback(() => {
const { getNodes } = store.getState()
const {
showOnboarding,
hasShownOnboarding,
notInitialWorkflow,
setShowOnboarding,
setHasShownOnboarding,
setShouldAutoOpenStartNodeSelector,
} = workflowStore.getState()
// Skip if already showing onboarding or it's the initial workflow creation
if (showOnboarding || notInitialWorkflow)
return
const nodes = getNodes()
// Check if canvas is completely empty (no nodes at all)
// Only trigger onboarding when canvas is completely blank to avoid data loss
const isCompletelyEmpty = nodes.length === 0
// Show onboarding only if canvas is completely empty and we haven't shown it before in this session
if (isCompletelyEmpty && !hasShownOnboarding) {
setShowOnboarding?.(true)
setHasShownOnboarding?.(true)
setShouldAutoOpenStartNodeSelector?.(true)
}
}, [store, workflowStore])
const handleOnboardingClose = useCallback(() => {
const {
setShowOnboarding,
setHasShownOnboarding,
setShouldAutoOpenStartNodeSelector,
hasSelectedStartNode,
setHasSelectedStartNode,
} = workflowStore.getState()
setShowOnboarding?.(false)
setHasShownOnboarding?.(true)
if (hasSelectedStartNode)
setHasSelectedStartNode?.(false)
else
setShouldAutoOpenStartNodeSelector?.(false)
}, [workflowStore])
// Check on mount and when nodes change
useEffect(() => {
// Small delay to ensure the workflow data is loaded
const timer = setTimeout(() => {
checkAndShowOnboarding()
}, 500)
return () => clearTimeout(timer)
}, [checkAndShowOnboarding])
return {
checkAndShowOnboarding,
handleOnboardingClose,
}
}