hit-detail.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import cn from 'classnames'
  4. import { useTranslation } from 'react-i18next'
  5. import ReactECharts from 'echarts-for-react'
  6. import { SegmentIndexTag } from '../documents/detail/completed'
  7. import s from '../documents/detail/completed/style.module.css'
  8. import type { SegmentDetailModel } from '@/models/datasets'
  9. import Divider from '@/app/components/base/divider'
  10. type IScatterChartProps = {
  11. data: Array<number[]>
  12. curr: Array<number[]>
  13. }
  14. const ScatterChart: FC<IScatterChartProps> = ({ data, curr }) => {
  15. const option = {
  16. xAxis: {},
  17. yAxis: {},
  18. tooltip: {
  19. trigger: 'item',
  20. axisPointer: {
  21. type: 'cross',
  22. },
  23. },
  24. series: [
  25. {
  26. type: 'effectScatter',
  27. symbolSize: 5,
  28. data: curr,
  29. },
  30. {
  31. type: 'scatter',
  32. symbolSize: 5,
  33. data,
  34. },
  35. ],
  36. }
  37. return (
  38. <ReactECharts option={option} style={{ height: 380, width: 430 }} />
  39. )
  40. }
  41. type IHitDetailProps = {
  42. segInfo?: Partial<SegmentDetailModel> & { id: string }
  43. vectorInfo?: { curr: Array<number[]>; points: Array<number[]> }
  44. }
  45. const HitDetail: FC<IHitDetailProps> = ({ segInfo, vectorInfo }) => {
  46. const { t } = useTranslation()
  47. const renderContent = () => {
  48. if (segInfo?.answer) {
  49. return (
  50. <>
  51. <div className='mt-2 mb-1 text-xs font-medium text-gray-500'>QUESTION</div>
  52. <div className='mb-4 text-md text-gray-800'>{segInfo.content}</div>
  53. <div className='mb-1 text-xs font-medium text-gray-500'>ANSWER</div>
  54. <div className='text-md text-gray-800'>{segInfo.answer}</div>
  55. </>
  56. )
  57. }
  58. return segInfo?.content
  59. }
  60. return (
  61. <div className='flex flex-row overflow-x-auto'>
  62. <div className="flex-1 bg-gray-25 p-6 min-w-[300px]">
  63. <div className="flex items-center">
  64. <SegmentIndexTag
  65. positionId={segInfo?.position || ''}
  66. className="w-fit mr-6"
  67. />
  68. <div className={cn(s.commonIcon, s.typeSquareIcon)} />
  69. <span className={cn('mr-6', s.numberInfo)}>
  70. {segInfo?.word_count} {t('datasetDocuments.segment.characters')}
  71. </span>
  72. <div className={cn(s.commonIcon, s.targetIcon)} />
  73. <span className={s.numberInfo}>
  74. {segInfo?.hit_count} {t('datasetDocuments.segment.hitCount')}
  75. </span>
  76. </div>
  77. <Divider />
  78. <div className={s.segModalContent}>{renderContent()}</div>
  79. <div className={s.keywordTitle}>
  80. {t('datasetDocuments.segment.keywords')}
  81. </div>
  82. <div className={s.keywordWrapper}>
  83. {!segInfo?.keywords?.length
  84. ? '-'
  85. : segInfo?.keywords?.map((word, index) => {
  86. return <div key={index} className={s.keyword}>{word}</div>
  87. })}
  88. </div>
  89. </div>
  90. <div className="flex-1 bg-white p-6">
  91. <div className="flex items-center">
  92. <div className={cn(s.commonIcon, s.bezierCurveIcon)} />
  93. <span className={s.numberInfo}>
  94. {t('datasetDocuments.segment.vectorHash')}
  95. </span>
  96. </div>
  97. <div
  98. className={cn(s.numberInfo, 'w-[400px] truncate text-gray-700 mt-1')}
  99. >
  100. {segInfo?.index_node_hash}
  101. </div>
  102. <ScatterChart data={vectorInfo?.points || []} curr={vectorInfo?.curr || []} />
  103. </div>
  104. </div>
  105. )
  106. }
  107. export default HitDetail