@@ -124,11 +124,6 @@ import { TableWidgetModel } from './table-widget.model';
124124export class TableWidgetRendererComponent
125125 extends WidgetRenderer < TableWidgetBaseModel , TableDataSource < TableRow > | undefined >
126126 implements OnInit {
127- private static readonly DEFAULT_PREFERENCES : TableWidgetPreferences = {
128- columns : [ ] ,
129- checkboxes : [ ]
130- } ;
131-
132127 private static readonly DEFAULT_TAB_INDEX : number = 0 ;
133128
134129 public viewItems : ToggleItem < string > [ ] = [ ] ;
@@ -228,7 +223,7 @@ export class TableWidgetRendererComponent
228223 }
229224
230225 private getSelectControls ( changed ?: TableSelectControl ) : Observable < TableSelectControl [ ] > {
231- return this . getPreferences ( ) . pipe (
226+ return this . getSessionPreferences ( ) . pipe (
232227 take ( 1 ) ,
233228 switchMap ( preferences =>
234229 forkJoinSafeEmpty (
@@ -300,7 +295,7 @@ export class TableWidgetRendererComponent
300295 }
301296
302297 private getColumnConfigs ( ) : Observable < TableColumnConfig [ ] > {
303- return this . getPreferences ( ) . pipe (
298+ return this . getLocalPreferences ( ) . pipe (
304299 switchMap ( preferences =>
305300 combineLatest ( [ this . getScope ( ) , this . api . change$ . pipe ( mapTo ( true ) , startWith ( true ) ) ] ) . pipe (
306301 switchMap ( ( [ scope ] ) => this . model . getColumns ( scope ) ) ,
@@ -366,8 +361,8 @@ export class TableWidgetRendererComponent
366361
367362 private updateSelectionPreferences ( tableSelectControls : TableSelectControl [ ] ) : void {
368363 if ( isNonEmptyString ( this . model . getId ( ) ) ) {
369- this . getPreferences ( ) . subscribe ( preferences =>
370- this . setPreferences ( {
364+ this . getSessionPreferences ( ) . subscribe ( preferences =>
365+ this . setSessionPreferences ( {
371366 ...preferences ,
372367 selections : tableSelectControls
373368 } )
@@ -401,8 +396,8 @@ export class TableWidgetRendererComponent
401396
402397 private updateCheckboxPreferences ( tableCheckboxControls : TableCheckboxControl [ ] ) : void {
403398 if ( isNonEmptyString ( this . model . getId ( ) ) ) {
404- this . getPreferences ( ) . subscribe ( preferences =>
405- this . setPreferences ( {
399+ this . getSessionPreferences ( ) . subscribe ( preferences =>
400+ this . setSessionPreferences ( {
406401 ...preferences ,
407402 checkboxes : tableCheckboxControls
408403 } )
@@ -411,7 +406,7 @@ export class TableWidgetRendererComponent
411406 }
412407
413408 private getCheckboxControls ( changed ?: TableCheckboxChange ) : Observable < TableCheckboxControl [ ] > {
414- return this . getPreferences ( ) . pipe (
409+ return this . getSessionPreferences ( ) . pipe (
415410 switchMap ( preferences =>
416411 forkJoinSafeEmpty (
417412 this . model
@@ -484,8 +479,8 @@ export class TableWidgetRendererComponent
484479
485480 public onColumnsChange ( columns : TableColumnConfig [ ] ) : void {
486481 if ( isNonEmptyString ( this . model . getId ( ) ) ) {
487- this . getPreferences ( ) . subscribe ( preferences =>
488- this . setPreferences ( {
482+ this . getLocalPreferences ( ) . subscribe ( preferences =>
483+ this . setLocalPreferences ( {
489484 ...preferences ,
490485 columns : columns . map ( column => this . dehydratePersistedColumnConfig ( column ) )
491486 } )
@@ -500,7 +495,7 @@ export class TableWidgetRendererComponent
500495 public onRowSelection ( selections : StatefulTableRow [ ] ) : void {
501496 this . selectedRows = selections ;
502497 /**
503- * Todo: Stich this with selection handlers
498+ * Todo: Stitch this with selection handlers
504499 */
505500 }
506501
@@ -552,27 +547,39 @@ export class TableWidgetRendererComponent
552547
553548 private getViewPreferences ( ) : Observable < TableWidgetViewPreferences > {
554549 return isNonEmptyString ( this . model . viewId )
555- ? this . preferenceService . get < TableWidgetViewPreferences > ( this . model . viewId , { } , StorageType . Session ) . pipe ( first ( ) )
550+ ? this . preferenceService . get < TableWidgetViewPreferences > ( this . model . viewId , { } , StorageType . Local ) . pipe ( first ( ) )
556551 : of ( { } ) ;
557552 }
558553
559554 private setViewPreferences ( preferences : TableWidgetViewPreferences ) : void {
560555 if ( isNonEmptyString ( this . model . viewId ) ) {
561- this . preferenceService . set ( this . model . viewId , preferences , StorageType . Session ) ;
556+ this . preferenceService . set ( this . model . viewId , preferences , StorageType . Local ) ;
557+ }
558+ }
559+
560+ private getLocalPreferences ( ) : Observable < TableWidgetLocalPreferences > {
561+ return isNonEmptyString ( this . model . getId ( ) )
562+ ? this . preferenceService
563+ . get < TableWidgetLocalPreferences > ( this . model . getId ( ) ! , { } , StorageType . Local )
564+ . pipe ( first ( ) )
565+ : of ( { } ) ;
566+ }
567+
568+ private setLocalPreferences ( preferences : TableWidgetLocalPreferences ) : void {
569+ if ( isNonEmptyString ( this . model . getId ( ) ) ) {
570+ this . preferenceService . set ( this . model . getId ( ) ! , preferences , StorageType . Local ) ;
562571 }
563572 }
564573
565- private getPreferences (
566- defaultPreferences : TableWidgetPreferences = TableWidgetRendererComponent . DEFAULT_PREFERENCES
567- ) : Observable < TableWidgetPreferences > {
574+ private getSessionPreferences ( ) : Observable < TableWidgetSessionPreferences > {
568575 return isNonEmptyString ( this . model . getId ( ) )
569576 ? this . preferenceService
570- . get < TableWidgetPreferences > ( this . model . getId ( ) ! , defaultPreferences , StorageType . Session )
577+ . get < TableWidgetSessionPreferences > ( this . model . getId ( ) ! , { } , StorageType . Session )
571578 . pipe ( first ( ) )
572- : of ( defaultPreferences ) ;
579+ : of ( { } ) ;
573580 }
574581
575- private setPreferences ( preferences : TableWidgetPreferences ) : void {
582+ private setSessionPreferences ( preferences : TableWidgetSessionPreferences ) : void {
576583 if ( isNonEmptyString ( this . model . getId ( ) ) ) {
577584 this . preferenceService . set ( this . model . getId ( ) ! , preferences , StorageType . Session ) ;
578585 }
@@ -607,8 +614,11 @@ interface TableWidgetViewPreferences {
607614 activeView ?: string ;
608615}
609616
610- interface TableWidgetPreferences {
617+ interface TableWidgetLocalPreferences {
611618 columns ?: PersistedTableColumnConfig [ ] ;
619+ }
620+
621+ interface TableWidgetSessionPreferences {
612622 checkboxes ?: TableCheckboxControl [ ] ;
613623 selections ?: TableSelectControl [ ] ;
614624}
0 commit comments