Skip to content
Open
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
1 change: 1 addition & 0 deletions tensorboard/webapp/metrics/store/metrics_reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,7 @@ const reducer = createReducer(

return {
...state,
unresolvedImportedPinnedCards: [],
cardMetadataMap: nextCardMetadataMap,
cardStateMap: nextCardStateMap,
cardStepIndex: nextCardStepIndex,
Expand Down
3 changes: 3 additions & 0 deletions tensorboard/webapp/metrics/store/metrics_reducers_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4539,6 +4539,9 @@ describe('metrics reducers', () => {
describe('#metricsClearAllPinnedCards', () => {
it('unpins all pinned cards', () => {
const beforeState = buildMetricsState({
unresolvedImportedPinnedCards: [
{tag: 'missing', plugin: PluginType.SCALARS},
],
cardMetadataMap: {
card1: createScalarCardMetadata(),
pinnedCopy1: createScalarCardMetadata(),
Expand Down
17 changes: 17 additions & 0 deletions tensorboard/webapp/metrics/views/main_view/main_view_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,9 @@ describe('metrics main view', () => {
it('does not show the button if getEnableGlobalPins is false', () => {
store.overrideSelector(selectors.getEnableGlobalPins, false);
store.overrideSelector(selectors.getPinnedCardsWithMetadata, []);
store.overrideSelector(selectors.getUnresolvedImportedPinnedCards, [
{plugin: PluginType.SCALARS, tag: 'missing'},
]);
const fixture = TestBed.createComponent(MainViewContainer);
fixture.detectChanges();

Expand Down Expand Up @@ -1655,6 +1658,20 @@ describe('metrics main view', () => {
expect(clearAllButton).toBeTruthy();
});

it('shows the button when the only pinned card has no matching data', () => {
store.overrideSelector(selectors.getPinnedCardsWithMetadata, []);
store.overrideSelector(selectors.getUnresolvedImportedPinnedCards, [
{plugin: PluginType.SCALARS, tag: 'missing'},
]);
const fixture = TestBed.createComponent(MainViewContainer);
fixture.detectChanges();

const clearAllButton = fixture.debugElement.query(
By.css('[aria-label="Clear all pinned cards"]')
);
expect(clearAllButton).toBeTruthy();
});

it('dispatch clear all action when the button is clicked', () => {
store.overrideSelector(selectors.getPinnedCardsWithMetadata, [
{cardId: 'card1', ...createCardMetadata(PluginType.SCALARS)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ import {CardIdWithMetadata} from '../metrics_view_types';
</span>
</span>
</div>
<div
class="right-items"
*ngIf="cardIdsWithMetadata.length > 0 && globalPinsEnabled"
>
<div class="right-items" *ngIf="showClearAllPins">
<button
mat-stroked-button
aria-label="Clear all pinned cards"
Expand All @@ -75,6 +72,6 @@ export class PinnedViewComponent {
@Input() cardObserver!: CardObserver;
@Input() cardIdsWithMetadata!: CardIdWithMetadata[];
@Input() lastPinnedCardTime: number | null = null;
@Input() globalPinsEnabled: boolean = false;
@Input() showClearAllPins: boolean = false;
@Output() onClearAllPinsClicked = new EventEmitter<void>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
import {ChangeDetectionStrategy, Component, Input, Signal} from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
computed,
Input,
Signal,
} from '@angular/core';
import {toSignal} from '@angular/core/rxjs-interop';
import {Store} from '@ngrx/store';
import {map, skip, startWith} from 'rxjs/operators';
import {State} from '../../../app_state';
import {getEnableGlobalPins} from '../../../selectors';
import {DeepReadonly} from '../../../util/types';
import {metricsClearAllPinnedCards} from '../../actions';
import {getLastPinnedCardTime, getPinnedCardsWithMetadata} from '../../store';
import {
getLastPinnedCardTime,
getPinnedCardsWithMetadata,
getUnresolvedImportedPinnedCards,
} from '../../store';
import {CardObserver} from '../card_renderer/card_lazy_loader';
import {CardIdWithMetadata} from '../metrics_view_types';

Expand All @@ -32,7 +42,7 @@ import {CardIdWithMetadata} from '../metrics_view_types';
[cardIdsWithMetadata]="cardIdsWithMetadata()"
[lastPinnedCardTime]="lastPinnedCardTime$ | async"
[cardObserver]="cardObserver"
[globalPinsEnabled]="globalPinsEnabled()"
[showClearAllPins]="showClearAllPins()"
(onClearAllPinsClicked)="onClearAllPinsClicked()"
></metrics-pinned-view-component>
`,
Expand All @@ -57,14 +67,22 @@ export class PinnedViewContainer {
// pins after page load.
skip(1)
);
this.globalPinsEnabled = this.store.selectSignal(getEnableGlobalPins);
const globalPinsEnabled = this.store.selectSignal(getEnableGlobalPins);
const unresolvedPins = this.store.selectSignal(
getUnresolvedImportedPinnedCards
);
this.showClearAllPins = computed(
() =>
globalPinsEnabled() &&
(this.cardIdsWithMetadata().length > 0 || unresolvedPins().length > 0)
);
}

readonly cardIdsWithMetadata: Signal<DeepReadonly<CardIdWithMetadata>[]>;

readonly lastPinnedCardTime$;

readonly globalPinsEnabled;
readonly showClearAllPins;

onClearAllPinsClicked() {
this.store.dispatch(metricsClearAllPinnedCards());
Expand Down