modify-retrieval-modal.tsx 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useRef, useState } from 'react'
  4. import { useClickAway } from 'ahooks'
  5. import { useTranslation } from 'react-i18next'
  6. import { XClose } from '@/app/components/base/icons/src/vender/line/general'
  7. import type { RetrievalConfig } from '@/types/app'
  8. import RetrievalMethodConfig from '@/app/components/datasets/common/retrieval-method-config'
  9. import EconomicalRetrievalMethodConfig from '@/app/components/datasets/common/economical-retrieval-method-config'
  10. import Button from '@/app/components/base/button'
  11. type Props = {
  12. indexMethod: string
  13. value: RetrievalConfig
  14. isShow: boolean
  15. onHide: () => void
  16. onSave: (value: RetrievalConfig) => void
  17. }
  18. const ModifyRetrievalModal: FC<Props> = ({
  19. indexMethod,
  20. value,
  21. isShow,
  22. onHide,
  23. onSave,
  24. }) => {
  25. const ref = useRef(null)
  26. const { t } = useTranslation()
  27. const [retrievalConfig, setRetrievalConfig] = useState(value)
  28. useClickAway(() => {
  29. if (ref)
  30. onHide()
  31. }, ref)
  32. if (!isShow)
  33. return null
  34. return (
  35. <div
  36. className='fixed top-16 right-2 flex flex-col bg-white border-[0.5px] border-gray-200 rounded-xl shadow-xl z-10'
  37. style={{
  38. width: 632,
  39. height: 'calc(100vh - 72px)',
  40. }}
  41. ref={ref}
  42. >
  43. <div className='shrink-0 flex justify-between items-center pl-6 pr-5 h-14 border-b border-b-gray-100'>
  44. <div className='text-base font-semibold text-gray-900'>
  45. <div>{t('datasetSettings.form.retrievalSetting.title')}</div>
  46. <div className='leading-[18px] text-xs font-normal text-gray-500'>
  47. <a target='_blank' href='https://docs.dify.ai/advanced/retrieval-augment' className='text-[#155eef]'>{t('datasetSettings.form.retrievalSetting.learnMore')}</a>
  48. {t('datasetSettings.form.retrievalSetting.description')}
  49. </div>
  50. </div>
  51. <div className='flex items-center'>
  52. <div
  53. onClick={onHide}
  54. className='flex justify-center items-center w-6 h-6 cursor-pointer'
  55. >
  56. <XClose className='w-4 h-4 text-gray-500' />
  57. </div>
  58. </div>
  59. </div>
  60. <div className='p-6 border-b' style={{
  61. borderBottom: 'rgba(0, 0, 0, 0.05)',
  62. }}>
  63. {indexMethod === 'high_quality'
  64. ? (
  65. <RetrievalMethodConfig
  66. value={retrievalConfig}
  67. onChange={setRetrievalConfig}
  68. />
  69. )
  70. : (
  71. <EconomicalRetrievalMethodConfig
  72. value={retrievalConfig}
  73. onChange={setRetrievalConfig}
  74. />
  75. )}
  76. </div>
  77. <div
  78. className='flex justify-end pt-6 px-6 border-t'
  79. style={{
  80. borderColor: 'rgba(0, 0, 0, 0.05)',
  81. }}
  82. >
  83. <Button className='mr-2 flex-shrink-0' onClick={onHide}>{t('common.operation.cancel')}</Button>
  84. <Button type='primary' className='flex-shrink-0' onClick={() => onSave(retrievalConfig)} >{t('common.operation.save')}</Button>
  85. </div>
  86. </div>
  87. )
  88. }
  89. export default React.memo(ModifyRetrievalModal)