mirror of https://github.com/langgenius/dify.git
add store of app detail
This commit is contained in:
parent
eab405af5b
commit
186b85cd62
|
|
@ -6,6 +6,7 @@ import cn from 'classnames'
|
|||
import useSWR from 'swr'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import s from './style.module.css'
|
||||
import { useStore } from '@/app/components/app/store'
|
||||
import AppSideBar from '@/app/components/app-sidebar'
|
||||
import { fetchAppDetail } from '@/service/apps'
|
||||
import { useAppContext } from '@/context/app-context'
|
||||
|
|
@ -27,14 +28,9 @@ const AppDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
|
|||
const pathname = usePathname()
|
||||
const { isCurrentWorkspaceManager } = useAppContext()
|
||||
const detailParams = { url: '/apps', id: appId }
|
||||
const { appDetail, setAppDetail } = useStore()
|
||||
const { data: response } = useSWR(detailParams, fetchAppDetail)
|
||||
|
||||
// redirections
|
||||
if (response && (response?.mode === 'workflow' || response?.mode === 'advanced-chat') && (pathname).endsWith('configuration'))
|
||||
router.replace(`/app/${appId}/workflow`)
|
||||
if (response && (response?.mode !== 'workflow' && response?.mode !== 'advanced-chat') && (pathname).endsWith('workflow'))
|
||||
router.replace(`/app/${appId}/configuration`)
|
||||
|
||||
const appModeName = (() => {
|
||||
if (response?.mode === 'chat' || response?.mode === 'advanced-chat')
|
||||
return t('app.types.chatbot')
|
||||
|
|
@ -86,10 +82,19 @@ const AppDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
|
|||
useEffect(() => {
|
||||
if (response?.name)
|
||||
document.title = `${(response.name || 'App')} - Dify`
|
||||
}, [response])
|
||||
if (response && response !== appDetail)
|
||||
setAppDetail(response)
|
||||
}, [appDetail, response, setAppDetail])
|
||||
|
||||
if (!response)
|
||||
return null
|
||||
|
||||
// redirections
|
||||
if (response && (response?.mode === 'workflow' || response?.mode === 'advanced-chat') && (pathname).endsWith('configuration'))
|
||||
router.replace(`/app/${appId}/workflow`)
|
||||
if (response && (response?.mode !== 'workflow' && response?.mode !== 'advanced-chat') && (pathname).endsWith('workflow'))
|
||||
router.replace(`/app/${appId}/configuration`)
|
||||
|
||||
return (
|
||||
<div className={cn(s.app, 'flex', 'overflow-hidden')}>
|
||||
<AppSideBar title={response.name} icon={response.icon} icon_background={response.icon_background} desc={appModeName} navigation={navigation} />
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import type { HtmlContentProps } from '@/app/components/base/popover'
|
|||
import CustomPopover from '@/app/components/base/popover'
|
||||
import Divider from '@/app/components/base/divider'
|
||||
import { asyncRunSafe } from '@/utils'
|
||||
import { getRedirection } from '@/utils/app-redirection'
|
||||
import { useProviderContext } from '@/context/provider-context'
|
||||
import { NEED_REFRESH_APP_LIST_KEY } from '@/config'
|
||||
|
||||
|
|
@ -207,8 +208,7 @@ const AppCard = ({ app, onRefresh }: AppCardProps) => {
|
|||
if (showSettingsModal)
|
||||
return
|
||||
e.preventDefault()
|
||||
|
||||
push(`/app/${app.id}/${isCurrentWorkspaceManager ? 'configuration' : 'overview'}`)
|
||||
getRedirection(isCurrentWorkspaceManager, app, push)
|
||||
}}
|
||||
className={style.listItem}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
import { create } from 'zustand'
|
||||
import type { App } from '@/types/app'
|
||||
|
||||
type State = {
|
||||
appDetail?: App
|
||||
}
|
||||
|
||||
type Action = {
|
||||
setAppDetail: (appDetail: App) => void
|
||||
}
|
||||
|
||||
export const useStore = create<State & Action>(set => ({
|
||||
appDetail: undefined,
|
||||
setAppDetail: appDetail => set(() => ({ appDetail })),
|
||||
}))
|
||||
|
|
@ -34,6 +34,7 @@ import {
|
|||
fetchWorkflowDraft,
|
||||
syncWorkflowDraft,
|
||||
} from '@/service/workflow'
|
||||
import { useStore as useAppStore } from '@/app/components/app/store'
|
||||
import Loading from '@/app/components/base/loading'
|
||||
import { FeaturesProvider } from '@/app/components/base/features'
|
||||
|
||||
|
|
@ -118,6 +119,9 @@ const WorkflowWrap: FC<WorkflowProps> = ({
|
|||
nodes,
|
||||
edges,
|
||||
}) => {
|
||||
const appDetail = useAppStore(state => state.appDetail)
|
||||
console.log(appDetail?.name)
|
||||
console.log(appDetail?.description)
|
||||
const appId = useParams().appId
|
||||
const { data, isLoading, error } = useSWR(`/apps/${appId}/workflows/draft`, fetchWorkflowDraft)
|
||||
const nodesInitialData = useNodesInitialData()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
export const getRedirection = (
|
||||
isCurrentWorkspaceManager: boolean,
|
||||
app: any,
|
||||
redirectionFunc: (href: string) => void,
|
||||
) => {
|
||||
if (!isCurrentWorkspaceManager) {
|
||||
redirectionFunc(`/app/${app.id}/overview`)
|
||||
}
|
||||
else {
|
||||
if (app.mode === 'workflow' || app.mode === 'advanced-chat')
|
||||
redirectionFunc(`/app/${app.id}/workflow`)
|
||||
else
|
||||
redirectionFunc(`/app/${app.id}/configuration`)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue