Skip to content

Commit c1f4256

Browse files
committed
fix: fix regression when there is attribute value and lazy load
1 parent d0ae11b commit c1f4256

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

packages/pluggableWidgets/combobox-web/src/helpers/BaseDatasourceOptionsProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ export class BaseDatasourceOptionsProvider extends BaseOptionsProvider<ObjectIte
8686
}
8787

8888
// used for initial load of selected value in case options are lazy loaded
89-
loadSelectedValue(attributeValue: string): void {
89+
loadSelectedValue(attributeValue: string, attrId?: ListAttributeValue["id"]): void {
9090
if (this.lazyLoading && this.ds && this.attributeId) {
91-
const filterCondition = datasourceFilter("containsExact", attributeValue, this.attributeId);
91+
const filterCondition = datasourceFilter("containsExact", attributeValue, attrId ?? this.attributeId);
9292
this.ds?.setFilter(filterCondition);
9393
this.ds.setLimit(1);
9494
}

packages/pluggableWidgets/combobox-web/src/helpers/Database/DatabaseSingleSelectionSelector.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ export class DatabaseSingleSelectionSelector<T extends string | Big, R extends E
5555
valueSourceAttribute
5656
} = extractDatabaseProps(props);
5757

58+
if (ds.status === "loading" && (!lazyLoading || ds.limit !== Infinity)) {
59+
return;
60+
}
61+
5862
this._attr = targetAttribute as R;
5963
this.readOnly = getReadonly(targetAttribute, props.customEditability, props.customEditabilityExpression);
6064
this.lazyLoader.updateProps(ds);
6165
this.lazyLoader.setLimit(
6266
this.lazyLoader.getLimit(ds.limit, this.readOnly, targetAttribute?.status ?? ds.status, lazyLoading)
6367
);
6468

65-
if (ds.status === "loading") {
66-
return;
67-
}
68-
6969
this.caption.updateProps({
7070
emptyOptionText: emptyOption,
7171
formattingAttributeOrExpression: captionProvider,
@@ -101,9 +101,18 @@ export class DatabaseSingleSelectionSelector<T extends string | Big, R extends E
101101
});
102102
if (obj) {
103103
this.currentId = obj;
104+
} else {
105+
// NOTE: should not hit this scope normally
106+
// if the value is not in the options list, but there is a value from attribute
107+
// there is probably a mismatch between the value and the datasource
108+
// logical next step is to try to reload the attribute value
109+
// this.options.loadSelectedValue(targetAttribute.value?.toString(), valueSourceAttribute?.id);
104110
}
105111
} else {
106-
this.options.loadSelectedValue(targetAttribute.value?.toString());
112+
// should hit on initial condition whereas:
113+
// no options are loaded yet : (allOptions.length > 0)
114+
// but there is a value from target attribute : (!this.currentId)
115+
this.options.loadSelectedValue(targetAttribute.value?.toString(), valueSourceAttribute?.id);
107116
}
108117
} else if (!targetAttribute.value && this.currentId) {
109118
this.currentId = null;

packages/pluggableWidgets/combobox-web/src/helpers/LazyLoadProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class LazyLoadProvider {
1818
getLimit(limit: number, readOnly: boolean, status: ValueStatus, lazyLoading: boolean): number | undefined {
1919
if (status !== "available" || readOnly === true) {
2020
if (status === "loading" && lazyLoading) {
21-
return this.limit === Infinity || !this.limit ? 1 : this.limit;
21+
return this.limit === Infinity || !this.limit ? 0 : this.limit;
2222
}
2323
return 0;
2424
}

0 commit comments

Comments
 (0)