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.

install-from-marketplace.tsx 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import {
  2. memo,
  3. useCallback,
  4. useState,
  5. } from 'react'
  6. import { useTheme } from 'next-themes'
  7. import { useTranslation } from 'react-i18next'
  8. import Link from 'next/link'
  9. import {
  10. RiArrowDownSLine,
  11. RiArrowRightUpLine,
  12. } from '@remixicon/react'
  13. import {
  14. useMarketplaceAllPlugins,
  15. } from './hooks'
  16. import Divider from '@/app/components/base/divider'
  17. import Loading from '@/app/components/base/loading'
  18. import ProviderCard from '@/app/components/plugins/provider-card'
  19. import List from '@/app/components/plugins/marketplace/list'
  20. import type { Plugin } from '@/app/components/plugins/types'
  21. import cn from '@/utils/classnames'
  22. import { getLocaleOnClient } from '@/i18n-config'
  23. import { getMarketplaceUrl } from '@/utils/var'
  24. type InstallFromMarketplaceProps = {
  25. providers: any[]
  26. searchText: string
  27. }
  28. const InstallFromMarketplace = ({
  29. providers,
  30. searchText,
  31. }: InstallFromMarketplaceProps) => {
  32. const { t } = useTranslation()
  33. const { theme } = useTheme()
  34. const [collapse, setCollapse] = useState(false)
  35. const locale = getLocaleOnClient()
  36. const {
  37. plugins: allPlugins,
  38. isLoading: isAllPluginsLoading,
  39. } = useMarketplaceAllPlugins(providers, searchText)
  40. const cardRender = useCallback((plugin: Plugin) => {
  41. if (plugin.type === 'bundle')
  42. return null
  43. return <ProviderCard key={plugin.plugin_id} payload={plugin} />
  44. }, [])
  45. return (
  46. <div className='mb-2'>
  47. <Divider className='!mt-4 h-px' />
  48. <div className='flex items-center justify-between'>
  49. <div className='system-md-semibold flex cursor-pointer items-center gap-1 text-text-primary' onClick={() => setCollapse(!collapse)}>
  50. <RiArrowDownSLine className={cn('h-4 w-4', collapse && '-rotate-90')} />
  51. {t('common.modelProvider.installDataSourceProvider')}
  52. </div>
  53. <div className='mb-2 flex items-center pt-2'>
  54. <span className='system-sm-regular pr-1 text-text-tertiary'>{t('common.modelProvider.discoverMore')}</span>
  55. <Link target="_blank" href={getMarketplaceUrl('', { theme })} className='system-sm-medium inline-flex items-center text-text-accent'>
  56. {t('plugin.marketplace.difyMarketplace')}
  57. <RiArrowRightUpLine className='h-4 w-4' />
  58. </Link>
  59. </div>
  60. </div>
  61. {!collapse && isAllPluginsLoading && <Loading type='area' />}
  62. {
  63. !isAllPluginsLoading && !collapse && (
  64. <List
  65. marketplaceCollections={[]}
  66. marketplaceCollectionPluginsMap={{}}
  67. plugins={allPlugins}
  68. showInstallButton
  69. locale={locale}
  70. cardContainerClassName='grid grid-cols-2 gap-2'
  71. cardRender={cardRender}
  72. emptyClassName='h-auto'
  73. />
  74. )
  75. }
  76. </div>
  77. )
  78. }
  79. export default memo(InstallFromMarketplace)