mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
feat: handle on update show update modal
This commit is contained in:
parent
27f794e197
commit
7e39565fd2
|
@ -28,7 +28,7 @@ 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 { useModalContext } from '@/context/modal-context'
|
||||||
|
import UpdateFromMarketplace from '@/app/components/plugins/update-plugin/from-market-place'
|
||||||
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'
|
||||||
|
|
||||||
|
@ -55,17 +55,35 @@ const DetailHeader = ({
|
||||||
source,
|
source,
|
||||||
tenant_id,
|
tenant_id,
|
||||||
version,
|
version,
|
||||||
|
latest_unique_identifier,
|
||||||
latest_version,
|
latest_version,
|
||||||
meta,
|
meta,
|
||||||
} = 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
|
||||||
|
const isFromMarketplace = source === PluginSource.marketplace
|
||||||
|
|
||||||
const hasNewVersion = useMemo(() => {
|
const hasNewVersion = useMemo(() => {
|
||||||
return source === PluginSource.github && latest_version !== version
|
if (isFromGitHub)
|
||||||
}, [source, latest_version, version])
|
return latest_version !== version
|
||||||
|
|
||||||
|
if (isFromMarketplace)
|
||||||
|
return !!latest_version && latest_version !== version
|
||||||
|
|
||||||
|
return false
|
||||||
|
}, [isFromGitHub, isFromMarketplace, latest_version, version])
|
||||||
|
|
||||||
|
const [isShowUpdateModal, {
|
||||||
|
setTrue: showUpdateModal,
|
||||||
|
setFalse: hideUpdateModal,
|
||||||
|
}] = useBoolean(false)
|
||||||
|
|
||||||
const handleUpdate = async () => {
|
const handleUpdate = async () => {
|
||||||
|
if (isFromMarketplace) {
|
||||||
|
showUpdateModal()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const fetchedReleases = await fetchReleases(author, name)
|
const fetchedReleases = await fetchReleases(author, name)
|
||||||
if (fetchedReleases.length === 0)
|
if (fetchedReleases.length === 0)
|
||||||
|
@ -106,6 +124,11 @@ const DetailHeader = ({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleUpdatedFromMarketplace = () => {
|
||||||
|
onUpdate()
|
||||||
|
hideUpdateModal()
|
||||||
|
}
|
||||||
|
|
||||||
const [isShowPluginInfo, {
|
const [isShowPluginInfo, {
|
||||||
setTrue: showPluginInfo,
|
setTrue: showPluginInfo,
|
||||||
setFalse: hidePluginInfo,
|
setFalse: hidePluginInfo,
|
||||||
|
@ -222,6 +245,24 @@ const DetailHeader = ({
|
||||||
isDisabled={deleting}
|
isDisabled={deleting}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{
|
||||||
|
isShowUpdateModal && (
|
||||||
|
<UpdateFromMarketplace
|
||||||
|
payload={{
|
||||||
|
originalPackageInfo: {
|
||||||
|
id: detail.plugin_unique_identifier,
|
||||||
|
payload: detail.declaration,
|
||||||
|
},
|
||||||
|
targetPackageInfo: {
|
||||||
|
id: latest_unique_identifier,
|
||||||
|
version: latest_version,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
onCancel={hideUpdateModal}
|
||||||
|
onSave={handleUpdatedFromMarketplace}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,7 @@ export type PluginDetail = {
|
||||||
endpoints_active: number
|
endpoints_active: number
|
||||||
version: string
|
version: string
|
||||||
latest_version: string
|
latest_version: string
|
||||||
|
latest_unique_identifier: string
|
||||||
source: PluginSource
|
source: PluginSource
|
||||||
meta?: MetaData
|
meta?: MetaData
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@ const UpdatePluginModal: FC<Props> = ({
|
||||||
const handleConfirm = useCallback(async () => {
|
const handleConfirm = useCallback(async () => {
|
||||||
if (uploadStep === UploadStep.notStarted) {
|
if (uploadStep === UploadStep.notStarted) {
|
||||||
setUploadStep(UploadStep.upgrading)
|
setUploadStep(UploadStep.upgrading)
|
||||||
|
try {
|
||||||
const {
|
const {
|
||||||
all_installed: isInstalled,
|
all_installed: isInstalled,
|
||||||
task_id: taskId,
|
task_id: taskId,
|
||||||
|
@ -76,6 +77,7 @@ const UpdatePluginModal: FC<Props> = ({
|
||||||
original_plugin_unique_identifier: originalPackageInfo.id,
|
original_plugin_unique_identifier: originalPackageInfo.id,
|
||||||
new_plugin_unique_identifier: targetPackageInfo.id,
|
new_plugin_unique_identifier: targetPackageInfo.id,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (isInstalled) {
|
if (isInstalled) {
|
||||||
onSave()
|
onSave()
|
||||||
return
|
return
|
||||||
|
@ -87,6 +89,11 @@ const UpdatePluginModal: FC<Props> = ({
|
||||||
})
|
})
|
||||||
onSave()
|
onSave()
|
||||||
}
|
}
|
||||||
|
catch (e) {
|
||||||
|
setUploadStep(UploadStep.notStarted)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
if (uploadStep === UploadStep.installed) {
|
if (uploadStep === UploadStep.installed) {
|
||||||
onSave()
|
onSave()
|
||||||
onCancel()
|
onCancel()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user