diff --git a/web/app/(commonLayout)/plugins/test/card/page.tsx b/web/app/(commonLayout)/plugins/test/card/page.tsx index 5c53f1e653..fb75397182 100644 --- a/web/app/(commonLayout)/plugins/test/card/page.tsx +++ b/web/app/(commonLayout)/plugins/test/card/page.tsx @@ -6,35 +6,53 @@ import CardMoreInfo from '@/app/components/plugins/card/card-more-info' // import ProviderCard from '@/app/components/plugins/provider-card' import Badge from '@/app/components/base/badge' import InstallBundle from '@/app/components/plugins/install-plugin/install-bundle' +import { useBoolean } from 'ahooks' const PluginList = () => { const pluginList = [toolNotion, extensionDallE, modelGPT4, customTool] + const [isShow, { + setFalse: hide, + }] = useBoolean(true) return (
- { }} fromDSLPayload={[ - // { - // type: 'marketplace', - // value: { - // plugin_unique_identifier: 'langgenius/google:0.0.2@dcb354c9d0fee60e6e9c9eb996e1e485bbef343ba8cd545c0cfb3ec80970f6f1', - // }, - // }, - { - type: 'github', - value: { - repo: 'YIXIAO0/test', - version: '1.11.5', - package: 'test.difypkg', - github_plugin_unique_identifier: 'yixiao0/test:0.0.1@3592166c87afcf944b4f13f27467a5c8f9e00bd349cb42033a072734a37431b4', - }, - }, - // { - // type: 'marketplace', - // value: { - // plugin_unique_identifier: 'langgenius/openai:0.0.1@f88fdb98d104466db16a425bfe3af8c1bcad45047a40fb802d98a989ac57a5a3', - // }, - // }, - ]} /> + {isShow && ( + + ) + }
{/*

Dify Plugin list

*/} {/*
diff --git a/web/app/components/plugins/install-plugin/install-bundle/index.tsx b/web/app/components/plugins/install-plugin/install-bundle/index.tsx index 54f00d68a4..4e57af59e0 100644 --- a/web/app/components/plugins/install-plugin/install-bundle/index.tsx +++ b/web/app/components/plugins/install-plugin/install-bundle/index.tsx @@ -3,8 +3,9 @@ import type { FC } from 'react' import Modal from '@/app/components/base/modal' import React, { useCallback, useState } from 'react' import { InstallStep } from '../../types' -import type { Dependency } from '../../types' +import type { Dependency, Plugin } from '../../types' import Install from './steps/install' +import Installed from './steps/installed' import { useTranslation } from 'react-i18next' const i18nPrefix = 'plugin.installModal' @@ -29,7 +30,8 @@ const InstallBundle: FC = ({ }) => { const { t } = useTranslation() const [step, setStep] = useState(installType === InstallType.fromMarketplace ? InstallStep.readyToInstall : InstallStep.uploading) - + const [installedPlugins, setInstalledPlugins] = useState([]) + const [installStatus, setInstallStatus] = useState<{ success: boolean }[]>([]) const getTitle = useCallback(() => { if (step === InstallStep.uploadFailed) return t(`${i18nPrefix}.uploadFailed`) @@ -41,6 +43,12 @@ const InstallBundle: FC = ({ return t(`${i18nPrefix}.installPlugin`) }, [step, t]) + const handleInstalled = useCallback((plugins: Plugin[], installStatus: { success: boolean }[]) => { + setInstallStatus(installStatus) + setInstalledPlugins(plugins) + setStep(InstallStep.installed) + }, []) + return ( = ({ + )} + {step === InstallStep.installed && ( + )} diff --git a/web/app/components/plugins/install-plugin/install-bundle/item/github-item.tsx b/web/app/components/plugins/install-plugin/install-bundle/item/github-item.tsx index 1a773ca6a8..49f7e448aa 100644 --- a/web/app/components/plugins/install-plugin/install-bundle/item/github-item.tsx +++ b/web/app/components/plugins/install-plugin/install-bundle/item/github-item.tsx @@ -29,7 +29,10 @@ const Item: FC = ({ const [payload, setPayload] = React.useState(null) useEffect(() => { if (data) { - const payload = pluginManifestToCardPluginProps(data.manifest) + const payload = { + ...pluginManifestToCardPluginProps(data.manifest), + plugin_id: data.unique_identifier, + } onFetchedPayload(payload) setPayload(payload) } diff --git a/web/app/components/plugins/install-plugin/install-bundle/steps/install-by-dsl-list.tsx b/web/app/components/plugins/install-plugin/install-bundle/steps/install-by-dsl-list.tsx index 1d1fe4e67c..aeafa8f18f 100644 --- a/web/app/components/plugins/install-plugin/install-bundle/steps/install-by-dsl-list.tsx +++ b/web/app/components/plugins/install-plugin/install-bundle/steps/install-by-dsl-list.tsx @@ -26,12 +26,12 @@ const InstallByDSLList: FC = ({ const [plugins, setPlugins, getPlugins] = useGetState([]) const handlePlugInFetched = useCallback((index: number) => { return (p: Plugin) => { - const nextPlugins = produce(plugins, (draft) => { + const nextPlugins = produce(getPlugins(), (draft) => { draft[index] = p }) setPlugins(nextPlugins) } - }, [plugins, setPlugins]) + }, [getPlugins, setPlugins]) const marketPlaceInDSLIndex = useMemo(() => { const res: number[] = [] diff --git a/web/app/components/plugins/install-plugin/install-bundle/steps/install.tsx b/web/app/components/plugins/install-plugin/install-bundle/steps/install.tsx index 72908abce8..5600481a69 100644 --- a/web/app/components/plugins/install-plugin/install-bundle/steps/install.tsx +++ b/web/app/components/plugins/install-plugin/install-bundle/steps/install.tsx @@ -7,23 +7,25 @@ import { RiLoader2Line } from '@remixicon/react' import { useTranslation } from 'react-i18next' import InstallByDSLList from './install-by-dsl-list' import { useInstallFromMarketplaceAndGitHub } from '@/service/use-plugins' - +import { useInvalidateInstalledPluginList } from '@/service/use-plugins' const i18nPrefix = 'plugin.installModal' type Props = { fromDSLPayload: Dependency[] + onInstalled: (plugins: Plugin[], installStatus: { success: boolean }[]) => void onCancel: () => void } const Install: FC = ({ fromDSLPayload, + onInstalled, onCancel, }) => { const { t } = useTranslation() const [selectedPlugins, setSelectedPlugins] = React.useState([]) const [selectedIndexes, setSelectedIndexes] = React.useState([]) const selectedPluginsNum = selectedPlugins.length - + const invalidateInstalledPluginList = useInvalidateInstalledPluginList() const handleSelect = (plugin: Plugin, selectedIndex: number) => { const isSelected = !!selectedPlugins.find(p => p.plugin_id === plugin.plugin_id) let nextSelectedPlugins @@ -44,10 +46,12 @@ const Install: FC = ({ // Install from marketplace and github const { mutate: installFromMarketplaceAndGitHub, isPending: isInstalling } = useInstallFromMarketplaceAndGitHub({ onSuccess: (res: { success: boolean }[]) => { - console.log(res) + onInstalled(selectedPlugins, res) + const hasInstallSuccess = res.some(r => r.success) + if (hasInstallSuccess) + invalidateInstalledPluginList() }, }) - console.log(canInstall, !isInstalling, selectedPlugins.length === 0) const handleInstall = () => { installFromMarketplaceAndGitHub(fromDSLPayload.filter((_d, index) => selectedIndexes.includes(index))) } diff --git a/web/app/components/plugins/install-plugin/install-bundle/steps/installed.tsx b/web/app/components/plugins/install-plugin/install-bundle/steps/installed.tsx new file mode 100644 index 0000000000..d6bb96ab2e --- /dev/null +++ b/web/app/components/plugins/install-plugin/install-bundle/steps/installed.tsx @@ -0,0 +1,55 @@ +'use client' +import type { FC } from 'react' +import React from 'react' +import type { Plugin } from '../../../types' +import Card from '@/app/components/plugins/card' +import Button from '@/app/components/base/button' +import { useTranslation } from 'react-i18next' +import Badge, { BadgeState } from '@/app/components/base/badge/index' + +type Props = { + list: Plugin[] + installStatus: { success: boolean }[] + onCancel: () => void +} + +const Installed: FC = ({ + list, + installStatus, + onCancel, +}) => { + const { t } = useTranslation() + return ( + <> +
+ {/*

{(isFailed && errMsg) ? errMsg : t(`plugin.installModal.${isFailed ? 'installFailedDesc' : 'installedSuccessfullyDesc'}`)}

*/} +
+ {list.map((plugin, index) => { + return ( + {plugin.version} : null} + /> + ) + })} +
+
+ {/* Action Buttons */} +
+ +
+ + ) +} + +export default React.memo(Installed) diff --git a/web/service/use-plugins.ts b/web/service/use-plugins.ts index fcbd5a01d7..91e42a8a26 100644 --- a/web/service/use-plugins.ts +++ b/web/service/use-plugins.ts @@ -121,6 +121,7 @@ export const useInstallFromMarketplaceAndGitHub = ({ }) return ({ success: true }) } + // eslint-disable-next-line unused-imports/no-unused-vars catch (e) { return Promise.resolve({ success: false }) }