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

Consistently Use selectors to pull state into containers

parent 9398bf45
Branches
Tags
No related merge requests found
Showing
with 53 additions and 32 deletions
...@@ -2,7 +2,7 @@ import { compose } from 'redux'; ...@@ -2,7 +2,7 @@ import { compose } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { withPlugins } from '../extend/withPlugins'; import { withPlugins } from '../extend/withPlugins';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
import { getTheme } from '../state/selectors'; import { getConfig, getTheme, getFullScreenEnabled } from '../state/selectors';
import { AppProviders } from '../components/AppProviders'; import { AppProviders } from '../components/AppProviders';
/** /**
...@@ -12,11 +12,11 @@ import { AppProviders } from '../components/AppProviders'; ...@@ -12,11 +12,11 @@ import { AppProviders } from '../components/AppProviders';
*/ */
const mapStateToProps = state => ( const mapStateToProps = state => (
{ {
classPrefix: state.config.classPrefix, classPrefix: getConfig(state).classPrefix,
isFullscreenEnabled: state.workspace.isFullscreenEnabled, isFullscreenEnabled: getFullScreenEnabled(state),
language: state.config.language, language: getConfig(state).language,
theme: getTheme(state), theme: getTheme(state),
translations: state.config.translations, translations: getConfig(state).translations,
} }
); );
......
...@@ -8,6 +8,7 @@ import { ...@@ -8,6 +8,7 @@ import {
getAnnotationResourcesByMotivationForCanvas, getAnnotationResourcesByMotivationForCanvas,
getCanvasLabel, getCanvasLabel,
getSelectedAnnotationId, getSelectedAnnotationId,
getConfig,
} from '../state/selectors'; } from '../state/selectors';
import { CanvasAnnotations } from '../components/CanvasAnnotations'; import { CanvasAnnotations } from '../components/CanvasAnnotations';
...@@ -31,7 +32,7 @@ const mapStateToProps = (state, { canvasId, windowId }) => ({ ...@@ -31,7 +32,7 @@ const mapStateToProps = (state, { canvasId, windowId }) => ({
state, { canvasId, windowId }, state, { canvasId, windowId },
), ),
), ),
htmlSanitizationRuleSet: state.config.annotations.htmlSanitizationRuleSet, htmlSanitizationRuleSet: getConfig(state).annotations.htmlSanitizationRuleSet,
label: getCanvasLabel(state, { label: getCanvasLabel(state, {
canvasId, canvasId,
windowId, windowId,
......
...@@ -4,7 +4,7 @@ import { withStyles } from '@material-ui/core'; ...@@ -4,7 +4,7 @@ import { withStyles } from '@material-ui/core';
import { withTranslation } from 'react-i18next'; import { withTranslation } from 'react-i18next';
import { withPlugins } from '../extend/withPlugins'; import { withPlugins } from '../extend/withPlugins';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
import { getThemeIds } from '../state/selectors'; import { getThemeIds, getConfig } from '../state/selectors';
import { ChangeThemeDialog } from '../components/ChangeThemeDialog'; import { ChangeThemeDialog } from '../components/ChangeThemeDialog';
/** /**
...@@ -22,7 +22,7 @@ const mapDispatchToProps = (dispatch, { windowId }) => ({ ...@@ -22,7 +22,7 @@ const mapDispatchToProps = (dispatch, { windowId }) => ({
* @private * @private
*/ */
const mapStateToProps = state => ({ const mapStateToProps = state => ({
selectedTheme: state.config.selectedTheme, selectedTheme: getConfig(state).selectedTheme,
themeIds: getThemeIds(state), themeIds: getThemeIds(state),
}); });
......
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
getManifest, getManifest,
getWindow, getWindow,
getViewer, getViewer,
getConfig,
} from '../state/selectors'; } from '../state/selectors';
/** mapStateToProps */ /** mapStateToProps */
...@@ -19,7 +20,7 @@ const mapStateToProps = (state, { companionWindowId, windowId }) => ({ ...@@ -19,7 +20,7 @@ const mapStateToProps = (state, { companionWindowId, windowId }) => ({
viewer: getViewer(state, { windowId }), viewer: getViewer(state, { windowId }),
window: getWindow(state, { windowId }), window: getWindow(state, { windowId }),
}, },
showJsError: state.config.window.showJsError, showJsError: getConfig(state).window.showJsError,
}); });
/** /**
......
...@@ -8,6 +8,7 @@ import { ...@@ -8,6 +8,7 @@ import {
getSearchAnnotationsForWindow, getSearchAnnotationsForWindow,
getSelectedContentSearchAnnotationIds, getSelectedContentSearchAnnotationIds,
getCurrentCanvas, getCurrentCanvas,
getConfig,
} from '../state/selectors'; } from '../state/selectors';
/** /**
...@@ -70,7 +71,7 @@ const mapStateToProps = (state, { canvas, windowId }) => { ...@@ -70,7 +71,7 @@ const mapStateToProps = (state, { canvas, windowId }) => {
return { return {
annotationsCount: canvasAnnotations.length, annotationsCount: canvasAnnotations.length,
annotationSelected: canvasAnnotations.some(a => selectedAnnotationIds.includes(a.id)), annotationSelected: canvasAnnotations.some(a => selectedAnnotationIds.includes(a.id)),
config: state.config.galleryView, config: getConfig(state).galleryView,
selected: currentCanvas && currentCanvas.id === canvas.id, selected: currentCanvas && currentCanvas.id === canvas.id,
}; };
}; };
......
...@@ -5,11 +5,12 @@ import { withStyles } from '@material-ui/core/styles'; ...@@ -5,11 +5,12 @@ import { withStyles } from '@material-ui/core/styles';
import { withPlugins } from '../extend/withPlugins'; import { withPlugins } from '../extend/withPlugins';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
import { MinimalWindow } from '../components/MinimalWindow'; import { MinimalWindow } from '../components/MinimalWindow';
import { getWindowConfig } from '../state/selectors';
/** mapStateToProps */ /** mapStateToProps */
const mapStateToProps = (state, { windowId }) => ({ const mapStateToProps = (state, { windowId }) => ({
allowClose: state.config.window.allowClose, allowClose: getWindowConfig(state, { windowId }).allowClose,
allowWindowSideBar: state.config.window.allowWindowSideBar, allowWindowSideBar: getWindowConfig(state, { windowId }).allowWindowSideBar,
}); });
/** /**
......
...@@ -43,7 +43,7 @@ const mapStateToProps = (state, { windowId }) => { ...@@ -43,7 +43,7 @@ const mapStateToProps = (state, { windowId }) => {
&& infoResponse.isFetching === false && infoResponse.isFetching === false
&& infoResponse.error === undefined)), && infoResponse.error === undefined)),
nonTiledImages: getVisibleCanvasNonTiledResources(state, { windowId }), nonTiledImages: getVisibleCanvasNonTiledResources(state, { windowId }),
osdConfig: state.config.osdConfig, osdConfig: getConfig(state).osdConfig,
viewerConfig: getViewer(state, { windowId }), viewerConfig: getViewer(state, { windowId }),
}; };
}; };
......
...@@ -7,9 +7,10 @@ import CanvasGroupings from '../lib/CanvasGroupings'; ...@@ -7,9 +7,10 @@ import CanvasGroupings from '../lib/CanvasGroupings';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
import { ThumbnailNavigation } from '../components/ThumbnailNavigation'; import { ThumbnailNavigation } from '../components/ThumbnailNavigation';
import { import {
getCompanionWindow, getWindow,
getNextCanvasGrouping, getPreviousCanvasGrouping, getNextCanvasGrouping, getPreviousCanvasGrouping,
getCanvases, getCanvasIndex, getWindowViewType, getCanvases, getCanvasIndex, getWindowViewType,
getSequenceViewingDirection, getSequenceViewingDirection, getConfig,
} from '../state/selectors'; } from '../state/selectors';
/** /**
...@@ -27,8 +28,10 @@ const mapStateToProps = (state, { windowId }) => { ...@@ -27,8 +28,10 @@ const mapStateToProps = (state, { windowId }) => {
canvasIndex: getCanvasIndex(state, { windowId }), canvasIndex: getCanvasIndex(state, { windowId }),
hasNextCanvas: !!getNextCanvasGrouping(state, { windowId }), hasNextCanvas: !!getNextCanvasGrouping(state, { windowId }),
hasPreviousCanvas: !!getPreviousCanvasGrouping(state, { windowId }), hasPreviousCanvas: !!getPreviousCanvasGrouping(state, { windowId }),
position: state.companionWindows[state.windows[windowId].thumbnailNavigationId].position, position: getCompanionWindow(state, {
thumbnailNavigation: state.config.thumbnailNavigation, companionWindowId: getWindow(state, { windowId }).thumbnailNavigationId,
}).position,
thumbnailNavigation: getConfig(state).thumbnailNavigation,
view: viewType, view: viewType,
viewingDirection: getSequenceViewingDirection(state, { windowId }), viewingDirection: getSequenceViewingDirection(state, { windowId }),
}; };
......
...@@ -7,6 +7,7 @@ import { withPlugins } from '../extend/withPlugins'; ...@@ -7,6 +7,7 @@ import { withPlugins } from '../extend/withPlugins';
import { import {
getCurrentCanvas, getCurrentCanvas,
getCanvasLabel, getCanvasLabel,
getWorkspace,
} from '../state/selectors'; } from '../state/selectors';
import { WindowCanvasNavigationControls } from '../components/WindowCanvasNavigationControls'; import { WindowCanvasNavigationControls } from '../components/WindowCanvasNavigationControls';
...@@ -16,7 +17,7 @@ const mapStateToProps = (state, { windowId }) => ({ ...@@ -16,7 +17,7 @@ const mapStateToProps = (state, { windowId }) => ({
canvasId: (getCurrentCanvas(state, { windowId }) || {}).id, canvasId: (getCurrentCanvas(state, { windowId }) || {}).id,
windowId, windowId,
}), }),
visible: state.workspace.focusedWindowId === windowId, visible: getWorkspace(state).focusedWindowId === windowId,
}); });
/** /**
......
...@@ -3,7 +3,7 @@ import { compose } from 'redux'; ...@@ -3,7 +3,7 @@ import { compose } from 'redux';
import { withTranslation } from 'react-i18next'; import { withTranslation } from 'react-i18next';
import { withPlugins } from '../extend/withPlugins'; import { withPlugins } from '../extend/withPlugins';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
import { getContainerId, getWindowTitles } from '../state/selectors'; import { getContainerId, getWindowIds, getWindowTitles } from '../state/selectors';
import { WindowList } from '../components/WindowList'; import { WindowList } from '../components/WindowList';
/** /**
...@@ -24,7 +24,7 @@ const mapStateToProps = state => ( ...@@ -24,7 +24,7 @@ const mapStateToProps = state => (
{ {
containerId: getContainerId(state), containerId: getContainerId(state),
titles: getWindowTitles(state), titles: getWindowTitles(state),
windowIds: Object.keys(state.windows), windowIds: getWindowIds(state),
} }
); );
......
...@@ -5,6 +5,7 @@ import { withStyles } from '@material-ui/core/styles'; ...@@ -5,6 +5,7 @@ import { withStyles } from '@material-ui/core/styles';
import { withPlugins } from '../extend/withPlugins'; import { withPlugins } from '../extend/withPlugins';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
import { import {
getCompanionWindow,
getManifestLocale, getManifestLocale,
getMetadataLocales, getMetadataLocales,
getVisibleCanvases, getVisibleCanvases,
...@@ -19,7 +20,8 @@ import { WindowSideBarInfoPanel } from '../components/WindowSideBarInfoPanel'; ...@@ -19,7 +20,8 @@ import { WindowSideBarInfoPanel } from '../components/WindowSideBarInfoPanel';
*/ */
const mapStateToProps = (state, { id, windowId }) => ({ const mapStateToProps = (state, { id, windowId }) => ({
availableLocales: getMetadataLocales(state, { companionWindowId: id, windowId }), availableLocales: getMetadataLocales(state, { companionWindowId: id, windowId }),
locale: state.companionWindows[id].locale || getManifestLocale(state, { windowId }), locale: getCompanionWindow(state, { companionWindowId: id }).locale
|| getManifestLocale(state, { windowId }),
selectedCanvases: getVisibleCanvases(state, { windowId }), selectedCanvases: getVisibleCanvases(state, { windowId }),
showLocalePicker: getWindowConfig(state, { windowId }).showLocalePicker, showLocalePicker: getWindowConfig(state, { windowId }).showLocalePicker,
}); });
......
...@@ -4,7 +4,10 @@ import { withTranslation } from 'react-i18next'; ...@@ -4,7 +4,10 @@ import { withTranslation } from 'react-i18next';
import { withStyles } from '@material-ui/core/styles'; import { withStyles } from '@material-ui/core/styles';
import { withPlugins } from '../extend/withPlugins'; import { withPlugins } from '../extend/withPlugins';
import { Workspace } from '../components/Workspace'; import { Workspace } from '../components/Workspace';
import { getMaximizedWindowsIds, getWindowIds, getWorkspaceType } from '../state/selectors'; import {
getMaximizedWindowsIds, getWindowIds, getWorkspaceType,
getConfig, getWorkspace,
} from '../state/selectors';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
/** /**
...@@ -14,11 +17,11 @@ import * as actions from '../state/actions'; ...@@ -14,11 +17,11 @@ import * as actions from '../state/actions';
*/ */
const mapStateToProps = state => ( const mapStateToProps = state => (
{ {
allowNewWindows: state.config.workspace.allowNewWindows, allowNewWindows: getConfig(state).workspace.allowNewWindows,
isWorkspaceControlPanelVisible: state.config.workspaceControlPanel.enabled, isWorkspaceControlPanelVisible: getConfig(state).workspaceControlPanel.enabled,
maximizedWindowIds: getMaximizedWindowsIds(state), maximizedWindowIds: getMaximizedWindowsIds(state),
windowIds: getWindowIds(state), windowIds: getWindowIds(state),
workspaceId: state.workspace.id, workspaceId: getWorkspace(state).id,
workspaceType: getWorkspaceType(state), workspaceType: getWorkspaceType(state),
} }
); );
......
...@@ -5,13 +5,14 @@ import { withStyles } from '@material-ui/core'; ...@@ -5,13 +5,14 @@ import { withStyles } from '@material-ui/core';
import { withPlugins } from '../extend/withPlugins'; import { withPlugins } from '../extend/withPlugins';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
import { WorkspaceAdd } from '../components/WorkspaceAdd'; import { WorkspaceAdd } from '../components/WorkspaceAdd';
import { getCatalog } from '../state/selectors';
/** /**
* mapStateToProps - to hook up connect * mapStateToProps - to hook up connect
* @memberof Workspace * @memberof Workspace
* @private * @private
*/ */
const mapStateToProps = state => ({ catalog: state.catalog }); const mapStateToProps = state => ({ catalog: getCatalog(state) });
/** /**
* mapDispatchToProps - used to hook up connect to action creators * mapDispatchToProps - used to hook up connect to action creators
......
...@@ -5,6 +5,7 @@ import { withStyles } from '@material-ui/core'; ...@@ -5,6 +5,7 @@ import { withStyles } from '@material-ui/core';
import withWidth from '@material-ui/core/withWidth'; import withWidth from '@material-ui/core/withWidth';
import { withPlugins } from '../extend/withPlugins'; import { withPlugins } from '../extend/withPlugins';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
import { getWindowIds, getWorkspace } from '../state/selectors';
import { WorkspaceAddButton } from '../components/WorkspaceAddButton'; import { WorkspaceAddButton } from '../components/WorkspaceAddButton';
/** /**
...@@ -13,13 +14,13 @@ import { WorkspaceAddButton } from '../components/WorkspaceAddButton'; ...@@ -13,13 +14,13 @@ import { WorkspaceAddButton } from '../components/WorkspaceAddButton';
* @private * @private
*/ */
const mapStateToProps = (state, { width }) => { const mapStateToProps = (state, { width }) => {
const { isWorkspaceAddVisible } = state.workspace; const { isWorkspaceAddVisible } = getWorkspace(state);
return { return {
isWorkspaceAddVisible, isWorkspaceAddVisible,
useExtendedFab: ( useExtendedFab: (
(width !== 'xs') (width !== 'xs')
&& !isWorkspaceAddVisible && !isWorkspaceAddVisible
&& Object.keys(state.windows).length === 0 && getWindowIds(state).length === 0
), ),
}; };
}; };
......
...@@ -3,7 +3,10 @@ import { connect } from 'react-redux'; ...@@ -3,7 +3,10 @@ import { connect } from 'react-redux';
import { withStyles } from '@material-ui/core'; import { withStyles } from '@material-ui/core';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
import WorkspaceElasticWindow from '../components/WorkspaceElasticWindow'; import WorkspaceElasticWindow from '../components/WorkspaceElasticWindow';
import { selectCompanionWindowDimensions } from '../state/selectors'; import {
selectCompanionWindowDimensions, getWorkspace,
getElasticLayout,
} from '../state/selectors';
/** /**
* mapStateToProps - to hook up connect * mapStateToProps - to hook up connect
...@@ -14,8 +17,8 @@ const mapStateToProps = (state, { windowId }) => ( ...@@ -14,8 +17,8 @@ const mapStateToProps = (state, { windowId }) => (
{ {
companionWindowDimensions: selectCompanionWindowDimensions(state, { windowId }), companionWindowDimensions: selectCompanionWindowDimensions(state, { windowId }),
focused: state.workspace.focusedWindowId === windowId, focused: state.workspace.focusedWindowId === windowId,
layout: state.elasticLayout[windowId], layout: getElasticLayout(state)[windowId],
workspace: state.workspace, workspace: getWorkspace(state),
} }
); );
......
...@@ -3,7 +3,10 @@ import { connect } from 'react-redux'; ...@@ -3,7 +3,10 @@ import { connect } from 'react-redux';
import { withTranslation } from 'react-i18next'; import { withTranslation } from 'react-i18next';
import { withPlugins } from '../extend/withPlugins'; import { withPlugins } from '../extend/withPlugins';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
import { getContainerId, getShowZoomControlsConfig, getThemeIds } from '../state/selectors'; import {
getContainerId, getShowZoomControlsConfig, getThemeIds,
getWorkspace,
} from '../state/selectors';
import { WorkspaceMenu } from '../components/WorkspaceMenu'; import { WorkspaceMenu } from '../components/WorkspaceMenu';
/** /**
...@@ -22,7 +25,7 @@ const mapDispatchToProps = { ...@@ -22,7 +25,7 @@ const mapDispatchToProps = {
*/ */
const mapStateToProps = state => ({ const mapStateToProps = state => ({
containerId: getContainerId(state), containerId: getContainerId(state),
isWorkspaceAddVisible: state.workspace.isWorkspaceAddVisible, isWorkspaceAddVisible: getWorkspace(state).isWorkspaceAddVisible,
showThemePicker: getThemeIds(state).length > 0, showThemePicker: getThemeIds(state).length > 0,
showZoomControls: getShowZoomControlsConfig(state), showZoomControls: getShowZoomControlsConfig(state),
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment