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