mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
just add
This commit is contained in:
@ -28,6 +28,12 @@ const PluginList = () => {
|
|||||||
github_plugin_unique_identifier: 'yixiao0/test:0.0.1@3592166c87afcf944b4f13f27467a5c8f9e00bd349cb42033a072734a37431b4',
|
github_plugin_unique_identifier: 'yixiao0/test:0.0.1@3592166c87afcf944b4f13f27467a5c8f9e00bd349cb42033a072734a37431b4',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: 'marketplace',
|
||||||
|
value: {
|
||||||
|
plugin_unique_identifier: 'langgenius/openai:0.0.1@f88fdb98d104466db16a425bfe3af8c1bcad45047a40fb802d98a989ac57a5a3',
|
||||||
|
},
|
||||||
|
},
|
||||||
]} />
|
]} />
|
||||||
<div className='mx-3 '>
|
<div className='mx-3 '>
|
||||||
{/* <h2 className='my-3'>Dify Plugin list</h2> */}
|
{/* <h2 className='my-3'>Dify Plugin list</h2> */}
|
||||||
|
|||||||
@ -11,17 +11,18 @@ import { useGetState } from 'ahooks'
|
|||||||
type Props = {
|
type Props = {
|
||||||
fromDSLPayload: Dependency[]
|
fromDSLPayload: Dependency[]
|
||||||
selectedPlugins: Plugin[]
|
selectedPlugins: Plugin[]
|
||||||
handleSelect: (plugin: Plugin) => void
|
onSelect: (plugin: Plugin, selectedIndex: number) => void
|
||||||
onLoadedAllPlugin: () => void
|
onLoadedAllPlugin: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const InstallByDSLList: FC<Props> = ({
|
const InstallByDSLList: FC<Props> = ({
|
||||||
fromDSLPayload,
|
fromDSLPayload,
|
||||||
selectedPlugins,
|
selectedPlugins,
|
||||||
handleSelect,
|
onSelect,
|
||||||
onLoadedAllPlugin,
|
onLoadedAllPlugin,
|
||||||
}) => {
|
}) => {
|
||||||
const { isLoading: isFetchingMarketplaceData, data: marketplaceRes } = useFetchPluginsInMarketPlaceByIds(fromDSLPayload.filter(d => d.type === 'marketplace').map(d => d.value.plugin_unique_identifier!))
|
const { isLoading: isFetchingMarketplaceData, data: marketplaceRes } = useFetchPluginsInMarketPlaceByIds(fromDSLPayload.filter(d => d.type === 'marketplace').map(d => d.value.plugin_unique_identifier!))
|
||||||
|
|
||||||
const [plugins, setPlugins, getPlugins] = useGetState<Plugin[]>([])
|
const [plugins, setPlugins, getPlugins] = useGetState<Plugin[]>([])
|
||||||
const handlePlugInFetched = useCallback((index: number) => {
|
const handlePlugInFetched = useCallback((index: number) => {
|
||||||
return (p: Plugin) => {
|
return (p: Plugin) => {
|
||||||
@ -59,6 +60,12 @@ const InstallByDSLList: FC<Props> = ({
|
|||||||
onLoadedAllPlugin()
|
onLoadedAllPlugin()
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [isLoadedAllData])
|
}, [isLoadedAllData])
|
||||||
|
|
||||||
|
const handleSelect = useCallback((index: number) => {
|
||||||
|
return () => {
|
||||||
|
onSelect(plugins[index], index)
|
||||||
|
}
|
||||||
|
}, [onSelect, plugins])
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{fromDSLPayload.map((d, index) => (
|
{fromDSLPayload.map((d, index) => (
|
||||||
@ -66,14 +73,14 @@ const InstallByDSLList: FC<Props> = ({
|
|||||||
? <GithubItem
|
? <GithubItem
|
||||||
key={index}
|
key={index}
|
||||||
checked={!!selectedPlugins.find(p => p.plugin_id === plugins[index]?.plugin_id)}
|
checked={!!selectedPlugins.find(p => p.plugin_id === plugins[index]?.plugin_id)}
|
||||||
onCheckedChange={handleSelect}
|
onCheckedChange={handleSelect(index)}
|
||||||
dependency={d}
|
dependency={d}
|
||||||
onFetchedPayload={handlePlugInFetched(index)}
|
onFetchedPayload={handlePlugInFetched(index)}
|
||||||
/>
|
/>
|
||||||
: <MarketplaceItem
|
: <MarketplaceItem
|
||||||
key={index}
|
key={index}
|
||||||
checked={!!selectedPlugins.find(p => p.plugin_id === plugins[index]?.plugin_id)}
|
checked={!!selectedPlugins.find(p => p.plugin_id === plugins[index]?.plugin_id)}
|
||||||
onCheckedChange={handleSelect}
|
onCheckedChange={handleSelect(index)}
|
||||||
payload={plugins[index] as Plugin}
|
payload={plugins[index] as Plugin}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import Button from '@/app/components/base/button'
|
|||||||
import { RiLoader2Line } from '@remixicon/react'
|
import { RiLoader2Line } from '@remixicon/react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import InstallByDSLList from './install-by-dsl-list'
|
import InstallByDSLList from './install-by-dsl-list'
|
||||||
|
import { useInstallFromMarketplaceAndGitHub } from '@/service/use-plugins'
|
||||||
|
|
||||||
const i18nPrefix = 'plugin.installModal'
|
const i18nPrefix = 'plugin.installModal'
|
||||||
|
|
||||||
@ -20,9 +21,10 @@ const Install: FC<Props> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [selectedPlugins, setSelectedPlugins] = React.useState<Plugin[]>([])
|
const [selectedPlugins, setSelectedPlugins] = React.useState<Plugin[]>([])
|
||||||
|
const [selectedIndexes, setSelectedIndexes] = React.useState<number[]>([])
|
||||||
const selectedPluginsNum = selectedPlugins.length
|
const selectedPluginsNum = selectedPlugins.length
|
||||||
|
|
||||||
const handleSelect = (plugin: Plugin) => {
|
const handleSelect = (plugin: Plugin, selectedIndex: number) => {
|
||||||
const isSelected = !!selectedPlugins.find(p => p.plugin_id === plugin.plugin_id)
|
const isSelected = !!selectedPlugins.find(p => p.plugin_id === plugin.plugin_id)
|
||||||
let nextSelectedPlugins
|
let nextSelectedPlugins
|
||||||
if (isSelected)
|
if (isSelected)
|
||||||
@ -30,13 +32,23 @@ const Install: FC<Props> = ({
|
|||||||
else
|
else
|
||||||
nextSelectedPlugins = [...selectedPlugins, plugin]
|
nextSelectedPlugins = [...selectedPlugins, plugin]
|
||||||
setSelectedPlugins(nextSelectedPlugins)
|
setSelectedPlugins(nextSelectedPlugins)
|
||||||
|
const nextSelectedIndexes = isSelected ? selectedIndexes.filter(i => i !== selectedIndex) : [...selectedIndexes, selectedIndex]
|
||||||
|
setSelectedIndexes(nextSelectedIndexes)
|
||||||
}
|
}
|
||||||
const [canInstall, setCanInstall] = React.useState(false)
|
const [canInstall, setCanInstall] = React.useState(false)
|
||||||
const handleLoadedAllPlugin = useCallback(() => {
|
const handleLoadedAllPlugin = useCallback(() => {
|
||||||
setCanInstall(true)
|
setCanInstall(true)
|
||||||
}, [])
|
}, [selectedPlugins, selectedIndexes])
|
||||||
const handleInstall = () => {
|
|
||||||
|
|
||||||
|
// Install from marketplace and github
|
||||||
|
const { mutate: installFromMarketplaceAndGitHub, isPending: isInstalling } = useInstallFromMarketplaceAndGitHub({
|
||||||
|
onSuccess: () => {
|
||||||
|
console.log('success!')
|
||||||
|
},
|
||||||
|
})
|
||||||
|
console.log(canInstall, !isInstalling, selectedPlugins.length === 0)
|
||||||
|
const handleInstall = () => {
|
||||||
|
installFromMarketplaceAndGitHub(fromDSLPayload.filter((_d, index) => selectedIndexes.includes(index)))
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -48,7 +60,7 @@ const Install: FC<Props> = ({
|
|||||||
<InstallByDSLList
|
<InstallByDSLList
|
||||||
fromDSLPayload={fromDSLPayload}
|
fromDSLPayload={fromDSLPayload}
|
||||||
selectedPlugins={selectedPlugins}
|
selectedPlugins={selectedPlugins}
|
||||||
handleSelect={handleSelect}
|
onSelect={handleSelect}
|
||||||
onLoadedAllPlugin={handleLoadedAllPlugin}
|
onLoadedAllPlugin={handleLoadedAllPlugin}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -63,11 +75,11 @@ const Install: FC<Props> = ({
|
|||||||
<Button
|
<Button
|
||||||
variant='primary'
|
variant='primary'
|
||||||
className='min-w-[72px] flex space-x-0.5'
|
className='min-w-[72px] flex space-x-0.5'
|
||||||
disabled={canInstall || selectedPlugins.length === 0}
|
disabled={!canInstall || isInstalling || selectedPlugins.length === 0}
|
||||||
onClick={handleInstall}
|
onClick={handleInstall}
|
||||||
>
|
>
|
||||||
{canInstall && <RiLoader2Line className='w-4 h-4 animate-spin-slow' />}
|
{isInstalling && <RiLoader2Line className='w-4 h-4 animate-spin-slow' />}
|
||||||
<span>{t(`${i18nPrefix}.${canInstall ? 'installing' : 'install'}`)}</span>
|
<span>{t(`${i18nPrefix}.${isInstalling ? 'installing' : 'install'}`)}</span>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -94,6 +94,42 @@ export const useUploadGitHub = (payload: {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useInstallFromMarketplaceAndGitHub = ({
|
||||||
|
onSuccess,
|
||||||
|
}: {
|
||||||
|
onSuccess?: () => void
|
||||||
|
}) => {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (payload: Dependency[]) => {
|
||||||
|
return Promise.all(payload.map(async (item) => {
|
||||||
|
try {
|
||||||
|
if (item.type === 'github') {
|
||||||
|
await post<InstallPackageResponse>('/workspaces/current/plugin/install/github', {
|
||||||
|
body: {
|
||||||
|
repo: item.value.repo!,
|
||||||
|
version: item.value.version!,
|
||||||
|
package: item.value.package!,
|
||||||
|
plugin_unique_identifier: item.value.github_plugin_unique_identifier!,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return ({ success: true })
|
||||||
|
}
|
||||||
|
await post<InstallPackageResponse>('/workspaces/current/plugin/install/marketplace', {
|
||||||
|
body: {
|
||||||
|
plugin_unique_identifiers: [item.value.plugin_unique_identifier!],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return ({ success: true })
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
return Promise.resolve({ success: false })
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
},
|
||||||
|
onSuccess,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export const useDebugKey = () => {
|
export const useDebugKey = () => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: [NAME_SPACE, 'debugKey'],
|
queryKey: [NAME_SPACE, 'debugKey'],
|
||||||
|
|||||||
Reference in New Issue
Block a user