Skip to content

Commit 981e14b

Browse files
authored
table widget browser storage (#1206)
* feat: clean up table widget preferences storage * feat: add view toggle preference * feat: add checkbox preferences * feat: add persistance for select filters * feat: fix publishSelectValues call * style: prettier * style: linting
1 parent 6d51d17 commit 981e14b

File tree

6 files changed

+318
-117
lines changed

6 files changed

+318
-117
lines changed

projects/components/src/table/controls/table-controls.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from '@angular/core';
1212
import { IconType } from '@hypertrace/assets-library';
1313
import { TypedSimpleChanges } from '@hypertrace/common';
14+
import { isEqual } from 'lodash-es';
1415
import { IconSize } from '../../icon/icon-size';
1516
import { MultiSelectJustify } from '../../multi-select/multi-select-justify';
1617
import { MultiSelectSearchMode, TriggerLabelDisplayMode } from '../../multi-select/multi-select.component';
@@ -101,6 +102,8 @@ import {
101102
})
102103
export class TableControlsComponent implements OnChanges {
103104
public readonly DEFAULT_SEARCH_PLACEHOLDER: string = 'Search...';
105+
@Input()
106+
public persistenceId?: string;
104107

105108
@Input()
106109
public searchEnabled?: boolean;
@@ -207,7 +210,7 @@ export class TableControlsComponent implements OnChanges {
207210

208211
private setActiveViewItem(): void {
209212
if (this.viewItems !== undefined) {
210-
this.activeViewItem = this.viewItems.find(item => item === this.activeViewItem) ?? this.viewItems[0];
213+
this.activeViewItem = this.findViewItem(this.activeViewItem);
211214
}
212215
}
213216

@@ -259,4 +262,8 @@ export class TableControlsComponent implements OnChanges {
259262
public onViewChange(item: ToggleItem<string>): void {
260263
this.viewChange.emit(item.value);
261264
}
265+
266+
private findViewItem(viewItem?: ToggleItem): ToggleItem | undefined {
267+
return this.viewItems?.find(item => isEqual(item, viewItem)) ?? this.viewItems![0];
268+
}
262269
}

projects/dashboards/src/widgets/base.model.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ export abstract class BaseModel {
1515
type: STRING_PROPERTY.type
1616
})
1717
public id?: string;
18+
19+
public getId(): string | undefined {
20+
return this.id;
21+
}
1822
}

projects/observability/src/shared/dashboard/widgets/table/table-widget-base.model.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ import { TableWidgetControlCheckboxOptionModel } from './table-widget-control-ch
2323
import { TableWidgetControlSelectOptionModel } from './table-widget-control-select-option.model';
2424

2525
export abstract class TableWidgetBaseModel extends BaseModel {
26+
@ModelProperty({
27+
key: 'viewId',
28+
displayName: 'Model View ID',
29+
type: STRING_PROPERTY.type
30+
})
31+
public viewId?: string;
32+
2633
@ModelProperty({
2734
// tslint:disable-next-line: no-object-literal-type-assertion
2835
type: {
@@ -126,6 +133,11 @@ export abstract class TableWidgetBaseModel extends BaseModel {
126133
return [];
127134
}
128135

136+
public getViewId(): string | undefined {
137+
// No-op here, but can be overridden
138+
return this.viewId;
139+
}
140+
129141
public setView(_view: string): void {
130142
// No-op here, but can be overridden
131143
return;

0 commit comments

Comments
 (0)