Merge branch 'feat/plugins' of https://github.com/langgenius/dify into feat/plugins

This commit is contained in:
twwu 2024-11-06 16:18:25 +08:00
commit b6a4af4041
4 changed files with 25 additions and 8 deletions

View File

@ -1,7 +1,7 @@
'use client' 'use client'
import type { FC } from 'react' import type { FC } from 'react'
import React from 'react' import React from 'react'
import type { PluginDeclaration, PluginManifestInMarket } from '../../types' import type { Plugin, PluginDeclaration, PluginManifestInMarket } from '../../types'
import Card from '../../card' import Card from '../../card'
import Button from '@/app/components/base/button' import Button from '@/app/components/base/button'
import { pluginManifestInMarketToPluginProps, pluginManifestToCardPluginProps } from '../utils' import { pluginManifestInMarketToPluginProps, pluginManifestToCardPluginProps } from '../utils'
@ -9,7 +9,7 @@ import { useTranslation } from 'react-i18next'
import Badge, { BadgeState } from '@/app/components/base/badge/index' import Badge, { BadgeState } from '@/app/components/base/badge/index'
type Props = { type Props = {
payload?: PluginDeclaration | PluginManifestInMarket | null payload?: Plugin | PluginDeclaration | PluginManifestInMarket | null
isMarketPayload?: boolean isMarketPayload?: boolean
isFailed: boolean isFailed: boolean
errMsg?: string | null errMsg?: string | null

View File

@ -2,7 +2,7 @@
import React, { useCallback, useState } from 'react' import React, { useCallback, useState } from 'react'
import Modal from '@/app/components/base/modal' import Modal from '@/app/components/base/modal'
import type { PluginManifestInMarket } from '../../types' import type { Plugin, PluginManifestInMarket } from '../../types'
import { InstallStep } from '../../types' import { InstallStep } from '../../types'
import Install from './steps/install' import Install from './steps/install'
import Installed from '../base/installed' import Installed from '../base/installed'
@ -12,7 +12,7 @@ const i18nPrefix = 'plugin.installModal'
type InstallFromMarketplaceProps = { type InstallFromMarketplaceProps = {
uniqueIdentifier: string uniqueIdentifier: string
manifest: PluginManifestInMarket manifest: PluginManifestInMarket | Plugin
onSuccess: () => void onSuccess: () => void
onClose: () => void onClose: () => void
} }
@ -36,7 +36,7 @@ const InstallFromMarketplace: React.FC<InstallFromMarketplaceProps> = ({
if (step === InstallStep.installFailed) if (step === InstallStep.installFailed)
return t(`${i18nPrefix}.installFailed`) return t(`${i18nPrefix}.installFailed`)
return t(`${i18nPrefix}.installPlugin`) return t(`${i18nPrefix}.installPlugin`)
}, [step]) }, [step, t])
const handleInstalled = useCallback(() => { const handleInstalled = useCallback(() => {
setStep(InstallStep.installed) setStep(InstallStep.installed)

View File

@ -2,7 +2,7 @@
import type { FC } from 'react' import type { FC } from 'react'
import React, { useMemo } from 'react' import React, { useMemo } from 'react'
import { RiInformation2Line } from '@remixicon/react' import { RiInformation2Line } from '@remixicon/react'
import type { PluginManifestInMarket } from '../../../types' import type { Plugin, PluginManifestInMarket } from '../../../types'
import Card from '../../../card' import Card from '../../../card'
import { pluginManifestInMarketToPluginProps } from '../../utils' import { pluginManifestInMarketToPluginProps } from '../../utils'
import Button from '@/app/components/base/button' import Button from '@/app/components/base/button'
@ -16,7 +16,7 @@ const i18nPrefix = 'plugin.installModal'
type Props = { type Props = {
uniqueIdentifier: string uniqueIdentifier: string
payload: PluginManifestInMarket payload: PluginManifestInMarket | Plugin
onCancel: () => void onCancel: () => void
onStartToInstall?: () => void onStartToInstall?: () => void
onInstalled: () => void onInstalled: () => void
@ -104,7 +104,7 @@ const Installed: FC<Props> = ({
<div className='flex p-2 items-start content-start gap-1 self-stretch flex-wrap rounded-2xl bg-background-section-burn'> <div className='flex p-2 items-start content-start gap-1 self-stretch flex-wrap rounded-2xl bg-background-section-burn'>
<Card <Card
className='w-full' className='w-full'
payload={pluginManifestInMarketToPluginProps(payload)} payload={pluginManifestInMarketToPluginProps(payload as PluginManifestInMarket)}
titleLeft={versionInfo} titleLeft={versionInfo}
/> />
</div> </div>

View File

@ -12,7 +12,9 @@ import DownloadCount from './card/base/download-count'
import Button from '@/app/components/base/button' import Button from '@/app/components/base/button'
import { useGetLanguage } from '@/context/i18n' import { useGetLanguage } from '@/context/i18n'
import { MARKETPLACE_URL_PREFIX } from '@/config' import { MARKETPLACE_URL_PREFIX } from '@/config'
import InstallFromMarketplace from '@/app/components/plugins/install-plugin/install-from-marketplace'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { useBoolean } from 'ahooks'
type Props = { type Props = {
className?: string className?: string
@ -24,6 +26,10 @@ const ProviderCard: FC<Props> = ({
payload, payload,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const [isShowInstallFromMarketplace, {
setTrue: showInstallFromMarketplace,
setFalse: hideInstallFromMarketplace,
}] = useBoolean(false)
const language = useGetLanguage() const language = useGetLanguage()
const { org, label } = payload const { org, label } = payload
@ -58,6 +64,7 @@ const ProviderCard: FC<Props> = ({
<Button <Button
className='flex-grow' className='flex-grow'
variant='primary' variant='primary'
onClick={showInstallFromMarketplace}
> >
{t('plugin.detailPanel.operation.install')} {t('plugin.detailPanel.operation.install')}
</Button> </Button>
@ -71,6 +78,16 @@ const ProviderCard: FC<Props> = ({
</a> </a>
</Button> </Button>
</div> </div>
{
isShowInstallFromMarketplace && (
<InstallFromMarketplace
manifest={payload as any}
uniqueIdentifier={payload.latest_package_identifier}
onClose={hideInstallFromMarketplace}
onSuccess={hideInstallFromMarketplace}
/>
)
}
</div> </div>
) )
} }