Skip to content

Commit d372fcf

Browse files
yordan-stgjulivan
authored andcommitted
fix: update providers to include timeout parameter
1 parent e1f3fd7 commit d372fcf

File tree

4 files changed

+11
-28
lines changed

4 files changed

+11
-28
lines changed

packages/pluggableWidgets/combobox-web/src/helpers/Association/BaseAssociationSelector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class BaseAssociationSelector<T extends string | string[], R extends Refe
2929

3030
constructor() {
3131
this.caption = new AssociationSimpleCaptionsProvider(this._valuesMap);
32-
this.options = new AssociationOptionsProvider(this.caption, this._valuesMap);
32+
this.options = new AssociationOptionsProvider(this.caption, this._valuesMap, 200);
3333
}
3434

3535
updateProps(props: ComboboxContainerProps): void {

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

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,22 @@ export class BaseDatasourceOptionsProvider extends BaseOptionsProvider<ObjectIte
1919
private ds?: ListValue;
2020
private attributeId?: ListAttributeValue["id"];
2121
protected loading: boolean = false;
22-
private debouncedSetFilter!: (filterCondition: FilterCondition | undefined) => void;
23-
private abortDebouncedFilter!: () => void;
24-
private filterInputDebounceInterval: number = 200;
22+
private debouncedSetFilter: (filterCondition: FilterCondition | undefined) => void;
23+
private filterInputDebounceInterval: number;
2524

2625
constructor(
2726
caption: CaptionsProvider,
28-
protected valuesMap: Map<string, ObjectItem>
27+
protected valuesMap: Map<string, ObjectItem>,
28+
filterInputDebounceInterval: number = 200
2929
) {
3030
super(caption);
31-
this.createDebouncedSetFilter();
32-
}
33-
34-
private createDebouncedSetFilter(): void {
35-
this.cleanup();
31+
this.filterInputDebounceInterval = filterInputDebounceInterval;
3632

37-
const [debouncedFn, abort] = debounce((filterCondition: FilterCondition | undefined) => {
33+
const [debouncedFn] = debounce((filterCondition: FilterCondition | undefined) => {
3834
this.ds?.setFilter(filterCondition);
3935
}, this.filterInputDebounceInterval);
4036

4137
this.debouncedSetFilter = debouncedFn;
42-
this.abortDebouncedFilter = abort;
4338
}
4439

4540
get sortOrder(): SortOrder {
@@ -69,10 +64,10 @@ export class BaseDatasourceOptionsProvider extends BaseOptionsProvider<ObjectIte
6964
getAll(): string[] {
7065
if (this.lazyLoading && this.attributeId) {
7166
if (this.searchTerm === "") {
72-
this.debouncedSetFilter!(undefined);
67+
this.debouncedSetFilter(undefined);
7368
} else {
7469
const filterCondition = datasourceFilter(this.filterType, this.searchTerm, this.attributeId);
75-
this.debouncedSetFilter!(filterCondition);
70+
this.debouncedSetFilter(filterCondition);
7671
}
7772

7873
return this.options;
@@ -122,12 +117,6 @@ export class BaseDatasourceOptionsProvider extends BaseOptionsProvider<ObjectIte
122117
this.filterType = props.filterType;
123118
this.lazyLoading = props.lazyLoading;
124119

125-
const newInterval = props.filterInputDebounceInterval ?? 200;
126-
if (newInterval !== this.filterInputDebounceInterval) {
127-
this.filterInputDebounceInterval = newInterval;
128-
this.createDebouncedSetFilter();
129-
}
130-
131120
if (this.lazyLoading) {
132121
if (props.ds.status === "loading") {
133122
this.loading = true;
@@ -141,10 +130,4 @@ export class BaseDatasourceOptionsProvider extends BaseOptionsProvider<ObjectIte
141130
items.forEach(i => this.valuesMap.set(i.id, i));
142131
this.options = Array.from(this.valuesMap.keys());
143132
}
144-
145-
cleanup(): void {
146-
if (this.abortDebouncedFilter) {
147-
this.abortDebouncedFilter();
148-
}
149-
}
150133
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class DatabaseMultiSelectionSelector implements MultiSelector {
3636

3737
constructor() {
3838
this.caption = new DatabaseCaptionsProvider(this._objectsMap);
39-
this.options = new DatabaseOptionsProvider(this.caption, this._objectsMap);
39+
this.options = new DatabaseOptionsProvider(this.caption, this._objectsMap, 200);
4040
}
4141

4242
getOptions(): string[] {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class DatabaseSingleSelectionSelector<T extends string | Big, R extends E
3535

3636
constructor() {
3737
this.caption = new DatabaseCaptionsProvider(this._objectsMap);
38-
this.options = new DatabaseOptionsProvider(this.caption, this._objectsMap);
38+
this.options = new DatabaseOptionsProvider(this.caption, this._objectsMap, 200);
3939
this.values = new DatabaseValuesProvider(this._objectsMap);
4040
}
4141

0 commit comments

Comments
 (0)