index.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import React from 'react'
  2. import {
  3. RiAddLine,
  4. // RiBookOpenLine, // zlwu12 2025-09-18 注释
  5. RiCloseLine,
  6. } from '@remixicon/react'
  7. import { useTranslation } from 'react-i18next'
  8. import ExternalKnowledgeAPICard from '../external-knowledge-api-card'
  9. import cn from '@/utils/classnames'
  10. import { useExternalKnowledgeApi } from '@/context/external-knowledge-api-context'
  11. import ActionButton from '@/app/components/base/action-button'
  12. import Button from '@/app/components/base/button'
  13. import Loading from '@/app/components/base/loading'
  14. import { useModalContext } from '@/context/modal-context'
  15. // zlwu12 2025-09-18 注释
  16. // import { useDocLink } from '@/context/i18n'
  17. type ExternalAPIPanelProps = {
  18. onClose: () => void
  19. }
  20. const ExternalAPIPanel: React.FC<ExternalAPIPanelProps> = ({ onClose }) => {
  21. const { t } = useTranslation()
  22. // zlwu12 2025-09-18 注释
  23. // const docLink = useDocLink()
  24. const { setShowExternalKnowledgeAPIModal } = useModalContext()
  25. const { externalKnowledgeApiList, mutateExternalKnowledgeApis, isLoading } = useExternalKnowledgeApi()
  26. const handleOpenExternalAPIModal = () => {
  27. setShowExternalKnowledgeAPIModal({
  28. payload: { name: '', settings: { endpoint: '', api_key: '' } },
  29. datasetBindings: [],
  30. onSaveCallback: () => {
  31. mutateExternalKnowledgeApis()
  32. },
  33. onCancelCallback: () => {
  34. mutateExternalKnowledgeApis()
  35. },
  36. isEditMode: false,
  37. })
  38. }
  39. return (
  40. <div
  41. tabIndex={-1}
  42. className={cn('absolute bottom-2 right-0 top-14 z-10 flex outline-none')}
  43. >
  44. <div
  45. className={cn(
  46. 'relative flex h-full w-[420px] flex-col rounded-l-2xl border border-components-panel-border bg-components-panel-bg-alt',
  47. )}
  48. >
  49. <div className='flex items-start self-stretch p-4 pb-0'>
  50. <div className='flex grow flex-col items-start gap-1'>
  51. <div className='system-xl-semibold self-stretch text-text-primary'>{t('dataset.externalAPIPanelTitle')}</div>
  52. <div className='body-xs-regular self-stretch text-text-tertiary'>{t('dataset.externalAPIPanelDescription')}</div>
  53. {/* zlwu12 2025-09-18 注释 */}
  54. {/* <a className='flex cursor-pointer items-center justify-center gap-1 self-stretch'
  55. href={docLink('/guides/knowledge-base/connect-external-knowledge-base')} target='_blank'>
  56. <RiBookOpenLine className='h-3 w-3 text-text-accent' />
  57. <div className='body-xs-regular grow text-text-accent'>{t('dataset.externalAPIPanelDocumentation')}</div>
  58. </a> */}
  59. </div>
  60. <div className='flex items-center'>
  61. <ActionButton onClick={() => onClose()}>
  62. <RiCloseLine className='h-4 w-4 text-text-tertiary' />
  63. </ActionButton>
  64. </div>
  65. </div>
  66. <div className='flex flex-col items-start justify-center gap-2 self-stretch px-4 py-3'>
  67. <Button
  68. variant={'primary'}
  69. className='flex items-center justify-center gap-0.5 px-3 py-2'
  70. onClick={handleOpenExternalAPIModal}
  71. >
  72. <RiAddLine className='h-4 w-4 text-components-button-primary-text' />
  73. <div className='system-sm-medium text-components-button-primary-text'>{t('dataset.createExternalAPI')}</div>
  74. </Button>
  75. </div>
  76. <div className='flex grow flex-col items-start gap-1 self-stretch px-4 py-0'>
  77. {isLoading
  78. ? (
  79. <Loading />
  80. )
  81. : (
  82. externalKnowledgeApiList.map(api => (
  83. <ExternalKnowledgeAPICard key={api.id} api={api} />
  84. ))
  85. )}
  86. </div>
  87. </div>
  88. </div>
  89. )
  90. }
  91. export default ExternalAPIPanel