@@ -57,11 +57,6 @@ import { TablesService } from 'src/app/services/tables.service';
5757 styleUrl : './saved-filters-dialog.component.css' ,
5858} )
5959export 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