1
1
import { FilterData } from "@mendix/filter-commons/typings/settings" ;
2
2
import { EnumFilterStore } from "@mendix/widget-plugin-dropdown-filter/stores/EnumFilterStore" ;
3
3
import { FilterAPI , getGlobalFilterContextObject } from "@mendix/widget-plugin-filtering/context" ;
4
- import { value } from "@mendix/widget-plugin-filtering/result-meta" ;
4
+ import { APIError } from "@mendix/widget-plugin-filtering/errors" ;
5
+ import { error , value } from "@mendix/widget-plugin-filtering/result-meta" ;
5
6
import { InputFilterStore , attrgroupFilterStore } from "@mendix/widget-plugin-filtering/stores/input/store-utils" ;
6
7
import { ObservableFilterHost } from "@mendix/widget-plugin-filtering/typings/ObservableFilterHost" ;
7
8
import { disposeBatch } from "@mendix/widget-plugin-mobx-kit/disposeBatch" ;
@@ -22,14 +23,24 @@ const { Provider } = getGlobalFilterContextObject();
22
23
23
24
export class ColumnFilterStore implements IColumnFilterStore {
24
25
private _widget : ReactNode ;
26
+ private _error : APIError | null ;
25
27
private _filterStore : FilterStore | null = null ;
26
28
private _context : FilterAPI ;
27
29
private _observerBag : ObserverBag ;
28
30
29
31
constructor ( props : ColumnsType , info : StaticInfo , dsViewState : FilterCondition | null , observerBag : ObserverBag ) {
30
32
this . _observerBag = observerBag ;
31
33
this . _widget = props . filter ;
32
- this . _filterStore = this . createFilterStore ( props , dsViewState ) ;
34
+ const storeResult = this . createFilterStore ( props , dsViewState ) ;
35
+ if ( storeResult === null ) {
36
+ this . _error = this . _filterStore = null ;
37
+ } else if ( storeResult . hasError ) {
38
+ this . _error = storeResult . error ;
39
+ this . _filterStore = null ;
40
+ } else {
41
+ this . _error = null ;
42
+ this . _filterStore = storeResult . value ;
43
+ }
33
44
this . _context = this . createContext ( this . _filterStore , info ) ;
34
45
35
46
makeObservable < this> ( this , {
@@ -45,9 +56,12 @@ export class ColumnFilterStore implements IColumnFilterStore {
45
56
return disposeAll ;
46
57
}
47
58
48
- private createFilterStore ( props : ColumnsType , dsViewState : FilterCondition | null ) : FilterStore | null {
59
+ private createFilterStore (
60
+ props : ColumnsType ,
61
+ dsViewState : FilterCondition | null
62
+ ) : ReturnType < typeof attrgroupFilterStore > | null {
49
63
if ( isListAttributeValue ( props . attribute ) ) {
50
- return attrgroupFilterStore ( props . attribute . type , [ props . attribute ] , dsViewState ) ;
64
+ return attrgroupFilterStore ( props . attribute . type , props . attribute , dsViewState ) ;
51
65
}
52
66
53
67
return null ;
@@ -57,10 +71,12 @@ export class ColumnFilterStore implements IColumnFilterStore {
57
71
return {
58
72
version : 3 ,
59
73
parentChannelName : info . filtersChannelName ,
60
- provider : value ( {
61
- type : "direct" ,
62
- store
63
- } ) ,
74
+ provider : this . _error
75
+ ? error ( this . _error )
76
+ : value ( {
77
+ type : "direct" ,
78
+ store
79
+ } ) ,
64
80
filterObserver : this . _observerBag . customFilterHost ,
65
81
sharedInitFilter : this . _observerBag . sharedInitFilter
66
82
} ;
0 commit comments