From ba51389e41132ad9bc55fd9e3008b6d7c2b200ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=92=E6=B9=9B?= <0x1304570@gmail.com> Date: Mon, 13 Nov 2023 22:20:04 +1300 Subject: [PATCH] fix(config-ui): missed default value in sync frequency (#6449) --- .../detail/components/sync-policy/index.tsx | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/config-ui/src/pages/blueprint/detail/components/sync-policy/index.tsx b/config-ui/src/pages/blueprint/detail/components/sync-policy/index.tsx index b4678aff84d..a191db7ecf1 100644 --- a/config-ui/src/pages/blueprint/detail/components/sync-policy/index.tsx +++ b/config-ui/src/pages/blueprint/detail/components/sync-policy/index.tsx @@ -16,7 +16,7 @@ * */ -import { useState, useMemo } from 'react'; +import { useState, useEffect, useMemo } from 'react'; import dayjs from 'dayjs'; import { Tag, Checkbox, FormGroup, InputGroup, Radio, RadioGroup } from '@blueprintjs/core'; import { TimePrecision } from '@blueprintjs/datetime'; @@ -53,7 +53,18 @@ export const SyncPolicy = ({ }: Props) => { const [selectedValue, setSelectedValue] = useState('Daily'); - const [timezone, quickTimeOpts, cronOpts] = useMemo(() => { + const cronOpts = getCronOptions(); + + useEffect(() => { + if (isManual) { + setSelectedValue('Manual'); + } else { + const opt = cronOpts.find((it) => it.value === cronConfig); + setSelectedValue(opt ? opt.label : 'Custom'); + } + }, []); + + const [timezone, quickTimeOpts] = useMemo(() => { const timezone = dayjs().format('ZZ').replace('00', ''); const quickTimeOpts = [ { label: 'Last 6 months', date: dayjs().subtract(6, 'month').toDate() }, @@ -61,10 +72,7 @@ export const SyncPolicy = ({ { label: 'Last 30 days', date: dayjs().subtract(30, 'day').toDate() }, { label: 'Last Year', date: dayjs().subtract(1, 'year').toDate() }, ]; - - const cronOpts = getCronOptions(); - - return [timezone, quickTimeOpts, cronOpts]; + return [timezone, quickTimeOpts]; }, []); const cron = useMemo(() => getCron(isManual, cronConfig), [isManual, cronConfig]);