refactor: switch plugin version component to not accept version

This commit is contained in:
AkaraChen 2025-01-07 10:55:42 +08:00
parent bdb9d676b1
commit a8c4870349
3 changed files with 12 additions and 16 deletions

View File

@ -158,9 +158,10 @@ export const AgentStrategySelector = memo((props: AgentStrategySelectorProps) =>
}
{showSwitchVersion && <SwitchPluginVersion
uniqueIdentifier={'langgenius/openai:12'}
onSelect={console.error}
version={''}
tooltip={t('workflow.nodes.agent.switchToNewVersion')}
onChange={() => {
// TODO: refresh all strategies
}}
/>}
</div>}
</div>

View File

@ -13,12 +13,11 @@ import { useCheckInstalled } from '@/service/use-plugins'
export type SwitchPluginVersionProps = {
uniqueIdentifier: string
tooltip?: string
version: string
onSelect: (version: string) => void
onChange?: (version: string) => void
}
export const SwitchPluginVersion: FC<SwitchPluginVersionProps> = (props) => {
const { uniqueIdentifier, tooltip, onSelect, version } = props
const { uniqueIdentifier, tooltip, onChange } = props
const [pluginId] = uniqueIdentifier.split(':')
const [isShow, setIsShow] = useState(false)
const [isShowUpdateModal, { setTrue: showUpdateModal, setFalse: hideUpdateModal }] = useBoolean(false)
@ -31,9 +30,9 @@ export const SwitchPluginVersion: FC<SwitchPluginVersionProps> = (props) => {
const handleUpdatedFromMarketplace = useCallback(() => {
hideUpdateModal()
onSelect(targetVersion!)
}, [hideUpdateModal, onSelect, targetVersion])
return <Tooltip popupContent={!isShow && tooltip} triggerMethod='hover'>
onChange?.(targetVersion!)
}, [hideUpdateModal, onChange, targetVersion])
return <Tooltip popupContent={!isShow && !isShowUpdateModal && tooltip} triggerMethod='hover'>
<div className='w-fit'>
{isShowUpdateModal && pluginDetail && <UpdateFromMarketplace
payload={{
@ -49,11 +48,11 @@ export const SwitchPluginVersion: FC<SwitchPluginVersionProps> = (props) => {
onCancel={hideUpdateModal}
onSave={handleUpdatedFromMarketplace}
/>}
<PluginVersionPicker
{pluginDetail && <PluginVersionPicker
isShow={isShow}
onShowChange={setIsShow}
pluginID={pluginId}
currentVersion={version}
currentVersion={pluginDetail.version}
onSelect={(state) => {
setTargetVersion(state.version)
showUpdateModal()
@ -67,14 +66,14 @@ export const SwitchPluginVersion: FC<SwitchPluginVersionProps> = (props) => {
uppercase={true}
text={
<>
<div>{version}</div>
<div>{pluginDetail.version}</div>
<RiArrowLeftRightLine className='ml-1 w-3 h-3 text-text-tertiary' />
</>
}
hasRedCornerMark={true}
/>
}
/>
/>}
</div>
</Tooltip>
}

View File

@ -1,17 +1,13 @@
'use client'
import { useState } from 'react'
import { SwitchPluginVersion } from '../components/workflow/nodes/_base/components/switch-plugin-version'
import { useTranslation } from 'react-i18next'
export default function Page() {
const [version, setVersion] = useState('0.0.1')
const { t } = useTranslation()
return <div className="p-20">
<SwitchPluginVersion
uniqueIdentifier={'langgenius/openai:12'}
onSelect={setVersion}
version={version}
tooltip={t('workflow.nodes.agent.switchToNewVersion')}
/>
</div>