Skip to content

Commit

Permalink
rename cardInteractiosn to newCardInteractions
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyajones committed Jun 16, 2023
1 parent 4597dc5 commit 5767947
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {Injectable} from '@angular/core';
import {Action, Store, createAction} from '@ngrx/store';
import {
State,
getCardInteractions,
getNewCardInteractions,
getCardMetadataMap,
getPreviousCardInteractions,
} from '../store';
Expand All @@ -42,7 +42,7 @@ export class CardInteractionEffects implements OnInitEffects {
return initAction();
}

private getCardInteractions$ = this.store.select(getCardInteractions).pipe(
private getCardInteractions$ = this.store.select(getNewCardInteractions).pipe(
// Don't get the initial state
skip(1)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {provideMockActions} from '@ngrx/effects/testing';
import * as actions from '../actions';
import {CardIdWithMetadata, PluginType} from '../internal_types';
import {
getCardInteractions,
getNewCardInteractions,
getCardMetadataMap,
getPreviousCardInteractions,
} from '../store';
Expand Down Expand Up @@ -117,7 +117,7 @@ describe('CardInteractions Effects', () => {
effects.cardInteractionsEffect$.subscribe();
expect(saveSpy).not.toHaveBeenCalled();

store.overrideSelector(getCardInteractions, {
store.overrideSelector(getNewCardInteractions, {
tagFilters: ['foo', 'bar'],
pins: [
{
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('CardInteractions Effects', () => {
});

it('merges current and previous card interactions', () => {
store.overrideSelector(getCardInteractions, {
store.overrideSelector(getNewCardInteractions, {
pins: [card1a],
clicks: [card1b],
tagFilters: ['foo'],
Expand All @@ -210,7 +210,7 @@ describe('CardInteractions Effects', () => {
});

it('does not emit duplicate cardIds', () => {
store.overrideSelector(getCardInteractions, {
store.overrideSelector(getNewCardInteractions, {
pins: [card1a],
clicks: [card1b],
tagFilters: ['foo'],
Expand Down
54 changes: 28 additions & 26 deletions tensorboard/webapp/metrics/store/metrics_reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ const {initialState, reducers: namespaceContextedReducer} =
pins: [],
clicks: [],
},
cardInteractions: {
newCardInteractions: {
tagFilters: [],
pins: [],
clicks: [],
Expand Down Expand Up @@ -741,39 +741,41 @@ const reducer = createReducer(
};
}),
on(actions.metricsTagFilterChanged, (state, {tagFilter}) => {
const nextCardInteractions = {
...state.cardInteractions,
const nextNewCardInteractions = {
...state.newCardInteractions,
};
const previousTagFilter = state.tagFilter;
// Ensuring we do not create redundant tag filter as the user types
if (tagFilter === '') {
nextCardInteractions.tagFilters = nextCardInteractions.tagFilters.slice(
0,
nextCardInteractions.tagFilters.length - 1
);
nextNewCardInteractions.tagFilters =
nextNewCardInteractions.tagFilters.slice(
0,
nextNewCardInteractions.tagFilters.length - 1
);
} else if (
previousTagFilter === '' ||
!nextCardInteractions.tagFilters.length
!nextNewCardInteractions.tagFilters.length
) {
nextCardInteractions.tagFilters = [
...nextCardInteractions.tagFilters,
nextNewCardInteractions.tagFilters = [
...nextNewCardInteractions.tagFilters,
tagFilter,
];
} else if (
tagFilter.includes(previousTagFilter) ||
previousTagFilter.includes(tagFilter)
) {
nextCardInteractions.tagFilters = nextCardInteractions.tagFilters.slice(
0,
nextCardInteractions.tagFilters.length - 1
);
nextCardInteractions.tagFilters.push(tagFilter);
nextNewCardInteractions.tagFilters =
nextNewCardInteractions.tagFilters.slice(
0,
nextNewCardInteractions.tagFilters.length - 1
);
nextNewCardInteractions.tagFilters.push(tagFilter);
}

return {
...state,
tagFilter,
cardInteractions: nextCardInteractions,
cardInteractions: nextNewCardInteractions,
};
}),
on(actions.metricsChangeTooltipSort, (state, {sort}) => {
Expand Down Expand Up @@ -1127,7 +1129,7 @@ const reducer = createReducer(
let nextCardMetadataMap = {...state.cardMetadataMap};
let nextCardStepIndexMap = {...state.cardStepIndex};
let nextCardStateMap = {...state.cardStateMap};
const nextCardInteractions = {...state.cardInteractions};
const nextNewCardInteractions = {...state.newCardInteractions};
const nextPreviousCardInteractions = {...state.previousCardInteractions};

if (isPinnedCopy) {
Expand All @@ -1138,7 +1140,7 @@ const reducer = createReducer(
delete nextCardMetadataMap[cardId];
delete nextCardStepIndexMap[cardId];
delete nextCardStateMap[cardId];
nextCardInteractions.pins = nextCardInteractions.pins.filter(
nextNewCardInteractions.pins = nextNewCardInteractions.pins.filter(
(cardMetadata) => originalCardId !== cardMetadata.cardId
);
nextPreviousCardInteractions.pins =
Expand All @@ -1163,12 +1165,12 @@ const reducer = createReducer(
nextCardStepIndexMap = resolvedResult.cardStepIndex;
nextCardStateMap = resolvedResult.cardStateMap;
if (
!nextCardInteractions.pins.find(
!nextNewCardInteractions.pins.find(
(metadata) => cardId === metadata.cardId
)
) {
nextCardInteractions.pins = [
...nextCardInteractions.pins,
nextNewCardInteractions.pins = [
...nextNewCardInteractions.pins,
{...nextCardMetadataMap[cardId], cardId},
];
}
Expand All @@ -1190,7 +1192,7 @@ const reducer = createReducer(
cardToPinnedCopy: nextCardToPinnedCopy,
cardToPinnedCopyCache: nextCardToPinnedCopyCache,
pinnedCardToOriginal: nextPinnedCardToOriginal,
cardInteractions: nextCardInteractions,
cardInteractions: nextNewCardInteractions,
previousCardInteractions: nextPreviousCardInteractions,
};
}),
Expand Down Expand Up @@ -1538,12 +1540,12 @@ const reducer = createReducer(
),
on(actions.metricsCardClicked, (state, {cardId}) => {
const nextClicksIds = new Set(
state.cardInteractions.clicks.map(({cardId}) => cardId)
state.newCardInteractions.clicks.map(({cardId}) => cardId)
);
nextClicksIds.add(cardId);

const nextCardInteractions = {
...state.cardInteractions,
const nextNewCardInteractions = {
...state.newCardInteractions,
clicks: Array.from(nextClicksIds).map((cardId) => ({
...state.cardMetadataMap[cardId],
cardId,
Expand All @@ -1552,7 +1554,7 @@ const reducer = createReducer(

return {
...state,
cardInteractions: nextCardInteractions,
newCardInteractions: nextNewCardInteractions,
};
})
);
Expand Down
4 changes: 1 addition & 3 deletions tensorboard/webapp/metrics/store/metrics_reducers_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ import {
CardId,
CardMetadata,
HistogramMode,
MinMaxStep,
NonPinnedCardId,
TooltipSort,
XAxisType,
} from '../types';
Expand Down Expand Up @@ -2884,7 +2882,7 @@ describe('metrics reducers', () => {
cardToPinnedCopyCache: new Map([['card1', expectedPinnedCopyId]]),
pinnedCardToOriginal: new Map([[expectedPinnedCopyId, 'card1']]),
timeSeriesData,
cardInteractions: {
newCardInteractions: {
pins: [
{
cardId: 'card1',
Expand Down
4 changes: 2 additions & 2 deletions tensorboard/webapp/metrics/store/metrics_selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ export const getPinnedCardsWithMetadata = createSelector(
}
);

export const getCardInteractions = createSelector(
export const getNewCardInteractions = createSelector(
selectMetricsState,
(state): CardInteractions => {
return state.cardInteractions;
return state.newCardInteractions;
}
);

Expand Down
2 changes: 1 addition & 1 deletion tensorboard/webapp/metrics/store/metrics_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export interface MetricsNonNamespacedState {
*/
visibleCardMap: Map<ElementId, CardId>;
previousCardInteractions: CardInteractions;
cardInteractions: CardInteractions;
newCardInteractions: CardInteractions;
}

export type MetricsState = NamespaceContextedState<
Expand Down
2 changes: 1 addition & 1 deletion tensorboard/webapp/metrics/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function buildBlankState(): MetricsState {
isSettingsPaneOpen: false,
isSlideoutMenuOpen: false,
tableEditorSelectedTab: DataTableMode.SINGLE,
cardInteractions: {
newCardInteractions: {
pins: [],
clicks: [],
tagFilters: [],
Expand Down

0 comments on commit 5767947

Please sign in to comment.