mirror of https://github.com/langgenius/dify.git
fix(trigger): oauth client params
This commit is contained in:
parent
96f0b7abe3
commit
735ebf6c59
|
|
@ -311,7 +311,7 @@ const BaseField = ({
|
|||
<span className='break-all'>
|
||||
{renderI18nObject(formSchema?.help as any)}
|
||||
</span>
|
||||
<RiExternalLinkLine className='ml-1 h-3 w-3' />
|
||||
<RiExternalLinkLine className='ml-1 h-3 w-3 shrink-0' />
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ export const CreateSubscriptionButton = ({ buttonType = CreateButtonType.FULL_BU
|
|||
},
|
||||
{
|
||||
value: SupportedCreationMethods.MANUAL,
|
||||
label: t('pluginTrigger.subscription.addType.options.manual.description'), // 使用 description 作为标题
|
||||
label: t('pluginTrigger.subscription.addType.options.manual.description'),
|
||||
extra: <Tooltip popupContent={t('pluginTrigger.subscription.addType.options.manual.tip')} />,
|
||||
show: supportedMethods.includes(SupportedCreationMethods.MANUAL),
|
||||
},
|
||||
|
|
@ -109,7 +109,7 @@ export const CreateSubscriptionButton = ({ buttonType = CreateButtonType.FULL_BU
|
|||
if (callbackData) {
|
||||
Toast.notify({
|
||||
type: 'success',
|
||||
message: t('pluginTrigger.modal.oauth.authorized'),
|
||||
message: t('pluginTrigger.modal.oauth.authorization.authSuccess'),
|
||||
})
|
||||
setSelectedCreateInfo({ type: SupportedCreationMethods.OAUTH, builder: response.subscription_builder })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,26 +42,25 @@ enum ClientTypeEnum {
|
|||
export const OAuthClientSettingsModal = ({ oauthConfig, onClose, showOAuthCreateModal }: Props) => {
|
||||
const { t } = useTranslation()
|
||||
const detail = usePluginStore(state => state.detail)
|
||||
const { configured, custom_enabled, system_configured, params } = oauthConfig || {}
|
||||
const { system_configured, params, oauth_client_schema } = oauthConfig || {}
|
||||
const [subscriptionBuilder, setSubscriptionBuilder] = useState<TriggerSubscriptionBuilder | undefined>()
|
||||
const [authorizationStatus, setAuthorizationStatus] = useState<AuthorizationStatusEnum>()
|
||||
|
||||
const [clientType, setClientType] = useState<ClientTypeEnum>(((configured && !custom_enabled) || (!configured && system_configured)) ? ClientTypeEnum.Default : ClientTypeEnum.Custom)
|
||||
const [clientType, setClientType] = useState<ClientTypeEnum>(system_configured ? ClientTypeEnum.Default : ClientTypeEnum.Custom)
|
||||
|
||||
const clientFormRef = React.useRef<FormRefObject>(null)
|
||||
|
||||
const oauthClientSchema = useMemo(() => {
|
||||
if (detail && params) {
|
||||
const clientSchema = detail?.declaration.trigger?.subscription_constructor?.oauth_schema?.client_schema || []
|
||||
if (oauth_client_schema && oauth_client_schema.length > 0 && params) {
|
||||
const oauthConfigPramaKeys = Object.keys(params || {})
|
||||
for (const schema of clientSchema) {
|
||||
for (const schema of oauth_client_schema) {
|
||||
if (oauthConfigPramaKeys.includes(schema.name))
|
||||
schema.default = params?.[schema.name]
|
||||
}
|
||||
return clientSchema
|
||||
return oauth_client_schema
|
||||
}
|
||||
return []
|
||||
}, [detail, params])
|
||||
}, [oauth_client_schema, params])
|
||||
|
||||
const providerName = detail?.provider || ''
|
||||
const { mutate: initiateOAuth } = useInitiateTriggerOAuth()
|
||||
|
|
|
|||
|
|
@ -1,105 +0,0 @@
|
|||
'use client'
|
||||
import React, { useEffect, useRef } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { RiEqualizer2Line } from '@remixicon/react'
|
||||
import cn from '@/utils/classnames'
|
||||
import Tooltip from '@/app/components/base/tooltip'
|
||||
import { ActionButton } from '@/app/components/base/action-button'
|
||||
import { SupportedCreationMethods } from '../../../types'
|
||||
import type { TriggerOAuthConfig } from '@/app/components/workflow/block-selector/types'
|
||||
|
||||
type Props = {
|
||||
onSelect: (type: SupportedCreationMethods) => void
|
||||
onClose: () => void
|
||||
position?: 'bottom' | 'right'
|
||||
className?: string
|
||||
supportedMethods: SupportedCreationMethods[]
|
||||
oauthConfig?: TriggerOAuthConfig
|
||||
}
|
||||
|
||||
export const CreateTypeDropdown = ({ onSelect, onClose, position = 'bottom', className, supportedMethods }: Props) => {
|
||||
const { t } = useTranslation()
|
||||
const dropdownRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node))
|
||||
onClose()
|
||||
}
|
||||
|
||||
document.addEventListener('mousedown', handleClickOutside)
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside)
|
||||
}, [onClose])
|
||||
|
||||
const onClickClientSettings = () => {
|
||||
// todo: show client settings
|
||||
}
|
||||
|
||||
const allOptions = [
|
||||
{
|
||||
key: SupportedCreationMethods.OAUTH,
|
||||
title: t('pluginTrigger.subscription.addType.options.oauth.title'),
|
||||
extraContent: <ActionButton onClick={onClickClientSettings}><RiEqualizer2Line className='h-4 w-4 text-text-tertiary' /></ActionButton>,
|
||||
show: supportedMethods.includes(SupportedCreationMethods.OAUTH),
|
||||
},
|
||||
{
|
||||
key: SupportedCreationMethods.APIKEY,
|
||||
title: t('pluginTrigger.subscription.addType.options.apikey.title'),
|
||||
show: supportedMethods.includes(SupportedCreationMethods.APIKEY),
|
||||
},
|
||||
{
|
||||
key: SupportedCreationMethods.MANUAL,
|
||||
title: t('pluginTrigger.subscription.addType.options.manual.description'), // 使用 description 作为标题
|
||||
tooltip: t('pluginTrigger.subscription.addType.options.manual.tip'),
|
||||
show: supportedMethods.includes(SupportedCreationMethods.MANUAL),
|
||||
},
|
||||
]
|
||||
|
||||
const options = allOptions.filter(option => option.show)
|
||||
|
||||
const handleOptionClick = (type: SupportedCreationMethods) => {
|
||||
onSelect(type)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={dropdownRef}
|
||||
className={cn(
|
||||
'absolute z-50 w-full rounded-xl border-[0.5px] border-components-panel-border bg-white/95 p-1 shadow-xl backdrop-blur-sm',
|
||||
position === 'bottom'
|
||||
? 'left-1/2 top-full mt-2 -translate-x-1/2'
|
||||
: 'right-full top-0 mr-2',
|
||||
className,
|
||||
)}
|
||||
>
|
||||
|
||||
{options.map((option, index) => {
|
||||
return (
|
||||
<>
|
||||
{index === options.length - 1 && <div className="my-1 h-px bg-divider-subtle" />}
|
||||
<button
|
||||
key={option.key}
|
||||
onClick={() => handleOptionClick(option.key)}
|
||||
className={cn(
|
||||
'flex h-8 w-full items-center gap-1 rounded-lg px-2 py-1 text-left transition-colors hover:bg-state-base-hover',
|
||||
)}
|
||||
>
|
||||
<div className="system-md-regular grow truncate text-text-secondary">
|
||||
{option.title}
|
||||
</div>
|
||||
{
|
||||
option.tooltip && (
|
||||
<Tooltip
|
||||
popupContent={option.tooltip}
|
||||
triggerClassName='h-4 w-4 shrink-0'
|
||||
/>
|
||||
)
|
||||
}
|
||||
{option.extraContent ? option.extraContent : null}
|
||||
</button>
|
||||
</>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -266,6 +266,7 @@ export type TriggerOAuthConfig = {
|
|||
custom_configured: boolean
|
||||
custom_enabled: boolean
|
||||
redirect_uri: string
|
||||
oauth_client_schema: ParametersSchema[]
|
||||
params: {
|
||||
client_id: string
|
||||
client_secret: string
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ const translation = {
|
|||
listNum: '{{num}} subscriptions',
|
||||
empty: {
|
||||
title: 'No subscriptions',
|
||||
description: 'Create your first subscription to start receiving events',
|
||||
button: 'New subscription',
|
||||
},
|
||||
createButton: {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ const translation = {
|
|||
listNum: '{{num}} 个订阅',
|
||||
empty: {
|
||||
title: '暂无订阅',
|
||||
description: '创建您的第一个订阅以开始接收事件',
|
||||
button: '新建订阅',
|
||||
},
|
||||
createButton: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue