Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timeseries: fix button toggle state issue #5398

Merged
merged 2 commits into from
Nov 4, 2021
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 @@ -17,30 +17,42 @@
<div class="toolbar">
<metrics-tag-filter></metrics-tag-filter>
<mat-button-toggle-group class="filter-view" multiple appearance="standard">
<mat-button-toggle
[checked]="filteredPluginTypes.size === 0"
<button
mat-button
class="filter-view-button"
role="checkbox"
[attr.aria-checked]="filteredPluginTypes.size === 0"
(click)="onPluginTypeAllToggled.emit()"
>
All
</mat-button-toggle>
<mat-button-toggle
[checked]="filteredPluginTypes.has(PluginType.SCALARS)"
</button>
<button
mat-button
class="filter-view-button"
role="checkbox"
[attr.aria-checked]="filteredPluginTypes.has(PluginType.SCALARS)"
(click)="onPluginTypeToggled.emit(PluginType.SCALARS)"
>
Scalars
</mat-button-toggle>
<mat-button-toggle
[checked]="filteredPluginTypes.has(PluginType.IMAGES)"
</button>
<button
mat-button
class="filter-view-button"
role="checkbox"
[attr.aria-checked]="filteredPluginTypes.has(PluginType.IMAGES)"
(click)="onPluginTypeToggled.emit(PluginType.IMAGES)"
>
Image
</mat-button-toggle>
<mat-button-toggle
[checked]="filteredPluginTypes.has(PluginType.HISTOGRAMS)"
</button>
<button
mat-button
class="filter-view-button"
role="checkbox"
[attr.aria-checked]="filteredPluginTypes.has(PluginType.HISTOGRAMS)"
(click)="onPluginTypeToggled.emit(PluginType.HISTOGRAMS)"
>
Histogram
</mat-button-toggle>
</button>
</mat-button-toggle-group>
<div class="right-items">
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,27 @@ limitations under the License.
}

.filter-view {
border-radius: 4px;
flex: none;
margin-right: 5px;

mat-button-toggle {
button {
$_height: 25px;
height: $_height;

border-radius: 0;
font-size: 12px;
font-weight: normal;
height: $_height;
line-height: $_height;
min-width: unset;
padding: 0 12px;

& + button {
@include tb-theme-foreground-prop(border-left, border, 1px solid);
}

::ng-deep .mat-button-toggle-label-content {
line-height: $_height;
&[aria-checked='true'] {
@include tb-theme-background-prop(background-color, selected-button);
}
}
}
Expand Down
22 changes: 8 additions & 14 deletions tensorboard/webapp/metrics/views/main_view/main_view_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,35 +210,29 @@ describe('metrics main view', () => {
fixture.detectChanges();

const buttons = fixture.debugElement.queryAll(
By.css('mat-button-toggle')
By.css('.filter-view-button')
);
expect(buttons.map((button) => button.properties['checked'])).toEqual([
true,
false,
false,
false,
]);
expect(
buttons.map((button) => button.attributes['aria-checked'])
).toEqual(['true', 'false', 'false', 'false']);

store.overrideSelector(
selectors.getMetricsFilteredPluginTypes,
new Set<PluginType>([PluginType.IMAGES])
);
store.refreshState();
fixture.detectChanges();
expect(buttons.map((button) => button.properties['checked'])).toEqual([
false,
false,
true,
false,
]);
expect(
buttons.map((button) => button.attributes['aria-checked'])
).toEqual(['false', 'false', 'true', 'false']);
});

it('dispatches action when clicked on a plugin type', () => {
const fixture = TestBed.createComponent(MainViewContainer);
fixture.detectChanges();

const [, scalars, images] = fixture.debugElement.queryAll(
By.css('mat-button-toggle')
By.css('.filter-view-button')
);

scalars.nativeElement.click();
Expand Down