mirror of
https://github.com/langgenius/dify.git
synced 2025-12-17 13:13:02 +00:00
Signed-off-by: lyzno1 <yuanyouhuilyz@gmail.com> Co-authored-by: Stream <Stream_2@qq.com> Co-authored-by: lyzno1 <92089059+lyzno1@users.noreply.github.com> Co-authored-by: zhsama <torvalds@linux.do> Co-authored-by: Harry <xh001x@hotmail.com> Co-authored-by: lyzno1 <yuanyouhuilyz@gmail.com> Co-authored-by: yessenia <yessenia.contact@gmail.com> Co-authored-by: hjlarry <hjlarry@163.com> 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 <twwu@dify.ai> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
'use client'
|
|
|
|
import type { ReactNode } from 'react'
|
|
import React, { createContext, useContext, useEffect, useState } from 'react'
|
|
import { usePathname } from 'next/navigation'
|
|
import { isInWorkflowPage } from '../workflow/constants'
|
|
|
|
/**
|
|
* Interface for the GotoAnything context
|
|
*/
|
|
type GotoAnythingContextType = {
|
|
/**
|
|
* Whether the current page is a workflow page
|
|
*/
|
|
isWorkflowPage: boolean
|
|
/**
|
|
* Whether the current page is a RAG pipeline page
|
|
*/
|
|
isRagPipelinePage: boolean
|
|
}
|
|
|
|
// Create context with default values
|
|
const GotoAnythingContext = createContext<GotoAnythingContextType>({
|
|
isWorkflowPage: false,
|
|
isRagPipelinePage: false,
|
|
})
|
|
|
|
/**
|
|
* Hook to use the GotoAnything context
|
|
*/
|
|
export const useGotoAnythingContext = () => useContext(GotoAnythingContext)
|
|
|
|
type GotoAnythingProviderProps = {
|
|
children: ReactNode
|
|
}
|
|
|
|
/**
|
|
* Provider component for GotoAnything context
|
|
*/
|
|
export const GotoAnythingProvider: React.FC<GotoAnythingProviderProps> = ({ children }) => {
|
|
const [isWorkflowPage, setIsWorkflowPage] = useState(false)
|
|
const [isRagPipelinePage, setIsRagPipelinePage] = useState(false)
|
|
const pathname = usePathname()
|
|
|
|
// Update context based on current pathname using more robust route matching
|
|
useEffect(() => {
|
|
if (!pathname) {
|
|
setIsWorkflowPage(false)
|
|
setIsRagPipelinePage(false)
|
|
return
|
|
}
|
|
|
|
// Workflow pages: /app/[appId]/workflow or /workflow/[token] (shared)
|
|
const isWorkflow = isInWorkflowPage()
|
|
// RAG Pipeline pages: /datasets/[datasetId]/pipeline
|
|
const isRagPipeline = /^\/datasets\/[^/]+\/pipeline$/.test(pathname)
|
|
|
|
setIsWorkflowPage(isWorkflow)
|
|
setIsRagPipelinePage(isRagPipeline)
|
|
}, [pathname])
|
|
|
|
return (
|
|
<GotoAnythingContext.Provider value={{ isWorkflowPage, isRagPipelinePage }}>
|
|
{children}
|
|
</GotoAnythingContext.Provider>
|
|
)
|
|
}
|