Skip to content
Snippets Groups Projects
Commit 0158e1a7 authored by Chris Beer's avatar Chris Beer
Browse files

Pan the elastic workspace to the focused window when selected in the window list

parent bbb8fbf3
Branches
Tags
No related merge requests found
...@@ -2,6 +2,55 @@ import * as actions from '../../../src/state/actions'; ...@@ -2,6 +2,55 @@ import * as actions from '../../../src/state/actions';
import ActionTypes from '../../../src/state/actions/action-types'; import ActionTypes from '../../../src/state/actions/action-types';
describe('window actions', () => { describe('window actions', () => {
describe('focusWindow', () => {
it('should return correct action object with pan=true', () => {
const expectedAction = {
type: ActionTypes.FOCUS_WINDOW,
windowId: 'window',
position: { x: -150, y: -188 },
};
const mockState = {
windows: {
window: { x: 50, y: 12 },
},
companionWindows: {},
};
const mockDispatch = jest.fn(() => ({}));
const mockGetState = jest.fn(() => mockState);
const thunk = actions.focusWindow('window', true);
thunk(mockDispatch, mockGetState);
const action = mockDispatch.mock.calls[0][0];
expect(action).toEqual(expectedAction);
});
it('should return correct action object with pan=false', () => {
const expectedAction = {
type: ActionTypes.FOCUS_WINDOW,
windowId: 'window',
position: {},
};
const mockState = {
windows: {
window: { x: 50, y: 12 },
},
companionWindows: {},
};
const mockDispatch = jest.fn(() => ({}));
const mockGetState = jest.fn(() => mockState);
const thunk = actions.focusWindow('window');
thunk(mockDispatch, mockGetState);
const action = mockDispatch.mock.calls[0][0];
expect(action).toEqual(expectedAction);
});
});
describe('addWindow', () => { describe('addWindow', () => {
it('should create a new window with merged defaults', () => { it('should create a new window with merged defaults', () => {
const options = { const options = {
......
...@@ -56,7 +56,7 @@ describe('WindowList', () => { ...@@ -56,7 +56,7 @@ describe('WindowList', () => {
).toBe(true); ).toBe(true);
wrapper.find('WithStyles(MenuItem)').simulate('click', {}); wrapper.find('WithStyles(MenuItem)').simulate('click', {});
expect(handleClose).toBeCalled(); expect(handleClose).toBeCalled();
expect(focusWindow).toBeCalledWith('xyz'); expect(focusWindow).toBeCalledWith('xyz', true);
}); });
}); });
......
...@@ -2,12 +2,23 @@ import { workspaceReducer } from '../../../src/state/reducers/workspace'; ...@@ -2,12 +2,23 @@ import { workspaceReducer } from '../../../src/state/reducers/workspace';
import ActionTypes from '../../../src/state/actions/action-types'; import ActionTypes from '../../../src/state/actions/action-types';
describe('workspace reducer', () => { describe('workspace reducer', () => {
it('should handle FOCUS_WINDOW without position coordinates', () => {
expect(workspaceReducer([], {
type: ActionTypes.FOCUS_WINDOW,
windowId: 'abc123',
})).toEqual({
focusedWindowId: 'abc123',
viewportPosition: {},
});
});
it('should handle FOCUS_WINDOW', () => { it('should handle FOCUS_WINDOW', () => {
expect(workspaceReducer([], { expect(workspaceReducer([], {
type: ActionTypes.FOCUS_WINDOW, type: ActionTypes.FOCUS_WINDOW,
windowId: 'abc123', windowId: 'abc123',
position: { x: 10, y: 50 },
})).toEqual({ })).toEqual({
focusedWindowId: 'abc123', focusedWindowId: 'abc123',
viewportPosition: { x: 10, y: 50 },
}); });
}); });
it('should handle SET_WORKSPACE_FULLSCREEN', () => { it('should handle SET_WORKSPACE_FULLSCREEN', () => {
......
...@@ -48,7 +48,7 @@ export class WindowList extends Component { ...@@ -48,7 +48,7 @@ export class WindowList extends Component {
<MenuItem <MenuItem
key={window.id} key={window.id}
selected={i === 0} selected={i === 0}
onClick={(e) => { focusWindow(window.id); handleClose(e); }} onClick={(e) => { focusWindow(window.id, true); handleClose(e); }}
> >
<Typography variant="body1"> <Typography variant="body1">
{ {
......
...@@ -7,8 +7,17 @@ import ActionTypes from './action-types'; ...@@ -7,8 +7,17 @@ import ActionTypes from './action-types';
* @param {String} windowId * @param {String} windowId
* @memberof ActionCreators * @memberof ActionCreators
*/ */
export function focusWindow(windowId) { export function focusWindow(windowId, pan = false) {
return { type: ActionTypes.FOCUS_WINDOW, windowId }; return (dispatch, getState) => {
const { windows } = getState();
const { x, y } = windows[windowId];
dispatch({
type: ActionTypes.FOCUS_WINDOW,
windowId,
position: pan ? { x: x - 200, y: y - 200 } : {},
});
};
} }
/** /**
......
...@@ -17,7 +17,14 @@ export const workspaceReducer = ( ...@@ -17,7 +17,14 @@ export const workspaceReducer = (
) => { ) => {
switch (action.type) { switch (action.type) {
case ActionTypes.FOCUS_WINDOW: case ActionTypes.FOCUS_WINDOW:
return { ...state, focusedWindowId: action.windowId }; return {
...state,
focusedWindowId: action.windowId,
viewportPosition: {
...state.viewportPosition,
...action.position,
},
};
case ActionTypes.SET_WORKSPACE_FULLSCREEN: case ActionTypes.SET_WORKSPACE_FULLSCREEN:
return { ...state, isFullscreenEnabled: action.isFullscreenEnabled }; return { ...state, isFullscreenEnabled: action.isFullscreenEnabled };
case ActionTypes.TOGGLE_ZOOM_CONTROLS: case ActionTypes.TOGGLE_ZOOM_CONTROLS:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment