hit-detail.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import { SegmentIndexTag } from '../documents/detail/completed'
  5. import s from '../documents/detail/completed/style.module.css'
  6. import cn from '@/utils/classnames'
  7. import type { SegmentDetailModel } from '@/models/datasets'
  8. import Divider from '@/app/components/base/divider'
  9. type IHitDetailProps = {
  10. segInfo?: Partial<SegmentDetailModel> & { id: string }
  11. }
  12. const HitDetail: FC<IHitDetailProps> = ({ segInfo }) => {
  13. const { t } = useTranslation()
  14. const renderContent = () => {
  15. if (segInfo?.answer) {
  16. return (
  17. <>
  18. <div className='mt-2 mb-1 text-xs font-medium text-gray-500'>QUESTION</div>
  19. <div className='mb-4 text-md text-gray-800'>{segInfo.content}</div>
  20. <div className='mb-1 text-xs font-medium text-gray-500'>ANSWER</div>
  21. <div className='text-md text-gray-800'>{segInfo.answer}</div>
  22. </>
  23. )
  24. }
  25. return <div className='mb-4 text-md text-gray-800 h-full'>{segInfo?.content}</div>
  26. }
  27. return (
  28. segInfo?.id === 'external'
  29. ? <div className='w-full overflow-x-auto px-2'>
  30. <div className={s.segModalContent}>{renderContent()}</div>
  31. </div>
  32. : <div className='overflow-x-auto'>
  33. <div className="flex items-center">
  34. <SegmentIndexTag
  35. positionId={segInfo?.position || ''}
  36. className="w-fit mr-6"
  37. />
  38. <div className={cn(s.commonIcon, s.typeSquareIcon)} />
  39. <span className={cn('mr-6', s.numberInfo)}>
  40. {segInfo?.word_count} {t('datasetDocuments.segment.characters')}
  41. </span>
  42. <div className={cn(s.commonIcon, s.targetIcon)} />
  43. <span className={s.numberInfo}>
  44. {segInfo?.hit_count} {t('datasetDocuments.segment.hitCount')}
  45. </span>
  46. </div>
  47. <Divider />
  48. <div className={s.segModalContent}>{renderContent()}</div>
  49. <div className={s.keywordTitle}>
  50. {t('datasetDocuments.segment.keywords')}
  51. </div>
  52. <div className={s.keywordWrapper}>
  53. {!segInfo?.keywords?.length
  54. ? '-'
  55. : segInfo?.keywords?.map((word, index) => {
  56. return <div key={index} className={s.keyword}>{word}</div>
  57. })}
  58. </div>
  59. </div>
  60. )
  61. }
  62. export default HitDetail