'use client' import type { FC } from 'react' import React, { useCallback } from 'react' import { useTranslation } from 'react-i18next' import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' import Badge from '@/app/components/base/badge' import type { OffsetOptions, Placement, } from '@floating-ui/react' import { useVersionListOfPlugin } from '@/service/use-plugins' import useTimestamp from '@/hooks/use-timestamp' import cn from '@/utils/classnames' type Props = { disabled?: boolean isShow: boolean onShowChange: (isShow: boolean) => void pluginID: string currentVersion: string trigger: React.ReactNode placement?: Placement offset?: OffsetOptions onSelect: ({ version, unique_identifier, }: { version: string unique_identifier: string }) => void } const PluginVersionPicker: FC = ({ disabled = false, isShow, onShowChange, pluginID, currentVersion, trigger, placement = 'bottom-start', offset = { mainAxis: 4, crossAxis: -16, }, onSelect, }) => { const { t } = useTranslation() const format = t('appLog.dateTimeFormat').split(' ')[0] const { formatDate } = useTimestamp() const handleTriggerClick = () => { if (disabled) return onShowChange(true) } const { data: res } = useVersionListOfPlugin(pluginID) const handleSelect = useCallback(({ version, unique_identifier }: { version: string unique_identifier: string }) => { if (currentVersion === version) return onSelect({ version, unique_identifier }) onShowChange(false) }, [currentVersion, onSelect, onShowChange]) return ( {trigger}
{t('plugin.detailPanel.switchVersion')}
{res?.data.versions.map(version => (
handleSelect({ version: version.version, unique_identifier: version.unique_identifier, })} >
{version.version}
{currentVersion === version.version && }
{formatDate(version.created_at, format)}
))}
) } export default React.memo(PluginVersionPicker)