Skip to content

Commit 7fe612e

Browse files
committed
fix: require both bounds in between filter validation
- Fix TemporalFilterEditor.canCommit to reject partial ranges (matching NumericFilterEditor) - Fix TemporalFilterEditor.handleCommit to use || guard and build complete {min, max} object - Fix isAddFilterDraftValueValid to require both bounds non-empty for between operator
1 parent 00aba37 commit 7fe612e

1 file changed

Lines changed: 14 additions & 19 deletions

File tree

packages/core/src/components/data-table/toolbar.tsx

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -971,9 +971,11 @@ function TemporalFilterEditor({
971971
const minEmpty = localValue.trim() === "";
972972
const maxEmpty = localValueMax.trim() === "";
973973
if (minEmpty && maxEmpty) return true; // will removeFilter
974-
const minValid = minEmpty || isTemporalFilterValueValid(config.type, localValue);
975-
const maxValid = maxEmpty || isTemporalFilterValueValid(config.type, localValueMax);
976-
return minValid && maxValid;
974+
if (minEmpty || maxEmpty) return false; // both required
975+
return (
976+
isTemporalFilterValueValid(config.type, localValue) &&
977+
isTemporalFilterValueValid(config.type, localValueMax)
978+
);
977979
}
978980
return localValue.trim() === "" || isTemporalFilterValueValid(config.type, localValue);
979981
})();
@@ -984,14 +986,13 @@ function TemporalFilterEditor({
984986
const maxEmpty = localValueMax.trim() === "";
985987
if (minEmpty && maxEmpty) {
986988
control.removeFilter(config.field);
989+
} else if (!minEmpty && !maxEmpty) {
990+
const minValid = isTemporalFilterValueValid(config.type, localValue);
991+
const maxValid = isTemporalFilterValueValid(config.type, localValueMax);
992+
if (!minValid || !maxValid) return;
993+
control.addFilter(config.field, localOp, { min: localValue, max: localValueMax });
987994
} else {
988-
const minValid = !minEmpty && isTemporalFilterValueValid(config.type, localValue);
989-
const maxValid = !maxEmpty && isTemporalFilterValueValid(config.type, localValueMax);
990-
if (!minValid && !maxValid) return;
991-
const range: { min?: string; max?: string } = {};
992-
if (minValid) range.min = localValue;
993-
if (maxValid) range.max = localValueMax;
994-
control.addFilter(config.field, localOp, range);
995+
return;
995996
}
996997
} else {
997998
if (localValue.trim() === "") {
@@ -1095,18 +1096,12 @@ function isAddFilterDraftValueValid(
10951096
const [min, max] = value;
10961097
const minEmpty = !min || min.trim() === "";
10971098
const maxEmpty = !max || max.trim() === "";
1098-
if (minEmpty && maxEmpty) return false;
1099+
if (minEmpty || maxEmpty) return false; // both required
10991100
if (type === "number") {
1100-
return (
1101-
(!minEmpty ? !Number.isNaN(Number(min)) : true) &&
1102-
(!maxEmpty ? !Number.isNaN(Number(max)) : true)
1103-
);
1101+
return !Number.isNaN(Number(min)) && !Number.isNaN(Number(max));
11041102
}
11051103
if (isTemporalFilterType(type)) {
1106-
return (
1107-
(!minEmpty ? isTemporalFilterValueValid(type, min) : true) &&
1108-
(!maxEmpty ? isTemporalFilterValueValid(type, max) : true)
1109-
);
1104+
return isTemporalFilterValueValid(type, min) && isTemporalFilterValueValid(type, max);
11101105
}
11111106
return true;
11121107
}

0 commit comments

Comments
 (0)