chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,153 @@
|
||||
import type { StatusDotStatus } from '@langgenius/dify-ui/status-dot'
|
||||
import type { ComponentPropsWithRef } from 'react'
|
||||
import type { Credential, PluginPayload } from './types'
|
||||
import { Button } from '@langgenius/dify-ui/button'
|
||||
import { cn } from '@langgenius/dify-ui/cn'
|
||||
import { StatusDot } from '@langgenius/dify-ui/status-dot'
|
||||
import { RiArrowDownSLine } from '@remixicon/react'
|
||||
import { memo, useCallback, useEffect, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Authorized, usePluginAuth } from '.'
|
||||
|
||||
type AuthorizedInNodeProps = {
|
||||
pluginPayload: PluginPayload
|
||||
onAuthorizationItemClick: (id: string) => void
|
||||
credentialId?: string
|
||||
onDefaultCredentialChange?: (id?: string) => void
|
||||
}
|
||||
const AuthorizedInNode = ({
|
||||
pluginPayload,
|
||||
onAuthorizationItemClick,
|
||||
credentialId,
|
||||
onDefaultCredentialChange,
|
||||
}: AuthorizedInNodeProps) => {
|
||||
const { t } = useTranslation(['common', 'plugin'])
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
const {
|
||||
canApiKey,
|
||||
canOAuth,
|
||||
credentials,
|
||||
isLoading,
|
||||
invalidPluginCredentialInfo,
|
||||
notAllowCustomCredential,
|
||||
} = usePluginAuth(pluginPayload, true, credentialId ? [credentialId] : undefined)
|
||||
const defaultCredentialId = credentials.find((c) => c.is_default)?.id
|
||||
|
||||
useEffect(() => {
|
||||
onDefaultCredentialChange?.(defaultCredentialId)
|
||||
}, [defaultCredentialId, onDefaultCredentialChange])
|
||||
|
||||
const renderTrigger = useCallback(
|
||||
(open: boolean, triggerProps: ComponentPropsWithRef<'button'>) => {
|
||||
let label = ''
|
||||
let removed = false
|
||||
let unavailable = false
|
||||
let color: StatusDotStatus = 'success'
|
||||
let defaultUnavailable = false
|
||||
if (!credentialId) {
|
||||
label = t(($) => $['auth.workspaceDefault'], { ns: 'plugin' })
|
||||
|
||||
const defaultCredential = credentials.find((c) => c.is_default)
|
||||
|
||||
if (isLoading) {
|
||||
color = 'disabled'
|
||||
} else if (!defaultCredential) {
|
||||
color = 'error'
|
||||
defaultUnavailable = true
|
||||
} else if (defaultCredential.not_allowed_to_use) {
|
||||
color = 'disabled'
|
||||
defaultUnavailable = true
|
||||
}
|
||||
} else {
|
||||
const credential = credentials.find((c) => c.id === credentialId)
|
||||
if (credential) label = credential.name
|
||||
else if (isLoading) {
|
||||
label = t(($) => $.loading, { ns: 'common' })
|
||||
color = 'disabled'
|
||||
} else {
|
||||
label = t(($) => $['auth.authRemoved'], { ns: 'plugin' })
|
||||
removed = true
|
||||
}
|
||||
unavailable = !!credential?.not_allowed_to_use && !credential?.from_enterprise
|
||||
|
||||
if (removed) color = 'error'
|
||||
else if (unavailable) color = 'disabled'
|
||||
}
|
||||
return (
|
||||
<Button
|
||||
{...triggerProps}
|
||||
size="small"
|
||||
className={cn(
|
||||
triggerProps.className,
|
||||
open && !removed && 'bg-components-button-ghost-bg-hover',
|
||||
removed && 'bg-transparent text-text-destructive',
|
||||
)}
|
||||
variant={defaultUnavailable || unavailable ? 'ghost' : 'secondary'}
|
||||
>
|
||||
<StatusDot status={color} />
|
||||
{label}
|
||||
{(unavailable || defaultUnavailable) && (
|
||||
<>
|
||||
|
||||
{t(($) => $['auth.unavailable'], { ns: 'plugin' })}
|
||||
</>
|
||||
)}
|
||||
<RiArrowDownSLine
|
||||
className={cn(
|
||||
'size-3.5 text-components-button-ghost-text',
|
||||
removed && 'text-text-destructive',
|
||||
)}
|
||||
/>
|
||||
</Button>
|
||||
)
|
||||
},
|
||||
[credentialId, credentials, isLoading, t],
|
||||
)
|
||||
const defaultUnavailable = credentials.find((c) => c.is_default)?.not_allowed_to_use
|
||||
const extraAuthorizationItems: Credential[] = [
|
||||
{
|
||||
id: '__workspace_default__',
|
||||
name: t(($) => $['auth.workspaceDefault'], { ns: 'plugin' }),
|
||||
provider: '',
|
||||
is_default: !credentialId,
|
||||
isWorkspaceDefault: true,
|
||||
not_allowed_to_use: defaultUnavailable,
|
||||
},
|
||||
]
|
||||
const handleAuthorizationItemClick = useCallback(
|
||||
(id: string) => {
|
||||
onAuthorizationItemClick(
|
||||
id === '__workspace_default__' && onDefaultCredentialChange
|
||||
? defaultCredentialId || id
|
||||
: id,
|
||||
)
|
||||
setIsOpen(false)
|
||||
},
|
||||
[defaultCredentialId, onDefaultCredentialChange, onAuthorizationItemClick, setIsOpen],
|
||||
)
|
||||
|
||||
return (
|
||||
<Authorized
|
||||
pluginPayload={pluginPayload}
|
||||
credentials={credentials}
|
||||
canOAuth={canOAuth}
|
||||
canApiKey={canApiKey}
|
||||
renderTrigger={renderTrigger}
|
||||
isOpen={isOpen}
|
||||
onOpenChange={setIsOpen}
|
||||
sideOffset={4}
|
||||
align="end"
|
||||
triggerPopupSameWidth={false}
|
||||
popupClassName="w-[360px]"
|
||||
disableSetDefault
|
||||
onItemClick={handleAuthorizationItemClick}
|
||||
extraAuthorizationItems={extraAuthorizationItems}
|
||||
showItemSelectedIcon
|
||||
selectedCredentialId={credentialId || '__workspace_default__'}
|
||||
onUpdate={invalidPluginCredentialInfo}
|
||||
notAllowCustomCredential={notAllowCustomCredential}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export default memo(AuthorizedInNode)
|
||||
Reference in new issue
Block a user