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,81 @@
|
||||
import { cleanup, render, screen } from '@testing-library/react'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vite-plus/test'
|
||||
import DeprecationNotice from '../deprecation-notice'
|
||||
|
||||
vi.mock('@/next/link', () => ({
|
||||
default: ({ children, href }: { children: React.ReactNode; href: string }) => (
|
||||
<a data-testid="link" href={href}>
|
||||
{children}
|
||||
</a>
|
||||
),
|
||||
}))
|
||||
|
||||
describe('DeprecationNotice', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
})
|
||||
|
||||
it('returns null when status is not "deleted"', () => {
|
||||
const { container } = render(
|
||||
<DeprecationNotice
|
||||
status="active"
|
||||
deprecatedReason="business_adjustments"
|
||||
alternativePluginId="alt-plugin"
|
||||
alternativePluginURL="/plugins/alt-plugin"
|
||||
/>,
|
||||
)
|
||||
expect(container.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('renders deprecation notice when status is "deleted"', () => {
|
||||
render(
|
||||
<DeprecationNotice
|
||||
status="deleted"
|
||||
deprecatedReason=""
|
||||
alternativePluginId=""
|
||||
alternativePluginURL=""
|
||||
/>,
|
||||
)
|
||||
expect(screen.getByText('plugin.detailPanel.deprecation.noReason')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders with valid reason and alternative plugin', () => {
|
||||
render(
|
||||
<DeprecationNotice
|
||||
status="deleted"
|
||||
deprecatedReason="business_adjustments"
|
||||
alternativePluginId="better-plugin"
|
||||
alternativePluginURL="/plugins/better-plugin"
|
||||
/>,
|
||||
)
|
||||
expect(screen.getByText('plugin.detailPanel.deprecation.fullMessage')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders only reason without alternative plugin', () => {
|
||||
render(
|
||||
<DeprecationNotice
|
||||
status="deleted"
|
||||
deprecatedReason="no_maintainer"
|
||||
alternativePluginId=""
|
||||
alternativePluginURL=""
|
||||
/>,
|
||||
)
|
||||
expect(screen.getByText(/plugin\.detailPanel\.deprecation\.onlyReason/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders no-reason message for invalid reason', () => {
|
||||
render(
|
||||
<DeprecationNotice
|
||||
status="deleted"
|
||||
deprecatedReason="unknown_reason"
|
||||
alternativePluginId=""
|
||||
alternativePluginURL=""
|
||||
/>,
|
||||
)
|
||||
expect(screen.getByText('plugin.detailPanel.deprecation.noReason')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,35 @@
|
||||
import { render, screen, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { describe, expect, it, vi } from 'vite-plus/test'
|
||||
import KeyValueItem from '../key-value-item'
|
||||
|
||||
const mockCopy = vi.fn()
|
||||
vi.mock('copy-to-clipboard', () => ({
|
||||
default: (...args: unknown[]) => mockCopy(...args),
|
||||
}))
|
||||
|
||||
describe('KeyValueItem', () => {
|
||||
it('renders label and value', () => {
|
||||
render(<KeyValueItem label="ID" value="abc-123" />)
|
||||
expect(screen.getByText('ID')).toBeInTheDocument()
|
||||
expect(screen.getByText('abc-123')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('associates the label with the copy action and announces the result', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<KeyValueItem label="Key" value="sk-secret" maskedValue="sk-***" />)
|
||||
expect(screen.getByText('sk-***')).toBeInTheDocument()
|
||||
expect(screen.queryByText('sk-secret')).not.toBeInTheDocument()
|
||||
|
||||
const keyGroup = screen.getByRole('group', { name: 'Key' })
|
||||
const copyButton = within(keyGroup).getByRole('button', {
|
||||
name: 'common.operation.copy: Key',
|
||||
})
|
||||
|
||||
await user.click(copyButton)
|
||||
|
||||
expect(mockCopy).toHaveBeenCalledWith('sk-secret')
|
||||
expect(copyButton).toHaveAccessibleName('common.operation.copy: Key')
|
||||
expect(within(keyGroup).getByRole('status')).toHaveTextContent('common.operation.copied: Key')
|
||||
})
|
||||
})
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { describe, expect, it } from 'vite-plus/test'
|
||||
import { Theme } from '@/types/app'
|
||||
import IconWithTooltip from '../icon-with-tooltip'
|
||||
|
||||
describe('IconWithTooltip', () => {
|
||||
it('exposes the badge meaning without opening the tooltip', () => {
|
||||
render(
|
||||
<IconWithTooltip
|
||||
theme={Theme.light}
|
||||
lightIconClassName="i-custom-public-plugins-partner-light"
|
||||
darkIconClassName="i-custom-public-plugins-partner-dark"
|
||||
popupContent="Partner plugin"
|
||||
/>,
|
||||
)
|
||||
|
||||
expect(screen.getByText('Partner plugin')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { FC } from 'react'
|
||||
import { cn } from '@langgenius/dify-ui/cn'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@langgenius/dify-ui/tooltip'
|
||||
import * as React from 'react'
|
||||
import { Theme } from '@/types/app'
|
||||
|
||||
type IconWithTooltipProps = {
|
||||
className?: string
|
||||
popupContent?: string
|
||||
theme: Theme
|
||||
lightIconClassName: string
|
||||
darkIconClassName: string
|
||||
}
|
||||
|
||||
const IconWithTooltip: FC<IconWithTooltipProps> = ({
|
||||
className,
|
||||
theme,
|
||||
popupContent,
|
||||
lightIconClassName,
|
||||
darkIconClassName,
|
||||
}) => {
|
||||
const isDark = theme === Theme.dark
|
||||
const iconClassName = cn(isDark ? darkIconClassName : lightIconClassName, 'size-5', className)
|
||||
const icon = (
|
||||
<span className="flex shrink-0 items-center justify-center">
|
||||
<span aria-hidden className={iconClassName} />
|
||||
{popupContent && <span className="sr-only">{popupContent}</span>}
|
||||
</span>
|
||||
)
|
||||
|
||||
if (!popupContent) return icon
|
||||
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger render={icon} />
|
||||
<TooltipContent>{popupContent}</TooltipContent>
|
||||
</Tooltip>
|
||||
)
|
||||
}
|
||||
|
||||
export default React.memo(IconWithTooltip)
|
||||
@@ -0,0 +1,26 @@
|
||||
'use client'
|
||||
|
||||
import type { FC } from 'react'
|
||||
import useTheme from '@/hooks/use-theme'
|
||||
import IconWithTooltip from './icon-with-tooltip'
|
||||
|
||||
type PartnerProps = {
|
||||
className?: string
|
||||
text: string
|
||||
}
|
||||
|
||||
const Partner: FC<PartnerProps> = ({ className, text }) => {
|
||||
const { theme } = useTheme()
|
||||
|
||||
return (
|
||||
<IconWithTooltip
|
||||
className={className}
|
||||
theme={theme}
|
||||
lightIconClassName={'i-custom-public-plugins-partner-light'}
|
||||
darkIconClassName={'i-custom-public-plugins-partner-dark'}
|
||||
popupContent={text}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export default Partner
|
||||
@@ -0,0 +1,24 @@
|
||||
import type { FC } from 'react'
|
||||
import useTheme from '@/hooks/use-theme'
|
||||
import IconWithTooltip from './icon-with-tooltip'
|
||||
|
||||
type VerifiedProps = {
|
||||
className?: string
|
||||
text: string
|
||||
}
|
||||
|
||||
const Verified: FC<VerifiedProps> = ({ className, text }) => {
|
||||
const { theme } = useTheme()
|
||||
|
||||
return (
|
||||
<IconWithTooltip
|
||||
className={className}
|
||||
theme={theme}
|
||||
lightIconClassName={'i-custom-public-plugins-verified-light'}
|
||||
darkIconClassName={'i-custom-public-plugins-verified-dark'}
|
||||
popupContent={text}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export default Verified
|
||||
@@ -0,0 +1,96 @@
|
||||
import type { FC } from 'react'
|
||||
import { Alert, AlertTitle } from '@langgenius/dify-ui/alert'
|
||||
import { camelCase } from 'es-toolkit/string'
|
||||
import * as React from 'react'
|
||||
import { useMemo } from 'react'
|
||||
import { Trans } from 'react-i18next'
|
||||
import { useTranslation } from '#i18n'
|
||||
import Link from '@/next/link'
|
||||
|
||||
type DeprecationNoticeProps = {
|
||||
status: 'deleted' | 'active'
|
||||
deprecatedReason: string
|
||||
alternativePluginId: string
|
||||
alternativePluginURL: string
|
||||
className?: string
|
||||
}
|
||||
|
||||
const i18nPrefix = 'detailPanel.deprecation'
|
||||
|
||||
type DeprecatedReasonKey = 'businessAdjustments' | 'ownershipTransferred' | 'noMaintainer'
|
||||
const validReasonKeys: DeprecatedReasonKey[] = [
|
||||
'businessAdjustments',
|
||||
'ownershipTransferred',
|
||||
'noMaintainer',
|
||||
]
|
||||
|
||||
function isValidReasonKey(key: string): key is DeprecatedReasonKey {
|
||||
return (validReasonKeys as string[]).includes(key)
|
||||
}
|
||||
|
||||
const DeprecationNotice: FC<DeprecationNoticeProps> = ({
|
||||
status,
|
||||
deprecatedReason,
|
||||
alternativePluginId,
|
||||
alternativePluginURL,
|
||||
className,
|
||||
}) => {
|
||||
const { t } = useTranslation(['plugin'])
|
||||
|
||||
const deprecatedReasonKey = useMemo(() => {
|
||||
if (!deprecatedReason) return null
|
||||
const key = camelCase(deprecatedReason)
|
||||
if (isValidReasonKey(key)) return key
|
||||
return null
|
||||
}, [deprecatedReason])
|
||||
|
||||
// Check if the deprecatedReasonKey exists in i18n
|
||||
const hasValidDeprecatedReason = deprecatedReasonKey !== null
|
||||
|
||||
if (status !== 'deleted') return null
|
||||
|
||||
return (
|
||||
<Alert type="warning" className={className}>
|
||||
<AlertTitle>
|
||||
{hasValidDeprecatedReason && alternativePluginId && (
|
||||
<Trans
|
||||
t={t}
|
||||
i18nKey={($) => $[`${i18nPrefix}.fullMessage`]}
|
||||
ns="plugin"
|
||||
components={{
|
||||
CustomLink: (
|
||||
<Link
|
||||
href={alternativePluginURL}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="underline"
|
||||
/>
|
||||
),
|
||||
}}
|
||||
values={{
|
||||
deprecatedReason: deprecatedReasonKey
|
||||
? t(($) => $[`${i18nPrefix}.reason.${deprecatedReasonKey}`], { ns: 'plugin' })
|
||||
: '',
|
||||
alternativePluginId,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{hasValidDeprecatedReason && !alternativePluginId && (
|
||||
<span>
|
||||
{t(($) => $[`${i18nPrefix}.onlyReason`], {
|
||||
ns: 'plugin',
|
||||
deprecatedReason: deprecatedReasonKey
|
||||
? t(($) => $[`${i18nPrefix}.reason.${deprecatedReasonKey}`], { ns: 'plugin' })
|
||||
: '',
|
||||
})}
|
||||
</span>
|
||||
)}
|
||||
{!hasValidDeprecatedReason && (
|
||||
<span>{t(($) => $[`${i18nPrefix}.noReason`], { ns: 'plugin' })}</span>
|
||||
)}
|
||||
</AlertTitle>
|
||||
</Alert>
|
||||
)
|
||||
}
|
||||
|
||||
export default React.memo(DeprecationNotice)
|
||||
@@ -0,0 +1,94 @@
|
||||
'use client'
|
||||
import { cn } from '@langgenius/dify-ui/cn'
|
||||
import { IconButton } from '@langgenius/dify-ui/icon-button'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@langgenius/dify-ui/tooltip'
|
||||
import copy from 'copy-to-clipboard'
|
||||
import { useCallback, useEffect, useId, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
type Props = Readonly<{
|
||||
label: string
|
||||
labelWidthClassName?: string
|
||||
value: string
|
||||
maskedValue?: string
|
||||
valueMaxWidthClassName?: string
|
||||
}>
|
||||
|
||||
function KeyValueItem({
|
||||
label,
|
||||
labelWidthClassName = 'w-10',
|
||||
value,
|
||||
maskedValue,
|
||||
valueMaxWidthClassName = 'max-w-[162px]',
|
||||
}: Props) {
|
||||
const { t } = useTranslation(['common'])
|
||||
const [isCopied, setIsCopied] = useState(false)
|
||||
const labelId = useId()
|
||||
const handleCopy = useCallback(() => {
|
||||
copy(value)
|
||||
setIsCopied(true)
|
||||
}, [value])
|
||||
|
||||
useEffect(() => {
|
||||
if (isCopied) {
|
||||
const timer = setTimeout(() => {
|
||||
setIsCopied(false)
|
||||
}, 2000)
|
||||
return () => {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}
|
||||
}, [isCopied])
|
||||
|
||||
const copiedLabel = t(($) => $['operation.copied'], { ns: 'common' })
|
||||
const copyLabel = t(($) => $['operation.copy'], { ns: 'common' })
|
||||
const copyButtonLabel = `${copyLabel}: ${label}`
|
||||
const copyStatus = `${copiedLabel}: ${label}`
|
||||
const tooltipLabel = isCopied ? copiedLabel : copyLabel
|
||||
|
||||
return (
|
||||
<div role="group" aria-labelledby={labelId} className="flex items-center gap-1">
|
||||
<span
|
||||
id={labelId}
|
||||
className={cn(
|
||||
'flex flex-col items-start justify-center system-xs-medium text-text-tertiary',
|
||||
labelWidthClassName,
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
</span>
|
||||
<div className="flex items-center justify-center gap-0.5">
|
||||
<span
|
||||
className={cn(valueMaxWidthClassName, 'truncate system-xs-medium text-text-secondary')}
|
||||
>
|
||||
{maskedValue || value}
|
||||
</span>
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<IconButton aria-label={copyButtonLabel} onClick={handleCopy}>
|
||||
{isCopied ? (
|
||||
<span
|
||||
aria-hidden
|
||||
className="i-custom-vender-line-files-copy-check size-3.5 shrink-0 text-text-tertiary"
|
||||
/>
|
||||
) : (
|
||||
<span
|
||||
aria-hidden
|
||||
className="i-ri-clipboard-line size-3.5 shrink-0 text-text-tertiary"
|
||||
/>
|
||||
)}
|
||||
</IconButton>
|
||||
}
|
||||
/>
|
||||
<TooltipContent>{tooltipLabel}</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<span role="status" aria-atomic="true" className="sr-only">
|
||||
{isCopied ? copyStatus : ''}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default KeyValueItem
|
||||
Reference in new issue
Block a user