@@ -42,9 +42,12 @@ export class DataReferenceComponent extends ContainerBaseComponent {
4242 this . children = this . pConn . getChildren ( ) ;
4343 this . #updateSelf( ) ;
4444
45- if ( ( [ 'Dropdown' , 'Checkbox' ] . includes ( this . firstChildMeta ?. type ) ) &&
45+ const shouldPreloadOptions =
46+ ( [ 'Dropdown' , 'Checkbox' ] . includes ( this . firstChildMeta ?. type ) ) &&
4647 this . rawViewMetadata . config ?. parameters &&
47- ! this . firstChildMeta . config . deferDatasource ) {
48+ ! this . firstChildMeta . config . deferDatasource ;
49+
50+ if ( shouldPreloadOptions ) {
4851 const { value, key, text } = this . firstChildMeta . config . datasource . fields ;
4952 PCore . getDataApiUtils ( )
5053 . getData ( this . refList , { dataViewParameters : this . parameters } , "" )
@@ -119,7 +122,6 @@ export class DataReferenceComponent extends ContainerBaseComponent {
119122 delete this . firstChildMeta . config . readOnly ;
120123 }
121124
122- // todo pelcm add readonly handling
123125 this . #setChildDatasource( ) ;
124126
125127 if ( this . firstChildMeta ?. type === "Dropdown" && ! this . firstChildMeta . config . deferDatasource ) {
@@ -191,19 +193,38 @@ export class DataReferenceComponent extends ContainerBaseComponent {
191193
192194
193195 #setChildDatasource( ) {
194- const { type, config } = this . firstChildMeta ;
196+ const { type } = this . firstChildMeta ;
195197
196- if ( [ 'Dropdown' , 'Checkbox' ] . includes ( type ) && ! config . deferDatasource && config . datasource ) {
197- const hasParameters = this . rawViewMetadata . config ?. parameters ;
198- config . datasource . source = hasParameters ? this . dropDownDataSource : `@DATASOURCE ${ this . refList } .pxResults` ;
199- } else if ( type === 'AutoComplete' ) {
200- config . datasource = this . refList ;
201- if ( this . rawViewMetadata . config ?. parameters ) {
202- config . parameters = this . parameters ;
203- }
198+ if ( type === 'AutoComplete' ) {
199+ this . #setAutoCompleteDatasource( ) ;
200+ } else if ( [ 'Dropdown' , 'Checkbox' ] . includes ( type ) ) {
201+ this . #setDropdownOrCheckboxDatasource( ) ;
202+ }
203+ }
204+
205+ #setAutoCompleteDatasource( ) {
206+ const { config } = this . firstChildMeta ;
207+ config . datasource = this . refList ;
208+
209+ const hasParameters = this . rawViewMetadata . config ?. parameters ;
210+ if ( hasParameters ) {
211+ config . parameters = this . parameters ;
204212 }
205213 }
206214
215+ #setDropdownOrCheckboxDatasource( ) {
216+ const { config } = this . firstChildMeta ;
217+
218+ if ( ! config . datasource || config . deferDatasource ) {
219+ return ;
220+ }
221+
222+ const hasParameters = this . rawViewMetadata . config ?. parameters ;
223+ config . datasource . source = hasParameters
224+ ? this . dropDownDataSource
225+ : `@DATASOURCE ${ this . refList } .pxResults` ;
226+ }
227+
207228 // Re-create first child with overridden props
208229 // Memoized child in order to stop unmount and remount of the child component when data reference
209230 // rerenders without any actual change
@@ -217,17 +238,6 @@ export class DataReferenceComponent extends ContainerBaseComponent {
217238 } ) ;
218239
219240 this . #setReadOnlyDisplayFlags( ) ;
220- // if (
221- // !this.canBeChangedInReviewMode &&
222- // this.isDisplayModeEnabled &&
223- // this.selectionMode === SELECTION_MODE.SINGLE
224- // ) {
225- // this.displaySingleRef = true;
226- // }
227- //
228- // if (this.isDisplayModeEnabled && this.selectionMode === SELECTION_MODE.MULTI) {
229- // this.displayMultiRef = true;
230- // }
231241
232242 // In the case of a datasource with parameters you cannot load the dropdown before the parameters
233243 if ( type === "Dropdown" && this . rawViewMetadata . config ?. parameters && this . dropDownDataSource === null ) {
@@ -262,11 +272,18 @@ export class DataReferenceComponent extends ContainerBaseComponent {
262272 const isSingleMode = this . selectionMode === SELECTION_MODE . SINGLE ;
263273 const isMultiMode = this . selectionMode === SELECTION_MODE . MULTI ;
264274
265- if ( isSingleMode && ( this . displayAs === 'readonly' || this . isDisplayModeEnabled ) && ! this . canBeChangedInReviewMode ) {
275+ const shouldDisplayOnlySingle = isSingleMode &&
276+ ( this . displayAs === 'readonly' || this . isDisplayModeEnabled ) &&
277+ ! this . canBeChangedInReviewMode ;
278+
279+ if ( shouldDisplayOnlySingle ) {
266280 this . props . displayOnlySingle = true ;
267281 }
268282
269- if ( isMultiMode && ( [ 'readonly' , 'readonlyMulti' , 'map' ] . includes ( this . displayAs ) || this . isDisplayModeEnabled ) ) {
283+ const shouldDisplayOnlyMulti = isMultiMode &&
284+ ( [ 'readonly' , 'readonlyMulti' , 'map' ] . includes ( this . displayAs ) || this . isDisplayModeEnabled ) ;
285+
286+ if ( shouldDisplayOnlyMulti ) {
270287 this . props . displayOnlyMulti = true ;
271288 }
272289 }
0 commit comments