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 rounded-xl bg-background-section-burn'>
  42. <div className='flex items-center px-3 py-[9px]'>
  43. <div className={cn(s[`${type}-icon`], 'mr-3 h-8 w-8 rounded-lg border border-divider-subtle !bg-background-default')} />
  44. <div className='grow'>
  45. <div className='flex h-5 items-center'>
  46. <div className='text-sm font-medium text-text-primary'>{t(`common.dataSource.${type}.title`)}</div>
  47. {isWebsite && (
  48. <div className='ml-1 rounded-md bg-components-badge-white-to-dark px-1.5 text-xs font-medium leading-[18px] 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. `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
  79. ${!readOnly ? 'cursor-pointer' : 'cursor-default opacity-50 grayscale'}`
  80. }
  81. onClick={onConfigure}
  82. >
  83. <RiAddLine className='mr-[5px] h-4 w-4 text-components-button-secondary-accent-text' />
  84. {t('common.dataSource.connect')}
  85. </div>}
  86. </>
  87. )
  88. }
  89. </>
  90. )}
  91. {isWebsite && !isConfigured && (
  92. <div
  93. className={
  94. `ml-3 flex h-7 items-center rounded-md border-[0.5px] border-components-button-secondary-border bg-components-button-secondary-bg
  95. px-3 text-xs font-medium text-components-button-secondary-accent-text
  96. ${!readOnly ? 'cursor-pointer' : 'cursor-default opacity-50 grayscale'}`
  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 h-[18px] items-center px-3'>
  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='ml-3 grow border-t border-t-divider-subtle' />
  112. </div>
  113. <div className='px-3 pb-3 pt-2'>
  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)