11import { 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" ;
43import { 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" ;
69import { FilterCondition } from "mendix/filters" ;
7- import { ListAttributeValue , ListAttributeListValue } from "mendix" ;
8- import { action , computed , makeObservable } from "mobx" ;
10+ import { computed , makeObservable } from "mobx" ;
911import { ReactNode , createElement } from "react" ;
1012import { ColumnsType } from "../../../../typings/DatagridProps" ;
1113import { 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+
1615export interface IColumnFilterStore {
1716 renderFilterWidgets ( ) : ReactNode ;
1817}
1918
20- type FilterStore = InputFilterStore | StaticSelectFilterStore | RefFilterStore ;
19+ type FilterStore = InputFilterStore | StaticSelectFilterStore ;
2120
2221const { Provider } = getGlobalFilterContextObject ( ) ;
2322
@@ -33,61 +32,20 @@ export class ColumnFilterStore implements IColumnFilterStore {
3332 this . _filterStore = this . createFilterStore ( props , dsViewState ) ;
3433 this . _context = this . createContext ( this . _filterStore , info ) ;
3534
36- makeObservable < this, "_updateStore" > ( this , {
37- _updateStore : action ,
38- condition2 : computed ,
39- updateProps : action
35+ makeObservable < this> ( this , {
36+ condition : computed
4037 } ) ;
4138 }
4239
4340 setup ( ) : ( ) => void {
44- const [ disposers , dispose ] = disposeFx ( ) ;
41+ const [ add , disposeAll ] = disposeBatch ( ) ;
4542 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 ( ) ) ;
6744 }
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 ;
8446 }
8547
8648 private createFilterStore ( props : ColumnsType , dsViewState : FilterCondition | null ) : FilterStore | null {
87- if ( props . filterAssociation ) {
88- return new RefFilterStore ( this . toRefselectProps ( props ) , dsViewState ) ;
89- }
90-
9149 if ( isListAttributeValue ( props . attribute ) ) {
9250 return attrgroupFilterStore ( props . attribute . type , [ props . attribute ] , dsViewState ) ;
9351 }
@@ -112,7 +70,7 @@ export class ColumnFilterStore implements IColumnFilterStore {
11270 return < Provider value = { this . _context } > { this . _widget } </ Provider > ;
11371 }
11472
115- get condition2 ( ) : FilterCondition | undefined {
73+ get condition ( ) : FilterCondition | undefined {
11674 return this . _filterStore ? this . _filterStore . condition : undefined ;
11775 }
11876
@@ -135,9 +93,6 @@ const isListAttributeValue = (
13593 return ! ! ( attribute && attribute . isList === false ) ;
13694} ;
13795
138- const errorMessage = ( propName : string ) : string =>
139- `Can't map ColumnsType to AssociationProperties: ${ propName } is undefined` ;
140-
14196export interface ObserverBag {
14297 customFilterHost : FilterObserver ;
14398 sharedInitFilter : Array < FilterCondition | undefined > ;
0 commit comments