Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
></ng-container>

<ng-container content>
<ng-container *ngFor="let dataRow of data">
<ng-container *ngFor="let dataRow of data; trackBy: trackByRuns">
<tb-data-table-content-row [attr.data-id]="dataRow.id">
<ng-container *ngFor="let header of getHeaders()">
<tb-data-table-content-cell
Expand Down
12 changes: 12 additions & 0 deletions tensorboard/webapp/runs/views/runs_table/runs_data_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,16 @@ export class RunsDataTable {
const input = event.target! as HTMLInputElement;
this.onRegexFilterChange.emit(input.value);
}

/**
* Using the `trackBy` directive allows you to control when an element contained
* by an `ngFor` is rerendered. In this case it is important that changes to
* the `color` attribute do NOT trigger rerenders because doing so will recreate
* and close the colorPicker.
*/
trackByRuns(index: number, data: TableData) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document what/why you're doing this? And can you add a test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a comment explaining how trackBy guards rerenders of items within an ngFor.
This is going to be very hard to test because it involves tracking whether a non angular component is rerendered.
I can add a test ensuring this get called, but since it's a framework feature I'm not sure that is worth doing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just a test for the logic in this function. it('returns the data object without the color attribute');

const dataWithoutColor = {...data};
delete dataWithoutColor.color;
return JSON.stringify(dataWithoutColor);
}
}
17 changes: 17 additions & 0 deletions tensorboard/webapp/runs/views/runs_table/runs_data_table_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,21 @@ describe('runs_data_table', () => {

expect(onRegexFilterChangeSpy).toHaveBeenCalledWith('myRegex');
});

it('trackByRuns serializes data while ignoring color', () => {
const fixture = createComponent({});
const dataTable = fixture.debugElement.query(By.directive(RunsDataTable));
expect(
dataTable.componentInstance.trackByRuns(0, {
id: 'run1',
color: 'orange',
hparam1: 1.234,
})
).toEqual(
JSON.stringify({
id: 'run1',
hparam1: 1.234,
})
);
});
});