Skip to content

Commit 89b3d11

Browse files
guguclaude
andcommitted
Clean up filter components: remove dead code, debug logs, and redundant state
Remove dead setWidgets() from saved-filters-dialog and panel, no-op cast.subscribe() calls, spurious @Injectable() decorators, debug console.log statements, commented-out code, and redundant textValue state in email/phone filters. Cache country and timezone lists at module level. Replace O(n) isWidget array scan with O(1) object lookup. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 45c4514 commit 89b3d11

14 files changed

Lines changed: 128 additions & 286 deletions

File tree

frontend/src/app/components/dashboard/db-table-view/db-table-filters-dialog/db-table-filters-dialog.component.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { getComparatorsFromUrl, getFiltersFromUrl } from 'src/app/lib/parse-filt
2323
import { getTableTypes } from 'src/app/lib/setup-table-row-structure';
2424
import { TableField, TableForeignKey, Widget } from 'src/app/models/table';
2525
import { ConnectionsService } from 'src/app/services/connections.service';
26-
import { TablesService } from 'src/app/services/tables.service';
2726
import { ContentLoaderComponent } from '../../../ui-components/content-loader/content-loader.component';
2827

2928
@Component({
@@ -65,22 +64,19 @@ export class DbTableFiltersDialogComponent implements OnInit, AfterViewInit {
6564
public differ: KeyValueDiffer<string, any>;
6665
public tableTypes: Object;
6766
public tableWidgets: object;
68-
public tableWidgetsList: string[] = [];
6967
public UIwidgets = { ...EditUIwidgets, ...FilterUIwidgets };
7068
public autofocusField: string | null = null;
7169

7270
constructor(
7371
@Inject(MAT_DIALOG_DATA) public data: any,
7472
private _connections: ConnectionsService,
75-
private _tables: TablesService,
7673
public route: ActivatedRoute,
7774
private differs: KeyValueDiffers,
7875
) {
7976
this.differ = this.differs.find({}).create();
8077
}
8178

8279
ngOnInit(): void {
83-
this._tables.cast.subscribe();
8480
this.tableForeignKeys = { ...this.data.structure.foreignKeys };
8581
this.tableRowFields = Object.assign(
8682
{},
@@ -90,36 +86,28 @@ export class DbTableFiltersDialogComponent implements OnInit, AfterViewInit {
9086
this.fields = this.data.structure.structure
9187
.filter((field: TableField) => this.getInputType(field.column_name) !== 'file')
9288
.map((field: TableField) => field.column_name);
93-
// this.foundFields = [...this.fields];
9489
this.tableRowStructure = Object.assign(
9590
{},
9691
...this.data.structure.structure.map((field: TableField) => {
9792
return { [field.column_name]: field };
9893
}),
9994
);
10095

101-
// Set autofocus field if provided
10296
if (this.data.autofocusField) {
10397
this.autofocusField = this.data.autofocusField;
10498
}
10599

106100
const queryParams = this.route.snapshot.queryParams;
107101

108-
// If saved_filter is present in queryParams, show empty form without applying filters
109102
if (queryParams.saved_filter) {
110-
// Show empty form without filters
111103
this.tableFilters = [];
112104
this.tableRowFieldsShown = {};
113105
this.tableRowFieldsComparator = {};
114106
} else {
115-
// Original behavior - parse and apply filters from URL
116107
let filters = {};
117108
if (queryParams.filters) filters = JsonURL.parse(queryParams.filters);
118-
// const filters = JsonURL.parse(queryParams.filters || '{}');
119109
const filtersValues = getFiltersFromUrl(filters);
120110

121-
console.log('Parsed filters from URL:', filtersValues);
122-
123111
if (Object.keys(filtersValues).length) {
124112
this.tableFilters = Object.keys(filtersValues).map((key) => key);
125113
this.tableRowFieldsShown = filtersValues;
@@ -146,7 +134,6 @@ export class DbTableFiltersDialogComponent implements OnInit, AfterViewInit {
146134
this.setWidgets(widgetsArray);
147135
}
148136

149-
// If autofocusField is provided, ensure it's in the filters list
150137
if (this.autofocusField && this.tableFilters && !this.tableFilters.includes(this.autofocusField)) {
151138
this.tableFilters.push(this.autofocusField);
152139
if (!this.tableRowFieldsShown[this.autofocusField]) {
@@ -164,7 +151,6 @@ export class DbTableFiltersDialogComponent implements OnInit, AfterViewInit {
164151
}
165152

166153
ngAfterViewInit(): void {
167-
// Set focus on the autofocus field after view is initialized
168154
if (this.autofocusField) {
169155
setTimeout(() => {
170156
this.focusOnField(this.autofocusField);
@@ -173,7 +159,6 @@ export class DbTableFiltersDialogComponent implements OnInit, AfterViewInit {
173159
}
174160

175161
focusOnField(fieldName: string) {
176-
// Try multiple selectors to find the input field
177162
const selectors = [
178163
`input[name*="${fieldName}"]`,
179164
`textarea[name*="${fieldName}"]`,
@@ -228,7 +213,6 @@ export class DbTableFiltersDialogComponent implements OnInit, AfterViewInit {
228213
}
229214

230215
setWidgets(widgets: Widget[]) {
231-
this.tableWidgetsList = widgets.map((widget: Widget) => widget.field_name);
232216
this.tableWidgets = Object.assign(
233217
{},
234218
...widgets.map((widget: Widget) => {
@@ -248,11 +232,11 @@ export class DbTableFiltersDialogComponent implements OnInit, AfterViewInit {
248232
}
249233

250234
trackByFn(_index: number, item: any) {
251-
return item.key; // or item.id
235+
return item.key;
252236
}
253237

254238
isWidget(columnName: string) {
255-
return this.tableWidgetsList.includes(columnName);
239+
return this.tableWidgets && columnName in this.tableWidgets;
256240
}
257241

258242
updateField = (updatedValue: any, field: string) => {

frontend/src/app/components/dashboard/db-table-view/saved-filters-panel/saved-filters-dialog/saved-filters-dialog.component.ts

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ import { TablesService } from 'src/app/services/tables.service';
5757
styleUrl: './saved-filters-dialog.component.css',
5858
})
5959
export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
60-
// @Input() connectionID: string;
61-
// @Input() tableName: string;
62-
// @Input() displayTableName: string;
63-
// @Input() filtersSet: any;
64-
6560
public tableFilters = [];
6661
public fieldSearchControl = new FormControl('');
6762
public fields: string[];
@@ -71,11 +66,9 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
7166
public tableRowStructure: Object;
7267
public tableRowFieldsShown: Object = {};
7368
public tableRowFieldsComparator: Object = {};
74-
// public tableForeignKeys: {[key: string]: TableForeignKey};
7569
public tableFiltersCount: number = 0;
7670
public tableTypes: Object;
7771
public tableWidgets: object;
78-
public tableWidgetsList: string[] = [];
7972
public UIwidgets = { ...EditUIwidgets, ...FilterUIwidgets };
8073
public dynamicColumn: string | null = null;
8174
public showAddConditionField = false;
@@ -95,8 +88,6 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
9588
) {}
9689

9790
ngOnInit(): void {
98-
this._tables.cast.subscribe();
99-
10091
if (this.data.filtersSet) {
10192
this.tableRowFieldsShown = Object.entries(this.data.filtersSet.filters).reduce((acc, [field, conditions]) => {
10293
const [_comparator, value] = Object.entries(conditions)[0];
@@ -113,7 +104,6 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
113104
{},
114105
);
115106

116-
// Initialize dynamic column if it exists in the filters set
117107
if (this.data.filtersSet.dynamic_column?.column_name) {
118108
this.tableRowFieldsShown[this.data.filtersSet.dynamic_column.column_name] = null;
119109
this.tableRowFieldsComparator[this.data.filtersSet.dynamic_column.column_name] =
@@ -122,7 +112,6 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
122112
}
123113
}
124114

125-
// this.tableForeignKeys = {...this.data.structure.foreignKeys};
126115
this.tableRowFields = Object.assign(
127116
{},
128117
...this.data.structure.map((field: TableField) => ({ [field.column_name]: undefined })),
@@ -140,10 +129,8 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
140129
}),
141130
);
142131

143-
// Setup widgets - data comes pre-processed as object { field_name: { widget_type, widget_params, ... } }
144132
const tableWidgets = this.data.tableWidgets;
145133
if (tableWidgets && Object.keys(tableWidgets).length) {
146-
this.tableWidgetsList = Object.keys(tableWidgets);
147134
this.tableWidgets = tableWidgets;
148135
}
149136

@@ -154,7 +141,6 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
154141
}
155142

156143
ngAfterViewInit(): void {
157-
// If editing an existing filter (has id), remove focus from the filter name input
158144
if (this.data.filtersSet && this.data.filtersSet.id) {
159145
setTimeout(() => {
160146
const nameInput = this.elementRef.nativeElement.querySelector(
@@ -192,36 +178,12 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
192178
return filterTypes[this._connections.currentConnection.type];
193179
}
194180

195-
setWidgets(widgets: any[]) {
196-
this.tableWidgetsList = widgets.map((widget: any) => widget.field_name);
197-
this.tableWidgets = Object.assign(
198-
{},
199-
...widgets.map((widget: any) => {
200-
let params;
201-
if (typeof widget.widget_params === 'string' && widget.widget_params !== '// No settings required') {
202-
try {
203-
params = JSON.parse(widget.widget_params);
204-
} catch (_e) {
205-
params = '';
206-
}
207-
} else if (typeof widget.widget_params !== 'string') {
208-
params = widget.widget_params;
209-
} else {
210-
params = '';
211-
}
212-
return {
213-
[widget.field_name]: { ...widget, widget_params: params },
214-
};
215-
}),
216-
);
217-
}
218-
219181
trackByFn(_index: number, item: any) {
220182
return item.key;
221183
}
222184

223185
isWidget(columnName: string) {
224-
return this.tableWidgetsList.includes(columnName);
186+
return this.tableWidgets && columnName in this.tableWidgets;
225187
}
226188

227189
updateComparatorFromComponent = (comparator: string, field: string) => {
@@ -231,7 +193,6 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
231193
updateField = (updatedValue: any, field: string) => {
232194
this.tableRowFieldsShown[field] = updatedValue;
233195
this.updateFiltersCount();
234-
// Reset conditions error when a filter is added
235196
if (this.showConditionsError && Object.keys(this.tableRowFieldsShown).length > 0) {
236197
this.showConditionsError = false;
237198
}
@@ -246,15 +207,13 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
246207
};
247208
this.fieldSearchControl.setValue('');
248209
this.updateFiltersCount();
249-
// Reset conditions error when a filter is added
250210
this.showConditionsError = false;
251211
if (this.hasSelectedFilters) {
252212
this.showAddConditionField = false;
253213
}
254214
}
255215

256216
handleInputBlur(): void {
257-
// Hide the field if it's empty when it loses focus
258217
if (!this.fieldSearchControl.value || this.fieldSearchControl.value.trim() === '') {
259218
setTimeout(() => {
260219
if (!this.fieldSearchControl.value || this.fieldSearchControl.value.trim() === '') {
@@ -265,7 +224,6 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
265224
}
266225

267226
updateComparator(event, fieldName: string) {
268-
console.log('Updating comparator for field:', fieldName, 'obj', this.tableRowFieldsComparator);
269227
if (event === 'empty') this.tableRowFieldsShown[fieldName] = '';
270228
}
271229

@@ -324,7 +282,6 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
324282
this.dynamicColumn = null;
325283
}
326284
this.updateFiltersCount();
327-
// Reset conditions error when filters are removed (will be re-validated on save)
328285
this.showConditionsError = false;
329286
if (!this.hasSelectedFilters) {
330287
this.showAddConditionField = false;
@@ -344,11 +301,9 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
344301
}
345302

346303
handleSaveFilters() {
347-
// Reset error flags
348304
this.showNameError = false;
349305
this.showConditionsError = false;
350306

351-
// Validate filter name
352307
if (!this.data.filtersSet.name || this.data.filtersSet.name.trim() === '') {
353308
this.showNameError = true;
354309
setTimeout(() => {
@@ -363,19 +318,13 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
363318
return;
364319
}
365320

366-
// Validate conditions - check if there are any filters
367-
// A valid filter must have a comparator defined
368-
// Either regular filters OR dynamic column with comparator should exist
369321
const hasRegularFilters = Object.keys(this.tableRowFieldsShown).some((key) => {
370-
// Skip dynamic column for regular filter check
371322
if (key === this.dynamicColumn) {
372323
return false;
373324
}
374-
// Check if comparator is defined (even if value is empty/null, comparator must exist)
375325
return this.tableRowFieldsComparator[key] !== undefined && this.tableRowFieldsComparator[key] !== null;
376326
});
377327

378-
// Check if dynamic column has a comparator (it counts as a valid filter condition)
379328
const hasDynamicColumnFilter =
380329
this.dynamicColumn &&
381330
this.tableRowFieldsComparator[this.dynamicColumn] !== undefined &&
@@ -391,7 +340,6 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
391340
conditionInput.focus();
392341
conditionInput.scrollIntoView({ behavior: 'smooth', block: 'center' });
393342
} else {
394-
// If input is not visible, show the add condition button area
395343
const addButton = this.elementRef.nativeElement.querySelector('.add-condition-footer button') as HTMLElement;
396344
if (addButton) {
397345
addButton.scrollIntoView({ behavior: 'smooth', block: 'center' });
@@ -406,13 +354,11 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
406354
let filters = {};
407355

408356
for (const key in this.tableRowFieldsShown) {
409-
// Skip fields that are marked as dynamic column
410357
if (key === this.dynamicColumn) {
411358
continue;
412359
}
413360

414361
if (this.tableRowFieldsComparator[key] !== undefined) {
415-
// If value is empty or undefined, use null
416362
const value =
417363
this.tableRowFieldsShown[key] === '' || this.tableRowFieldsShown[key] === undefined
418364
? null
@@ -424,15 +370,12 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
424370
}
425371
}
426372

427-
// const filters = JsonURL.stringify( this.filters );
428373
payload = {
429374
name: this.data.filtersSet.name,
430375
filters,
431376
};
432377

433-
// Only add dynamic_column if one is selected
434378
if (this.dynamicColumn) {
435-
// Create object with column_name and comparator properties
436379
payload.dynamic_column = {
437380
column_name: this.dynamicColumn,
438381
comparator: this.tableRowFieldsComparator[this.dynamicColumn] || '',
@@ -471,16 +414,5 @@ export class SavedFiltersDialogComponent implements OnInit, AfterViewInit {
471414
);
472415
}
473416
}
474-
475-
// saveFilter() {
476-
477-
// this._tables.createSavedFilter(this.data.connectionID, this.data.tableName, payload)
478-
// .subscribe(() => {
479-
// this.dialogRef.close(true);
480-
// }, (error) => {
481-
// console.error('Error saving filter:', error);
482-
// this.snackBar.open('Error saving filter', 'Close', { duration: 3000 });
483-
// });
484-
// }
485417
}
486418
}

0 commit comments

Comments
 (0)