Skip to content

Commit e94366a

Browse files
committed
fix: update providers to include timeout parameter
1 parent 33c8ea2 commit e94366a

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;
@@ -118,12 +113,6 @@ export class BaseDatasourceOptionsProvider extends BaseOptionsProvider<ObjectIte
118113
this.filterType = props.filterType;
119114
this.lazyLoading = props.lazyLoading;
120115

121-
const newInterval = props.filterInputDebounceInterval ?? 200;
122-
if (newInterval !== this.filterInputDebounceInterval) {
123-
this.filterInputDebounceInterval = newInterval;
124-
this.createDebouncedSetFilter();
125-
}
126-
127116
if (this.lazyLoading) {
128117
if (props.ds.status === "loading") {
129118
this.loading = true;
@@ -137,10 +126,4 @@ export class BaseDatasourceOptionsProvider extends BaseOptionsProvider<ObjectIte
137126
items.forEach(i => this.valuesMap.set(i.id, i));
138127
this.options = Array.from(this.valuesMap.keys());
139128
}
140-
141-
cleanup(): void {
142-
if (this.abortDebouncedFilter) {
143-
this.abortDebouncedFilter();
144-
}
145-
}
146129
}

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)