Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
186b85cd
Commit
186b85cd
authored
Mar 05, 2024
by
JzoNg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add store of app detail
parent
eab405af
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
9 deletions
+48
-9
layout.tsx
...p/(commonLayout)/app/(appDetailLayout)/[appId]/layout.tsx
+12
-7
AppCard.tsx
web/app/(commonLayout)/apps/AppCard.tsx
+2
-2
store.ts
web/app/components/app/store.ts
+15
-0
index.tsx
web/app/components/workflow/index.tsx
+4
-0
app-redirection.ts
web/utils/app-redirection.ts
+15
-0
No files found.
web/app/(commonLayout)/app/(appDetailLayout)/[appId]/layout.tsx
View file @
186b85cd
...
...
@@ -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
}
/>
...
...
web/app/(commonLayout)/apps/AppCard.tsx
View file @
186b85cd
...
...
@@ -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
}
>
...
...
web/app/components/app/store.ts
0 → 100644
View file @
186b85cd
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
})),
}))
web/app/components/workflow/index.tsx
View file @
186b85cd
...
...
@@ -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
()
...
...
web/utils/app-redirection.ts
0 → 100644
View file @
186b85cd
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`
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment