mirror of
https://github.com/langgenius/dify.git
synced 2026-04-26 18:27:15 +08:00
chore: update the 'Update plugin from GitHub'
This commit is contained in:
parent
0d08b6cf51
commit
4c0e4e490a
@ -316,7 +316,7 @@ const PortalSelect: FC<PortalSelectProps> = ({
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const localPlaceholder = placeholder || t('common.placeholder.select')
|
const localPlaceholder = placeholder || t('common.placeholder.select')
|
||||||
const selectedItem = items.find(item => item.value === value)
|
const selectedItem = value ? items.find(item => item.value === value) : undefined
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PortalToFollowElem
|
<PortalToFollowElem
|
||||||
@ -343,6 +343,7 @@ const PortalSelect: FC<PortalSelectProps> = ({
|
|||||||
>
|
>
|
||||||
{selectedItem?.name ?? localPlaceholder}
|
{selectedItem?.name ?? localPlaceholder}
|
||||||
</span>
|
</span>
|
||||||
|
<div className='mx-0.5'>{installedValue && selectedItem && selectedItem.value !== installedValue && <Badge>{installedValue} {'->'} {selectedItem.value} </Badge>}</div>
|
||||||
<ChevronDownIcon className='shrink-0 h-4 w-4 text-gray-400' />
|
<ChevronDownIcon className='shrink-0 h-4 w-4 text-gray-400' />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -356,8 +357,8 @@ const PortalSelect: FC<PortalSelectProps> = ({
|
|||||||
<div
|
<div
|
||||||
key={item.value}
|
key={item.value}
|
||||||
className={`
|
className={`
|
||||||
flex items-center justify-between px-2.5 h-9 cursor-pointer rounded-lg hover:bg-gray-100 text-gray-700
|
flex items-center justify-between px-2.5 h-9 cursor-pointer rounded-lg hover:bg-state-base-hover text-text-secondary
|
||||||
${item.value === value && 'bg-gray-100'}
|
${item.value === value && 'bg-state-base-hover'}
|
||||||
`}
|
`}
|
||||||
title={item.name}
|
title={item.name}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
|||||||
@ -64,10 +64,10 @@ export const useGitHubUpload = () => {
|
|||||||
return GitHubPackage
|
return GitHubPackage
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
setError('Error installing package')
|
setError('Error uploading package')
|
||||||
Toast.notify({
|
Toast.notify({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: 'Error installing package',
|
message: 'Error uploading package',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import Modal from '@/app/components/base/modal'
|
|||||||
import type { Item } from '@/app/components/base/select'
|
import type { Item } from '@/app/components/base/select'
|
||||||
import type { InstallState } from '@/app/components/plugins/types'
|
import type { InstallState } from '@/app/components/plugins/types'
|
||||||
import { useGitHubReleases } from '../hooks'
|
import { useGitHubReleases } from '../hooks'
|
||||||
import { parseGitHubUrl } from '../utils'
|
import { convertRepoToUrl, parseGitHubUrl } from '../utils'
|
||||||
import type { PluginDeclaration, UpdateFromGitHubPayload } from '../../types'
|
import type { PluginDeclaration, UpdateFromGitHubPayload } from '../../types'
|
||||||
import { InstallStepFromGitHub } from '../../types'
|
import { InstallStepFromGitHub } from '../../types'
|
||||||
import Toast from '@/app/components/base/toast'
|
import Toast from '@/app/components/base/toast'
|
||||||
@ -17,7 +17,7 @@ import useGetIcon from '@/app/components/plugins/install-plugin/base/use-get-ico
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { usePluginPageContext } from '../../plugin-page/context'
|
import { usePluginPageContext } from '../../plugin-page/context'
|
||||||
|
|
||||||
const i18nPrefix = 'plugin.installModal'
|
const i18nPrefix = 'plugin.installFromGitHub'
|
||||||
|
|
||||||
type InstallFromGitHubProps = {
|
type InstallFromGitHubProps = {
|
||||||
updatePayload?: UpdateFromGitHubPayload
|
updatePayload?: UpdateFromGitHubPayload
|
||||||
@ -27,14 +27,25 @@ type InstallFromGitHubProps = {
|
|||||||
|
|
||||||
const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ updatePayload, onClose }) => {
|
const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ updatePayload, onClose }) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
// const updatePayloadTest = {
|
||||||
|
// originalPackageInfo: {
|
||||||
|
// id: '0299ff5e-40cc-4690-9308-6687cf344a21',
|
||||||
|
// repo: 'YIXIAO0/test',
|
||||||
|
// version: '1.10.1',
|
||||||
|
// package: 'openai.difypkg',
|
||||||
|
// }
|
||||||
|
// }
|
||||||
const [state, setState] = useState<InstallState>({
|
const [state, setState] = useState<InstallState>({
|
||||||
step: updatePayload ? InstallStepFromGitHub.selectPackage : InstallStepFromGitHub.setUrl,
|
step: updatePayload ? InstallStepFromGitHub.selectPackage : InstallStepFromGitHub.setUrl,
|
||||||
repoUrl: updatePayload?.originalPackageInfo.repo || '',
|
repoUrl: updatePayload?.originalPackageInfo?.repo
|
||||||
selectedVersion: updatePayload?.originalPackageInfo.version || '',
|
? convertRepoToUrl(updatePayload.originalPackageInfo.repo)
|
||||||
selectedPackage: updatePayload?.originalPackageInfo.package || '',
|
: '',
|
||||||
|
selectedVersion: '',
|
||||||
|
selectedPackage: '',
|
||||||
releases: [],
|
releases: [],
|
||||||
})
|
})
|
||||||
const { getIconUrl } = useGetIcon()
|
const { getIconUrl } = useGetIcon()
|
||||||
|
const { fetchReleases } = useGitHubReleases()
|
||||||
const [uniqueIdentifier, setUniqueIdentifier] = useState<string | null>(null)
|
const [uniqueIdentifier, setUniqueIdentifier] = useState<string | null>(null)
|
||||||
const [manifest, setManifest] = useState<PluginDeclaration | null>(null)
|
const [manifest, setManifest] = useState<PluginDeclaration | null>(null)
|
||||||
const [errorMsg, setErrorMsg] = useState<string | null>(null)
|
const [errorMsg, setErrorMsg] = useState<string | null>(null)
|
||||||
@ -55,15 +66,13 @@ const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ updatePayload, on
|
|||||||
})) || [])
|
})) || [])
|
||||||
: []
|
: []
|
||||||
|
|
||||||
const { fetchReleases } = useGitHubReleases()
|
|
||||||
|
|
||||||
const getTitle = useCallback(() => {
|
const getTitle = useCallback(() => {
|
||||||
if (state.step === InstallStepFromGitHub.installed)
|
if (state.step === InstallStepFromGitHub.installed)
|
||||||
return t(`${i18nPrefix}.installedSuccessfully`)
|
return t(`${i18nPrefix}.installedSuccessfully`)
|
||||||
if (state.step === InstallStepFromGitHub.installFailed)
|
if (state.step === InstallStepFromGitHub.installFailed)
|
||||||
return t(`${i18nPrefix}.installFailed`)
|
return t(`${i18nPrefix}.installFailed`)
|
||||||
|
|
||||||
return t(`${i18nPrefix}.installPlugin`)
|
return updatePayload ? t(`${i18nPrefix}.updatePlugin`) : t(`${i18nPrefix}.installPlugin`)
|
||||||
}, [state.step])
|
}, [state.step])
|
||||||
|
|
||||||
const handleUrlSubmit = async () => {
|
const handleUrlSubmit = async () => {
|
||||||
@ -190,6 +199,7 @@ const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ updatePayload, on
|
|||||||
)}
|
)}
|
||||||
{state.step === InstallStepFromGitHub.readyToInstall && (
|
{state.step === InstallStepFromGitHub.readyToInstall && (
|
||||||
<Loaded
|
<Loaded
|
||||||
|
updatePayload={updatePayload!}
|
||||||
uniqueIdentifier={uniqueIdentifier!}
|
uniqueIdentifier={uniqueIdentifier!}
|
||||||
payload={manifest as any}
|
payload={manifest as any}
|
||||||
repoUrl={state.repoUrl}
|
repoUrl={state.repoUrl}
|
||||||
|
|||||||
@ -2,18 +2,19 @@
|
|||||||
|
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import Button from '@/app/components/base/button'
|
import Button from '@/app/components/base/button'
|
||||||
import type { PluginDeclaration } from '../../../types'
|
import type { PluginDeclaration, UpdateFromGitHubPayload } from '../../../types'
|
||||||
import Card from '../../../card'
|
import Card from '../../../card'
|
||||||
import Badge, { BadgeState } from '@/app/components/base/badge/index'
|
import Badge, { BadgeState } from '@/app/components/base/badge/index'
|
||||||
import { pluginManifestToCardPluginProps } from '../../utils'
|
import { pluginManifestToCardPluginProps } from '../../utils'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { installPackageFromGitHub } from '@/service/plugins'
|
import { installPackageFromGitHub, uninstallPlugin } from '@/service/plugins'
|
||||||
import { RiLoader2Line } from '@remixicon/react'
|
import { RiLoader2Line } from '@remixicon/react'
|
||||||
import { usePluginTasksStore } from '@/app/components/plugins/plugin-page/store'
|
import { usePluginTasksStore } from '@/app/components/plugins/plugin-page/store'
|
||||||
import checkTaskStatus from '../../base/check-task-status'
|
import checkTaskStatus from '../../base/check-task-status'
|
||||||
import { parseGitHubUrl } from '../../utils'
|
import { parseGitHubUrl } from '../../utils'
|
||||||
|
|
||||||
type LoadedProps = {
|
type LoadedProps = {
|
||||||
|
updatePayload: UpdateFromGitHubPayload
|
||||||
uniqueIdentifier: string
|
uniqueIdentifier: string
|
||||||
payload: PluginDeclaration
|
payload: PluginDeclaration
|
||||||
repoUrl: string
|
repoUrl: string
|
||||||
@ -27,6 +28,7 @@ type LoadedProps = {
|
|||||||
const i18nPrefix = 'plugin.installModal'
|
const i18nPrefix = 'plugin.installModal'
|
||||||
|
|
||||||
const Loaded: React.FC<LoadedProps> = ({
|
const Loaded: React.FC<LoadedProps> = ({
|
||||||
|
updatePayload,
|
||||||
uniqueIdentifier,
|
uniqueIdentifier,
|
||||||
payload,
|
payload,
|
||||||
repoUrl,
|
repoUrl,
|
||||||
@ -54,6 +56,9 @@ const Loaded: React.FC<LoadedProps> = ({
|
|||||||
uniqueIdentifier,
|
uniqueIdentifier,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (updatePayload && isInstalled)
|
||||||
|
await uninstallPlugin(updatePayload.originalPackageInfo.id)
|
||||||
|
|
||||||
if (isInstalled) {
|
if (isInstalled) {
|
||||||
onInstalled()
|
onInstalled()
|
||||||
return
|
return
|
||||||
@ -64,10 +69,15 @@ const Loaded: React.FC<LoadedProps> = ({
|
|||||||
taskId,
|
taskId,
|
||||||
pluginUniqueIdentifier: uniqueIdentifier,
|
pluginUniqueIdentifier: uniqueIdentifier,
|
||||||
})
|
})
|
||||||
|
|
||||||
onInstalled()
|
onInstalled()
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
onFailed(e instanceof Error ? e.message : String(e))
|
if (typeof e === 'string') {
|
||||||
|
onFailed(e)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
onFailed()
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
setIsInstalling(false)
|
setIsInstalling(false)
|
||||||
|
|||||||
@ -41,7 +41,7 @@ const SelectPackage: React.FC<SelectPackageProps> = ({
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const isEdit = Boolean(updatePayload)
|
const isEdit = Boolean(updatePayload)
|
||||||
const [isUploading, setIsUploading] = React.useState(false)
|
const [isUploading, setIsUploading] = React.useState(false)
|
||||||
const { handleUpload, error } = useGitHubUpload()
|
const { handleUpload } = useGitHubUpload()
|
||||||
|
|
||||||
const handleUploadPackage = async () => {
|
const handleUploadPackage = async () => {
|
||||||
if (isUploading) return
|
if (isUploading) return
|
||||||
@ -59,7 +59,6 @@ const SelectPackage: React.FC<SelectPackageProps> = ({
|
|||||||
catch (e: any) {
|
catch (e: any) {
|
||||||
if (e.response?.message)
|
if (e.response?.message)
|
||||||
onFailed(e.response?.message)
|
onFailed(e.response?.message)
|
||||||
|
|
||||||
else
|
else
|
||||||
onFailed(t('plugin.error.uploadFailed'))
|
onFailed(t('plugin.error.uploadFailed'))
|
||||||
}
|
}
|
||||||
@ -74,16 +73,15 @@ const SelectPackage: React.FC<SelectPackageProps> = ({
|
|||||||
htmlFor='version'
|
htmlFor='version'
|
||||||
className='flex flex-col justify-center items-start self-stretch text-text-secondary'
|
className='flex flex-col justify-center items-start self-stretch text-text-secondary'
|
||||||
>
|
>
|
||||||
<span className='system-sm-semibold'>{isEdit ? t('plugin.installFromGitHub.updateVersion')
|
<span className='system-sm-semibold'>{t('plugin.installFromGitHub.selectVersion')}</span>
|
||||||
: t('plugin.installFromGitHub.selectVersion')}
|
|
||||||
</span>
|
|
||||||
</label>
|
</label>
|
||||||
<PortalSelect
|
<PortalSelect
|
||||||
value={selectedVersion}
|
value={selectedVersion}
|
||||||
onSelect={onSelectVersion}
|
onSelect={onSelectVersion}
|
||||||
items={versions}
|
items={versions}
|
||||||
|
installedValue={updatePayload?.originalPackageInfo.version}
|
||||||
placeholder={t('plugin.installFromGitHub.selectVersionPlaceholder') || ''}
|
placeholder={t('plugin.installFromGitHub.selectVersionPlaceholder') || ''}
|
||||||
popupClassName='w-[432px] z-[1001]'
|
popupClassName='w-[512px] z-[1001]'
|
||||||
/>
|
/>
|
||||||
<label
|
<label
|
||||||
htmlFor='package'
|
htmlFor='package'
|
||||||
@ -96,7 +94,7 @@ const SelectPackage: React.FC<SelectPackageProps> = ({
|
|||||||
onSelect={onSelectPackage}
|
onSelect={onSelectPackage}
|
||||||
items={packages}
|
items={packages}
|
||||||
placeholder={t('plugin.installFromGitHub.selectPackagePlaceholder') || ''}
|
placeholder={t('plugin.installFromGitHub.selectPackagePlaceholder') || ''}
|
||||||
popupClassName='w-[432px] z-[1001]'
|
popupClassName='w-[512px] z-[1001]'
|
||||||
/>
|
/>
|
||||||
<div className='flex justify-end items-center gap-2 self-stretch mt-4'>
|
<div className='flex justify-end items-center gap-2 self-stretch mt-4'>
|
||||||
{!isEdit
|
{!isEdit
|
||||||
|
|||||||
@ -51,3 +51,7 @@ export const parseGitHubUrl = (url: string): GitHubUrlInfo => {
|
|||||||
const match = url.match(/^https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/?$/)
|
const match = url.match(/^https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/?$/)
|
||||||
return match ? { isValid: true, owner: match[1], repo: match[2] } : { isValid: false }
|
return match ? { isValid: true, owner: match[1], repo: match[2] } : { isValid: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const convertRepoToUrl = (repo: string) => {
|
||||||
|
return repo ? `https://github.com/${repo}` : ''
|
||||||
|
}
|
||||||
|
|||||||
@ -86,7 +86,10 @@ const translation = {
|
|||||||
},
|
},
|
||||||
installFromGitHub: {
|
installFromGitHub: {
|
||||||
installPlugin: 'Install plugin from GitHub',
|
installPlugin: 'Install plugin from GitHub',
|
||||||
updateVersion: 'Update plugin from GitHub',
|
updatePlugin: 'Update plugin from GitHub',
|
||||||
|
installedSuccessfully: 'Installation successful',
|
||||||
|
installFailed: 'Installation failed',
|
||||||
|
uploadFailed: 'Upload failed',
|
||||||
gitHubRepo: 'GitHub repository',
|
gitHubRepo: 'GitHub repository',
|
||||||
selectVersion: 'Select version',
|
selectVersion: 'Select version',
|
||||||
selectVersionPlaceholder: 'Please select a version',
|
selectVersionPlaceholder: 'Please select a version',
|
||||||
|
|||||||
@ -86,7 +86,10 @@ const translation = {
|
|||||||
},
|
},
|
||||||
installFromGitHub: {
|
installFromGitHub: {
|
||||||
installPlugin: '从 GitHub 安装插件',
|
installPlugin: '从 GitHub 安装插件',
|
||||||
updateVersion: '更新 GitHub 插件',
|
updatePlugin: '更新来自 GitHub 的插件',
|
||||||
|
installedSuccessfully: '安装成功',
|
||||||
|
installFailed: '安装失败',
|
||||||
|
uploadFailed: '上传失败',
|
||||||
gitHubRepo: 'GitHub 仓库',
|
gitHubRepo: 'GitHub 仓库',
|
||||||
selectVersion: '选择版本',
|
selectVersion: '选择版本',
|
||||||
selectVersionPlaceholder: '请选择一个版本',
|
selectVersionPlaceholder: '请选择一个版本',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user