diff --git a/web/app/components/plugins/update-plugin/from-market-place.tsx b/web/app/components/plugins/update-plugin/from-market-place.tsx index e0f9e2bc01..e0b54a1acf 100644 --- a/web/app/components/plugins/update-plugin/from-market-place.tsx +++ b/web/app/components/plugins/update-plugin/from-market-place.tsx @@ -10,6 +10,9 @@ import Badge, { BadgeState } from '@/app/components/base/badge/index' import type { UpdateFromMarketPlacePayload } from '../types' import { pluginManifestToCardPluginProps } from '@/app/components/plugins/install-plugin/utils' import useGetIcon from '../install-plugin/base/use-get-icon' +import { updateFromMarketPlace } from '@/service/plugins' +import checkTaskStatus from '@/app/components/plugins/install-plugin/base/check-task-status' +import { usePluginTasksStore } from '@/app/components/plugins/plugin-page/store' const i18nPrefix = 'plugin.upgrade' @@ -43,7 +46,18 @@ const UpdatePluginModal: FC = ({ setIcon(icon) })() }, [originalPackageInfo, getIconUrl]) + const { + check, + stop, + } = checkTaskStatus() + const handleCancel = () => { + stop() + onCancel() + } + const [uploadStep, setUploadStep] = useState(UploadStep.notStarted) + const setPluginTasksWithPolling = usePluginTasksStore(s => s.setPluginTasksWithPolling) + const configBtnText = useMemo(() => { return ({ [UploadStep.notStarted]: t(`${i18nPrefix}.upgrade`), @@ -52,19 +66,41 @@ const UpdatePluginModal: FC = ({ })[uploadStep] }, [t, uploadStep]) - const handleConfirm = useCallback(() => { + const handleConfirm = useCallback(async () => { if (uploadStep === UploadStep.notStarted) { setUploadStep(UploadStep.upgrading) - setTimeout(() => { - setUploadStep(UploadStep.installed) - }, 1500) - return + const { + all_installed: isInstalled, + task_id: taskId, + } = await updateFromMarketPlace({ + original_plugin_unique_identifier: originalPackageInfo.id, + new_plugin_unique_identifier: targetPackageInfo.id, + }) + if (isInstalled) { + onSave() + return + } + setPluginTasksWithPolling() + await check({ + taskId, + pluginUniqueIdentifier: targetPackageInfo.id, + }) + onSave() } if (uploadStep === UploadStep.installed) { onSave() onCancel() } - }, [onCancel, onSave, uploadStep]) + }, [onCancel, onSave, uploadStep, check, originalPackageInfo.id, setPluginTasksWithPolling, targetPackageInfo.id]) + const usedInAppInfo = useMemo(() => { + return ( +
+
{t(`${i18nPrefix}.usedInApps`, { num: 3 })}
+ {/* show the used apps */} + +
+ ) + }, [t]) return ( = ({ {`${originalPackageInfo.payload.version} -> ${targetPackageInfo.version}`} -
-
{t(`${i18nPrefix}.usedInApps`, { num: 3 })}
- {/* show the used apps */} - -
+ {false && usedInAppInfo} } /> @@ -101,7 +133,7 @@ const UpdatePluginModal: FC = ({
{uploadStep === UploadStep.notStarted && ( diff --git a/web/service/plugins.ts b/web/service/plugins.ts index e122b8efea..774dbc54f2 100644 --- a/web/service/plugins.ts +++ b/web/service/plugins.ts @@ -71,6 +71,12 @@ export const installPackageFromLocal = async (uniqueIdentifier: string) => { }) } +export const updateFromMarketPlace = async (body: Record) => { + return post('/workspaces/current/plugin/upgrade/marketplace', { + body, + }) +} + export const uploadGitHub = async (repoUrl: string, selectedVersion: string, selectedPackage: string) => { return post('/workspaces/current/plugin/upload/github', { body: {