index.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useMemo } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import { useRouter } from 'next/navigation'
  6. import cn from '@/utils/classnames'
  7. import Log from '@/app/components/app/log'
  8. import WorkflowLog from '@/app/components/app/workflow-log'
  9. import Annotation from '@/app/components/app/annotation'
  10. import Loading from '@/app/components/base/loading'
  11. import { PageType } from '@/app/components/base/features/new-feature-panel/annotation-reply/type'
  12. import TabSlider from '@/app/components/base/tab-slider-plain'
  13. import { useStore as useAppStore } from '@/app/components/app/store'
  14. type Props = {
  15. pageType: PageType
  16. }
  17. const LogAnnotation: FC<Props> = ({
  18. pageType,
  19. }) => {
  20. const { t } = useTranslation()
  21. const router = useRouter()
  22. const appDetail = useAppStore(state => state.appDetail)
  23. const options = useMemo(() => {
  24. if (appDetail?.mode === 'completion')
  25. return [{ value: PageType.log, text: t('appLog.title') }]
  26. return [
  27. { value: PageType.log, text: t('appLog.title') },
  28. { value: PageType.annotation, text: t('appAnnotation.title') },
  29. ]
  30. }, [appDetail])
  31. if (!appDetail) {
  32. return (
  33. <div className='flex h-full items-center justify-center bg-white'>
  34. <Loading />
  35. </div>
  36. )
  37. }
  38. return (
  39. <div className='pt-3 px-6 h-full flex flex-col'>
  40. {appDetail.mode !== 'workflow' && (
  41. <TabSlider
  42. className='shrink-0'
  43. value={pageType}
  44. onChange={(value) => {
  45. router.push(`/app/${appDetail.id}/${value === PageType.log ? 'logs' : 'annotations'}`)
  46. }}
  47. options={options}
  48. />
  49. )}
  50. <div className={cn('grow h-0', appDetail.mode !== 'workflow' && 'mt-3')}>
  51. {pageType === PageType.log && appDetail.mode !== 'workflow' && (<Log appDetail={appDetail} />)}
  52. {pageType === PageType.annotation && (<Annotation appDetail={appDetail} />)}
  53. {pageType === PageType.log && appDetail.mode === 'workflow' && (<WorkflowLog appDetail={appDetail} />)}
  54. </div>
  55. </div>
  56. )
  57. }
  58. export default React.memo(LogAnnotation)