mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 17:18:40 +08:00
check update
This commit is contained in:
parent
1f1c61541e
commit
ebdf72fffc
@ -13,6 +13,8 @@ import Description from '../card/base/description'
|
|||||||
import Icon from '../card/base/card-icon'
|
import Icon from '../card/base/card-icon'
|
||||||
import Title from '../card/base/title'
|
import Title from '../card/base/title'
|
||||||
import OrgInfo from '../card/base/org-info'
|
import OrgInfo from '../card/base/org-info'
|
||||||
|
import { useGitHubReleases } from '../install-plugin/hooks'
|
||||||
|
import { compareVersion, getLatestVersion } from '@/utils/semver'
|
||||||
import OperationDropdown from './operation-dropdown'
|
import OperationDropdown from './operation-dropdown'
|
||||||
import PluginInfo from '@/app/components/plugins/plugin-page/plugin-info'
|
import PluginInfo from '@/app/components/plugins/plugin-page/plugin-info'
|
||||||
import ActionButton from '@/app/components/base/action-button'
|
import ActionButton from '@/app/components/base/action-button'
|
||||||
@ -20,10 +22,13 @@ import Button from '@/app/components/base/button'
|
|||||||
import Badge from '@/app/components/base/badge'
|
import Badge from '@/app/components/base/badge'
|
||||||
import Confirm from '@/app/components/base/confirm'
|
import Confirm from '@/app/components/base/confirm'
|
||||||
import Tooltip from '@/app/components/base/tooltip'
|
import Tooltip from '@/app/components/base/tooltip'
|
||||||
|
import Toast from '@/app/components/base/toast'
|
||||||
import { BoxSparkleFill } from '@/app/components/base/icons/src/vender/plugin'
|
import { BoxSparkleFill } from '@/app/components/base/icons/src/vender/plugin'
|
||||||
import { Github } from '@/app/components/base/icons/src/public/common'
|
import { Github } from '@/app/components/base/icons/src/public/common'
|
||||||
import { uninstallPlugin } from '@/service/plugins'
|
import { uninstallPlugin } from '@/service/plugins'
|
||||||
import { useGetLanguage } from '@/context/i18n'
|
import { useGetLanguage } from '@/context/i18n'
|
||||||
|
import { useModalContext } from '@/context/modal-context'
|
||||||
|
|
||||||
import { API_PREFIX, MARKETPLACE_URL_PREFIX } from '@/config'
|
import { API_PREFIX, MARKETPLACE_URL_PREFIX } from '@/config'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
|
|
||||||
@ -32,16 +37,18 @@ const i18nPrefix = 'plugin.action'
|
|||||||
type Props = {
|
type Props = {
|
||||||
detail: PluginDetail
|
detail: PluginDetail
|
||||||
onHide: () => void
|
onHide: () => void
|
||||||
onDelete: () => void
|
onUpdate: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const DetailHeader = ({
|
const DetailHeader = ({
|
||||||
detail,
|
detail,
|
||||||
onHide,
|
onHide,
|
||||||
onDelete,
|
onUpdate,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const locale = useGetLanguage()
|
const locale = useGetLanguage()
|
||||||
|
const { fetchReleases } = useGitHubReleases()
|
||||||
|
const { setShowUpdatePluginModal } = useModalContext()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
installation_id,
|
installation_id,
|
||||||
@ -53,13 +60,51 @@ const DetailHeader = ({
|
|||||||
} = detail
|
} = detail
|
||||||
const { author, name, label, description, icon, verified } = detail.declaration
|
const { author, name, label, description, icon, verified } = detail.declaration
|
||||||
const isFromGitHub = source === PluginSource.github
|
const isFromGitHub = source === PluginSource.github
|
||||||
// Only plugin installed from GitHub need to check if it's the new version
|
|
||||||
const hasNewVersion = useMemo(() => {
|
const hasNewVersion = useMemo(() => {
|
||||||
return source === PluginSource.github && latest_version !== version
|
return source === PluginSource.github && latest_version !== version
|
||||||
}, [source, latest_version, version])
|
}, [source, latest_version, version])
|
||||||
|
|
||||||
// #plugin TODO# update plugin
|
const handleUpdate = async () => {
|
||||||
const handleUpdate = () => { }
|
try {
|
||||||
|
const fetchedReleases = await fetchReleases(author, name)
|
||||||
|
if (fetchedReleases.length === 0)
|
||||||
|
return
|
||||||
|
const versions = fetchedReleases.map(release => release.tag_name)
|
||||||
|
const latestVersion = getLatestVersion(versions)
|
||||||
|
if (compareVersion(latestVersion, version) === 1) {
|
||||||
|
setShowUpdatePluginModal({
|
||||||
|
onSaveCallback: () => {
|
||||||
|
onUpdate()
|
||||||
|
},
|
||||||
|
payload: {
|
||||||
|
type: PluginSource.github,
|
||||||
|
github: {
|
||||||
|
originalPackageInfo: {
|
||||||
|
id: installation_id,
|
||||||
|
repo: meta!.repo,
|
||||||
|
version: meta!.version,
|
||||||
|
package: meta!.package,
|
||||||
|
releases: fetchedReleases,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Toast.notify({
|
||||||
|
type: 'info',
|
||||||
|
message: 'No new version available',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Toast.notify({
|
||||||
|
type: 'error',
|
||||||
|
message: 'Failed to compare versions',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const [isShowPluginInfo, {
|
const [isShowPluginInfo, {
|
||||||
setTrue: showPluginInfo,
|
setTrue: showPluginInfo,
|
||||||
@ -82,9 +127,9 @@ const DetailHeader = ({
|
|||||||
hideDeleting()
|
hideDeleting()
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
hideDeleteConfirm()
|
hideDeleteConfirm()
|
||||||
onDelete()
|
onUpdate()
|
||||||
}
|
}
|
||||||
}, [hideDeleteConfirm, hideDeleting, installation_id, showDeleting, onDelete])
|
}, [hideDeleteConfirm, hideDeleting, installation_id, showDeleting, onUpdate])
|
||||||
|
|
||||||
// #plugin TODO# used in apps
|
// #plugin TODO# used in apps
|
||||||
// const usedInApps = 3
|
// const usedInApps = 3
|
||||||
@ -141,6 +186,7 @@ const DetailHeader = ({
|
|||||||
</div>
|
</div>
|
||||||
<div className='flex gap-1'>
|
<div className='flex gap-1'>
|
||||||
<OperationDropdown
|
<OperationDropdown
|
||||||
|
source={detail.source}
|
||||||
onInfo={showPluginInfo}
|
onInfo={showPluginInfo}
|
||||||
onCheckVersion={handleUpdate}
|
onCheckVersion={handleUpdate}
|
||||||
onRemove={showDeleteConfirm}
|
onRemove={showDeleteConfirm}
|
||||||
|
|||||||
@ -10,11 +10,11 @@ import { usePluginPageContext } from '@/app/components/plugins/plugin-page/conte
|
|||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onDelete: () => void
|
onUpdate: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const PluginDetailPanel: FC<Props> = ({
|
const PluginDetailPanel: FC<Props> = ({
|
||||||
onDelete,
|
onUpdate,
|
||||||
}) => {
|
}) => {
|
||||||
const pluginDetail = usePluginPageContext(v => v.currentPluginDetail)
|
const pluginDetail = usePluginPageContext(v => v.currentPluginDetail)
|
||||||
const setCurrentPluginDetail = usePluginPageContext(v => v.setCurrentPluginDetail)
|
const setCurrentPluginDetail = usePluginPageContext(v => v.setCurrentPluginDetail)
|
||||||
@ -39,7 +39,7 @@ const PluginDetailPanel: FC<Props> = ({
|
|||||||
<DetailHeader
|
<DetailHeader
|
||||||
detail={pluginDetail}
|
detail={pluginDetail}
|
||||||
onHide={handleHide}
|
onHide={handleHide}
|
||||||
onDelete={onDelete}
|
onUpdate={onUpdate}
|
||||||
/>
|
/>
|
||||||
<div className='grow overflow-y-auto'>
|
<div className='grow overflow-y-auto'>
|
||||||
{!!pluginDetail.declaration.tool && <ActionList />}
|
{!!pluginDetail.declaration.tool && <ActionList />}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React, { useCallback, useRef, useState } from 'react'
|
import React, { useCallback, useRef, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import { PluginSource } from '../types'
|
||||||
import { RiArrowRightUpLine, RiMoreFill } from '@remixicon/react'
|
import { RiArrowRightUpLine, RiMoreFill } from '@remixicon/react'
|
||||||
import ActionButton from '@/app/components/base/action-button'
|
import ActionButton from '@/app/components/base/action-button'
|
||||||
// import Button from '@/app/components/base/button'
|
// import Button from '@/app/components/base/button'
|
||||||
@ -13,6 +14,7 @@ import {
|
|||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
source: PluginSource
|
||||||
onInfo: () => void
|
onInfo: () => void
|
||||||
onCheckVersion: () => void
|
onCheckVersion: () => void
|
||||||
onRemove: () => void
|
onRemove: () => void
|
||||||
@ -20,10 +22,11 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const OperationDropdown: FC<Props> = ({
|
const OperationDropdown: FC<Props> = ({
|
||||||
|
source,
|
||||||
|
detailUrl,
|
||||||
onInfo,
|
onInfo,
|
||||||
onCheckVersion,
|
onCheckVersion,
|
||||||
onRemove,
|
onRemove,
|
||||||
detailUrl,
|
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [open, doSetOpen] = useState(false)
|
const [open, doSetOpen] = useState(false)
|
||||||
@ -56,25 +59,33 @@ const OperationDropdown: FC<Props> = ({
|
|||||||
</PortalToFollowElemTrigger>
|
</PortalToFollowElemTrigger>
|
||||||
<PortalToFollowElemContent className='z-50'>
|
<PortalToFollowElemContent className='z-50'>
|
||||||
<div className='w-[160px] p-1 bg-components-panel-bg-blur rounded-xl border-[0.5px] border-components-panel-border shadow-lg'>
|
<div className='w-[160px] p-1 bg-components-panel-bg-blur rounded-xl border-[0.5px] border-components-panel-border shadow-lg'>
|
||||||
<div
|
{source === PluginSource.github && (
|
||||||
onClick={() => {
|
<div
|
||||||
onInfo()
|
onClick={() => {
|
||||||
handleTrigger()
|
onInfo()
|
||||||
}}
|
handleTrigger()
|
||||||
className='px-3 py-1.5 rounded-lg text-text-secondary system-md-regular cursor-pointer hover:bg-state-base-hover'
|
}}
|
||||||
>{t('plugin.detailPanel.operation.info')}</div>
|
className='px-3 py-1.5 rounded-lg text-text-secondary system-md-regular cursor-pointer hover:bg-state-base-hover'
|
||||||
<div
|
>{t('plugin.detailPanel.operation.info')}</div>
|
||||||
onClick={() => {
|
)}
|
||||||
onCheckVersion()
|
{source === PluginSource.github && (
|
||||||
handleTrigger()
|
<div
|
||||||
}}
|
onClick={() => {
|
||||||
className='px-3 py-1.5 rounded-lg text-text-secondary system-md-regular cursor-pointer hover:bg-state-base-hover'
|
onCheckVersion()
|
||||||
>{t('plugin.detailPanel.operation.checkUpdate')}</div>
|
handleTrigger()
|
||||||
<a href={detailUrl} target='_blank' className='flex items-center px-3 py-1.5 rounded-lg text-text-secondary system-md-regular cursor-pointer hover:bg-state-base-hover'>
|
}}
|
||||||
<span className='grow'>{t('plugin.detailPanel.operation.viewDetail')}</span>
|
className='px-3 py-1.5 rounded-lg text-text-secondary system-md-regular cursor-pointer hover:bg-state-base-hover'
|
||||||
<RiArrowRightUpLine className='shrink-0 w-3.5 h-3.5 text-text-tertiary' />
|
>{t('plugin.detailPanel.operation.checkUpdate')}</div>
|
||||||
</a>
|
)}
|
||||||
<div className='my-1 h-px bg-divider-subtle'></div>
|
{source === PluginSource.marketplace && (
|
||||||
|
<a href={detailUrl} target='_blank' className='flex items-center px-3 py-1.5 rounded-lg text-text-secondary system-md-regular cursor-pointer hover:bg-state-base-hover'>
|
||||||
|
<span className='grow'>{t('plugin.detailPanel.operation.viewDetail')}</span>
|
||||||
|
<RiArrowRightUpLine className='shrink-0 w-3.5 h-3.5 text-text-tertiary' />
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
{(source === PluginSource.marketplace || source === PluginSource.github) && (
|
||||||
|
<div className='my-1 h-px bg-divider-subtle'></div>
|
||||||
|
)}
|
||||||
<div
|
<div
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onRemove()
|
onRemove()
|
||||||
|
|||||||
@ -48,7 +48,7 @@ const PluginsPanel = () => {
|
|||||||
) : (
|
) : (
|
||||||
<Empty />
|
<Empty />
|
||||||
)}
|
)}
|
||||||
<PluginDetailPanel onDelete={() => invalidateInstalledPluginList()}/>
|
<PluginDetailPanel onUpdate={() => invalidateInstalledPluginList()}/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user