1
1
import { FilterAPI , getGlobalFilterContextObject } from "@mendix/widget-plugin-filtering/context" ;
2
- import { RefFilterStore , RefFilterStoreProps } from "@mendix/widget-plugin-filtering/stores/picker/RefFilterStore" ;
3
- import { StaticSelectFilterStore } from "@mendix/widget-plugin-filtering/stores/picker/StaticSelectFilterStore" ;
2
+ import { StaticSelectFilterStore } from "@mendix/widget-plugin-dropdown-filter/stores/StaticSelectFilterStore" ;
4
3
import { InputFilterStore , attrgroupFilterStore } from "@mendix/widget-plugin-filtering/stores/input/store-utils" ;
5
- import { ensure } from "@mendix/widget-plugin-platform/utils/ensure" ;
4
+ import { FilterData } from "@mendix/filter-commons/typings/settings" ;
5
+ import { value } from "@mendix/widget-plugin-filtering/result-meta" ;
6
+ import { FilterObserver } from "@mendix/widget-plugin-filtering/typings/FilterObserver" ;
7
+ import { disposeBatch } from "@mendix/widget-plugin-mobx-kit/disposeBatch" ;
8
+ import { ListAttributeListValue , ListAttributeValue } from "mendix" ;
6
9
import { FilterCondition } from "mendix/filters" ;
7
- import { ListAttributeValue , ListAttributeListValue } from "mendix" ;
8
- import { action , computed , makeObservable } from "mobx" ;
10
+ import { computed , makeObservable } from "mobx" ;
9
11
import { ReactNode , createElement } from "react" ;
10
12
import { ColumnsType } from "../../../../typings/DatagridProps" ;
11
13
import { StaticInfo } from "../../../typings/static-info" ;
12
- import { FilterData } from "@mendix/widget-plugin-filtering/typings/settings" ;
13
- import { value } from "@mendix/widget-plugin-filtering/result-meta" ;
14
- import { disposeFx } from "@mendix/widget-plugin-filtering/mobx-utils" ;
15
- import { FilterObserver } from "@mendix/widget-plugin-filtering/typings/FilterObserver" ;
14
+
16
15
export interface IColumnFilterStore {
17
16
renderFilterWidgets ( ) : ReactNode ;
18
17
}
19
18
20
- type FilterStore = InputFilterStore | StaticSelectFilterStore | RefFilterStore ;
19
+ type FilterStore = InputFilterStore | StaticSelectFilterStore ;
21
20
22
21
const { Provider } = getGlobalFilterContextObject ( ) ;
23
22
@@ -33,61 +32,20 @@ export class ColumnFilterStore implements IColumnFilterStore {
33
32
this . _filterStore = this . createFilterStore ( props , dsViewState ) ;
34
33
this . _context = this . createContext ( this . _filterStore , info ) ;
35
34
36
- makeObservable < this, "_updateStore" > ( this , {
37
- _updateStore : action ,
38
- condition2 : computed ,
39
- updateProps : action
35
+ makeObservable < this> ( this , {
36
+ condition : computed
40
37
} ) ;
41
38
}
42
39
43
40
setup ( ) : ( ) => void {
44
- const [ disposers , dispose ] = disposeFx ( ) ;
41
+ const [ add , disposeAll ] = disposeBatch ( ) ;
45
42
if ( this . _filterStore && "setup" in this . _filterStore ) {
46
- disposers . push ( this . _filterStore . setup ( ) ) ;
47
- }
48
- return dispose ;
49
- }
50
-
51
- updateProps ( props : ColumnsType ) : void {
52
- this . _widget = props . filter ;
53
- this . _updateStore ( props ) ;
54
- }
55
-
56
- private _updateStore ( props : ColumnsType ) : void {
57
- const store = this . _filterStore ;
58
-
59
- if ( store === null ) {
60
- return ;
61
- }
62
-
63
- if ( store . storeType === "refselect" ) {
64
- store . updateProps ( this . toRefselectProps ( props ) ) ;
65
- } else if ( isListAttributeValue ( props . attribute ) ) {
66
- store . updateProps ( [ props . attribute ] ) ;
43
+ add ( this . _filterStore . setup ( ) ) ;
67
44
}
68
- }
69
-
70
- private toRefselectProps ( props : ColumnsType ) : RefFilterStoreProps {
71
- const searchAttrId = props . filterAssociationOptionLabelAttr ?. id ;
72
- const caption =
73
- props . filterCaptionType === "expression"
74
- ? ensure ( props . filterAssociationOptionLabel , errorMessage ( "filterAssociationOptionLabel" ) )
75
- : ensure ( props . filterAssociationOptionLabelAttr , errorMessage ( "filterAssociationOptionLabelAttr" ) ) ;
76
-
77
- return {
78
- ref : ensure ( props . filterAssociation , errorMessage ( "filterAssociation" ) ) ,
79
- datasource : ensure ( props . filterAssociationOptions , errorMessage ( "filterAssociationOptions" ) ) ,
80
- searchAttrId,
81
- fetchOptionsLazy : props . fetchOptionsLazy ,
82
- caption
83
- } ;
45
+ return disposeAll ;
84
46
}
85
47
86
48
private createFilterStore ( props : ColumnsType , dsViewState : FilterCondition | null ) : FilterStore | null {
87
- if ( props . filterAssociation ) {
88
- return new RefFilterStore ( this . toRefselectProps ( props ) , dsViewState ) ;
89
- }
90
-
91
49
if ( isListAttributeValue ( props . attribute ) ) {
92
50
return attrgroupFilterStore ( props . attribute . type , [ props . attribute ] , dsViewState ) ;
93
51
}
@@ -112,7 +70,7 @@ export class ColumnFilterStore implements IColumnFilterStore {
112
70
return < Provider value = { this . _context } > { this . _widget } </ Provider > ;
113
71
}
114
72
115
- get condition2 ( ) : FilterCondition | undefined {
73
+ get condition ( ) : FilterCondition | undefined {
116
74
return this . _filterStore ? this . _filterStore . condition : undefined ;
117
75
}
118
76
@@ -135,9 +93,6 @@ const isListAttributeValue = (
135
93
return ! ! ( attribute && attribute . isList === false ) ;
136
94
} ;
137
95
138
- const errorMessage = ( propName : string ) : string =>
139
- `Can't map ColumnsType to AssociationProperties: ${ propName } is undefined` ;
140
-
141
96
export interface ObserverBag {
142
97
customFilterHost : FilterObserver ;
143
98
sharedInitFilter : Array < FilterCondition | undefined > ;
0 commit comments