mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-05-30 10:05:15 +08:00
fix: fix chatbot publish and restore handling (#15462)
This commit is contained in:
parent
ed5596a8f4
commit
b6b1903a37
@ -45,6 +45,7 @@ export type AppPublisherProps = {
|
|||||||
multipleModelConfigs?: ModelAndParameter[]
|
multipleModelConfigs?: ModelAndParameter[]
|
||||||
/** modelAndParameter is passed when debugWithMultipleModel is true */
|
/** modelAndParameter is passed when debugWithMultipleModel is true */
|
||||||
onPublish?: (params?: any) => Promise<any> | any
|
onPublish?: (params?: any) => Promise<any> | any
|
||||||
|
onRestore?: () => Promise<any> | any
|
||||||
onToggle?: (state: boolean) => void
|
onToggle?: (state: boolean) => void
|
||||||
crossAxisOffset?: number
|
crossAxisOffset?: number
|
||||||
toolPublished?: boolean
|
toolPublished?: boolean
|
||||||
@ -62,6 +63,7 @@ const AppPublisher = ({
|
|||||||
debugWithMultipleModel = false,
|
debugWithMultipleModel = false,
|
||||||
multipleModelConfigs = [],
|
multipleModelConfigs = [],
|
||||||
onPublish,
|
onPublish,
|
||||||
|
onRestore,
|
||||||
onToggle,
|
onToggle,
|
||||||
crossAxisOffset = 0,
|
crossAxisOffset = 0,
|
||||||
toolPublished,
|
toolPublished,
|
||||||
@ -76,13 +78,14 @@ const AppPublisher = ({
|
|||||||
const { app_base_url: appBaseURL = '', access_token: accessToken = '' } = appDetail?.site ?? {}
|
const { app_base_url: appBaseURL = '', access_token: accessToken = '' } = appDetail?.site ?? {}
|
||||||
const appMode = (appDetail?.mode !== 'completion' && appDetail?.mode !== 'workflow') ? 'chat' : appDetail.mode
|
const appMode = (appDetail?.mode !== 'completion' && appDetail?.mode !== 'workflow') ? 'chat' : appDetail.mode
|
||||||
const appURL = `${appBaseURL}/${appMode}/${accessToken}`
|
const appURL = `${appBaseURL}/${appMode}/${accessToken}`
|
||||||
|
const isChatApp = ['chat', 'agent-chat', 'completion'].includes(appDetail?.mode || '')
|
||||||
|
|
||||||
const language = useGetLanguage()
|
const language = useGetLanguage()
|
||||||
const formatTimeFromNow = useCallback((time: number) => {
|
const formatTimeFromNow = useCallback((time: number) => {
|
||||||
return dayjs(time).locale(language === 'zh_Hans' ? 'zh-cn' : language.replace('_', '-')).fromNow()
|
return dayjs(time).locale(language === 'zh_Hans' ? 'zh-cn' : language.replace('_', '-')).fromNow()
|
||||||
}, [language])
|
}, [language])
|
||||||
|
|
||||||
const handlePublish = async (params?: ModelAndParameter | PublishWorkflowParams) => {
|
const handlePublish = useCallback(async (params?: ModelAndParameter | PublishWorkflowParams) => {
|
||||||
try {
|
try {
|
||||||
await onPublish?.(params)
|
await onPublish?.(params)
|
||||||
setPublished(true)
|
setPublished(true)
|
||||||
@ -90,7 +93,15 @@ const AppPublisher = ({
|
|||||||
catch {
|
catch {
|
||||||
setPublished(false)
|
setPublished(false)
|
||||||
}
|
}
|
||||||
}
|
}, [onPublish])
|
||||||
|
|
||||||
|
const handleRestore = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
await onRestore?.()
|
||||||
|
setOpen(false)
|
||||||
|
}
|
||||||
|
catch {}
|
||||||
|
}, [onRestore])
|
||||||
|
|
||||||
const handleTrigger = useCallback(() => {
|
const handleTrigger = useCallback(() => {
|
||||||
const state = !open
|
const state = !open
|
||||||
@ -122,20 +133,27 @@ const AppPublisher = ({
|
|||||||
|
|
||||||
const [embeddingModalOpen, setEmbeddingModalOpen] = useState(false)
|
const [embeddingModalOpen, setEmbeddingModalOpen] = useState(false)
|
||||||
|
|
||||||
const openPublishModal = () => {
|
const openPublishModal = useCallback(() => {
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
setPublishModalOpen(true)
|
setPublishModalOpen(true)
|
||||||
}
|
}, [])
|
||||||
|
|
||||||
const closePublishModal = () => {
|
const closePublishModal = useCallback(() => {
|
||||||
setPublishModalOpen(false)
|
setPublishModalOpen(false)
|
||||||
}
|
}, [])
|
||||||
|
|
||||||
|
const onClickPublishBtn = useCallback(() => {
|
||||||
|
if (isChatApp)
|
||||||
|
handlePublish()
|
||||||
|
else
|
||||||
|
openPublishModal()
|
||||||
|
}, [isChatApp, handlePublish, openPublishModal])
|
||||||
|
|
||||||
useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.shift.p`, (e) => {
|
useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.shift.p`, (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (publishDisabled || published)
|
if (publishDisabled || published)
|
||||||
return
|
return
|
||||||
openPublishModal()
|
onClickPublishBtn()
|
||||||
}
|
}
|
||||||
, { exactMatch: true, useCapture: true })
|
, { exactMatch: true, useCapture: true })
|
||||||
|
|
||||||
@ -168,8 +186,18 @@ const AppPublisher = ({
|
|||||||
</div>
|
</div>
|
||||||
{publishedAt
|
{publishedAt
|
||||||
? (
|
? (
|
||||||
<div className='flex items-center system-sm-medium text-text-secondary'>
|
<div className='flex justify-between items-center'>
|
||||||
{t('workflow.common.publishedAt')} {formatTimeFromNow(publishedAt)}
|
<div className='flex items-center system-sm-medium text-text-secondary'>
|
||||||
|
{t('workflow.common.publishedAt')} {formatTimeFromNow(publishedAt)}
|
||||||
|
</div>
|
||||||
|
{isChatApp && <Button
|
||||||
|
variant='secondary-accent'
|
||||||
|
size='small'
|
||||||
|
onClick={handleRestore}
|
||||||
|
disabled={published}
|
||||||
|
>
|
||||||
|
{t('workflow.common.restore')}
|
||||||
|
</Button>}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
: (
|
: (
|
||||||
@ -189,7 +217,7 @@ const AppPublisher = ({
|
|||||||
<Button
|
<Button
|
||||||
variant='primary'
|
variant='primary'
|
||||||
className='w-full mt-3'
|
className='w-full mt-3'
|
||||||
onClick={openPublishModal}
|
onClick={onClickPublishBtn}
|
||||||
disabled={publishDisabled || published}
|
disabled={publishDisabled || published}
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user