From 3be44bd7859c7d1041f6636b7862dce7274cfa8d Mon Sep 17 00:00:00 2001 From: lawvs <18554747+lawvs@users.noreply.github.com> Date: Wed, 7 Aug 2024 18:26:08 +0800 Subject: [PATCH] fix: format preset input --- .../filter/src/views/data-input-views.tsx | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/packages/filter/src/views/data-input-views.tsx b/packages/filter/src/views/data-input-views.tsx index d1e9eae..2854856 100644 --- a/packages/filter/src/views/data-input-views.tsx +++ b/packages/filter/src/views/data-input-views.tsx @@ -20,17 +20,18 @@ export const presetDataInputSpecs: DataInputViewSpec[] = [ if (!requiredDataSchema.length) { return null; } + const value = rule.args?.[0] as string | undefined; return ( { - if (!value.length) { + value={value} + onChange={(newValue) => { + if (!newValue.length) { updateInput([]); return; } - updateInput([value]); + updateInput([newValue]); return; }} /> @@ -45,13 +46,18 @@ export const presetDataInputSpecs: DataInputViewSpec[] = [ if (!requiredDataSchema.length) { return null; } + const value = (rule.args?.[0] as number) ?? ""; return ( { - updateInput([value]); + value={value} + onChange={(newValue) => { + if (!newValue.length) { + updateInput([]); + return; + } + updateInput([+newValue]); return; }} /> @@ -66,13 +72,20 @@ export const presetDataInputSpecs: DataInputViewSpec[] = [ if (!requiredDataSchema.length) { return null; } + const value = + (rule.args?.[0] as Date | undefined)?.toISOString().slice(0, 10) ?? ""; return ( { - updateInput([value]); + // "yyyy-MM-dd" + value={value} + onChange={(newValue) => { + if (!newValue) { + updateInput([]); + return; + } + updateInput([new Date(newValue)]); }} /> );