Skip to content
Snippets Groups Projects
Commit 36ca72dc authored by Jessie Keck's avatar Jessie Keck
Browse files

Use the id stored in config object in redux to create a scoped query selector...

Use the id stored in config object in redux to create a scoped query selector to the mirador-viewer (and pass that to the various MUI Menus as the container prop.
parent d5202ddd
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ describe('WindowList', () => { ...@@ -17,6 +17,7 @@ describe('WindowList', () => {
wrapper = shallow( wrapper = shallow(
<WindowList <WindowList
containerId="mirador"
anchorEl={{}} anchorEl={{}}
manifests={manifests} manifests={manifests}
windows={windows} windows={windows}
...@@ -36,6 +37,7 @@ describe('WindowList', () => { ...@@ -36,6 +37,7 @@ describe('WindowList', () => {
wrapper = shallow( wrapper = shallow(
<WindowList <WindowList
containerId="mirador"
anchorEl={{}} anchorEl={{}}
manifests={manifests} manifests={manifests}
windows={windows} windows={windows}
...@@ -64,6 +66,7 @@ describe('WindowList', () => { ...@@ -64,6 +66,7 @@ describe('WindowList', () => {
wrapper = shallow( wrapper = shallow(
<WindowList <WindowList
containerId="mirador"
anchorEl={{}} anchorEl={{}}
manifests={manifests} manifests={manifests}
windows={windows} windows={windows}
......
...@@ -11,6 +11,7 @@ import { WindowTopMenu } from '../../../src/components/WindowTopMenu'; ...@@ -11,6 +11,7 @@ import { WindowTopMenu } from '../../../src/components/WindowTopMenu';
function createWrapper(props) { function createWrapper(props) {
return shallow( return shallow(
<WindowTopMenu <WindowTopMenu
containerId="mirador"
windowId="xyz" windowId="xyz"
handleClose={() => {}} handleClose={() => {}}
anchorEl={null} anchorEl={null}
......
...@@ -14,6 +14,7 @@ describe('WorkspaceMenu', () => { ...@@ -14,6 +14,7 @@ describe('WorkspaceMenu', () => {
toggleZoomControls = jest.fn(); toggleZoomControls = jest.fn();
wrapper = shallow( wrapper = shallow(
<WorkspaceMenu <WorkspaceMenu
containerId="mirador"
handleClose={handleClose} handleClose={handleClose}
showZoomControls={showZoomControls} showZoomControls={showZoomControls}
toggleZoomControls={toggleZoomControls} toggleZoomControls={toggleZoomControls}
......
...@@ -4,6 +4,7 @@ import Menu from '@material-ui/core/Menu'; ...@@ -4,6 +4,7 @@ import Menu from '@material-ui/core/Menu';
import MenuItem from '@material-ui/core/MenuItem'; import MenuItem from '@material-ui/core/MenuItem';
import ListSubheader from '@material-ui/core/ListSubheader'; import ListSubheader from '@material-ui/core/ListSubheader';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import ns from '../config/css-ns';
/** /**
*/ */
...@@ -29,10 +30,16 @@ export class WindowList extends Component { ...@@ -29,10 +30,16 @@ export class WindowList extends Component {
*/ */
render() { render() {
const { const {
handleClose, anchorEl, windows, focusWindow, t, containerId, handleClose, anchorEl, windows, focusWindow, t,
} = this.props; } = this.props;
return ( return (
<Menu id="window-list-menu" anchorEl={anchorEl} open={Boolean(anchorEl)} onClose={handleClose}> <Menu
id="window-list-menu"
container={document.querySelector(`#${containerId} .${ns('viewer')}`)}
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={handleClose}
>
<ListSubheader> <ListSubheader>
<Button color="inherit" aria-label={t('closeMenu')} onClick={handleClose} align="right" style={{ float: 'right' }}>&times;</Button> <Button color="inherit" aria-label={t('closeMenu')} onClick={handleClose} align="right" style={{ float: 'right' }}>&times;</Button>
{t('openWindows')} {t('openWindows')}
...@@ -55,6 +62,7 @@ export class WindowList extends Component { ...@@ -55,6 +62,7 @@ export class WindowList extends Component {
} }
WindowList.propTypes = { WindowList.propTypes = {
containerId: PropTypes.string.isRequired,
focusWindow: PropTypes.func.isRequired, focusWindow: PropTypes.func.isRequired,
handleClose: PropTypes.func.isRequired, handleClose: PropTypes.func.isRequired,
anchorEl: PropTypes.object, // eslint-disable-line react/forbid-prop-types anchorEl: PropTypes.object, // eslint-disable-line react/forbid-prop-types
......
...@@ -5,6 +5,7 @@ import Divider from '@material-ui/core/Divider'; ...@@ -5,6 +5,7 @@ import Divider from '@material-ui/core/Divider';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import WindowThumbnailSettings from '../containers/WindowThumbnailSettings'; import WindowThumbnailSettings from '../containers/WindowThumbnailSettings';
import WindowViewSettings from '../containers/WindowViewSettings'; import WindowViewSettings from '../containers/WindowViewSettings';
import ns from '../config/css-ns';
/** /**
*/ */
...@@ -14,12 +15,20 @@ export class WindowTopMenu extends Component { ...@@ -14,12 +15,20 @@ export class WindowTopMenu extends Component {
* @return * @return
*/ */
render() { render() {
const { handleClose, anchorEl, windowId } = this.props; const {
containerId, handleClose, anchorEl, windowId,
} = this.props;
// const {} = this.state; // const {} = this.state;
return ( return (
<> <>
<Menu id={`window-menu_${windowId}`} anchorEl={anchorEl} open={Boolean(anchorEl)} onClose={handleClose}> <Menu
id={`window-menu_${windowId}`}
container={document.querySelector(`#${containerId} .${ns('viewer')}`)}
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={handleClose}
>
<ListItem> <ListItem>
<WindowViewSettings windowId={windowId} /> <WindowViewSettings windowId={windowId} />
</ListItem> </ListItem>
...@@ -35,6 +44,7 @@ export class WindowTopMenu extends Component { ...@@ -35,6 +44,7 @@ export class WindowTopMenu extends Component {
} }
WindowTopMenu.propTypes = { WindowTopMenu.propTypes = {
containerId: PropTypes.string.isRequired,
windowId: PropTypes.string.isRequired, windowId: PropTypes.string.isRequired,
handleClose: PropTypes.func.isRequired, handleClose: PropTypes.func.isRequired,
anchorEl: PropTypes.object, // eslint-disable-line react/forbid-prop-types anchorEl: PropTypes.object, // eslint-disable-line react/forbid-prop-types
......
...@@ -15,6 +15,7 @@ import { NestedMenu } from './NestedMenu'; ...@@ -15,6 +15,7 @@ import { NestedMenu } from './NestedMenu';
import WindowList from '../containers/WindowList'; import WindowList from '../containers/WindowList';
import WorkspaceSettings from '../containers/WorkspaceSettings'; import WorkspaceSettings from '../containers/WorkspaceSettings';
import WorkspaceExport from '../containers/WorkspaceExport'; import WorkspaceExport from '../containers/WorkspaceExport';
import ns from '../config/css-ns';
/** /**
*/ */
...@@ -72,7 +73,7 @@ export class WorkspaceMenu extends Component { ...@@ -72,7 +73,7 @@ export class WorkspaceMenu extends Component {
*/ */
render() { render() {
const { const {
handleClose, anchorEl, t, showZoomControls, containerId, handleClose, anchorEl, t, showZoomControls,
} = this.props; } = this.props;
const { const {
...@@ -84,7 +85,13 @@ export class WorkspaceMenu extends Component { ...@@ -84,7 +85,13 @@ export class WorkspaceMenu extends Component {
return ( return (
<> <>
<Menu id="workspace-menu" anchorEl={anchorEl} open={Boolean(anchorEl)} onClose={handleClose}> <Menu
id="workspace-menu"
container={document.querySelector(`#${containerId} .${ns('viewer')}`)}
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={handleClose}
>
<MenuItem <MenuItem
aria-haspopup="true" aria-haspopup="true"
onClick={(e) => { this.handleMenuItemClick('windowList', e); handleClose(e); }} onClick={(e) => { this.handleMenuItemClick('windowList', e); handleClose(e); }}
...@@ -158,6 +165,7 @@ export class WorkspaceMenu extends Component { ...@@ -158,6 +165,7 @@ export class WorkspaceMenu extends Component {
} }
WorkspaceMenu.propTypes = { WorkspaceMenu.propTypes = {
containerId: PropTypes.string.isRequired,
handleClose: PropTypes.func.isRequired, handleClose: PropTypes.func.isRequired,
toggleZoomControls: PropTypes.func, toggleZoomControls: PropTypes.func,
showZoomControls: PropTypes.bool, showZoomControls: PropTypes.bool,
......
...@@ -20,6 +20,7 @@ const mapDispatchToProps = { ...@@ -20,6 +20,7 @@ const mapDispatchToProps = {
*/ */
const mapStateToProps = state => ( const mapStateToProps = state => (
{ {
containerId: state.config.id,
windows: state.windows, windows: state.windows,
manifests: state.manifests, manifests: state.manifests,
} }
......
import { compose } from 'redux';
import { connect } from 'react-redux';
import miradorWithPlugins from '../lib/miradorWithPlugins'; import miradorWithPlugins from '../lib/miradorWithPlugins';
import { WindowTopMenu } from '../components/WindowTopMenu'; import { WindowTopMenu } from '../components/WindowTopMenu';
export default miradorWithPlugins(WindowTopMenu); /**
* mapStateToProps - to hook up connect
* @memberof WindowTopMenu
* @private
*/
const mapStateToProps = state => ({
containerId: state.config.id,
});
const enhance = compose(
connect(mapStateToProps, null),
miradorWithPlugins,
);
export default enhance(WindowTopMenu);
...@@ -17,9 +17,10 @@ const mapDispatchToProps = { toggleZoomControls: actions.toggleZoomControls }; ...@@ -17,9 +17,10 @@ const mapDispatchToProps = { toggleZoomControls: actions.toggleZoomControls };
* @memberof WindowViewer * @memberof WindowViewer
* @private * @private
*/ */
const mapStateToProps = state => ( const mapStateToProps = state => ({
{ showZoomControls: state.workspace.showZoomControls } containerId: state.config.id,
); showZoomControls: state.workspace.showZoomControls,
});
const enhance = compose( const enhance = compose(
withTranslation(), withTranslation(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment