From 2fd083629d5dfa124ef2959c62ecb21e3249fba5 Mon Sep 17 00:00:00 2001 From: AkaraChen Date: Wed, 8 Jan 2025 15:58:05 +0800 Subject: [PATCH] feat: new switch plugin version --- .../plugins/plugin-mutation-model/index.tsx | 38 ++++++----- .../components/switch-plugin-version.tsx | 63 ++++++++++++++----- .../workflow/nodes/agent/default.ts | 2 +- web/i18n/en-US/workflow.ts | 13 +++- web/i18n/zh-Hans/workflow.ts | 7 +++ 5 files changed, 89 insertions(+), 34 deletions(-) diff --git a/web/app/components/plugins/plugin-mutation-model/index.tsx b/web/app/components/plugins/plugin-mutation-model/index.tsx index fadfd9a957..36ab670ab3 100644 --- a/web/app/components/plugins/plugin-mutation-model/index.tsx +++ b/web/app/components/plugins/plugin-mutation-model/index.tsx @@ -8,14 +8,15 @@ import type { UseMutationResult } from '@tanstack/react-query' type Props = { plugin: Plugin - onSave: () => void onCancel: () => void - mutation: UseMutationResult + mutation: Pick + mutate: () => void confirmButtonText: ReactNode cancelButtonText: ReactNode modelTitle: ReactNode description: ReactNode cardTitleLeft: ReactNode + modalBottomLeft?: ReactNode } const PluginMutationModal: FC = ({ @@ -27,6 +28,8 @@ const PluginMutationModal: FC = ({ modelTitle, description, cardTitleLeft, + mutate, + modalBottomLeft, }: Props) => { return ( = ({ titleLeft={cardTitleLeft} /> -
- {mutation.isPending && ( - + )} + - )} - +
) diff --git a/web/app/components/workflow/nodes/_base/components/switch-plugin-version.tsx b/web/app/components/workflow/nodes/_base/components/switch-plugin-version.tsx index fc517ccf1d..6d0aed8a44 100644 --- a/web/app/components/workflow/nodes/_base/components/switch-plugin-version.tsx +++ b/web/app/components/workflow/nodes/_base/components/switch-plugin-version.tsx @@ -3,13 +3,18 @@ import Badge from '@/app/components/base/badge' import Tooltip from '@/app/components/base/tooltip' import PluginVersionPicker from '@/app/components/plugins/update-plugin/plugin-version-picker' -import { RiArrowLeftRightLine } from '@remixicon/react' +import { RiArrowLeftRightLine, RiExternalLinkLine } from '@remixicon/react' import type { ReactNode } from 'react' import { type FC, useCallback, useState } from 'react' -import UpdateFromMarketplace from '@/app/components/plugins/update-plugin/from-market-place' import { useBoolean } from 'ahooks' -import { useCheckInstalled } from '@/service/use-plugins' +import { useCheckInstalled, useUpdatePackageFromMarketPlace } from '@/service/use-plugins' import cn from '@/utils/classnames' +import PluginMutationModel from '@/app/components/plugins/plugin-mutation-model' +import useGetIcon from '@/app/components/plugins/install-plugin/base/use-get-icon' +import { pluginManifestToCardPluginProps } from '@/app/components/plugins/install-plugin/utils' +import { Badge as Badge2, BadgeState } from '@/app/components/base/badge/index' +import Link from 'next/link' +import { useTranslation } from 'react-i18next' export type SwitchPluginVersionProps = { uniqueIdentifier: string @@ -38,21 +43,49 @@ export const SwitchPluginVersion: FC = (props) => { pluginDetails.refetch() onChange?.(target!.version) }, [hideUpdateModal, onChange, pluginDetails, target]) + const { getIconUrl } = useGetIcon() + const icon = pluginDetail?.declaration.icon ? getIconUrl(pluginDetail.declaration.icon) : undefined + const mutation = useUpdatePackageFromMarketPlace() + const install = () => { + mutation.mutate( + { + new_plugin_unique_identifier: target!.pluginUniqueIden, + original_plugin_unique_identifier: uniqueIdentifier, + }, + { + onSuccess() { + handleUpdatedFromMarketplace() + }, + }) + } + const { t } = useTranslation() return
- {isShowUpdateModal && pluginDetail && + + {`${pluginDetail.version} -> ${target!.version}`} + + } + modalBottomLeft={ + + + {t('workflow.nodes.agent.installPlugin.changelog')} + + + + } />} {pluginDetail && = { if (!strategy) { return { isValid: false, - errorMessage: t('workflow.checkList.strategyNotSelected'), + errorMessage: t('workflow.nodes.agent.checkList.strategyNotSelected'), } } for (const param of strategy.parameters) { diff --git a/web/i18n/en-US/workflow.ts b/web/i18n/en-US/workflow.ts index 279654a857..b25a1b4915 100644 --- a/web/i18n/en-US/workflow.ts +++ b/web/i18n/en-US/workflow.ts @@ -755,9 +755,16 @@ const translation = { }, json: 'agent generated json', }, - }, - checkList: { - strategyNotSelected: 'Strategy not selected', + checkList: { + strategyNotSelected: 'Strategy not selected', + }, + installPlugin: { + title: 'Install Plugin', + desc: 'About to install the following plugin', + changelog: 'Change log', + install: 'Install', + cancel: 'Cancel', + }, }, }, tracing: { diff --git a/web/i18n/zh-Hans/workflow.ts b/web/i18n/zh-Hans/workflow.ts index 80c53702ab..4cbd5246bf 100644 --- a/web/i18n/zh-Hans/workflow.ts +++ b/web/i18n/zh-Hans/workflow.ts @@ -758,6 +758,13 @@ const translation = { checkList: { strategyNotSelected: '未选择策略', }, + installPlugin: { + title: '安装插件', + desc: '即将安装以下插件', + changelog: '更新日志', + install: '安装', + cancel: '取消', + }, }, }, tracing: {