Skip to content

Commit 04e3ff5

Browse files
authored
fix: issues with checkbox diffing (#699)
1 parent 44533ab commit 04e3ff5

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

projects/components/src/select/select.component.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
font-size: 14px;
130130
align-items: center;
131131
justify-content: space-between;
132+
white-space: nowrap;
132133

133134
.select-option-info {
134135
display: flex;

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,22 @@ export class TableControlsComponent implements OnChanges {
152152

153153
public ngOnChanges(changes: TypedSimpleChanges<this>): void {
154154
if (changes.checkboxControls) {
155-
this.checkboxSelections = this.checkboxControls
156-
? this.checkboxControls.filter(control => control.value).map(control => control.label)
157-
: [];
158-
159-
this.checkboxDiffer?.diff(this.checkboxSelections);
155+
this.diffCheckboxes();
160156
}
161157

162158
if (changes.viewItems) {
163159
this.setActiveViewItem();
164160
}
165161
}
166162

163+
private diffCheckboxes(): void {
164+
this.checkboxSelections = this.checkboxControls
165+
? this.checkboxControls.filter(control => control.value).map(control => control.label)
166+
: [];
167+
168+
this.checkboxDiffer?.diff(this.checkboxSelections);
169+
}
170+
167171
private setActiveViewItem(): void {
168172
if (this.viewItems !== undefined) {
169173
this.activeViewItem = this.viewItems.find(item => item === this.activeViewItem) ?? this.viewItems[0];
@@ -210,6 +214,9 @@ export class TableControlsComponent implements OnChanges {
210214
});
211215
}
212216
});
217+
218+
this.checkboxSelections = checks;
219+
this.checkboxDiffer?.diff(this.checkboxSelections);
213220
}
214221

215222
public onViewChange(item: ToggleItem<string>): void {

projects/distributed-tracing/src/shared/dashboard/widgets/table/table-widget-renderer.component.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ import { Renderer } from '@hypertrace/hyperdash';
2929
import { RendererApi, RENDERER_API } from '@hypertrace/hyperdash-angular';
3030
import { capitalize, isEmpty, pick } from 'lodash-es';
3131
import { BehaviorSubject, combineLatest, Observable, of, Subject } from 'rxjs';
32-
import { filter, first, map, pairwise, share, startWith, switchMap, tap } from 'rxjs/operators';
32+
import { filter, map, pairwise, share, startWith, switchMap, take, tap } from 'rxjs/operators';
3333
import { AttributeMetadata, toFilterAttributeType } from '../../../graphql/model/metadata/attribute-metadata';
3434
import { MetadataService } from '../../../services/metadata/metadata.service';
3535
import { InteractionHandler } from '../../interaction/interaction-handler';
3636
import { TableWidgetBaseModel } from './table-widget-base.model';
3737
import { SpecificationBackedTableColumnDef } from './table-widget-column.model';
38+
import { LabeledTableControlOption } from './table-widget-control.model';
3839
import { TableWidgetViewToggleModel } from './table-widget-view-toggle.model';
3940
import { TableWidgetModel } from './table-widget.model';
4041

@@ -167,7 +168,7 @@ export class TableWidgetRendererComponent
167168
.map(selectControlModel =>
168169
// Fetch the values for the selectFilter dropdown
169170
selectControlModel.getOptions().pipe(
170-
first(),
171+
take(1),
171172
map(options => {
172173
const selectOptions = options.map(option => ({
173174
label: option.label,
@@ -191,7 +192,7 @@ export class TableWidgetRendererComponent
191192
.filter(checkboxControlModel => checkboxControlModel.visible)
192193
.map(checkboxControlModel =>
193194
checkboxControlModel.getOptions().pipe(
194-
first(),
195+
take(1),
195196
map(options => ({
196197
label: checkboxControlModel.checked ? options[0].label : options[1].label,
197198
value: checkboxControlModel.checked,
@@ -300,7 +301,8 @@ export class TableWidgetRendererComponent
300301
this.selectFilterSubject.next(this.mergeFilters(changed.option.metaValue));
301302
break;
302303
case TableControlOptionType.UnsetFilter:
303-
break; // Not supported - No use case yet
304+
this.selectFilterSubject.next(this.removeFilters(changed.option.metaValue));
305+
break;
304306
default:
305307
assertUnreachable(changed.option);
306308
}
@@ -310,10 +312,10 @@ export class TableWidgetRendererComponent
310312
this.checkboxControls$ = forkJoinSafeEmpty(
311313
this.model.getCheckboxControlOptions().map(checkboxControlModel =>
312314
checkboxControlModel.getOptions().pipe(
313-
first(),
315+
take(1),
314316
map(options => {
315317
options.forEach(option => {
316-
if (option === changed.option) {
318+
if (this.isLabeledOptionMatch(option, changed.option as LabeledTableControlOption)) {
317319
checkboxControlModel.checked = changed.option.value === true;
318320
}
319321
});
@@ -329,6 +331,10 @@ export class TableWidgetRendererComponent
329331
);
330332
}
331333

334+
private isLabeledOptionMatch(option1: LabeledTableControlOption, option2: LabeledTableControlOption): boolean {
335+
return option1.label === option2.label && option1.value === option2.value;
336+
}
337+
332338
public onSearchChange(text: string): void {
333339
const searchFilter: TableFilter = {
334340
field: this.api.model.getSearchAttribute()!,
@@ -385,13 +391,15 @@ export class TableWidgetRendererComponent
385391
}
386392

387393
private mergeFilters(tableFilter: TableFilter): TableFilter[] {
388-
const existingSelectFiltersWithChangedRemoved = this.selectFilterSubject
389-
.getValue()
390-
.filter(existingFilter => existingFilter.field !== tableFilter.field);
394+
const existingSelectFiltersWithChangedRemoved = this.removeFilters(tableFilter.field);
391395

392396
return [...existingSelectFiltersWithChangedRemoved, tableFilter].filter(f => f.value !== undefined); // Remove filters that are unset
393397
}
394398

399+
private removeFilters(field: string): TableFilter[] {
400+
return this.selectFilterSubject.getValue().filter(existingFilter => existingFilter.field !== field);
401+
}
402+
395403
private mergeQueryProperties(properties: Dictionary<unknown>): Dictionary<unknown> {
396404
return {
397405
...this.queryPropertiesSubject.getValue(),

0 commit comments

Comments
 (0)