hit-detail.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import cn from 'classnames'
  4. import { useTranslation } from 'react-i18next'
  5. import { SegmentIndexTag } from '../documents/detail/completed'
  6. import s from '../documents/detail/completed/style.module.css'
  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 segInfo?.content
  26. }
  27. return (
  28. <div className='overflow-x-auto'>
  29. <div className="bg-gray-25 p-6">
  30. <div className="flex items-center">
  31. <SegmentIndexTag
  32. positionId={segInfo?.position || ''}
  33. className="w-fit mr-6"
  34. />
  35. <div className={cn(s.commonIcon, s.typeSquareIcon)} />
  36. <span className={cn('mr-6', s.numberInfo)}>
  37. {segInfo?.word_count} {t('datasetDocuments.segment.characters')}
  38. </span>
  39. <div className={cn(s.commonIcon, s.targetIcon)} />
  40. <span className={s.numberInfo}>
  41. {segInfo?.hit_count} {t('datasetDocuments.segment.hitCount')}
  42. </span>
  43. </div>
  44. <Divider />
  45. <div className={s.segModalContent}>{renderContent()}</div>
  46. <div className={s.keywordTitle}>
  47. {t('datasetDocuments.segment.keywords')}
  48. </div>
  49. <div className={s.keywordWrapper}>
  50. {!segInfo?.keywords?.length
  51. ? '-'
  52. : segInfo?.keywords?.map((word, index) => {
  53. return <div key={index} className={s.keyword}>{word}</div>
  54. })}
  55. </div>
  56. </div>
  57. </div>
  58. )
  59. }
  60. export default HitDetail