index.tsx 3.5 KB

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