'use client' import { useRef, useState } from 'react' import { RiAddLine, RiArrowDownSLine } from '@remixicon/react' import Button from '@/app/components/base/button' import { MagicBox } from '@/app/components/base/icons/src/vender/solid/mediaAndDevices' import { FileZip } from '@/app/components/base/icons/src/vender/solid/files' import { Github } from '@/app/components/base/icons/src/vender/solid/general' import InstallFromGitHub from '@/app/components/plugins/install-plugin/install-from-github' import InstallFromLocalPackage from '@/app/components/plugins/install-plugin/install-from-local-package' import cn from '@/utils/classnames' import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' import { useSelector as useAppContextSelector } from '@/context/app-context' import { useTranslation } from 'react-i18next' import { SUPPORT_INSTALL_LOCAL_FILE_EXTENSIONS } from '@/config' type Props = { onSwitchToMarketplaceTab: () => void } const InstallPluginDropdown = ({ onSwitchToMarketplaceTab, }: Props) => { const { t } = useTranslation() const fileInputRef = useRef(null) const [isMenuOpen, setIsMenuOpen] = useState(false) const [selectedAction, setSelectedAction] = useState(null) const [selectedFile, setSelectedFile] = useState(null) const { enable_marketplace } = useAppContextSelector(s => s.systemFeatures) const handleFileChange = (event: React.ChangeEvent) => { const file = event.target.files?.[0] if (file) { setSelectedFile(file) setSelectedAction('local') setIsMenuOpen(false) } } // TODO TEST INSTALL : uninstall // const [pluginLists, setPluginLists] = useState([]) // useEffect(() => { // (async () => { // const list: any = await get('workspaces/current/plugin/list') // })() // }) // const handleUninstall = async (id: string) => { // const res = await post('workspaces/current/plugin/uninstall', { body: { plugin_installation_id: id } }) // console.log(res) // } return (
setIsMenuOpen(v => !v)}>
{t('plugin.installFrom')}
{[ ...( (enable_marketplace && true) ? [{ icon: MagicBox, text: t('plugin.source.marketplace'), action: 'marketplace' }] : [] ), { icon: Github, text: t('plugin.source.github'), action: 'github' }, { icon: FileZip, text: t('plugin.source.local'), action: 'local' }, ].map(({ icon: Icon, text, action }) => (
{ if (action === 'local') { fileInputRef.current?.click() } else if (action === 'marketplace') { onSwitchToMarketplaceTab() setIsMenuOpen(false) } else { setSelectedAction(action) setIsMenuOpen(false) } }} > {text}
))}
{selectedAction === 'github' && { }} onClose={() => setSelectedAction(null)} />} {selectedAction === 'local' && selectedFile && ( setSelectedAction(null)} onSuccess={() => { }} /> ) } {/* {pluginLists.map((item: any) => (
handleUninstall(item.id)}>{item.name} 卸载
))} */}
) } export default InstallPluginDropdown