@@ -14,19 +14,18 @@ import { GateProvider } from "@mendix/widget-plugin-mobx-kit/GateProvider";
1414import { DerivedPropsGate , SetupComponentHost } from "@mendix/widget-plugin-mobx-kit/main" ;
1515import { useConst } from "@mendix/widget-plugin-mobx-kit/react/useConst" ;
1616import { useSetup } from "@mendix/widget-plugin-mobx-kit/react/useSetup" ;
17-
1817import { generateUUID } from "@mendix/widget-plugin-platform/framework/generate-uuid" ;
1918import { Container , injected , token } from "brandi" ;
2019import { useEffect } from "react" ;
2120import { DatagridContainerProps , SelectionCounterPositionEnum } from "../typings/DatagridProps" ;
2221import { DatasourceParamsController } from "./controllers/DatasourceParamsController" ;
2322import { DerivedLoaderController , DerivedLoaderControllerConfig } from "./controllers/DerivedLoaderController" ;
2423import { PaginationConfig , PaginationController } from "./controllers/PaginationController" ;
24+ import { datagridConfig , DatagridConfig } from "./Datagrid.config" ;
2525import { ColumnGroupStore } from "./helpers/state/ColumnGroupStore" ;
2626import { GridBasicData } from "./helpers/state/GridBasicData" ;
2727import { GridPersonalizationStore } from "./helpers/state/GridPersonalizationStore" ;
2828import { DatagridSetupService } from "./services/DatagridSetupService" ;
29- import { StaticInfo } from "./typings/static-info" ;
3029import { SelectAllBarViewModel } from "./view-models/SelectAllBarViewModel" ;
3130import { SelectionProgressDialogViewModel } from "./view-models/SelectionProgressDialogViewModel" ;
3231
@@ -61,6 +60,7 @@ type MainGateProps = Pick<
6160/** Tokens to resolve dependencies from the container. */
6261export const TOKENS = {
6362 basicDate : token < GridBasicData > ( "GridBasicData" ) ,
63+ config : token < DatagridConfig > ( "DatagridConfig" ) ,
6464 columnsStore : token < ColumnGroupStore > ( "ColumnGroupStore" ) ,
6565 combinedFilter : token < CombinedFilter > ( "CombinedFilter" ) ,
6666 combinedFilterConfig : token < CombinedFilterConfig > ( "CombinedFilterKey" ) ,
@@ -81,7 +81,6 @@ export const TOKENS = {
8181 selectionCounter : token < SelectionCounterViewModel > ( "SelectionCounterViewModel" ) ,
8282 selectionCounterPosition : token < SelectionCounterPositionEnum > ( "SelectionCounterPositionEnum" ) ,
8383 setupService : token < SetupComponentHost > ( "DatagridSetupHost" ) ,
84- staticInfo : token < StaticInfo > ( "StaticInfo" ) ,
8584 enableSelectAll : token < boolean > ( "enableSelectAll" ) ,
8685 selectAllProgressService : token < TaskProgressService > ( "SelectAllProgressService" ) ,
8786 selectAllGate : token < DerivedPropsGate < SelectAllGateProps > > ( "SelectAllGateForProps" ) ,
@@ -91,7 +90,7 @@ export const TOKENS = {
9190} ;
9291
9392/** Deps injections */
94- injected ( ColumnGroupStore , TOKENS . setupService , TOKENS . mainGate , TOKENS . staticInfo , TOKENS . filterHost ) ;
93+ injected ( ColumnGroupStore , TOKENS . setupService , TOKENS . mainGate , TOKENS . config , TOKENS . filterHost ) ;
9594injected ( GridBasicData , TOKENS . mainGate ) ;
9695injected ( CombinedFilter , TOKENS . setupService , TOKENS . combinedFilterConfig ) ;
9796injected ( WidgetFilterAPI , TOKENS . parentChannelName , TOKENS . filterHost ) ;
@@ -138,7 +137,7 @@ class DatagridContainer extends Container {
138137 * Setup container bindings.
139138 * @remark Make sure not to bind things that already exist in root container.
140139 */
141- init ( props : MainGateProps , root : RootContainer , selectAllModule : Container ) : DatagridContainer {
140+ init ( props : DatagridContainerProps , root : RootContainer , selectAllModule : Container ) : DatagridContainer {
142141 this . extend ( root ) ;
143142
144143 // Connect select all module
@@ -161,6 +160,10 @@ class DatagridContainer extends Container {
161160 this . bind ( TOKENS . mainGate ) . toConstant ( gateProvider . gate ) ;
162161 this . bind ( TOKENS . queryGate ) . toConstant ( gateProvider . gate ) ;
163162
163+ // Bind config
164+ const config = datagridConfig ( props ) ;
165+ this . bind ( TOKENS . config ) . toConstant ( config ) ;
166+
164167 // Columns store
165168 this . bind ( TOKENS . columnsStore ) . toInstance ( ColumnGroupStore ) . inSingletonScope ( ) ;
166169
@@ -192,9 +195,7 @@ class DatagridContainer extends Container {
192195 this . bind ( TOKENS . paginationService ) . toInstance ( PaginationController ) . inSingletonScope ( ) ;
193196
194197 // Events channel for child widgets
195- this . bind ( TOKENS . parentChannelName )
196- . toInstance ( ( ) => `Datagrid@${ generateUUID ( ) } ` )
197- . inSingletonScope ( ) ;
198+ this . bind ( TOKENS . parentChannelName ) . toConstant ( config . filtersChannelName ) ;
198199
199200 // Loader view model
200201 this . bind ( TOKENS . loaderViewModel ) . toInstance ( DerivedLoaderController ) . inSingletonScope ( ) ;
@@ -208,12 +209,6 @@ class DatagridContainer extends Container {
208209 // Selection progress dialog view model
209210 this . bind ( TOKENS . selectionDialogViewModel ) . toInstance ( SelectionProgressDialogViewModel ) . inSingletonScope ( ) ;
210211
211- // Bind static info
212- this . bind ( TOKENS . staticInfo ) . toConstant ( {
213- name : props . name ,
214- filtersChannelName : this . get ( TOKENS . parentChannelName )
215- } ) ;
216-
217212 // Bind refresh interval
218213 this . bind ( TOKENS . refreshInterval ) . toConstant ( props . refreshInterval * 1000 ) ;
219214
@@ -246,7 +241,7 @@ class DatagridContainer extends Container {
246241 // Make sure essential services are created upfront
247242 this . get ( TOKENS . paramsService ) ;
248243 this . get ( TOKENS . paginationService ) ;
249- if ( this . isSettingsStorageEnabled ( props ) ) {
244+ if ( config . settingsStorageEnabled ) {
250245 this . get ( TOKENS . personalizationService ) ;
251246 }
252247
@@ -256,12 +251,6 @@ class DatagridContainer extends Container {
256251 return this ;
257252 }
258253
259- private isSettingsStorageEnabled ( props : MainGateProps ) : boolean {
260- if ( props . configurationStorageType === "localStorage" ) return true ;
261- if ( props . configurationStorageType === "attribute" && props . configurationAttribute ) return true ;
262- return false ;
263- }
264-
265254 setProps = ( _props : MainGateProps ) : void => {
266255 throw new Error ( `${ this . id } is not initialized yet` ) ;
267256 } ;
0 commit comments