Skip to content

Commit 30209d6

Browse files
Refactor: split #setChildDatasource into dedicated methods and simplify #initMultiMode
1 parent ea8c94f commit 30209d6

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

scripts/dxcomponents/components/containers/templates/data-reference.component.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -193,34 +193,36 @@ export class DataReferenceComponent extends ContainerBaseComponent {
193193

194194

195195
#setChildDatasource() {
196-
const { type, config } = this.firstChildMeta;
197-
198-
// Early exit: AutoComplete has its own simple datasource logic
196+
const { type } = this.firstChildMeta;
197+
199198
if (type === 'AutoComplete') {
200-
config.datasource = this.refList;
201-
202-
const hasParameters = this.rawViewMetadata.config?.parameters;
203-
if (hasParameters) {
204-
config.parameters = this.parameters;
205-
}
206-
return;
199+
this.#setAutoCompleteDatasource();
200+
} else if (['Dropdown', 'Checkbox'].includes(type)) {
201+
this.#setDropdownOrCheckboxDatasource();
207202
}
208-
209-
// Early exit: Only handle Dropdown and Checkbox with non-deferred datasources
210-
const isDropdownOrCheckbox = ['Dropdown', 'Checkbox'].includes(type);
211-
const hasDatasource = config.datasource;
212-
const shouldLoadImmediately = !config.deferDatasource;
213-
214-
if (!isDropdownOrCheckbox || !hasDatasource || !shouldLoadImmediately) {
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;
212+
}
213+
}
214+
215+
#setDropdownOrCheckboxDatasource() {
216+
const { config } = this.firstChildMeta;
217+
218+
if (!config.datasource || config.deferDatasource) {
215219
return;
216220
}
217-
218-
// Set datasource based on whether parameters are configured
221+
219222
const hasParameters = this.rawViewMetadata.config?.parameters;
220-
const preloadedDataSource = this.dropDownDataSource;
221-
const dynamicDataSourcePath = `@DATASOURCE ${this.refList}.pxResults`;
222-
223-
config.datasource.source = hasParameters ? preloadedDataSource : dynamicDataSourcePath;
223+
config.datasource.source = hasParameters
224+
? this.dropDownDataSource
225+
: `@DATASOURCE ${this.refList}.pxResults`;
224226
}
225227

226228
// Re-create first child with overridden props

scripts/dxcomponents/components/fields/check-box.component.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,10 @@ export class CheckBoxComponent extends FieldBaseComponent {
100100
}
101101

102102
#initMultiMode() {
103-
const hasReferenceList = this.referenceList?.length > 0;
104-
const isEditable = !this.props.readOnly;
105-
106-
if (!hasReferenceList || !isEditable) {
107-
return;
103+
if (this.referenceList?.length > 0 && !this.props.readOnly) {
104+
this.pConn.setReferenceList(this.selectionList);
105+
updateNewInstructions(this.pConn, this.selectionList);
108106
}
109-
110-
this.pConn.setReferenceList(this.selectionList);
111-
updateNewInstructions(this.pConn, this.selectionList);
112107
}
113108

114109
#handleChangeMultiMode(element) {

0 commit comments

Comments
 (0)