diff --git a/src/actions/profile-view.js b/src/actions/profile-view.js index a26c2e78d5..8e35ef8b70 100644 --- a/src/actions/profile-view.js +++ b/src/actions/profile-view.js @@ -62,6 +62,7 @@ import type { MarkerIndex, Transform, ThreadsKey, + Milliseconds, } from 'firefox-profiler/types'; /** @@ -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, + }; +} diff --git a/src/reducers/profile-view.js b/src/reducers/profile-view.js index b5131561b9..9e294c486b 100644 --- a/src/reducers/profile-view.js +++ b/src/reducers/profile-view.js @@ -29,6 +29,7 @@ import type { CallNodePath, IndexIntoFuncTable, ThreadsKey, + Milliseconds, } from 'firefox-profiler/types'; import { objectMap } from '../utils/flow'; @@ -571,6 +572,22 @@ const rightClickedMarker: Reducer = ( } }; +/** + * TODO: This is not used yet, see issue #222 + * This is for tracking mouse position in timeline-axis + */ +const mouseTimePosition: Reducer = ( + 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. @@ -620,6 +637,7 @@ const profileViewReducer: Reducer = wrapReducerInResetter( rightClickedTrack, rightClickedCallNode, rightClickedMarker, + mouseTimePosition, }), profile, full: combineReducers({ diff --git a/src/selectors/profile.js b/src/selectors/profile.js index 3477311e43..84f7e2c9d0 100644 --- a/src/selectors/profile.js +++ b/src/selectors/profile.js @@ -112,6 +112,9 @@ export const getCommittedRange: Selector = createSelector( } ); +export const getMouseTimePosition: Selector = state => + getProfileViewOptions(state).mouseTimePosition; + export const getPreviewSelection: Selector = state => getProfileViewOptions(state).previewSelection; diff --git a/src/test/store/profile-view.test.js b/src/test/store/profile-view.test.js index dbda933c67..7cdb672e64 100644 --- a/src/test/store/profile-view.test.js +++ b/src/test/store/profile-view.test.js @@ -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); + }); +}); diff --git a/src/types/actions.js b/src/types/actions.js index bec5763dc8..4d1ab99700 100644 --- a/src/types/actions.js +++ b/src/types/actions.js @@ -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' @@ -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, diff --git a/src/types/state.js b/src/types/state.js index 1a96f4ae31..7a7d4f75eb 100644 --- a/src/types/state.js +++ b/src/types/state.js @@ -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 { @@ -94,6 +94,7 @@ export type ProfileViewState = { rightClickedTrack: TrackReference | null, rightClickedCallNode: RightClickedCallNode | null, rightClickedMarker: RightClickedMarker | null, + mouseTimePosition: Milliseconds | null, |}, +profile: Profile | null, +full: FullProfileViewState,