From c46b5f2fd00a0b689394788bbb7dc8173333ce1d Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 23 Oct 2024 15:26:31 +0800 Subject: [PATCH] feat: handle install search params and hide --- .../steps/install.tsx | 74 +++++++++++++++++++ .../steps/installed.tsx | 46 ++++++++++++ .../components/plugins/plugin-page/index.tsx | 42 +++++++++++ 3 files changed, 162 insertions(+) create mode 100644 web/app/components/plugins/install-plugin/install-from-marketplace/steps/install.tsx create mode 100644 web/app/components/plugins/install-plugin/install-from-marketplace/steps/installed.tsx 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 new file mode 100644 index 0000000000..5067dff908 --- /dev/null +++ b/web/app/components/plugins/install-plugin/install-from-marketplace/steps/install.tsx @@ -0,0 +1,74 @@ +'use client' +import type { FC } from 'react' +import React from '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 { RiLoader2Line } from '@remixicon/react' + +const i18nPrefix = 'plugin.installModal' + +type Props = { + payload: PluginDeclaration + onCancel: () => void + onInstalled: () => void +} + +const Installed: FC = ({ + payload, + onCancel, + onInstalled, +}) => { + const { t } = useTranslation() + const [isInstalling, setIsInstalling] = React.useState(false) + + const handleInstall = async () => { + if (isInstalling) return + setIsInstalling(true) + await sleep(1500) + onInstalled() + } + + return ( + <> +
+
+

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

+

+ }} + /> +

+
+
+ +
+
+ {/* Action Buttons */} +
+ {!isInstalling && ( + + )} + +
+ + ) +} +export default React.memo(Installed) diff --git a/web/app/components/plugins/install-plugin/install-from-marketplace/steps/installed.tsx b/web/app/components/plugins/install-plugin/install-from-marketplace/steps/installed.tsx new file mode 100644 index 0000000000..34fad51691 --- /dev/null +++ b/web/app/components/plugins/install-plugin/install-from-marketplace/steps/installed.tsx @@ -0,0 +1,46 @@ +'use client' +import type { FC } from 'react' +import React from 'react' +import type { PluginDeclaration } from '../../../types' +import Card from '../../../card' +import Button from '@/app/components/base/button' +import { pluginManifestToCardPluginProps } from '../../utils' +import { useTranslation } from 'react-i18next' + +type Props = { + payload: PluginDeclaration + onCancel: () => void + +} + +const Installed: FC = ({ + payload, + onCancel, +}) => { + const { t } = useTranslation() + return ( + <> +
+

The plugin has been installed successfully.

+
+ +
+
+ {/* Action Buttons */} +
+ +
+ + ) +} +export default React.memo(Installed) diff --git a/web/app/components/plugins/plugin-page/index.tsx b/web/app/components/plugins/plugin-page/index.tsx index 7ec7dbfae8..6c73f0c6ee 100644 --- a/web/app/components/plugins/plugin-page/index.tsx +++ b/web/app/components/plugins/plugin-page/index.tsx @@ -24,6 +24,13 @@ import Tooltip from '@/app/components/base/tooltip' import cn from '@/utils/classnames' import PermissionSetModal from '@/app/components/plugins/permission-setting-modal/modal' import { useSelector as useAppContextSelector } from '@/context/app-context' +import InstallFromMarketplace from '../install-plugin/install-from-marketplace' +import { + useRouter, + useSearchParams, +} from 'next/navigation' + +const PACKAGE_IDS_KEY = 'package-ids' export type PluginPageProps = { plugins: React.ReactNode @@ -34,6 +41,21 @@ const PluginPage = ({ marketplace, }: PluginPageProps) => { const { t } = useTranslation() + const searchParams = useSearchParams() + const { replace } = useRouter() + + // just support install one package now + const packageId = useMemo(() => { + const idStrings = searchParams.get(PACKAGE_IDS_KEY) + try { + return idStrings ? JSON.parse(idStrings)[0] : '' + } + catch (e) { + return '' + } + }, [searchParams]) + const isInstallPackage = !!packageId + const { canManagement, canDebugger, @@ -72,6 +94,18 @@ 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 (
)} + + { + isShowInstallFromMarketplace && ( + + ) + }
) }