index.tsx 4.7 KB

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