Skip to content

Commit b65f483

Browse files
committed
remove effect usage
1 parent d4cdbfb commit b65f483

File tree

4 files changed

+22
-26
lines changed

4 files changed

+22
-26
lines changed

frontend/src/app/components/ui-components/filter-fields/foreign-key/foreign-key.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[required]="required" [disabled]="disabled" [readonly]="readonly"
1212
[(ngModel)]="currentDisplayedString"
1313
[matAutocomplete]="auto"
14-
(ngModelChange)="searchTerm.set($event)">
14+
(ngModelChange)="onSearchInput()">
1515
<mat-autocomplete autoActiveFirstOption #auto="matAutocomplete" (optionSelected)="updateRelatedLink($event)">
1616
@for (suggestion of suggestions(); track suggestion.fieldValue) {
1717
<mat-option

frontend/src/app/components/ui-components/filter-fields/foreign-key/foreign-key.component.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { CommonModule } from '@angular/common';
2-
import { Component, effect, Input, signal } from '@angular/core';
3-
import { toObservable, toSignal } from '@angular/core/rxjs-interop';
2+
import { Component, Input, signal } from '@angular/core';
43
import { FormsModule } from '@angular/forms';
54
import { MatAutocompleteModule, MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
65
import { MatFormFieldModule } from '@angular/material/form-field';
@@ -10,7 +9,6 @@ import { MatSpinner } from '@angular/material/progress-spinner';
109
import { MatTooltipModule } from '@angular/material/tooltip';
1110
import { RouterModule } from '@angular/router';
1211
import { firstValueFrom } from 'rxjs';
13-
import { debounceTime } from 'rxjs/operators';
1412
import { ConnectionsService } from 'src/app/services/connections.service';
1513
import { TablesService } from 'src/app/services/tables.service';
1614
import { BaseFilterFieldComponent } from '../base-filter-field/base-filter-field.component';
@@ -55,20 +53,13 @@ export class ForeignKeyFilterComponent extends BaseFilterFieldComponent {
5553
public identityColumn: string;
5654
public primaeyKeys: { data_type: string; column_name: string }[];
5755

58-
searchTerm = signal('');
59-
60-
private _debouncedTerm = toSignal(toObservable(this.searchTerm).pipe(debounceTime(500)), { initialValue: '' });
56+
private _debounceTimer: ReturnType<typeof setTimeout>;
6157

6258
constructor(
6359
private _tables: TablesService,
6460
private _connections: ConnectionsService,
6561
) {
6662
super();
67-
effect(() => {
68-
const _term = this._debouncedTerm();
69-
if (this.currentDisplayedString === '') this.onFieldChange.emit(null);
70-
this.fetchSuggestions();
71-
});
7263
}
7364

7465
async ngOnInit(): Promise<void> {
@@ -152,6 +143,14 @@ export class ForeignKeyFilterComponent extends BaseFilterFieldComponent {
152143
}
153144
}
154145

146+
onSearchInput(): void {
147+
clearTimeout(this._debounceTimer);
148+
this._debounceTimer = setTimeout(() => {
149+
if (this.currentDisplayedString === '') this.onFieldChange.emit(null);
150+
this.fetchSuggestions();
151+
}, 500);
152+
}
153+
155154
async fetchSuggestions(): Promise<void> {
156155
const currentRow = this.suggestions()?.find(
157156
(suggestion) => suggestion.displayString === this.currentDisplayedString,

frontend/src/app/components/ui-components/record-edit-fields/foreign-key/foreign-key.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[required]="required" [disabled]="disabled" [readonly]="readonly"
1111
[(ngModel)]="currentDisplayedString"
1212
[matAutocomplete]="auto"
13-
(ngModelChange)="searchTerm.set($event)">
13+
(ngModelChange)="onSearchInput()">
1414
<mat-autocomplete autoActiveFirstOption #auto="matAutocomplete" (optionSelected)="updateRelatedLink($event)">
1515
@for (suggestion of suggestions(); track suggestion.fieldValue) {
1616
<mat-option

frontend/src/app/components/ui-components/record-edit-fields/foreign-key/foreign-key.component.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { CommonModule } from '@angular/common';
2-
import { Component, effect, Input, signal } from '@angular/core';
3-
import { toObservable, toSignal } from '@angular/core/rxjs-interop';
2+
import { Component, Input, signal } from '@angular/core';
43
import { FormsModule } from '@angular/forms';
54
import { MatAutocompleteModule, MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
65
import { MatFormFieldModule } from '@angular/material/form-field';
@@ -10,7 +9,6 @@ import { MatSpinner } from '@angular/material/progress-spinner';
109
import { MatTooltipModule } from '@angular/material/tooltip';
1110
import { RouterModule } from '@angular/router';
1211
import { firstValueFrom } from 'rxjs';
13-
import { debounceTime } from 'rxjs/operators';
1412
import { TableForeignKey } from 'src/app/models/table';
1513
import { ConnectionsService } from 'src/app/services/connections.service';
1614
import { TablesService } from 'src/app/services/tables.service';
@@ -57,20 +55,13 @@ export class ForeignKeyEditComponent extends BaseEditFieldComponent {
5755
public primaeyKeys: { data_type: string; column_name: string }[];
5856

5957
public fkRelations: TableForeignKey = null;
60-
searchTerm = signal('');
61-
62-
private _debouncedTerm = toSignal(toObservable(this.searchTerm).pipe(debounceTime(500)), { initialValue: '' });
58+
private _debounceTimer: ReturnType<typeof setTimeout>;
6359

6460
constructor(
6561
private _tables: TablesService,
6662
private _connections: ConnectionsService,
6763
) {
6864
super();
69-
effect(() => {
70-
const _term = this._debouncedTerm();
71-
if (this.currentDisplayedString === '') this.onFieldChange.emit(null);
72-
this.fetchSuggestions();
73-
});
7465
}
7566

7667
async ngOnInit(): Promise<void> {
@@ -160,14 +151,20 @@ export class ForeignKeyEditComponent extends BaseEditFieldComponent {
160151
}
161152
}
162153

154+
onSearchInput(): void {
155+
clearTimeout(this._debounceTimer);
156+
this._debounceTimer = setTimeout(() => {
157+
if (this.currentDisplayedString === '') this.onFieldChange.emit(null);
158+
this.fetchSuggestions();
159+
}, 500);
160+
}
161+
163162
async fetchSuggestions(): Promise<void> {
164163
const currentRow = this.suggestions()?.find(
165164
(suggestion) => suggestion.displayString === this.currentDisplayedString,
166165
);
167166
if (currentRow !== undefined) {
168167
this.currentFieldValue = currentRow.fieldValue;
169-
console.log(this.label + 'this.currentFieldValue');
170-
console.log(this.currentFieldValue);
171168
this.onFieldChange.emit(this.currentFieldValue);
172169
} else {
173170
this.fetching.set(true);

0 commit comments

Comments
 (0)