index.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import cn from 'classnames'
  5. import { useTranslation } from 'react-i18next'
  6. import { useRouter } from 'next/navigation'
  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/app/configuration/toolbox/annotation/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 = [
  24. { value: PageType.log, text: t('appLog.title') },
  25. { value: PageType.annotation, text: t('appAnnotation.title') },
  26. ]
  27. if (!appDetail) {
  28. return (
  29. <div className='flex h-full items-center justify-center bg-white'>
  30. <Loading />
  31. </div>
  32. )
  33. }
  34. return (
  35. <div className='pt-4 px-6 h-full flex flex-col'>
  36. {appDetail.mode !== 'workflow' && (
  37. <TabSlider
  38. className='shrink-0'
  39. value={pageType}
  40. onChange={(value) => {
  41. router.push(`/app/${appDetail.id}/${value === PageType.log ? 'logs' : 'annotations'}`)
  42. }}
  43. options={options}
  44. />
  45. )}
  46. <div className={cn('grow', appDetail.mode !== 'workflow' && 'mt-3')}>
  47. {pageType === PageType.log && appDetail.mode !== 'workflow' && (<Log appDetail={appDetail} />)}
  48. {pageType === PageType.annotation && (<Annotation appDetail={appDetail} />)}
  49. {pageType === PageType.log && appDetail.mode === 'workflow' && (<WorkflowLog appDetail={appDetail} />)}
  50. </div>
  51. </div>
  52. )
  53. }
  54. export default React.memo(LogAnnotation)