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.

index.tsx 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. const getProviderName = (): string => {
  41. if (provider === DataSourceProvider.fireCrawl) return '🔥 Firecrawl'
  42. if (provider === DataSourceProvider.waterCrawl) return 'WaterCrawl'
  43. return 'Jina Reader'
  44. }
  45. return (
  46. <div className='mb-2 rounded-xl bg-background-section-burn'>
  47. <div className='flex items-center px-3 py-[9px]'>
  48. <div className={cn(s[`${type}-icon`], 'mr-3 h-8 w-8 rounded-lg border border-divider-subtle !bg-background-default')} />
  49. <div className='grow'>
  50. <div className='flex h-5 items-center'>
  51. <div className='text-sm font-medium text-text-primary'>{t(`common.dataSource.${type}.title`)}</div>
  52. {isWebsite && (
  53. <div className='ml-1 rounded-md bg-components-badge-white-to-dark px-1.5 text-xs font-medium leading-[18px] text-text-secondary'>
  54. <span className='text-text-tertiary'>{t('common.dataSource.website.with')}</span> {getProviderName()}
  55. </div>
  56. )}
  57. </div>
  58. {
  59. !isConfigured && (
  60. <div className='system-xs-medium text-text-tertiary'>
  61. {t(`common.dataSource.${type}.description`)}
  62. </div>
  63. )
  64. }
  65. </div>
  66. {isNotion && (
  67. <>
  68. {
  69. isConfigured
  70. ? (
  71. <Button
  72. disabled={readOnly}
  73. className='ml-3'
  74. onClick={onConfigure}
  75. >
  76. {t('common.dataSource.configure')}
  77. </Button>
  78. )
  79. : (
  80. <>
  81. {isSupportList && <div
  82. className={
  83. `system-sm-medium flex min-h-7 items-center rounded-md border-[0.5px] border-components-button-secondary-border bg-components-button-secondary-bg px-3 py-1 text-components-button-secondary-accent-text
  84. ${!readOnly ? 'cursor-pointer' : 'cursor-default opacity-50 grayscale'}`
  85. }
  86. onClick={onConfigure}
  87. >
  88. <RiAddLine className='mr-[5px] h-4 w-4 text-components-button-secondary-accent-text' />
  89. {t('common.dataSource.connect')}
  90. </div>}
  91. </>
  92. )
  93. }
  94. </>
  95. )}
  96. {isWebsite && !isConfigured && (
  97. <div
  98. className={
  99. `ml-3 flex h-7 items-center rounded-md border-[0.5px] border-components-button-secondary-border bg-components-button-secondary-bg
  100. px-3 text-xs font-medium text-components-button-secondary-accent-text
  101. ${!readOnly ? 'cursor-pointer' : 'cursor-default opacity-50 grayscale'}`
  102. }
  103. onClick={!readOnly ? onConfigure : undefined}
  104. >
  105. {t('common.dataSource.configure')}
  106. </div>
  107. )}
  108. </div>
  109. {
  110. isConfigured && (
  111. <>
  112. <div className='flex h-[18px] items-center px-3'>
  113. <div className='system-xs-medium text-text-tertiary'>
  114. {isNotion ? t('common.dataSource.notion.connectedWorkspace') : t('common.dataSource.website.configuredCrawlers')}
  115. </div>
  116. <div className='ml-3 grow border-t border-t-divider-subtle' />
  117. </div>
  118. <div className='px-3 pb-3 pt-2'>
  119. {
  120. configuredList.map(item => (
  121. <ConfigItem
  122. key={item.id}
  123. type={type}
  124. payload={item}
  125. onRemove={onRemove}
  126. notionActions={notionActions}
  127. readOnly={readOnly}
  128. />
  129. ))
  130. }
  131. </div>
  132. </>
  133. )
  134. }
  135. </div>
  136. )
  137. }
  138. export default React.memo(Panel)