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.

configure.tsx 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import {
  2. memo,
  3. useMemo,
  4. } from 'react'
  5. import {
  6. RiAddLine,
  7. } from '@remixicon/react'
  8. import { useTranslation } from 'react-i18next'
  9. import {
  10. PortalToFollowElem,
  11. PortalToFollowElemContent,
  12. PortalToFollowElemTrigger,
  13. } from '@/app/components/base/portal-to-follow-elem'
  14. import Button from '@/app/components/base/button'
  15. import {
  16. AddApiKeyButton,
  17. AddOAuthButton,
  18. } from '@/app/components/plugins/plugin-auth'
  19. import type { DataSourceAuth } from './types'
  20. import type {
  21. AddApiKeyButtonProps,
  22. AddOAuthButtonProps,
  23. PluginPayload,
  24. } from '@/app/components/plugins/plugin-auth/types'
  25. type ConfigureProps = {
  26. item: DataSourceAuth
  27. pluginPayload: PluginPayload
  28. onUpdate?: () => void
  29. disabled?: boolean
  30. }
  31. const Configure = ({
  32. item,
  33. pluginPayload,
  34. onUpdate,
  35. disabled,
  36. }: ConfigureProps) => {
  37. const { t } = useTranslation()
  38. const canApiKey = item.credential_schema?.length
  39. const oAuthData = item.oauth_schema || {}
  40. const canOAuth = oAuthData.client_schema?.length
  41. const oAuthButtonProps: AddOAuthButtonProps = useMemo(() => {
  42. return {
  43. buttonText: t('plugin.auth.addOAuth'),
  44. pluginPayload,
  45. }
  46. }, [pluginPayload, t])
  47. const apiKeyButtonProps: AddApiKeyButtonProps = useMemo(() => {
  48. return {
  49. pluginPayload,
  50. buttonText: t('plugin.auth.addApi'),
  51. }
  52. }, [pluginPayload, t])
  53. return (
  54. <>
  55. <PortalToFollowElem
  56. placement='bottom-end'
  57. offset={{
  58. mainAxis: 4,
  59. crossAxis: -4,
  60. }}
  61. >
  62. <PortalToFollowElemTrigger>
  63. <Button
  64. variant='secondary-accent'
  65. >
  66. <RiAddLine className='h-4 w-4' />
  67. {t('common.dataSource.configure')}
  68. </Button>
  69. </PortalToFollowElemTrigger>
  70. <PortalToFollowElemContent className='z-[61]'>
  71. <div className='w-[240px] space-y-1.5 rounded-xl border-[0.5px] border-components-panel-border bg-components-panel-bg-blur p-2 shadow-lg'>
  72. {
  73. !!canOAuth && (
  74. <AddOAuthButton
  75. {...oAuthButtonProps}
  76. onUpdate={onUpdate}
  77. oAuthData={{
  78. schema: oAuthData.client_schema || [],
  79. is_oauth_custom_client_enabled: oAuthData.is_oauth_custom_client_enabled,
  80. is_system_oauth_params_exists: oAuthData.is_system_oauth_params_exists,
  81. client_params: oAuthData.oauth_custom_client_params,
  82. redirect_uri: oAuthData.redirect_uri,
  83. }}
  84. disabled={disabled}
  85. />
  86. )
  87. }
  88. {
  89. !!canApiKey && !!canOAuth && (
  90. <div className='system-2xs-medium-uppercase flex h-4 items-center p-2 text-text-quaternary'>
  91. <div className='mr-2 h-[1px] grow bg-gradient-to-l from-[rgba(16,24,40,0.08)]' />
  92. OR
  93. <div className='ml-2 h-[1px] grow bg-gradient-to-r from-[rgba(16,24,40,0.08)]' />
  94. </div>
  95. )
  96. }
  97. {
  98. !!canApiKey && (
  99. <AddApiKeyButton
  100. {...apiKeyButtonProps}
  101. formSchemas={item.credential_schema}
  102. onUpdate={onUpdate}
  103. disabled={disabled}
  104. />
  105. )
  106. }
  107. </div>
  108. </PortalToFollowElemContent>
  109. </PortalToFollowElem>
  110. </>
  111. )
  112. }
  113. export default memo(Configure)