(core) New date filter with a calendar view

Summary:
Implements the new date filtering panel. Design results from long
discussion between: Alex, Anais, Cyprien and Dmitry.

Test environment: https://grist-new-date-range-filter.fly.dev/

Test Plan: Include various new tests.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D3720
This commit is contained in:
Cyprien P
2022-09-14 11:04:20 +02:00
parent 7dc49f3c85
commit 620e86a9f1
18 changed files with 1526 additions and 213 deletions

View File

@@ -1,6 +1,9 @@
import {ColumnFilterFunc, makeFilterFunc} from "app/common/ColumnFilterFunc";
import {CellValue} from 'app/common/DocActions';
import {FilterSpec, FilterState, isRangeFilter, makeFilterState} from "app/common/FilterState";
import {
FilterSpec, FilterState, IRelativeDateSpec, isRangeFilter, isRelativeBound, makeFilterState
} from "app/common/FilterState";
import {toUnixTimestamp} from "app/common/RelativeDates";
import {nativeCompare} from 'app/common/gutil';
import {Computed, Disposable, Observable} from 'grainjs';
@@ -14,8 +17,8 @@ import {Computed, Disposable, Observable} from 'grainjs';
*/
export class ColumnFilter extends Disposable {
public min = Observable.create<number|undefined>(this, undefined);
public max = Observable.create<number|undefined>(this, undefined);
public min = Observable.create<number|undefined|IRelativeDateSpec>(this, undefined);
public max = Observable.create<number|undefined|IRelativeDateSpec>(this, undefined);
public readonly filterFunc = Observable.create<ColumnFilterFunc>(this, () => true);
@@ -25,6 +28,8 @@ export class ColumnFilter extends Disposable {
// Computed that returns the current filter state.
public readonly state: Computed<FilterState> = Computed.create(this, this.filterFunc, () => this._getState());
public readonly isRange: Computed<boolean> = Computed.create(this, this.filterFunc, () => this._isRange());
private _include: boolean;
private _values: Set<CellValue>;
@@ -119,6 +124,12 @@ export class ColumnFilter extends Disposable {
return this.makeFilterJson() !== this._initialFilterJson;
}
public getBoundsValue(minMax: 'min' | 'max'): number | undefined {
const value = this[minMax].get();
return isRelativeBound(value) ? toUnixTimestamp(value) : value;
}
private _updateState(): void {
this.filterFunc.set(makeFilterFunc(this._getState(), this._columnType));
}