You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rule-detail.tsx 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import React, { useCallback } from 'react'
  2. import { IndexingType } from '@/app/components/datasets/create/step-two'
  3. import { ProcessMode, type ProcessRuleResponse } from '@/models/datasets'
  4. import { RETRIEVE_METHOD } from '@/types/app'
  5. import { useTranslation } from 'react-i18next'
  6. import { FieldInfo } from '@/app/components/datasets/documents/detail/metadata'
  7. import Image from 'next/image'
  8. import { indexMethodIcon, retrievalIcon } from '@/app/components/datasets/create/icons'
  9. type RuleDetailProps = {
  10. sourceData?: ProcessRuleResponse
  11. indexingType?: IndexingType
  12. retrievalMethod?: RETRIEVE_METHOD
  13. }
  14. const RuleDetail = ({
  15. sourceData,
  16. indexingType,
  17. retrievalMethod,
  18. }: RuleDetailProps) => {
  19. const { t } = useTranslation()
  20. const getValue = useCallback((field: string) => {
  21. let value = '-'
  22. switch (field) {
  23. case 'mode':
  24. value = !sourceData?.mode
  25. ? value
  26. // eslint-disable-next-line sonarjs/no-nested-conditional
  27. : sourceData.mode === ProcessMode.general
  28. ? (t('datasetDocuments.embedding.custom') as string)
  29. // eslint-disable-next-line sonarjs/no-nested-conditional
  30. : `${t('datasetDocuments.embedding.hierarchical')} · ${sourceData?.rules?.parent_mode === 'paragraph'
  31. ? t('dataset.parentMode.paragraph')
  32. : t('dataset.parentMode.fullDoc')}`
  33. break
  34. }
  35. return value
  36. }, [sourceData, t])
  37. return (
  38. <div className='flex flex-col gap-1'>
  39. <FieldInfo
  40. label={t('datasetDocuments.embedding.mode')}
  41. displayedValue={getValue('mode')}
  42. />
  43. <FieldInfo
  44. label={t('datasetCreation.stepTwo.indexMode')}
  45. displayedValue={t(`datasetCreation.stepTwo.${indexingType === IndexingType.ECONOMICAL ? 'economical' : 'qualified'}`) as string}
  46. valueIcon={
  47. <Image
  48. className='size-4'
  49. src={
  50. indexingType === IndexingType.ECONOMICAL
  51. ? indexMethodIcon.economical
  52. : indexMethodIcon.high_quality
  53. }
  54. alt=''
  55. />
  56. }
  57. />
  58. <FieldInfo
  59. label={t('datasetSettings.form.retrievalSetting.title')}
  60. displayedValue={t(`dataset.retrieval.${indexingType === IndexingType.ECONOMICAL ? 'keyword_search' : retrievalMethod}.title`) as string}
  61. valueIcon={
  62. <Image
  63. className='size-4'
  64. src={
  65. retrievalMethod === RETRIEVE_METHOD.fullText
  66. ? retrievalIcon.fullText
  67. // eslint-disable-next-line sonarjs/no-nested-conditional
  68. : retrievalMethod === RETRIEVE_METHOD.hybrid
  69. ? retrievalIcon.hybrid
  70. : retrievalIcon.vector
  71. }
  72. alt=''
  73. />
  74. }
  75. />
  76. </div>
  77. )
  78. }
  79. export default React.memo(RuleDetail)