import type { ReactElement, ReactNode } from 'react' import type { TriggerParams } from '@/app/components/base/date-and-time-picker/types' import type { AutoUpdateConfig } from '@/app/components/plugins/reference-setting-modal/auto-update-setting/types' import type { dayjsToTimeOfDay } from '@/app/components/plugins/reference-setting-modal/auto-update-setting/utils' import type { PluginCategoryEnum } from '@/app/components/plugins/types' import { cn } from '@langgenius/dify-ui/cn' import { RadioGroup } from '@langgenius/dify-ui/radio-group' import { useState } from 'react' import { Trans, useTranslation } from 'react-i18next' import TimePicker from '@/app/components/base/date-and-time-picker/time-picker' import { ACCOUNT_SETTING_TAB } from '@/app/components/header/account-setting/constants' import PluginsPicker from '@/app/components/plugins/reference-setting-modal/auto-update-setting/plugins-picker' import { AUTO_UPDATE_MODE, AUTO_UPDATE_STRATEGY } from '@/app/components/plugins/reference-setting-modal/auto-update-setting/types' import { convertLocalSecondsToUTCDaySeconds } from '@/app/components/plugins/reference-setting-modal/auto-update-setting/utils' import { useModalContextSelector } from '@/context/modal-context' import UpdateSettingOptionCard from './update-setting-option-card' type Option = { value: Value label: string } type UpdateSettingDialogFormProps = { autoUpgrade: AutoUpdateConfig category: PluginCategoryEnum plugins: string[] scopeOptions: Option[] strategyOptions: Option[] timezone: string updateTimeValue: string minuteFilter: (minutes: string[]) => string[] onAutoUpgradeChange: (payload: Partial) => void onPluginsChange: (newPlugins: string[]) => void onRequestClose: () => void onUpdateTimeChange: (value: Parameters[0]) => void renderTimePickerTrigger: (params: TriggerParams) => ReactElement } const updateSettingFormLabelClassName = 'flex min-h-6 w-full items-center system-sm-medium text-text-secondary' function SettingTimeZone({ children, onRequestClose, }: { children?: ReactNode onRequestClose: () => void }) { const setShowAccountSettingModal = useModalContextSelector(s => s.setShowAccountSettingModal) return ( ) } const UpdateSettingDialogForm = ({ autoUpgrade, category, plugins, scopeOptions, strategyOptions, timezone, updateTimeValue, minuteFilter, onAutoUpgradeChange, onPluginsChange, onRequestClose, onUpdateTimeChange, renderTimePickerTrigger, }: UpdateSettingDialogFormProps) => { const { t } = useTranslation() const [previewStrategy, setPreviewStrategy] = useState() const displayedStrategy = previewStrategy ?? autoUpgrade.strategy_setting const getStrategyDescription = (strategy: AUTO_UPDATE_STRATEGY) => { switch (strategy) { case AUTO_UPDATE_STRATEGY.disabled: return t('autoUpdate.strategy.disabled.description', { ns: 'plugin' }) case AUTO_UPDATE_STRATEGY.fixOnly: return t('autoUpdate.strategy.fixOnly.description', { ns: 'plugin' }) case AUTO_UPDATE_STRATEGY.latest: return t('autoUpdate.strategy.latest.description', { ns: 'plugin' }) default: return '' } } const strategyDescription = getStrategyDescription(displayedStrategy) return (
{t('autoUpdate.autoUpdate', { ns: 'plugin' })}
aria-label={t('autoUpdate.autoUpdate', { ns: 'plugin' })} className="flex w-full gap-2" value={autoUpgrade.strategy_setting} onValueChange={strategy_setting => onAutoUpgradeChange({ strategy_setting })} > {strategyOptions.map(option => ( key={option.value} value={option.value} label={option.label} onFocus={() => setPreviewStrategy(option.value)} onBlur={() => setPreviewStrategy(undefined)} onMouseEnter={() => setPreviewStrategy(option.value)} onMouseLeave={() => setPreviewStrategy(undefined)} /> ))}
{strategyDescription}
{autoUpgrade.strategy_setting !== AUTO_UPDATE_STRATEGY.disabled && ( <>
{t('autoUpdate.updateTime', { ns: 'plugin' })}
, }} />
onAutoUpgradeChange({ upgrade_time_of_day: convertLocalSecondsToUTCDaySeconds(0, timezone), })} title={t('autoUpdate.updateTime', { ns: 'plugin' })} minuteFilter={minuteFilter} renderTrigger={renderTimePickerTrigger} placement="bottom-start" />
{t('autoUpdate.scope', { ns: 'plugin' })}
aria-label={t('autoUpdate.scope', { ns: 'plugin' })} className="flex w-full gap-2" value={autoUpgrade.upgrade_mode} onValueChange={upgrade_mode => onAutoUpgradeChange({ upgrade_mode })} > {scopeOptions.map(option => ( key={option.value} value={option.value} label={option.label} /> ))}
{autoUpgrade.upgrade_mode !== AUTO_UPDATE_MODE.update_all && ( )}
)}
) } export default UpdateSettingDialogForm