feat: show package item in bundle
This commit is contained in:
parent
27b1a51572
commit
a093a48675
@ -22,9 +22,21 @@ const InstallByDSLList: FC<Props> = ({
|
||||
onSelect,
|
||||
onLoadedAllPlugin,
|
||||
}) => {
|
||||
const { isLoading: isFetchingMarketplaceData, data: marketplaceRes } = useFetchPluginsInMarketPlaceByIds(allPlugins.filter(d => d.type === 'marketplace').map(d => d.value.plugin_unique_identifier!))
|
||||
const { isLoading: isFetchingMarketplaceData, data: marketplaceRes } = useFetchPluginsInMarketPlaceByIds(allPlugins.filter(d => d.type === 'marketplace').map(d => (d as GitHubItemAndMarketPlaceDependency).value.plugin_unique_identifier!))
|
||||
|
||||
const [plugins, setPlugins, getPlugins] = useGetState<Plugin[]>([])
|
||||
const [plugins, setPlugins, getPlugins] = useGetState<(Plugin | undefined)[]>((() => {
|
||||
const hasLocalPackage = allPlugins.some(d => d.type === 'package')
|
||||
if (!hasLocalPackage)
|
||||
return []
|
||||
|
||||
const _plugins = allPlugins.map((d) => {
|
||||
if (d.type === 'package')
|
||||
return (d as any).value.manifest
|
||||
|
||||
return undefined
|
||||
})
|
||||
return _plugins
|
||||
})())
|
||||
|
||||
const [errorIndexes, setErrorIndexes] = useState<number[]>([])
|
||||
|
||||
@ -53,15 +65,20 @@ const InstallByDSLList: FC<Props> = ({
|
||||
}, [allPlugins])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isFetchingMarketplaceData && marketplaceRes?.data.plugins && marketplaceRes?.data.plugins.length > 0) {
|
||||
if (!isFetchingMarketplaceData && marketplaceRes?.data.plugins) {
|
||||
const payloads = marketplaceRes?.data.plugins
|
||||
|
||||
const failedIndex: number[] = []
|
||||
const nextPlugins = produce(getPlugins(), (draft) => {
|
||||
marketPlaceInDSLIndex.forEach((index, i) => {
|
||||
draft[index] = payloads[i]
|
||||
if (payloads[i])
|
||||
draft[index] = payloads[i]
|
||||
else
|
||||
failedIndex.push(index)
|
||||
})
|
||||
})
|
||||
setPlugins(nextPlugins)
|
||||
if (failedIndex.length > 0)
|
||||
setErrorIndexes([...errorIndexes, ...failedIndex])
|
||||
// marketplaceRes?.data.plugins
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
@ -76,7 +93,7 @@ const InstallByDSLList: FC<Props> = ({
|
||||
|
||||
const handleSelect = useCallback((index: number) => {
|
||||
return () => {
|
||||
onSelect(plugins[index], index)
|
||||
onSelect(plugins[index]!, index)
|
||||
}
|
||||
}, [onSelect, plugins])
|
||||
return (
|
||||
|
@ -2,8 +2,10 @@ import { useCallback, useState } from 'react'
|
||||
import type {
|
||||
DebugInfo as DebugInfoTypes,
|
||||
Dependency,
|
||||
GitHubItemAndMarketPlaceDependency,
|
||||
InstallPackageResponse,
|
||||
InstalledPluginListResponse,
|
||||
PackageDependency,
|
||||
Permissions,
|
||||
PluginTask,
|
||||
PluginsFromMarketplaceResponse,
|
||||
@ -119,21 +121,33 @@ export const useInstallFromMarketplaceAndGitHub = ({
|
||||
return Promise.all(payload.map(async (item) => {
|
||||
try {
|
||||
if (item.type === 'github') {
|
||||
const data = item as GitHubItemAndMarketPlaceDependency
|
||||
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!,
|
||||
repo: data.value.repo!,
|
||||
version: data.value.version!,
|
||||
package: data.value.package!,
|
||||
plugin_unique_identifier: data.value.github_plugin_unique_identifier!,
|
||||
},
|
||||
})
|
||||
}
|
||||
if (item.type === 'marketplace') {
|
||||
const data = item as GitHubItemAndMarketPlaceDependency
|
||||
|
||||
await post<InstallPackageResponse>('/workspaces/current/plugin/install/marketplace', {
|
||||
body: {
|
||||
plugin_unique_identifiers: [data.value.plugin_unique_identifier!],
|
||||
},
|
||||
})
|
||||
}
|
||||
if (item.type === 'package') {
|
||||
const data = item as PackageDependency
|
||||
await post<InstallPackageResponse>('/workspaces/current/plugin/install/pkg', {
|
||||
body: {
|
||||
plugin_unique_identifiers: [data.value.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 })
|
||||
}
|
||||
// eslint-disable-next-line unused-imports/no-unused-vars
|
||||
|
Loading…
Reference in New Issue
Block a user