refactor: switch plugin version component to not accept version

pull/12560/head
AkaraChen 1 year ago
parent bdb9d676b1
commit a8c4870349

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

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

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

Loading…
Cancel
Save