Skip to content

Commit

Permalink
fix: format preset input
Browse files Browse the repository at this point in the history
  • Loading branch information
lawvs committed Aug 7, 2024
1 parent 2ba90f8 commit 3be44bd
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions packages/filter/src/views/data-input-views.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ export const presetDataInputSpecs: DataInputViewSpec[] = [
if (!requiredDataSchema.length) {
return null;
}
const value = rule.args?.[0] as string | undefined;
return (
<InputView
ref={ref}
type="text"
value={(rule.args?.[0] as string) ?? ""}
onChange={(value) => {
if (!value.length) {
value={value}
onChange={(newValue) => {
if (!newValue.length) {
updateInput([]);
return;
}
updateInput([value]);
updateInput([newValue]);
return;
}}
/>
Expand All @@ -45,13 +46,18 @@ export const presetDataInputSpecs: DataInputViewSpec[] = [
if (!requiredDataSchema.length) {
return null;
}
const value = (rule.args?.[0] as number) ?? "";
return (
<InputView
ref={ref}
type="number"
value={(rule.args?.[0] as string) ?? ""}
onChange={(value) => {
updateInput([value]);
value={value}
onChange={(newValue) => {
if (!newValue.length) {
updateInput([]);
return;
}
updateInput([+newValue]);
return;
}}
/>
Expand All @@ -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 (
<InputView
ref={ref}
type="date"
value={(rule.args?.[0] as string) ?? ""}
onChange={(value) => {
updateInput([value]);
// "yyyy-MM-dd"
value={value}
onChange={(newValue) => {
if (!newValue) {
updateInput([]);
return;
}
updateInput([new Date(newValue)]);
}}
/>
);
Expand Down

0 comments on commit 3be44bd

Please sign in to comment.