diff --git a/web/app/components/plugins/card/index.tsx b/web/app/components/plugins/card/index.tsx index be68ab0ae1..b9ff8ecfda 100644 --- a/web/app/components/plugins/card/index.tsx +++ b/web/app/components/plugins/card/index.tsx @@ -41,7 +41,7 @@ const Card = ({ const { type, name, org, label, brief, icon, verified } = payload const getLocalizedText = (obj: Record | undefined) => - obj?.[locale] || obj?.['en-US'] || '' + obj?.[locale] || obj?.['en-US'] || obj?.en_US || '' const wrapClassName = cn('relative p-4 pb-3 border-[0.5px] border-components-panel-border bg-components-panel-on-panel-item-bg hover-bg-components-panel-on-panel-item-bg rounded-xl shadow-xs', className) if (isLoading) { diff --git a/web/app/components/plugins/install-plugin/base/installed.tsx b/web/app/components/plugins/install-plugin/base/installed.tsx index af39b47995..8322c3e5eb 100644 --- a/web/app/components/plugins/install-plugin/base/installed.tsx +++ b/web/app/components/plugins/install-plugin/base/installed.tsx @@ -1,15 +1,16 @@ 'use client' import type { FC } from 'react' import React from 'react' -import type { PluginDeclaration } from '../../types' +import type { PluginDeclaration, PluginManifestInMarket } from '../../types' import Card from '../../card' import Button from '@/app/components/base/button' -import { pluginManifestToCardPluginProps } from '../utils' +import { pluginManifestInMarketToPluginProps, pluginManifestToCardPluginProps } from '../utils' import { useTranslation } from 'react-i18next' import Badge, { BadgeState } from '@/app/components/base/badge/index' type Props = { - payload?: PluginDeclaration | null + payload?: PluginDeclaration | PluginManifestInMarket | null + isMarketPayload?: boolean isFailed: boolean errMsg?: string | null onCancel: () => void @@ -17,6 +18,7 @@ type Props = { const Installed: FC = ({ payload, + isMarketPayload, isFailed, errMsg, onCancel, @@ -30,10 +32,10 @@ const Installed: FC = ({
{payload.version}} + titleLeft={{(payload as PluginDeclaration).version || (payload as PluginManifestInMarket).latest_version}} />
)} diff --git a/web/app/components/plugins/install-plugin/install-from-marketplace/index.tsx b/web/app/components/plugins/install-plugin/install-from-marketplace/index.tsx index 16126e30a0..17eca59dc3 100644 --- a/web/app/components/plugins/install-plugin/install-from-marketplace/index.tsx +++ b/web/app/components/plugins/install-plugin/install-from-marketplace/index.tsx @@ -2,7 +2,7 @@ import React, { useCallback, useState } from 'react' import Modal from '@/app/components/base/modal' -import type { PluginDeclaration } from '../../types' +import type { PluginManifestInMarket } from '../../types' import { InstallStep } from '../../types' import Install from './steps/install' import Installed from '../base/installed' @@ -10,9 +10,9 @@ import { useTranslation } from 'react-i18next' const i18nPrefix = 'plugin.installModal' -interface InstallFromMarketplaceProps { +type InstallFromMarketplaceProps = { uniqueIdentifier: string - manifest: PluginDeclaration + manifest: PluginManifestInMarket onSuccess: () => void onClose: () => void } @@ -75,6 +75,7 @@ const InstallFromMarketplace: React.FC = ({ ([InstallStep.installed, InstallStep.installFailed].includes(step)) && ( void onInstalled: () => void onFailed: (message?: string) => void @@ -74,14 +74,14 @@ const Installed: FC = ({ const versionInfo = useMemo(() => { return (<>{ - payload.version === toInstallVersion || !supportCheckInstalled + payload.latest_version === toInstallVersion || !supportCheckInstalled ? ( - {payload.version} + {payload.latest_version} ) : ( <> - {`${payload.version} -> ${toInstallVersion}`} + {`${payload.latest_version} -> ${toInstallVersion}`}
Used in 3 apps
@@ -101,7 +101,7 @@ const Installed: FC = ({
diff --git a/web/app/components/plugins/install-plugin/utils.ts b/web/app/components/plugins/install-plugin/utils.ts index bd5453dd8c..8b3e850deb 100644 --- a/web/app/components/plugins/install-plugin/utils.ts +++ b/web/app/components/plugins/install-plugin/utils.ts @@ -1,4 +1,4 @@ -import type { Plugin, PluginDeclaration } from '../types' +import type { Plugin, PluginDeclaration, PluginManifestInMarket } from '../types' export const pluginManifestToCardPluginProps = (pluginManifest: PluginDeclaration): Plugin => { return { @@ -20,3 +20,24 @@ export const pluginManifestToCardPluginProps = (pluginManifest: PluginDeclaratio }, } } + +export const pluginManifestInMarketToPluginProps = (pluginManifest: PluginManifestInMarket): Plugin => { + return { + type: pluginManifest.category, + category: pluginManifest.category, + name: pluginManifest.name, + version: pluginManifest.latest_version, + latest_version: pluginManifest.latest_version, + org: pluginManifest.org, + label: pluginManifest.label, + brief: pluginManifest.brief, + icon: pluginManifest.icon, + verified: pluginManifest.verified, + introduction: pluginManifest.introduction, + repository: '', + install_count: 0, + endpoint: { + settings: [], + }, + } +} diff --git a/web/app/components/plugins/plugin-page/index.tsx b/web/app/components/plugins/plugin-page/index.tsx index 80f8f22ade..93eb3dcabf 100644 --- a/web/app/components/plugins/plugin-page/index.tsx +++ b/web/app/components/plugins/plugin-page/index.tsx @@ -29,9 +29,10 @@ import { useRouter, useSearchParams, } from 'next/navigation' -import type { PluginDeclaration } from '../types' +import type { PluginDeclaration, PluginManifestInMarket } from '../types' import { sleep } from '@/utils' import { fetchManifestFromMarketPlace } from '@/service/plugins' +import { marketplaceApiPrefix } from '@/config' const PACKAGE_IDS_KEY = 'package-ids' @@ -68,14 +69,18 @@ const PluginPage = ({ url.searchParams.delete(PACKAGE_IDS_KEY) replace(url.toString()) } - const [manifest, setManifest] = useState(null) + const [manifest, setManifest] = useState(null) useEffect(() => { (async () => { await sleep(100) if (packageId) { const { data } = await fetchManifestFromMarketPlace(encodeURIComponent(packageId)) - setManifest(data.plugin) + const { plugin } = data + setManifest({ + ...plugin, + icon: `${marketplaceApiPrefix}/plugins/${plugin.org}/${plugin.name}/icon`, + }) showInstallFromMarketplace() } })() @@ -229,7 +234,7 @@ const PluginPage = ({ { isShowInstallFromMarketplace && ( + category: PluginType + latest_version: string + brief: Record + introduction: string + verified: boolean +} + export type PluginDetail = { id: string created_at: string diff --git a/web/service/plugins.ts b/web/service/plugins.ts index 6a2cb063fd..4cc48286ff 100644 --- a/web/service/plugins.ts +++ b/web/service/plugins.ts @@ -7,6 +7,7 @@ import type { EndpointsResponse, InstallPackageResponse, PluginDeclaration, + PluginManifestInMarket, TaskStatusResponse, UpdateEndpointRequest, } from '@/app/components/plugins/types' @@ -80,7 +81,7 @@ export const fetchManifest = async (uniqueIdentifier: string) => { } export const fetchManifestFromMarketPlace = async (uniqueIdentifier: string) => { - return getMarketplace<{ data: { plugin: PluginDeclaration } }>(`/plugins/identifier?unique_identifier=${uniqueIdentifier}`) + return getMarketplace<{ data: { plugin: PluginManifestInMarket } }>(`/plugins/identifier?unique_identifier=${uniqueIdentifier}`) } export const installPackageFromMarketPlace = async (uniqueIdentifier: string) => {