(core) Allows range filter for Date, DateTime columns

Summary:
This diff is first of a series of 3 commits to enable range filering
for Date and DateTime columns. Diff only enable setting date's min/max
throw typing dates, Date picker and relative ranges are left for
follow-up commits.

 - Exposes columns value formatter to the range input
 - Fixes column filter func to work with dates

Test Plan:
Adds Date to projects range filter test
Adds Date/DateTime to nbrowser ColumnFilterMenu tests

Reviewers: alexmojaki

Reviewed By: alexmojaki

Subscribers: alexmojaki

Differential Revision: https://phab.getgrist.com/D3455
This commit is contained in:
Cyprien P
2022-06-23 10:01:12 +02:00
parent 9fffb491f9
commit 64ff9ccd0a
6 changed files with 46 additions and 27 deletions

View File

@@ -1,18 +1,18 @@
import {CellValue} from "app/common/DocActions";
import {FilterState, isRangeFilter, makeFilterState} from "app/common/FilterState";
import {decodeObject} from "app/plugin/objtypes";
import {isList, isListType, isNumberType} from "./gristTypes";
import {isDateLikeType, isList, isListType, isNumberType} from "./gristTypes";
export type ColumnFilterFunc = (value: CellValue) => boolean;
// Returns a filter function for a particular column: the function takes a cell value and returns
// whether it's accepted according to the given FilterState.
export function makeFilterFunc(state: FilterState,
columnType?: string): ColumnFilterFunc {
columnType: string = ''): ColumnFilterFunc {
if (isRangeFilter(state)) {
const {min, max} = state;
if (isNumberType(columnType)) {
if (isNumberType(columnType) || isDateLikeType(columnType)) {
return (val) => {
if (typeof val !== 'number') { return false; }
return (

View File

@@ -329,6 +329,10 @@ export function isNumberType(type: string|undefined) {
return ['Numeric', 'Int'].includes(type || '');
}
export function isDateLikeType(type: string) {
return type === 'Date' || type.startsWith('DateTime');
}
export function isFullReferencingType(type: string) {
return type.startsWith('Ref:') || isRefListType(type);
}