@@ -2,8 +2,8 @@ import * as R from 'ramda';
2
2
3
3
import { memoizeOneFactory } from 'core/memoizer' ;
4
4
5
- import { VisibleColumns , IVisibleColumn } from 'dash-table/components/Table/props' ;
6
- import { SingleColumnSyntaxTree , MultiColumnsSyntaxTree , getSingleColumnMap } from 'dash-table/syntax-tree' ;
5
+ import { VisibleColumns , IVisibleColumn , SetFilter } from 'dash-table/components/Table/props' ;
6
+ import { SingleColumnSyntaxTree , MultiColumnsSyntaxTree , getMultiColumnQueryString , getSingleColumnMap } from 'dash-table/syntax-tree' ;
7
7
8
8
const cloneIf = (
9
9
current : Map < string , SingleColumnSyntaxTree > ,
@@ -61,20 +61,49 @@ export default memoizeOneFactory((
61
61
return newMap ;
62
62
} ) ;
63
63
64
- export const updateMap = (
65
- map : Map < string , SingleColumnSyntaxTree > ,
66
- column : IVisibleColumn ,
67
- value : any
68
- ) : Map < string , SingleColumnSyntaxTree > => {
69
- const safeColumnId = column . id . toString ( ) ;
70
-
64
+ function updateMap ( map : Map < string , SingleColumnSyntaxTree > , column : IVisibleColumn , value : any ) {
65
+ const id = column . id . toString ( ) ;
71
66
const newMap = new Map < string , SingleColumnSyntaxTree > ( map ) ;
72
67
73
68
if ( value && value . length ) {
74
- newMap . set ( safeColumnId , new SingleColumnSyntaxTree ( value , column ) ) ;
69
+ newMap . set ( id , new SingleColumnSyntaxTree ( value , column ) ) ;
75
70
} else {
76
- newMap . delete ( safeColumnId ) ;
71
+ newMap . delete ( id ) ;
77
72
}
78
73
79
74
return newMap ;
75
+ }
76
+
77
+ function updateState ( map : Map < string , SingleColumnSyntaxTree > , setFilter : SetFilter ) {
78
+ const asts = Array . from ( map . values ( ) ) ;
79
+ const globalFilter = getMultiColumnQueryString ( asts ) ;
80
+
81
+ const rawGlobalFilter = R . map (
82
+ ast => ast . query || '' ,
83
+ R . filter < SingleColumnSyntaxTree > ( ast => Boolean ( ast ) , asts )
84
+ ) . join ( ' && ' ) ;
85
+
86
+ setFilter ( globalFilter , rawGlobalFilter , map ) ;
87
+ }
88
+
89
+ export const updateColumnFilter = (
90
+ map : Map < string , SingleColumnSyntaxTree > ,
91
+ column : IVisibleColumn ,
92
+ value : any ,
93
+ setFilter : SetFilter
94
+ ) => {
95
+ map = updateMap ( map , column , value ) ;
96
+ updateState ( map , setFilter ) ;
97
+ } ;
98
+
99
+ export const clearColumnsFilter = (
100
+ map : Map < string , SingleColumnSyntaxTree > ,
101
+ columns : VisibleColumns ,
102
+ setFilter : SetFilter
103
+ ) => {
104
+ R . forEach ( column => {
105
+ map = updateMap ( map , column , '' ) ;
106
+ } , columns ) ;
107
+
108
+ updateState ( map , setFilter ) ;
80
109
} ;
0 commit comments