Skip to content

Commit 0924bd3

Browse files
committed
add removeAllPins effect in metrics effect
1 parent f0c3a54 commit 0924bd3

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

tensorboard/webapp/metrics/effects/index.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,21 @@ export class MetricsEffects implements OnInitEffects {
316316
})
317317
);
318318

319+
private readonly removeAllPins$ = this.actions$.pipe(
320+
ofType(actions.metricsClearAllPinnedCards),
321+
withLatestFrom(
322+
this.store.select(selectors.getEnableGlobalPins),
323+
this.store.select(selectors.getShouldPersistSettings)
324+
),
325+
filter(
326+
([, enableGlobalPins, shouldPersistSettings]) =>
327+
enableGlobalPins && shouldPersistSettings
328+
),
329+
tap(() => {
330+
this.savedPinsDataSource.removeAllScalarPins();
331+
})
332+
);
333+
319334
/**
320335
* In general, this effect dispatch the following actions:
321336
*
@@ -356,7 +371,11 @@ export class MetricsEffects implements OnInitEffects {
356371
/**
357372
* Subscribes to: dashboard shown (initAction).
358373
*/
359-
this.loadSavedPins$
374+
this.loadSavedPins$,
375+
/**
376+
* Subscribes to: metricsClearAllPinnedCards.
377+
*/
378+
this.removeAllPins$
360379
);
361380
},
362381
{dispatch: false}

tensorboard/webapp/metrics/effects/metrics_effects_test.ts

+38
Original file line numberDiff line numberDiff line change
@@ -985,5 +985,43 @@ describe('metrics effects', () => {
985985
expect(actualActions).toEqual([]);
986986
});
987987
});
988+
989+
describe('removeAllPins', () => {
990+
let removeAllScalarPinsSpy: jasmine.Spy;
991+
992+
beforeEach(() => {
993+
removeAllScalarPinsSpy = spyOn(
994+
savedPinsDataSource,
995+
'removeAllScalarPins'
996+
);
997+
store.overrideSelector(selectors.getEnableGlobalPins, true);
998+
store.refreshState();
999+
});
1000+
1001+
it('removes all pins by calling removeAllScalarPins method', () => {
1002+
console.log(removeAllScalarPinsSpy, 'spyspy');
1003+
actions$.next(actions.metricsClearAllPinnedCards());
1004+
1005+
expect(removeAllScalarPinsSpy).toHaveBeenCalled();
1006+
});
1007+
1008+
it('does not remove pins if getEnableGlobalPins is false', () => {
1009+
store.overrideSelector(selectors.getEnableGlobalPins, false);
1010+
store.refreshState();
1011+
1012+
actions$.next(actions.metricsClearAllPinnedCards());
1013+
1014+
expect(removeAllScalarPinsSpy).not.toHaveBeenCalled();
1015+
});
1016+
1017+
it('does not remove pins if getShouldPersistSettings is false', () => {
1018+
store.overrideSelector(selectors.getShouldPersistSettings, false);
1019+
store.refreshState();
1020+
1021+
actions$.next(actions.metricsClearAllPinnedCards());
1022+
1023+
expect(removeAllScalarPinsSpy).not.toHaveBeenCalled();
1024+
});
1025+
});
9881026
});
9891027
});

tensorboard/webapp/metrics/testing.ts

+2
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ export class TestingSavedPinsDataSource {
405405
getSavedScalarPins() {
406406
return [];
407407
}
408+
409+
removeAllScalarPins() {}
408410
}
409411

410412
export function provideTestingSavedPinsDataSource() {

0 commit comments

Comments
 (0)