mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
fix: market icon not show
This commit is contained in:
parent
746838e276
commit
3b032f086d
|
@ -3,7 +3,7 @@ import type { FC } from 'react'
|
||||||
import Modal from '@/app/components/base/modal'
|
import Modal from '@/app/components/base/modal'
|
||||||
import React, { useCallback, useState } from 'react'
|
import React, { useCallback, useState } from 'react'
|
||||||
import { InstallStep } from '../../types'
|
import { InstallStep } from '../../types'
|
||||||
import type { Dependency, Plugin } from '../../types'
|
import type { Dependency, InstallStatusResponse, Plugin } from '../../types'
|
||||||
import Install from './steps/install'
|
import Install from './steps/install'
|
||||||
import Installed from './steps/installed'
|
import Installed from './steps/installed'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
@ -31,7 +31,7 @@ const InstallBundle: FC<Props> = ({
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [step, setStep] = useState<InstallStep>(installType === InstallType.fromMarketplace ? InstallStep.readyToInstall : InstallStep.uploading)
|
const [step, setStep] = useState<InstallStep>(installType === InstallType.fromMarketplace ? InstallStep.readyToInstall : InstallStep.uploading)
|
||||||
const [installedPlugins, setInstalledPlugins] = useState<Plugin[]>([])
|
const [installedPlugins, setInstalledPlugins] = useState<Plugin[]>([])
|
||||||
const [installStatus, setInstallStatus] = useState<{ success: boolean }[]>([])
|
const [installStatus, setInstallStatus] = useState<InstallStatusResponse[]>([])
|
||||||
const getTitle = useCallback(() => {
|
const getTitle = useCallback(() => {
|
||||||
if (step === InstallStep.uploadFailed)
|
if (step === InstallStep.uploadFailed)
|
||||||
return t(`${i18nPrefix}.uploadFailed`)
|
return t(`${i18nPrefix}.uploadFailed`)
|
||||||
|
@ -43,7 +43,7 @@ const InstallBundle: FC<Props> = ({
|
||||||
return t(`${i18nPrefix}.installPlugin`)
|
return t(`${i18nPrefix}.installPlugin`)
|
||||||
}, [step, t])
|
}, [step, t])
|
||||||
|
|
||||||
const handleInstalled = useCallback((plugins: Plugin[], installStatus: { success: boolean }[]) => {
|
const handleInstalled = useCallback((plugins: Plugin[], installStatus: InstallStatusResponse[]) => {
|
||||||
setInstallStatus(installStatus)
|
setInstallStatus(installStatus)
|
||||||
setInstalledPlugins(plugins)
|
setInstalledPlugins(plugins)
|
||||||
setStep(InstallStep.installed)
|
setStep(InstallStep.installed)
|
||||||
|
|
|
@ -6,17 +6,20 @@ import Card from '../../../card'
|
||||||
import Checkbox from '@/app/components/base/checkbox'
|
import Checkbox from '@/app/components/base/checkbox'
|
||||||
import Badge, { BadgeState } from '@/app/components/base/badge/index'
|
import Badge, { BadgeState } from '@/app/components/base/badge/index'
|
||||||
import useGetIcon from '../../base/use-get-icon'
|
import useGetIcon from '../../base/use-get-icon'
|
||||||
|
import { MARKETPLACE_API_PREFIX } from '@/config'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
checked: boolean
|
checked: boolean
|
||||||
onCheckedChange: (plugin: Plugin) => void
|
onCheckedChange: (plugin: Plugin) => void
|
||||||
payload: Plugin
|
payload: Plugin
|
||||||
|
isFromMarketPlace?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const LoadedItem: FC<Props> = ({
|
const LoadedItem: FC<Props> = ({
|
||||||
checked,
|
checked,
|
||||||
onCheckedChange,
|
onCheckedChange,
|
||||||
payload,
|
payload,
|
||||||
|
isFromMarketPlace,
|
||||||
}) => {
|
}) => {
|
||||||
const { getIconUrl } = useGetIcon()
|
const { getIconUrl } = useGetIcon()
|
||||||
return (
|
return (
|
||||||
|
@ -30,7 +33,7 @@ const LoadedItem: FC<Props> = ({
|
||||||
className='grow'
|
className='grow'
|
||||||
payload={{
|
payload={{
|
||||||
...payload,
|
...payload,
|
||||||
icon: getIconUrl(payload.icon),
|
icon: isFromMarketPlace ? `${MARKETPLACE_API_PREFIX}/plugins/${payload.org}/${payload.name}/icon` : getIconUrl(payload.icon),
|
||||||
}}
|
}}
|
||||||
titleLeft={payload.version ? <Badge className='mx-1' size="s" state={BadgeState.Default}>{payload.version}</Badge> : null}
|
titleLeft={payload.version ? <Badge className='mx-1' size="s" state={BadgeState.Default}>{payload.version}</Badge> : null}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -22,6 +22,7 @@ const MarketPlaceItem: FC<Props> = ({
|
||||||
checked={checked}
|
checked={checked}
|
||||||
onCheckedChange={onCheckedChange}
|
onCheckedChange={onCheckedChange}
|
||||||
payload={payload}
|
payload={payload}
|
||||||
|
isFromMarketPlace
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use client'
|
'use client'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React, { useCallback } from 'react'
|
import React, { useCallback } from 'react'
|
||||||
import type { Dependency, Plugin } from '../../../types'
|
import type { Dependency, InstallStatusResponse, Plugin } from '../../../types'
|
||||||
import Button from '@/app/components/base/button'
|
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'
|
||||||
|
@ -12,7 +12,7 @@ const i18nPrefix = 'plugin.installModal'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
fromDSLPayload: Dependency[]
|
fromDSLPayload: Dependency[]
|
||||||
onInstalled: (plugins: Plugin[], installStatus: { success: boolean }[]) => void
|
onInstalled: (plugins: Plugin[], installStatus: InstallStatusResponse[]) => void
|
||||||
onCancel: () => void
|
onCancel: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,8 +45,13 @@ const Install: FC<Props> = ({
|
||||||
|
|
||||||
// Install from marketplace and github
|
// Install from marketplace and github
|
||||||
const { mutate: installFromMarketplaceAndGitHub, isPending: isInstalling } = useInstallFromMarketplaceAndGitHub({
|
const { mutate: installFromMarketplaceAndGitHub, isPending: isInstalling } = useInstallFromMarketplaceAndGitHub({
|
||||||
onSuccess: (res: { success: boolean }[]) => {
|
onSuccess: (res: InstallStatusResponse[]) => {
|
||||||
onInstalled(selectedPlugins, res)
|
onInstalled(selectedPlugins, res.map((r, i) => {
|
||||||
|
return ({
|
||||||
|
...r,
|
||||||
|
isFromMarketPlace: fromDSLPayload[selectedIndexes[i]].type === 'marketplace',
|
||||||
|
})
|
||||||
|
}))
|
||||||
const hasInstallSuccess = res.some(r => r.success)
|
const hasInstallSuccess = res.some(r => r.success)
|
||||||
if (hasInstallSuccess)
|
if (hasInstallSuccess)
|
||||||
invalidateInstalledPluginList()
|
invalidateInstalledPluginList()
|
||||||
|
|
|
@ -7,10 +7,11 @@ import Button from '@/app/components/base/button'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import Badge, { BadgeState } from '@/app/components/base/badge/index'
|
import Badge, { BadgeState } from '@/app/components/base/badge/index'
|
||||||
import useGetIcon from '../../base/use-get-icon'
|
import useGetIcon from '../../base/use-get-icon'
|
||||||
|
import { MARKETPLACE_API_PREFIX } from '@/config'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
list: Plugin[]
|
list: Plugin[]
|
||||||
installStatus: { success: boolean }[]
|
installStatus: { success: boolean, isFromMarketPlace: boolean }[]
|
||||||
onCancel: () => void
|
onCancel: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ const Installed: FC<Props> = ({
|
||||||
className='w-full'
|
className='w-full'
|
||||||
payload={{
|
payload={{
|
||||||
...plugin,
|
...plugin,
|
||||||
icon: getIconUrl(plugin.icon),
|
icon: installStatus[index].isFromMarketPlace ? `${MARKETPLACE_API_PREFIX}/plugins/${plugin.org}/${plugin.name}/icon` : getIconUrl(plugin.icon),
|
||||||
}}
|
}}
|
||||||
installed={installStatus[index].success}
|
installed={installStatus[index].success}
|
||||||
installFailed={!installStatus[index].success}
|
installFailed={!installStatus[index].success}
|
||||||
|
|
|
@ -238,6 +238,11 @@ export type InstallPackageResponse = {
|
||||||
task_id: string
|
task_id: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type InstallStatusResponse = {
|
||||||
|
success: boolean,
|
||||||
|
isFromMarketPlace?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
export type updatePackageResponse = {
|
export type updatePackageResponse = {
|
||||||
all_installed: boolean
|
all_installed: boolean
|
||||||
task_id: string
|
task_id: string
|
||||||
|
|
Loading…
Reference in New Issue
Block a user