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
1 change: 1 addition & 0 deletions tensorboard/webapp/metrics/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ tf_ts_library(
"//tensorboard/webapp/angular:expect_angular_core_testing",
"//tensorboard/webapp/angular:expect_angular_platform_browser_animations",
"//tensorboard/webapp/angular:expect_angular_platform_browser_dynamic_testing",
"//tensorboard/webapp/feature_flag",
"//tensorboard/webapp/metrics/store:metrics_initial_state_provider",
"//tensorboard/webapp/metrics/store:types",
"//tensorboard/webapp/metrics/views",
Expand Down
8 changes: 6 additions & 2 deletions tensorboard/webapp/metrics/effects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export class MetricsEffects implements OnInitEffects {
})
);

private readonly removeSavedPinsOnDisable$ = this.actions$.pipe(
private readonly removeAllPins$ = this.actions$.pipe(
ofType(actions.metricsClearAllPinnedCards),
withLatestFrom(
this.store.select(selectors.getEnableGlobalPins),
Expand All @@ -356,7 +356,7 @@ export class MetricsEffects implements OnInitEffects {
})
);

private readonly disableSavingPins$ = this.actions$.pipe(
private readonly removeSavedPinsOnDisable$ = this.actions$.pipe(
ofType(actions.metricsEnableSavingPinsToggled),
withLatestFrom(
this.store.select(selectors.getEnableGlobalPins),
Expand Down Expand Up @@ -423,6 +423,10 @@ export class MetricsEffects implements OnInitEffects {
/**
* Subscribes to: metricsClearAllPinnedCards.
*/
this.removeAllPins$,
/**
* Subscribes to: metricsEnableSavingPinsToggled.
*/
this.removeSavedPinsOnDisable$
);
},
Expand Down
85 changes: 85 additions & 0 deletions tensorboard/webapp/metrics/effects/metrics_effects_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,22 @@ describe('metrics effects', () => {
expect(saveScalarPinSpy).not.toHaveBeenCalled();
expect(removeScalarPinSpy).not.toHaveBeenCalled();
});

it('does not pin the card if getMetricsSavingPinsEnabled is false', () => {
store.overrideSelector(selectors.getMetricsSavingPinsEnabled, false);
store.refreshState();

actions$.next(
actions.cardPinStateToggled({
cardId: 'card1',
wasPinned: false,
canCreateNewPins: true,
})
);

expect(saveScalarPinSpy).not.toHaveBeenCalled();
expect(removeScalarPinSpy).not.toHaveBeenCalled();
});
});

describe('loadSavedPins', () => {
Expand Down Expand Up @@ -984,6 +1000,19 @@ describe('metrics effects', () => {

expect(actualActions).toEqual([]);
});

it('does not load saved pins if getMetricsSavingPinsEnabled is false', () => {
getSavedScalarPinsSpy = spyOn(
savedPinsDataSource,
'getSavedScalarPins'
).and.returnValue(['tagA', 'tagB']);
store.overrideSelector(selectors.getMetricsSavingPinsEnabled, false);
store.refreshState();

actions$.next(TEST_ONLY.initAction());

expect(actualActions).toEqual([]);
});
});

describe('removeAllPins', () => {
Expand Down Expand Up @@ -1021,6 +1050,62 @@ describe('metrics effects', () => {

expect(removeAllScalarPinsSpy).not.toHaveBeenCalled();
});

it('does not remove pins if getMetricsSavingPinsEnabled is false', () => {
store.overrideSelector(selectors.getMetricsSavingPinsEnabled, false);
store.refreshState();

actions$.next(actions.metricsClearAllPinnedCards());

expect(removeAllScalarPinsSpy).not.toHaveBeenCalled();
});
});

describe('removeSavedPinsOnDisable', () => {
let removeAllScalarPinsSpy: jasmine.Spy;

beforeEach(() => {
removeAllScalarPinsSpy = spyOn(
savedPinsDataSource,
'removeAllScalarPins'
);
store.overrideSelector(selectors.getEnableGlobalPins, true);
store.overrideSelector(selectors.getMetricsSavingPinsEnabled, false);
store.refreshState();
});

it('removes all pins by calling metricsEnableSavingPinsToggled method', () => {
actions$.next(actions.metricsEnableSavingPinsToggled());

expect(removeAllScalarPinsSpy).toHaveBeenCalled();
});

it('does not remove pins if getEnableGlobalPins is false', () => {
store.overrideSelector(selectors.getEnableGlobalPins, false);
store.refreshState();

actions$.next(actions.metricsEnableSavingPinsToggled());

expect(removeAllScalarPinsSpy).not.toHaveBeenCalled();
});

it('does not remove pins if getShouldPersistSettings is false', () => {
store.overrideSelector(selectors.getShouldPersistSettings, false);
store.refreshState();

actions$.next(actions.metricsEnableSavingPinsToggled());

expect(removeAllScalarPinsSpy).not.toHaveBeenCalled();
});

it('does not remove pins if getMetricsSavingPinsEnabled is true', () => {
store.overrideSelector(selectors.getMetricsSavingPinsEnabled, true);
store.refreshState();

actions$.next(actions.metricsEnableSavingPinsToggled());

expect(removeAllScalarPinsSpy).not.toHaveBeenCalled();
});
});
});
});