mirror of https://github.com/langgenius/dify.git
feat: choose time
This commit is contained in:
parent
dc5e974a78
commit
bc75d810c4
|
|
@ -1,13 +1,18 @@
|
|||
import React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
const Header = () => {
|
||||
type Props = {
|
||||
title?: string
|
||||
}
|
||||
const Header = ({
|
||||
title,
|
||||
}: Props) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className='flex flex-col border-b-[0.5px] border-divider-regular'>
|
||||
<div className='system-md-semibold flex items-center px-2 py-1.5 text-text-primary'>
|
||||
{t('time.title.pickTime')}
|
||||
{title || t('time.title.pickTime')}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ const TimePicker = ({
|
|||
onChange,
|
||||
onClear,
|
||||
renderTrigger,
|
||||
title,
|
||||
popupClassName,
|
||||
}: TimePickerProps) => {
|
||||
const { t } = useTranslation()
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
|
|
@ -142,10 +144,10 @@ const TimePicker = ({
|
|||
</div>
|
||||
)}
|
||||
</PortalToFollowElemTrigger>
|
||||
<PortalToFollowElemContent className='z-50'>
|
||||
<PortalToFollowElemContent className={cn('z-50', popupClassName)}>
|
||||
<div className='mt-1 w-[252px] rounded-xl border-[0.5px] border-components-panel-border bg-components-panel-bg shadow-lg shadow-shadow-shadow-5'>
|
||||
{/* Header */}
|
||||
<Header />
|
||||
<Header title={title} />
|
||||
|
||||
{/* Time Options */}
|
||||
<Options
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ export type TimePickerProps = {
|
|||
onChange: (date: Dayjs | undefined) => void
|
||||
onClear: () => void
|
||||
renderTrigger?: () => React.ReactNode
|
||||
title?: string
|
||||
popupClassName?: string
|
||||
}
|
||||
|
||||
export type TimePickerFooterProps = {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { AutoUpdateConfig } from './types'
|
||||
import { AUTO_UPDATE_MODE, AUTO_UPDATE_STRATEGY } from './types'
|
||||
export const defaultValue: AutoUpdateConfig = {
|
||||
strategy_setting: AUTO_UPDATE_STRATEGY.disabled,
|
||||
strategy_setting: AUTO_UPDATE_STRATEGY.fixOnly, // For test
|
||||
upgrade_time_of_day: 0,
|
||||
upgrade_mode: AUTO_UPDATE_MODE.update_all,
|
||||
exclude_plugins: [],
|
||||
|
|
|
|||
|
|
@ -5,9 +5,24 @@ import { AUTO_UPDATE_STRATEGY, type AutoUpdateConfig } from './types'
|
|||
import Label from '../label'
|
||||
import StrategyPicker from './strategy-picker'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import TimePicker from '@/app/components/base/date-and-time-picker/time-picker'
|
||||
import type { Dayjs } from 'dayjs'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
const i18nPrefix = 'plugin.autoUpdate'
|
||||
|
||||
const timeOfDayToDayjs = (timeOfDay: number): Dayjs => {
|
||||
const hours = Math.floor(timeOfDay / 3600)
|
||||
const minutes = (timeOfDay - hours * 3600) / 60
|
||||
const res = dayjs().startOf('day').hour(hours).minute(minutes)
|
||||
return res
|
||||
}
|
||||
|
||||
const dayjsToTimeOfDay = (date?: Dayjs): number => {
|
||||
if(!date) return 0
|
||||
return date.hour() * 3600 + date.minute() * 60
|
||||
}
|
||||
|
||||
type Props = {
|
||||
payload: AutoUpdateConfig
|
||||
onChange: (payload: AutoUpdateConfig) => void
|
||||
|
|
@ -18,7 +33,7 @@ const AutoUpdateSetting: FC<Props> = ({
|
|||
onChange,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const { strategy_setting } = payload
|
||||
const { strategy_setting, upgrade_time_of_day } = payload
|
||||
const strategyDescription = useMemo(() => {
|
||||
switch (strategy_setting) {
|
||||
case AUTO_UPDATE_STRATEGY.fixOnly:
|
||||
|
|
@ -53,6 +68,13 @@ const AutoUpdateSetting: FC<Props> = ({
|
|||
<>
|
||||
<div className='flex items-center justify-between'>
|
||||
<Label label={t(`${i18nPrefix}.updateTime`)} />
|
||||
<TimePicker
|
||||
value={timeOfDayToDayjs(upgrade_time_of_day)}
|
||||
onChange={v => handleChange('upgrade_time_of_day')(dayjsToTimeOfDay(v))}
|
||||
onClear={() => handleChange('upgrade_time_of_day')(0)}
|
||||
popupClassName='z-[99]'
|
||||
title={t(`${i18nPrefix}.updateTime`)}
|
||||
/>
|
||||
</div>
|
||||
<div className='flex items-center'>
|
||||
<Label label={t(`${i18nPrefix}.specifyPluginsToUpdate`)} />
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ const translation = {
|
|||
selectedDescription: 'Always update to latest version',
|
||||
},
|
||||
},
|
||||
updateTimeTitle: 'Update time',
|
||||
},
|
||||
pluginInfoModal: {
|
||||
title: 'Plugin info',
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ const translation = {
|
|||
selectedDescription: '始终更新到最新版本',
|
||||
},
|
||||
},
|
||||
updateTimeTitle: '更新时间',
|
||||
},
|
||||
pluginInfoModal: {
|
||||
title: '插件信息',
|
||||
|
|
|
|||
Loading…
Reference in New Issue