Commit 5afa5fb0 authored by JzoNg's avatar JzoNg

app switch

parent 93e2dc4f
...@@ -257,7 +257,7 @@ const AppInfo = ({ expand }: IAppInfoProps) => { ...@@ -257,7 +257,7 @@ const AppInfo = ({ expand }: IAppInfoProps) => {
</div> </div>
</> </>
)} )}
{(appDetail.mode === 'completion' || appDetail.model_config?.prompt_type === 'advanced') && ( {(appDetail.mode === 'completion' || appDetail.mode === 'chat') && (
<> <>
<Divider className="!my-1" /> <Divider className="!my-1" />
<div <div
......
import React, { useCallback, useEffect, useState } from 'react' import React, { useEffect, useState } from 'react'
import NavLink from './navLink' import NavLink from './navLink'
import type { NavIcon } from './navLink' import type { NavIcon } from './navLink'
import AppBasic from './basic' import AppBasic from './basic'
...@@ -32,13 +32,9 @@ const AppDetailNav = ({ title, desc, icon, icon_background, navigation, extraInf ...@@ -32,13 +32,9 @@ const AppDetailNav = ({ title, desc, icon, icon_background, navigation, extraInf
const [modeState, setModeState] = useState(appSidebarExpand) const [modeState, setModeState] = useState(appSidebarExpand)
const expand = modeState === 'expand' const expand = modeState === 'expand'
const handleToggle = useCallback(() => { const handleToggle = (state: string) => {
setModeState((prev) => { setAppSiderbarExpand(state === 'expand' ? 'collapse' : 'expand')
const next = prev === 'expand' ? 'collapse' : 'expand' }
setAppSiderbarExpand(next)
return next
})
}, [setAppSiderbarExpand])
useEffect(() => { useEffect(() => {
if (appSidebarExpand) { if (appSidebarExpand) {
...@@ -100,7 +96,7 @@ const AppDetailNav = ({ title, desc, icon, icon_background, navigation, extraInf ...@@ -100,7 +96,7 @@ const AppDetailNav = ({ title, desc, icon, icon_background, navigation, extraInf
> >
<div <div
className='flex items-center justify-center w-6 h-6 text-gray-500 cursor-pointer' className='flex items-center justify-center w-6 h-6 text-gray-500 cursor-pointer'
onClick={handleToggle} onClick={() => handleToggle(modeState)}
> >
{ {
expand expand
......
...@@ -9,7 +9,7 @@ import s from './style.module.css' ...@@ -9,7 +9,7 @@ import s from './style.module.css'
import Button from '@/app/components/base/button' import Button from '@/app/components/base/button'
import Modal from '@/app/components/base/modal' import Modal from '@/app/components/base/modal'
import { ToastContext } from '@/app/components/base/toast' import { ToastContext } from '@/app/components/base/toast'
import { importApp } from '@/service/apps' import { deleteApp, switchApp } from '@/service/apps'
import { useAppContext } from '@/context/app-context' import { useAppContext } from '@/context/app-context'
import { useProviderContext } from '@/context/provider-context' import { useProviderContext } from '@/context/provider-context'
import AppsFull from '@/app/components/billing/apps-full-in-dialog' import AppsFull from '@/app/components/billing/apps-full-in-dialog'
...@@ -29,7 +29,7 @@ type SwitchAppModalProps = { ...@@ -29,7 +29,7 @@ type SwitchAppModalProps = {
} }
const SwitchAppModal = ({ show, appDetail, onSuccess, onClose }: SwitchAppModalProps) => { const SwitchAppModal = ({ show, appDetail, onSuccess, onClose }: SwitchAppModalProps) => {
const { push } = useRouter() const { push, replace } = useRouter()
const { t } = useTranslation() const { t } = useTranslation()
const { notify } = useContext(ToastContext) const { notify } = useContext(ToastContext)
...@@ -43,18 +43,21 @@ const SwitchAppModal = ({ show, appDetail, onSuccess, onClose }: SwitchAppModalP ...@@ -43,18 +43,21 @@ const SwitchAppModal = ({ show, appDetail, onSuccess, onClose }: SwitchAppModalP
const [removeOriginal, setRemoveOriginal] = useState<boolean>(false) const [removeOriginal, setRemoveOriginal] = useState<boolean>(false)
const goStart = async () => { const goStart = async () => {
// ###TODO### SWITCH
try { try {
const app = await importApp({ const { new_app_id: newAppID } = await switchApp(appDetail.id)
data: '',
})
if (onSuccess) if (onSuccess)
onSuccess() onSuccess()
if (onClose) if (onClose)
onClose() onClose()
notify({ type: 'success', message: t('app.newApp.appCreated') }) notify({ type: 'success', message: t('app.newApp.appCreated') })
if (removeOriginal)
await deleteApp(appDetail.id)
localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1') localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1')
getRedirection(isCurrentWorkspaceManager, app, push) getRedirection(
isCurrentWorkspaceManager,
{ id: newAppID },
removeOriginal ? replace : push,
)
} }
catch (e) { catch (e) {
notify({ type: 'error', message: t('app.newApp.appCreateFailed') }) notify({ type: 'error', message: t('app.newApp.appCreateFailed') })
......
...@@ -18,7 +18,7 @@ const DetailPanel: FC<ILogDetail> = ({ runID, onClose }) => { ...@@ -18,7 +18,7 @@ const DetailPanel: FC<ILogDetail> = ({ runID, onClose }) => {
<XClose className='w-4 h-4 text-gray-500' /> <XClose className='w-4 h-4 text-gray-500' />
</span> </span>
<h1 className='shrink-0 px-4 py-1 text-md font-semibold text-gray-900'>{t('appLog.runDetail.workflowTitle')}</h1> <h1 className='shrink-0 px-4 py-1 text-md font-semibold text-gray-900'>{t('appLog.runDetail.workflowTitle')}</h1>
<Run activeTab='RESULT' runID={runID}/> <Run activeTab='TRACING' runID={runID}/>
</div> </div>
) )
} }
......
...@@ -38,7 +38,7 @@ const RunPanel: FC<RunProps> = ({ activeTab, runID }) => { ...@@ -38,7 +38,7 @@ const RunPanel: FC<RunProps> = ({ activeTab, runID }) => {
{/* panel detal */} {/* panel detal */}
<div className={cn('grow bg-white h-0 overflow-y-auto', currentTab === 'TRACING' && '!bg-gray-50')}> <div className={cn('grow bg-white h-0 overflow-y-auto', currentTab === 'TRACING' && '!bg-gray-50')}>
{currentTab === 'RESULT' && <Result runID={runID} />} {currentTab === 'RESULT' && <Result runID={runID} />}
{currentTab === 'TRACING' && <Tracing />} {currentTab === 'TRACING' && <Tracing runID={runID} />}
</div> </div>
</div> </div>
) )
......
'use client' 'use client'
import type { FC } from 'react' import type { FC } from 'react'
import React, { useState } from 'react' import React, { useState } from 'react'
import { useTranslation } from 'react-i18next' // import { useTranslation } from 'react-i18next'
// import cn from 'classnames' // import cn from 'classnames'
import { BlockEnum } from '../types' import { BlockEnum } from '../types'
import NodePanel from './node' import NodePanel from './node'
type TracingProps = { type TracingProps = {
// appId: string runID: string
} }
const nodeInfoFake = { const nodeInfoFake = {
...@@ -18,8 +18,8 @@ const nodeInfoFake = { ...@@ -18,8 +18,8 @@ const nodeInfoFake = {
status: 'succeeded', status: 'succeeded',
} }
const Tracing: FC<TracingProps> = () => { const Tracing: FC<TracingProps> = ({ runID }) => {
const { t } = useTranslation() // const { t } = useTranslation()
const [nodeCollapsed, setCurrentTab] = useState<boolean>(false) const [nodeCollapsed, setCurrentTab] = useState<boolean>(false)
const collapseStateChange = () => { const collapseStateChange = () => {
......
...@@ -36,6 +36,10 @@ export const importApp: Fetcher<AppDetailResponse, { data: string; name?: string ...@@ -36,6 +36,10 @@ export const importApp: Fetcher<AppDetailResponse, { data: string; name?: string
return post<AppDetailResponse>('apps/import', { body: { name, description, icon, icon_background } }) return post<AppDetailResponse>('apps/import', { body: { name, description, icon, icon_background } })
} }
export const switchApp: Fetcher<{ new_app_id: string }, string> = (appID) => {
return post<{ new_app_id: string }>(`apps/${appID}/convert-to-workflow`)
}
export const deleteApp: Fetcher<CommonResponse, string> = (appID) => { export const deleteApp: Fetcher<CommonResponse, string> = (appID) => {
return del<CommonResponse>(`apps/${appID}`) return del<CommonResponse>(`apps/${appID}`)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment