mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-11 02:49:01 +08:00
fix: Prevent redirection to /overview when accessing /workflow. (#11733)
This commit is contained in:
parent
dfa9a91906
commit
1325246da8
@ -25,6 +25,7 @@ import { fetchAppDetail, fetchAppSSO } from '@/service/apps'
|
|||||||
import AppContext, { useAppContext } from '@/context/app-context'
|
import AppContext, { useAppContext } from '@/context/app-context'
|
||||||
import Loading from '@/app/components/base/loading'
|
import Loading from '@/app/components/base/loading'
|
||||||
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
|
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
|
||||||
|
import type { App } from '@/types/app'
|
||||||
|
|
||||||
export type IAppDetailLayoutProps = {
|
export type IAppDetailLayoutProps = {
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
@ -41,12 +42,14 @@ const AppDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
|
|||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
const media = useBreakpoints()
|
const media = useBreakpoints()
|
||||||
const isMobile = media === MediaType.mobile
|
const isMobile = media === MediaType.mobile
|
||||||
const { isCurrentWorkspaceEditor } = useAppContext()
|
const { isCurrentWorkspaceEditor, isLoadingCurrentWorkspace } = useAppContext()
|
||||||
const { appDetail, setAppDetail, setAppSiderbarExpand } = useStore(useShallow(state => ({
|
const { appDetail, setAppDetail, setAppSiderbarExpand } = useStore(useShallow(state => ({
|
||||||
appDetail: state.appDetail,
|
appDetail: state.appDetail,
|
||||||
setAppDetail: state.setAppDetail,
|
setAppDetail: state.setAppDetail,
|
||||||
setAppSiderbarExpand: state.setAppSiderbarExpand,
|
setAppSiderbarExpand: state.setAppSiderbarExpand,
|
||||||
})))
|
})))
|
||||||
|
const [isLoadingAppDetail, setIsLoadingAppDetail] = useState(false)
|
||||||
|
const [appDetailRes, setAppDetailRes] = useState<App | null>(null)
|
||||||
const [navigation, setNavigation] = useState<Array<{
|
const [navigation, setNavigation] = useState<Array<{
|
||||||
name: string
|
name: string
|
||||||
href: string
|
href: string
|
||||||
@ -107,33 +110,43 @@ const AppDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setAppDetail()
|
setAppDetail()
|
||||||
|
setIsLoadingAppDetail(true)
|
||||||
fetchAppDetail({ url: '/apps', id: appId }).then((res) => {
|
fetchAppDetail({ url: '/apps', id: appId }).then((res) => {
|
||||||
// redirection
|
setAppDetailRes(res)
|
||||||
const canIEditApp = isCurrentWorkspaceEditor
|
|
||||||
if (!canIEditApp && (pathname.endsWith('configuration') || pathname.endsWith('workflow') || pathname.endsWith('logs'))) {
|
|
||||||
router.replace(`/app/${appId}/overview`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if ((res.mode === 'workflow' || res.mode === 'advanced-chat') && (pathname).endsWith('configuration')) {
|
|
||||||
router.replace(`/app/${appId}/workflow`)
|
|
||||||
}
|
|
||||||
else if ((res.mode !== 'workflow' && res.mode !== 'advanced-chat') && (pathname).endsWith('workflow')) {
|
|
||||||
router.replace(`/app/${appId}/configuration`)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
setAppDetail({ ...res, enable_sso: false })
|
|
||||||
setNavigation(getNavigations(appId, isCurrentWorkspaceEditor, res.mode))
|
|
||||||
if (systemFeatures.enable_web_sso_switch_component && canIEditApp) {
|
|
||||||
fetchAppSSO({ appId }).then((ssoRes) => {
|
|
||||||
setAppDetail({ ...res, enable_sso: ssoRes.enabled })
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).catch((e: any) => {
|
}).catch((e: any) => {
|
||||||
if (e.status === 404)
|
if (e.status === 404)
|
||||||
router.replace('/apps')
|
router.replace('/apps')
|
||||||
|
}).finally(() => {
|
||||||
|
setIsLoadingAppDetail(false)
|
||||||
})
|
})
|
||||||
}, [appId, isCurrentWorkspaceEditor, systemFeatures, getNavigations, pathname, router, setAppDetail])
|
}, [appId, router, setAppDetail])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!appDetailRes || isLoadingCurrentWorkspace || isLoadingAppDetail)
|
||||||
|
return
|
||||||
|
const res = appDetailRes
|
||||||
|
// redirection
|
||||||
|
const canIEditApp = isCurrentWorkspaceEditor
|
||||||
|
if (!canIEditApp && (pathname.endsWith('configuration') || pathname.endsWith('workflow') || pathname.endsWith('logs'))) {
|
||||||
|
router.replace(`/app/${appId}/overview`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if ((res.mode === 'workflow' || res.mode === 'advanced-chat') && (pathname).endsWith('configuration')) {
|
||||||
|
router.replace(`/app/${appId}/workflow`)
|
||||||
|
}
|
||||||
|
else if ((res.mode !== 'workflow' && res.mode !== 'advanced-chat') && (pathname).endsWith('workflow')) {
|
||||||
|
router.replace(`/app/${appId}/configuration`)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setAppDetail({ ...res, enable_sso: false })
|
||||||
|
setNavigation(getNavigations(appId, isCurrentWorkspaceEditor, res.mode))
|
||||||
|
if (systemFeatures.enable_web_sso_switch_component && canIEditApp) {
|
||||||
|
fetchAppSSO({ appId }).then((ssoRes) => {
|
||||||
|
setAppDetail({ ...res, enable_sso: ssoRes.enabled })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [appDetailRes, appId, getNavigations, isCurrentWorkspaceEditor, isLoadingAppDetail, isLoadingCurrentWorkspace, pathname, router, setAppDetail, systemFeatures.enable_web_sso_switch_component])
|
||||||
|
|
||||||
useUnmount(() => {
|
useUnmount(() => {
|
||||||
setAppDetail()
|
setAppDetail()
|
||||||
|
@ -31,6 +31,7 @@ export type AppContextValue = {
|
|||||||
pageContainerRef: React.RefObject<HTMLDivElement>
|
pageContainerRef: React.RefObject<HTMLDivElement>
|
||||||
langeniusVersionInfo: LangGeniusVersionResponse
|
langeniusVersionInfo: LangGeniusVersionResponse
|
||||||
useSelector: typeof useSelector
|
useSelector: typeof useSelector
|
||||||
|
isLoadingCurrentWorkspace: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialLangeniusVersionInfo = {
|
const initialLangeniusVersionInfo = {
|
||||||
@ -77,6 +78,7 @@ const AppContext = createContext<AppContextValue>({
|
|||||||
pageContainerRef: createRef(),
|
pageContainerRef: createRef(),
|
||||||
langeniusVersionInfo: initialLangeniusVersionInfo,
|
langeniusVersionInfo: initialLangeniusVersionInfo,
|
||||||
useSelector,
|
useSelector,
|
||||||
|
isLoadingCurrentWorkspace: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
export function useSelector<T>(selector: (value: AppContextValue) => T): T {
|
export function useSelector<T>(selector: (value: AppContextValue) => T): T {
|
||||||
@ -92,7 +94,7 @@ export const AppContextProvider: FC<AppContextProviderProps> = ({ children }) =>
|
|||||||
|
|
||||||
const { data: appList, mutate: mutateApps } = useSWR({ url: '/apps', params: { page: 1, limit: 30, name: '' } }, fetchAppList)
|
const { data: appList, mutate: mutateApps } = useSWR({ url: '/apps', params: { page: 1, limit: 30, name: '' } }, fetchAppList)
|
||||||
const { data: userProfileResponse, mutate: mutateUserProfile } = useSWR({ url: '/account/profile', params: {} }, fetchUserProfile)
|
const { data: userProfileResponse, mutate: mutateUserProfile } = useSWR({ url: '/account/profile', params: {} }, fetchUserProfile)
|
||||||
const { data: currentWorkspaceResponse, mutate: mutateCurrentWorkspace } = useSWR({ url: '/workspaces/current', params: {} }, fetchCurrentWorkspace)
|
const { data: currentWorkspaceResponse, mutate: mutateCurrentWorkspace, isLoading: isLoadingCurrentWorkspace } = useSWR({ url: '/workspaces/current', params: {} }, fetchCurrentWorkspace)
|
||||||
|
|
||||||
const { data: systemFeatures } = useSWR({ url: '/console/system-features' }, getSystemFeatures, {
|
const { data: systemFeatures } = useSWR({ url: '/console/system-features' }, getSystemFeatures, {
|
||||||
fallbackData: defaultSystemFeatures,
|
fallbackData: defaultSystemFeatures,
|
||||||
@ -157,6 +159,7 @@ export const AppContextProvider: FC<AppContextProviderProps> = ({ children }) =>
|
|||||||
isCurrentWorkspaceEditor,
|
isCurrentWorkspaceEditor,
|
||||||
isCurrentWorkspaceDatasetOperator,
|
isCurrentWorkspaceDatasetOperator,
|
||||||
mutateCurrentWorkspace,
|
mutateCurrentWorkspace,
|
||||||
|
isLoadingCurrentWorkspace,
|
||||||
}}>
|
}}>
|
||||||
<div className='flex flex-col h-full overflow-y-auto'>
|
<div className='flex flex-col h-full overflow-y-auto'>
|
||||||
{globalThis.document?.body?.getAttribute('data-public-maintenance-notice') && <MaintenanceNotice />}
|
{globalThis.document?.body?.getAttribute('data-public-maintenance-notice') && <MaintenanceNotice />}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user