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

Update getThumbnailNavigationPosition to use reselect

parent 34d13c3d
No related branches found
No related tags found
No related merge requests found
......@@ -36,17 +36,17 @@ describe('getThumbnailNavigationPosition', () => {
};
it('should return thumbnail navigation position if window exists', () => {
const received = getThumbnailNavigationPosition(state, 'a');
const received = getThumbnailNavigationPosition(state, { windowId: 'a' });
expect(received).toBe('bottom');
});
it('should return undefined if position does not exist in window', () => {
const received = getThumbnailNavigationPosition(state, 'b');
const received = getThumbnailNavigationPosition(state, { windowId: 'b' });
expect(received).toBeUndefined();
});
it('should return undefined if window does not exists', () => {
const received = getThumbnailNavigationPosition(state, 'c');
const received = getThumbnailNavigationPosition(state, { windowId: 'c' });
expect(received).toBeUndefined();
});
});
......
......@@ -18,7 +18,7 @@ const mapStateToProps = (state, props) => ({
window: state.windows[props.window.id],
workspaceType: state.config.workspace.type,
label: getManifestTitle(state, { windowId: props.window.id }),
thumbnailNavigationPosition: getThumbnailNavigationPosition(state, props.window.id),
thumbnailNavigationPosition: getThumbnailNavigationPosition(state, { windowId: props.window.id }),
});
/**
......
......@@ -19,9 +19,9 @@ const mapDispatchToProps = { setWindowThumbnailPosition: actions.setWindowThumbn
* @memberof WindowViewer
* @private
*/
const mapStateToProps = (state, props) => (
const mapStateToProps = (state, { windowId }) => (
{
thumbnailNavigationPosition: getThumbnailNavigationPosition(state, props.windowId),
thumbnailNavigationPosition: getThumbnailNavigationPosition(state, { windowId }),
}
);
......
......@@ -77,22 +77,25 @@ export function getIdAndContentOfResources(resources) {
}));
}
/** */
function getWindow(state, { windowId }) {
return state.windows && state.windows[windowId];
}
/** Return position of thumbnail navigation in a certain window.
* @param {object} state
* @param {String} windowId
* @param {String}
*/
export function getThumbnailNavigationPosition(state, windowId) {
return state.windows[windowId]
&& state.windows[windowId].thumbnailNavigationId
&& state.companionWindows[state.windows[windowId].thumbnailNavigationId]
&& state.companionWindows[state.windows[windowId].thumbnailNavigationId].position;
}
/** */
function getWindow(state, { windowId }) {
return state.windows && state.windows[windowId];
}
export const getThumbnailNavigationPosition = createSelector(
[
getWindow,
state => state.companionWindows,
],
(window, companionWindows) => window
&& companionWindows[window.thumbnailNavigationId]
&& companionWindows[window.thumbnailNavigationId].position,
);
/** Return type of view in a certain window.
* @param {object} state
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment