index.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import { RiAddLine } from '@remixicon/react'
  6. import type { ConfigItemType } from './config-item'
  7. import ConfigItem from './config-item'
  8. import s from './style.module.css'
  9. import { DataSourceType } from './types'
  10. import Button from '@/app/components/base/button'
  11. import { DataSourceProvider } from '@/models/common'
  12. import cn from '@/utils/classnames'
  13. type Props = {
  14. type: DataSourceType
  15. provider?: DataSourceProvider
  16. isConfigured: boolean
  17. onConfigure: () => void
  18. readOnly: boolean
  19. isSupportList?: boolean
  20. configuredList: ConfigItemType[]
  21. onRemove: () => void
  22. notionActions?: {
  23. onChangeAuthorizedPage: () => void
  24. }
  25. }
  26. const Panel: FC<Props> = ({
  27. type,
  28. provider,
  29. isConfigured,
  30. onConfigure,
  31. readOnly,
  32. configuredList,
  33. isSupportList,
  34. onRemove,
  35. notionActions,
  36. }) => {
  37. const { t } = useTranslation()
  38. const isNotion = type === DataSourceType.notion
  39. const isWebsite = type === DataSourceType.website
  40. return (
  41. <div className='mb-2 bg-background-section-burn rounded-xl'>
  42. <div className='flex items-center px-3 py-[9px]'>
  43. <div className={cn(s[`${type}-icon`], 'w-8 h-8 mr-3 border border-divider-subtle rounded-lg !bg-background-default')} />
  44. <div className='grow'>
  45. <div className='flex items-center h-5'>
  46. <div className='text-sm font-medium text-text-primary'>{t(`common.dataSource.${type}.title`)}</div>
  47. {isWebsite && (
  48. <div className='ml-1 leading-[18px] px-1.5 rounded-md bg-components-badge-white-to-dark text-xs font-medium text-text-secondary'>
  49. <span className='text-text-tertiary'>{t('common.dataSource.website.with')}</span> { provider === DataSourceProvider.fireCrawl ? '🔥 Firecrawl' : 'Jina Reader'}
  50. </div>
  51. )}
  52. </div>
  53. {
  54. !isConfigured && (
  55. <div className='system-xs-medium text-text-tertiary'>
  56. {t(`common.dataSource.${type}.description`)}
  57. </div>
  58. )
  59. }
  60. </div>
  61. {isNotion && (
  62. <>
  63. {
  64. isConfigured
  65. ? (
  66. <Button
  67. disabled={readOnly}
  68. className='ml-3'
  69. onClick={onConfigure}
  70. >
  71. {t('common.dataSource.configure')}
  72. </Button>
  73. )
  74. : (
  75. <>
  76. {isSupportList && <div
  77. className={
  78. `flex items-center px-3 py-1 min-h-7 bg-components-button-secondary-bg border-[0.5px] border-components-button-secondary-border system-sm-medium text-components-button-secondary-accent-text rounded-md
  79. ${!readOnly ? 'cursor-pointer' : 'grayscale opacity-50 cursor-default'}`
  80. }
  81. onClick={onConfigure}
  82. >
  83. <RiAddLine className='w-4 h-4 text-components-button-secondary-accent-text mr-[5px]' />
  84. {t('common.dataSource.connect')}
  85. </div>}
  86. </>
  87. )
  88. }
  89. </>
  90. )}
  91. {isWebsite && !isConfigured && (
  92. <div
  93. className={
  94. `flex items-center ml-3 px-3 h-7 bg-components-button-secondary-bg border-[0.5px] border-components-button-secondary-border
  95. rounded-md text-xs font-medium text-components-button-secondary-accent-text
  96. ${!readOnly ? 'cursor-pointer' : 'grayscale opacity-50 cursor-default'}`
  97. }
  98. onClick={!readOnly ? onConfigure : undefined}
  99. >
  100. {t('common.dataSource.configure')}
  101. </div>
  102. )}
  103. </div>
  104. {
  105. isConfigured && (
  106. <>
  107. <div className='flex items-center px-3 h-[18px]'>
  108. <div className='system-xs-medium text-text-tertiary'>
  109. {isNotion ? t('common.dataSource.notion.connectedWorkspace') : t('common.dataSource.website.configuredCrawlers')}
  110. </div>
  111. <div className='grow ml-3 border-t border-t-divider-subtle' />
  112. </div>
  113. <div className='px-3 pt-2 pb-3'>
  114. {
  115. configuredList.map(item => (
  116. <ConfigItem
  117. key={item.id}
  118. type={type}
  119. payload={item}
  120. onRemove={onRemove}
  121. notionActions={notionActions}
  122. readOnly={readOnly}
  123. />
  124. ))
  125. }
  126. </div>
  127. </>
  128. )
  129. }
  130. </div>
  131. )
  132. }
  133. export default React.memo(Panel)