Skip to content
Snippets Groups Projects
Unverified Commit ee1f7c9c authored by aeschylus's avatar aeschylus Committed by GitHub
Browse files

Merge pull request #2193 from ProjectMirador/2122-cascade-windows

Cascade window positions in elastic mode; fixes #2122
parents bbb8fbf3 87eeca9a
No related branches found
No related tags found
No related merge requests found
...@@ -18,8 +18,8 @@ describe('window actions', () => { ...@@ -18,8 +18,8 @@ describe('window actions', () => {
manifestId: null, manifestId: null,
maximized: false, maximized: false,
rangeId: null, rangeId: null,
x: 200, x: 260,
y: 200, y: 300,
sideBarPanel: 'info', sideBarPanel: 'info',
width: 400, width: 400,
height: 400, height: 400,
...@@ -31,7 +31,19 @@ describe('window actions', () => { ...@@ -31,7 +31,19 @@ describe('window actions', () => {
{ position: 'far-bottom', content: 'thumbnail_navigation' }, { position: 'far-bottom', content: 'thumbnail_navigation' },
], ],
}; };
const action = actions.addWindow(options);
const mockState = {
windows: { a: {}, b: {} },
};
const mockDispatch = jest.fn(() => ({}));
const mockGetState = jest.fn(() => mockState);
const thunk = actions.addWindow(options);
thunk(mockDispatch, mockGetState);
const action = mockDispatch.mock.calls[0][0];
expect(action).toMatchObject(expectedAction); expect(action).toMatchObject(expectedAction);
expect(action.window.companionWindowIds.length).toEqual(2); expect(action.window.companionWindowIds.length).toEqual(2);
expect(action.window.companionWindowIds[0]).toEqual(action.companionWindows[0].id); expect(action.window.companionWindowIds[0]).toEqual(action.companionWindows[0].id);
......
...@@ -18,6 +18,10 @@ export function focusWindow(windowId) { ...@@ -18,6 +18,10 @@ export function focusWindow(windowId) {
* @memberof ActionCreators * @memberof ActionCreators
*/ */
export function addWindow(options) { export function addWindow(options) {
return (dispatch, getState) => {
const { windows } = getState();
const numWindows = Object.keys(windows).length;
const cwDefault = `cw-${uuid()}`; const cwDefault = `cw-${uuid()}`;
const cwThumbs = `cw-${uuid()}`; const cwThumbs = `cw-${uuid()}`;
const defaultOptions = { const defaultOptions = {
...@@ -29,21 +33,23 @@ export function addWindow(options) { ...@@ -29,21 +33,23 @@ export function addWindow(options) {
thumbnailNavigationId: cwThumbs, thumbnailNavigationId: cwThumbs,
width: 400, width: 400,
height: 400, height: 400,
x: 200, x: 200 + (Math.floor(numWindows / 10) * 50 + (numWindows * 30) % 300),
y: 200, y: 200 + ((numWindows * 50) % 300),
companionWindowIds: [cwDefault, cwThumbs], companionWindowIds: [cwDefault, cwThumbs],
sideBarPanel: 'info', sideBarPanel: 'info',
rotation: null, rotation: null,
view: 'single', view: 'single',
maximized: false, maximized: false,
}; };
return {
dispatch({
type: ActionTypes.ADD_WINDOW, type: ActionTypes.ADD_WINDOW,
window: { ...defaultOptions, ...options }, window: { ...defaultOptions, ...options },
companionWindows: [ companionWindows: [
{ id: cwDefault, position: 'left', content: 'info' }, { id: cwDefault, position: 'left', content: 'info' },
{ id: cwThumbs, position: options.thumbnailNavigationPosition || 'far-bottom', content: 'thumbnail_navigation' }, { id: cwThumbs, position: options.thumbnailNavigationPosition || 'far-bottom', content: 'thumbnail_navigation' },
], ],
});
}; };
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment