Skip to content

Commit

Permalink
Added changeMouseTimePosition and getMouseTimePosition actions, reduc…
Browse files Browse the repository at this point in the history
…er, selector and test (Merge PR firefox-devtools#2917)

This is part 1 of issue firefox-devtools#222.
  • Loading branch information
julienw committed Oct 21, 2020
2 parents e5bd0fd + 7abde84 commit 4d1193d
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/actions/profile-view.js
Expand Up @@ -62,6 +62,7 @@ import type {
MarkerIndex,
Transform,
ThreadsKey,
Milliseconds,
} from 'firefox-profiler/types';

/**
Expand Down Expand Up @@ -1361,3 +1362,12 @@ export function setDataSource(dataSource: DataSource): Action {
dataSource,
};
}

export function changeMouseTimePosition(
mouseTimePosition: Milliseconds | null
): Action {
return {
type: 'CHANGE_MOUSE_TIME_POSITION',
mouseTimePosition,
};
}
18 changes: 18 additions & 0 deletions src/reducers/profile-view.js
Expand Up @@ -29,6 +29,7 @@ import type {
CallNodePath,
IndexIntoFuncTable,
ThreadsKey,
Milliseconds,
} from 'firefox-profiler/types';
import { objectMap } from '../utils/flow';

Expand Down Expand Up @@ -571,6 +572,22 @@ const rightClickedMarker: Reducer<RightClickedMarker | null> = (
}
};

/**
* TODO: This is not used yet, see issue #222
* This is for tracking mouse position in timeline-axis
*/
const mouseTimePosition: Reducer<Milliseconds | null> = (
state = null,
action
) => {
switch (action.type) {
case 'CHANGE_MOUSE_TIME_POSITION':
return action.mouseTimePosition;
default:
return state;
}
};

/**
* The origins timeline is experimental. See the OriginsTimeline component
* for more information.
Expand Down Expand Up @@ -620,6 +637,7 @@ const profileViewReducer: Reducer<ProfileViewState> = wrapReducerInResetter(
rightClickedTrack,
rightClickedCallNode,
rightClickedMarker,
mouseTimePosition,
}),
profile,
full: combineReducers({
Expand Down
3 changes: 3 additions & 0 deletions src/selectors/profile.js
Expand Up @@ -112,6 +112,9 @@ export const getCommittedRange: Selector<StartEndRange> = createSelector(
}
);

export const getMouseTimePosition: Selector<Milliseconds | null> = state =>
getProfileViewOptions(state).mouseTimePosition;

export const getPreviewSelection: Selector<PreviewSelection> = state =>
getProfileViewOptions(state).previewSelection;

Expand Down
18 changes: 18 additions & 0 deletions src/test/store/profile-view.test.js
Expand Up @@ -3604,3 +3604,21 @@ describe('getProcessedEventDelays', function() {
]);
});
});

// This test is for 'mouseTimePosition' redux store, which tracks mouse position in timeline-axis
describe('mouseTimePosition', function() {
function setup() {
const profile = getProfileFromTextSamples('A');
return storeWithProfile(profile.profile);
}

it('should get mouse time position', () => {
const { dispatch, getState } = setup();

dispatch(ProfileView.changeMouseTimePosition(null));
expect(ProfileViewSelectors.getMouseTimePosition(getState())).toBeNull();

dispatch(ProfileView.changeMouseTimePosition(1000));
expect(ProfileViewSelectors.getMouseTimePosition(getState())).toBe(1000);
});
});
6 changes: 5 additions & 1 deletion src/types/actions.js
Expand Up @@ -29,7 +29,7 @@ import type { Transform, TransformStacksPerThread } from './transforms';
import type { IndexIntoZipFileTable } from '../profile-logic/zip-files';
import type { TabSlug } from '../app-logic/tabs-handling';
import type { UrlState, UploadState, State } from './state';
import type { CssPixels, StartEndRange } from './units';
import type { CssPixels, StartEndRange, Milliseconds } from './units';

export type DataSource =
| 'none'
Expand Down Expand Up @@ -401,6 +401,10 @@ type UrlStateAction =
+type: 'SET_DATA_SOURCE',
+dataSource: DataSource,
|}
| {|
+type: 'CHANGE_MOUSE_TIME_POSITION',
+mouseTimePosition: Milliseconds | null,
|}
| {|
+type: 'TOGGLE_RESOURCES_PANEL',
+selectedThreadIndexes: Set<ThreadIndex>,
Expand Down
3 changes: 2 additions & 1 deletion src/types/state.js
Expand Up @@ -16,7 +16,7 @@ import type {
CheckedSharingOptions,
} from './actions';
import type { TabSlug } from '../app-logic/tabs-handling';
import type { StartEndRange, CssPixels } from './units';
import type { StartEndRange, CssPixels, Milliseconds } from './units';
import type { Profile, ThreadIndex, Pid, BrowsingContextID } from './profile';

import type {
Expand Down Expand Up @@ -94,6 +94,7 @@ export type ProfileViewState = {
rightClickedTrack: TrackReference | null,
rightClickedCallNode: RightClickedCallNode | null,
rightClickedMarker: RightClickedMarker | null,
mouseTimePosition: Milliseconds | null,
|},
+profile: Profile | null,
+full: FullProfileViewState,
Expand Down

0 comments on commit 4d1193d

Please sign in to comment.