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 ddea0c346f..411e2cf1f1 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 @@ -1,132 +1,73 @@ 'use client' -import React, { useMemo, useState } from 'react' -import { RiInformation2Line } from '@remixicon/react' -import Card from '../../card' -import { extensionDallE, modelGPT4, toolNotion } from '../../card/card-mock' +import React, { useCallback, useState } from 'react' import Modal from '@/app/components/base/modal' -import Button from '@/app/components/base/button' -import Checkbox from '@/app/components/base/checkbox' -import Badge, { BadgeState } from '@/app/components/base/badge/index' +import type { PluginDeclaration } from '../../types' +import { InstallStep } from '../../types' +import Install from './steps/install' +import Installed from './steps/installed' +import { useTranslation } from 'react-i18next' + +const i18nPrefix = 'plugin.installModal' type InstallFromMarketplaceProps = { + packageId: string + manifest: PluginDeclaration + onSuccess: () => void onClose: () => void } -const InstallFromMarketplace: React.FC = ({ onClose }) => { - const plugins = useMemo(() => [toolNotion, extensionDallE, modelGPT4], []) - const [selectedPlugins, setSelectedPlugins] = useState>(new Set()) - const [isInstalling, setIsInstalling] = useState(false) - const [nextStep, setNextStep] = useState(false) +const InstallFromMarketplace: React.FC = ({ + packageId, + manifest, + onSuccess, + onClose, +}) => { + const { t } = useTranslation() + // readyToInstall -> check installed -> installed + const [step, setStep] = useState(InstallStep.readyToInstall) - const mockInstall = async () => { - setIsInstalling(true) - await new Promise(resolve => setTimeout(resolve, 1500)) - setIsInstalling(false) - } + // TODO: check installed in beta version. - const pluginsToShow = useMemo(() => { - if (plugins.length === 1 || (nextStep && selectedPlugins.size === 1)) - return plugins.length === 1 ? plugins : plugins.filter((_, index) => selectedPlugins.has(index)) + const getTitle = useCallback(() => { + if (step === InstallStep.installed) + return t(`${i18nPrefix}.installedSuccessfully`) + return t(`${i18nPrefix}.installPlugin`) + }, []) - return nextStep ? plugins.filter((_, index) => selectedPlugins.has(index)) : plugins - }, [plugins, nextStep, selectedPlugins]) - - const renderPluginCard = (plugin: any, index: number) => ( - {plugin.version} - ) - : ( - <> - - {`${plugin.version} -> ${plugin.latest_version}`} - -
-
Used in 3 apps
- -
- - ) - } - /> - ) + const handleInstalled = useCallback(async () => { + setStep(InstallStep.installed) + }, []) return (
- {nextStep ? (isInstalling ? 'Install plugin' : 'Installation successful') : 'Install plugin'} + {getTitle()}
-
-
-
- {(nextStep && !isInstalling) - ? `The following ${pluginsToShow.length === 1 ? 'plugin has' : `${pluginsToShow.length} plugins have`} been installed successfully` - : `About to install the following ${pluginsToShow.length === 1 ? 'plugin' : `${pluginsToShow.length} plugins`}`} -
-
-
- {pluginsToShow.map((plugin, index) => ( -
1 && !nextStep) ? 'pl-1 items-center gap-2' : ''} flex-grow`}> - {(plugins.length > 1 && !nextStep) && ( - { - const newSelectedPlugins = new Set(selectedPlugins) - newSelectedPlugins.has(index) ? newSelectedPlugins.delete(index) : newSelectedPlugins.add(index) - setSelectedPlugins(newSelectedPlugins) - }} - /> - )} - {renderPluginCard(plugin, index)} -
- ))} -
-
-
- {nextStep - ? ( - - ) - : ( - <> - - - - )} -
+ { + step === InstallStep.readyToInstall && ( + + ) + } + { + step === InstallStep.installed && ( + + ) + }
) } diff --git a/web/app/components/plugins/install-plugin/install-from-marketplace/steps/install.tsx b/web/app/components/plugins/install-plugin/install-from-marketplace/steps/install.tsx index 5067dff908..eb5072b7e3 100644 --- a/web/app/components/plugins/install-plugin/install-from-marketplace/steps/install.tsx +++ b/web/app/components/plugins/install-plugin/install-from-marketplace/steps/install.tsx @@ -1,13 +1,15 @@ 'use client' import type { FC } from 'react' -import React from 'react' +import React, { useMemo } from 'react' +import { RiInformation2Line } from '@remixicon/react' import type { PluginDeclaration } from '../../../types' import Card from '../../../card' import { pluginManifestToCardPluginProps } from '../../utils' import Button from '@/app/components/base/button' import { sleep } from '@/utils' -import { Trans, useTranslation } from 'react-i18next' +import { useTranslation } from 'react-i18next' import { RiLoader2Line } from '@remixicon/react' +import Badge, { BadgeState } from '@/app/components/base/badge/index' const i18nPrefix = 'plugin.installModal' @@ -32,22 +34,40 @@ const Installed: FC = ({ onInstalled() } + const toInstallVersion = '1.3.0' + const supportCheckInstalled = false // TODO: check installed in beta version. + + const versionInfo = useMemo(() => { + return (<>{ + payload.version === toInstallVersion || !supportCheckInstalled + ? ( + {payload.version} + ) + : ( + <> + + {`${payload.version} -> ${toInstallVersion}`} + +
+
Used in 3 apps
+ +
+ + ) + }) + }, [payload]) + return ( <>

{t(`${i18nPrefix}.readyToInstall`)}

-

- }} - /> -

diff --git a/web/app/components/plugins/plugin-page/index.tsx b/web/app/components/plugins/plugin-page/index.tsx index 6c73f0c6ee..9d432df664 100644 --- a/web/app/components/plugins/plugin-page/index.tsx +++ b/web/app/components/plugins/plugin-page/index.tsx @@ -1,6 +1,6 @@ 'use client' -import { useMemo, useState } from 'react' +import { useEffect, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { RiDragDropLine, @@ -29,6 +29,9 @@ import { useRouter, useSearchParams, } from 'next/navigation' +import type { PluginDeclaration } from '../types' +import { toolNotionManifest } from '../card/card-mock' +import { sleep } from '@/utils' const PACKAGE_IDS_KEY = 'package-ids' @@ -54,7 +57,28 @@ const PluginPage = ({ return '' } }, [searchParams]) - const isInstallPackage = !!packageId + const [isShowInstallFromMarketplace, { + setTrue: showInstallFromMarketplace, + setFalse: doHideInstallFromMarketplace, + }] = useBoolean(false) + + const hideInstallFromMarketplace = () => { + doHideInstallFromMarketplace() + const url = new URL(window.location.href) + url.searchParams.delete(PACKAGE_IDS_KEY) + replace(url.toString()) + } + const [manifest, setManifest] = useState(null) + + useEffect(() => { + (async () => { + await sleep(100) + if (packageId) { + setManifest(toolNotionManifest) + showInstallFromMarketplace() + } + })() + }, [packageId]) const { canManagement, @@ -94,18 +118,6 @@ const PluginPage = ({ const { dragging, fileUploader, fileChangeHandle, removeFile } = uploaderProps - const [isShowInstallFromMarketplace, { - setTrue: showInstallFromMarketplace, - setFalse: doHideInstallFromMarketplace, - }] = useBoolean(isInstallPackage) - - const hideInstallFromMarketplace = () => { - doHideInstallFromMarketplace() - const url = new URL(window.location.href) - url.searchParams.delete(PACKAGE_IDS_KEY) - replace(url.toString()) - } - return (
) }