Skip to content
Snippets Groups Projects
Commit de0a1a00 authored by Mathias Maaß's avatar Mathias Maaß
Browse files

Remove plugin related stuff as prerequisite for #2098.

parent 48cf3e96
No related branches found
No related tags found
No related merge requests found
Showing
with 4 additions and 230 deletions
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>Mirador</title>
</head>
<body>
<div id="mirador" style="position: absolute; top: 0; bottom: 0; left: 0; right: 0;"></div>
<script src="../../../node_modules/react/umd/react.development.js"></script>
<!-- Request from CDN if unavailable locally -->
<script type="text/javascript">
if (!window.React) {
var script = document.createElement('script'); script.src = "https://unpkg.com/react@16/umd/react.development.js"; script.crossorigin = true; document.head.appendChild(script)
}
</script>
<script src="../../../node_modules/react-dom/umd/react-dom.development.js"></script>
<!-- Request from CDN if unavailable locally -->
<script type="text/javascript">
if (!window.ReactDOM) {
var script = document.createElement('script'); script.src = "https://unpkg.com/react-dom@16/umd/react-dom.development.js"; script.crossorigin = true; document.head.appendChild(script)
}
</script>
<script>document.write("<script type='text/javascript' src='../../../dist/mirador.min.js?v=" + Date.now() + "'><\/script>");</script>
<script type="text/javascript">
class MiradorShareButton extends React.Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
alert('Share this stuff')
}
render() {
return React.createElement('button', { className: 'share', onClick: this.handleClick}, 'Share');
}
}
const miradorShareButton = {
name: 'miradorShareButton',
component: MiradorShareButton,
parent: 'WindowTopBarButtons',
}
Mirador.plugins.miradorShareButton = miradorShareButton;
class MiradorRuler extends React.Component {
constructor(props) {
super(props);
this._isMounted = false;
this.state = {
zooming: false,
}
this.zoomToColor = this.zoomToColor.bind(this);
}
componentDidMount() {
this._isMounted = true;
const that = this;
this.props.pluginParent().viewer.addHandler('zoom', (e) => {
if (that._isMounted) {
that.props.setZooming('123', true);
that.setState({
zooming: true
})
}
})
// Super hacky don't do this for real
function resetStyle() {
if (that._isMounted) {
that.props.setZooming('123', false);
that.setState({
zooming: false
})
}
setTimeout(resetStyle, 750)
}
resetStyle();
}
componentWillUnmount() {
this._isMounted = false;
if (this.props.pluginParent()) {
this.props.pluginParent().viewer.removeHandler('zoom');
}
}
zoomToColor(zooming) {
if (zooming) {
return 'red'
}
return 'black'
}
render() {
return React.createElement('div', {className: 'mirador-ruler', style: { position: 'absolute', bottom: 0, color: this.zoomToColor(this.state.zooming)}}, 'I am a ruler')
}
}
const zoomReducer = (state = {}, action) => {
switch (action.type) {
case 'SET_ZOOMING':
return action.zooming;
default:
return state;
}
};
const setZooming = (windowId, zooming) => {
return { type: 'SET_ZOOMING', windowId, zooming };
}
const miradorRuler = {
name: 'miradorRuler',
component: MiradorRuler,
parent: 'OpenSeadragonViewer',
reducers: {
zooming: zoomReducer
},
actions: {
setZooming: setZooming
},
mapStateToProps: ({ manifests }, props) => {
return {
manifests // return the part of the state I need here.
}
},
mapDispatchToProps: (dispatch) => {
return {
setZooming: (windowId, level) => (
dispatch(setZooming(windowId, level))
),
}
},
}
Mirador.plugins.miradorRuler = miradorRuler;
var miradorInstance = Mirador.viewer({
id: 'mirador',
plugins: ['miradorShareButton', 'miradorRuler']
});
</script>
</body>
</html>
/* global miradorInstance */
describe('Mirador plugin use', () => {
beforeAll(async () => {
await page.goto('http://127.0.0.1:4488/__tests__/integration/mirador/plugins.html');
await expect(page).toClick('#addBtn');
await expect(page).toClick('.mirador-add-resource-button');
await expect(page).toFill('#manifestURL', 'http://localhost:5000/api/sn904cj3439');
await expect(page).toClick('#fetchBtn');
await expect(page).toMatchElement('[data-manifestid="http://localhost:5000/api/sn904cj3439"] button');
await expect(page).toClick('[data-manifestid="http://localhost:5000/api/sn904cj3439"] button');
});
it('displays "Share Button" plugin', async () => {
await expect(page).toMatchElement('button', { text: 'Share' });
page.on('dialog', async (dialog) => {
expect(dialog.message()).toBe('Share this stuff');
await dialog.dismiss();
});
await expect(page).toClick('button.share');
});
it('displays "Ruler" plugin', async () => {
await expect(page).toMatchElement('.mirador-ruler');
// await page.waitFor(1000);
// Test that composed reducer and actions are working.
const zooming = await page.evaluate(() => (
miradorInstance.store.getState().zooming
));
await expect(zooming).toBe(false);
});
});
......@@ -23,7 +23,7 @@ describe('CompanionWindowFactory', () => {
content: 'info',
});
expect(wrapper.find('WithStyles(Connect(Connect(miradorWithPlugins(WindowSideBarInfoPanel))))').length).toBe(1);
expect(wrapper.find('WithStyles(Connect(WindowSideBarInfoPanel))').length).toBe(1);
});
});
......
......@@ -10,6 +10,6 @@ describe('WindowSideBar', () => {
it('renders without an error', () => {
expect(wrapper.find('WithStyles(Drawer)').length).toBe(1);
expect(wrapper.find('WithStyles(Connect(Connect(miradorWithPlugins(WindowSideBarButtons))))').length).toBe(1);
expect(wrapper.find('WithStyles(Connect(WindowSideBarButtons))').length).toBe(1);
});
});
......@@ -22,6 +22,6 @@ describe('WorkspaceControlPanel', () => {
it('renders without an error', () => {
expect(wrapper.find('WithStyles(AppBar)').length).toBe(1);
expect(wrapper.find('Connect(miradorWithPlugins(WorkspaceControlPanelButtons))').length).toBe(1);
expect(wrapper.find('WorkspaceControlPanelButtons').length).toBe(1);
});
});
import componentPlugins from '../../../src/lib/componentPlugins';
describe('componentPlugins', () => {
const originalMirador = window.Mirador;
beforeAll(() => {
window.Mirador = {
plugins: {
fooPlugin: {
name: 'fooPlugin',
parent: 'FooComponent',
},
barPlugin: {
name: 'barPlugin',
parent: 'FooComponent',
},
},
};
});
afterAll(() => {
window.Mirador = originalMirador;
});
it('only selects plugins that are defined in config', () => {
expect(componentPlugins('FooComponent', ['barPlugin'])[0].name).toEqual('barPlugin');
expect(componentPlugins('FooComponent', ['barPlugin']).length).toEqual(1);
});
it('only selects plugins that define component as parent', () => {
expect(componentPlugins('BarComponent', ['barPlugin'])).toEqual([]);
expect(componentPlugins('FooComponent', ['fooPlugin']).length).toEqual(1);
});
});
......@@ -3,7 +3,6 @@ import { connect } from 'react-redux';
import { withTranslation } from 'react-i18next';
import { withStyles } from '@material-ui/core';
import * as actions from '../state/actions';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import { CompanionWindow } from '../components/CompanionWindow';
/**
......@@ -78,7 +77,6 @@ const enhance = compose(
withTranslation(),
withStyles(styles),
connect(mapStateToProps, mapDispatchToProps),
miradorWithPlugins,
);
export default enhance(CompanionWindow);
......@@ -3,7 +3,6 @@ import { connect } from 'react-redux';
import { withTranslation } from 'react-i18next';
import { withStyles } from '@material-ui/core';
import { fade } from '@material-ui/core/styles/colorManipulator';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import { OpenSeadragonViewer } from '../components/OpenSeadragonViewer';
import * as actions from '../state/actions';
import {
......@@ -59,7 +58,6 @@ const enhance = compose(
withStyles(styles),
withTranslation(),
connect(mapStateToProps, mapDispatchToProps),
miradorWithPlugins,
// further HOC go here
);
......
import { compose } from 'redux';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import { PrimaryWindow } from '../components/PrimaryWindow';
const enhance = compose(
miradorWithPlugins,
// further HOC go here
);
......
......@@ -2,7 +2,6 @@ import { compose } from 'redux';
import { connect } from 'react-redux';
import { withTranslation } from 'react-i18next';
import { withStyles } from '@material-ui/core/styles';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import CanvasGroupings from '../lib/CanvasGroupings';
import * as actions from '../state/actions';
import { ThumbnailNavigation } from '../components/ThumbnailNavigation';
......@@ -42,7 +41,6 @@ const enhance = compose(
withStyles(styles),
withTranslation(),
connect(mapStateToProps, mapDispatchToProps),
miradorWithPlugins,
// further HOC go here
);
......
import { compose } from 'redux';
import { connect } from 'react-redux';
import { withTranslation } from 'react-i18next';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import * as actions from '../state/actions';
import { ViewerNavigation } from '../components/ViewerNavigation';
......@@ -17,7 +16,6 @@ const mapDispatchToProps = {
const enhance = compose(
withTranslation(),
connect(null, mapDispatchToProps),
miradorWithPlugins,
// further HOC go here
);
......
import { connect } from 'react-redux';
import { compose } from 'redux';
import { withStyles } from '@material-ui/core';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import { WindowSideBar } from '../components/WindowSideBar';
/**
......@@ -43,7 +42,6 @@ const styles = theme => ({
const enhance = compose(
withStyles(styles),
connect(mapStateToProps, null),
miradorWithPlugins,
);
export default enhance(WindowSideBar);
......@@ -3,7 +3,6 @@ import { connect } from 'react-redux';
import { withStyles } from '@material-ui/core';
import { withTranslation } from 'react-i18next';
import * as actions from '../state/actions';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import {
getCompanionWindowForPosition,
getSelectedCanvas,
......@@ -60,7 +59,6 @@ const enhance = compose(
withTranslation(),
withStyles(style),
connect(mapStateToProps, mapDispatchToProps),
miradorWithPlugins,
);
export default enhance(WindowSideBarButtons);
......@@ -2,7 +2,6 @@ import { compose } from 'redux';
import { connect } from 'react-redux';
import { withTranslation } from 'react-i18next';
import { withStyles } from '@material-ui/core';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import {
getDestructuredMetadata,
getCanvasLabel,
......@@ -44,7 +43,6 @@ const enhance = compose(
withTranslation(),
withStyles(styles),
connect(mapStateToProps, null),
miradorWithPlugins,
);
export default enhance(WindowSideBarInfoPanel);
import { compose } from 'redux';
import { connect } from 'react-redux';
import { withTranslation } from 'react-i18next';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import * as actions from '../state/actions';
import { getThumbnailNavigationPosition } from '../state/selectors';
import { WindowThumbnailSettings } from '../components/WindowThumbnailSettings';
......@@ -27,7 +26,6 @@ const mapStateToProps = (state, props) => (
const enhance = compose(
withTranslation(),
connect(mapStateToProps, mapDispatchToProps),
miradorWithPlugins,
// further HOC go here
);
......
......@@ -3,7 +3,6 @@ import { connect } from 'react-redux';
import { withTranslation } from 'react-i18next';
import { withStyles } from '@material-ui/core';
import * as actions from '../state/actions';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import { getWindowManifest, getManifestTitle } from '../state/selectors';
import { WindowTopBar } from '../components/WindowTopBar';
......@@ -46,7 +45,6 @@ const enhance = compose(
withTranslation(),
withStyles(styles),
connect(mapStateToProps, mapDispatchToProps),
miradorWithPlugins,
);
export default enhance(WindowTopBar);
import miradorWithPlugins from '../lib/miradorWithPlugins';
import { WindowTopBarButtons } from '../components/WindowTopBarButtons';
export default miradorWithPlugins(WindowTopBarButtons);
export default WindowTopBarButtons;
import { compose } from 'redux';
import { connect } from 'react-redux';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import { WindowTopMenu } from '../components/WindowTopMenu';
/**
......@@ -14,7 +13,6 @@ const mapStateToProps = state => ({
const enhance = compose(
connect(mapStateToProps, null),
miradorWithPlugins,
);
export default enhance(WindowTopMenu);
import { compose } from 'redux';
import { withTranslation } from 'react-i18next';
import { withStyles } from '@material-ui/core';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import { WindowTopMenuButton } from '../components/WindowTopMenuButton';
/**
......@@ -21,7 +20,6 @@ const styles = theme => ({
const enhance = compose(
withTranslation(),
withStyles(styles),
miradorWithPlugins,
);
export default enhance(WindowTopMenuButton);
import { compose } from 'redux';
import { connect } from 'react-redux';
import { withTranslation } from 'react-i18next';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import * as actions from '../state/actions';
import { getWindowViewType } from '../state/selectors';
import { WindowViewSettings } from '../components/WindowViewSettings';
......@@ -27,7 +26,6 @@ const mapStateToProps = (state, props) => (
const enhance = compose(
withTranslation(),
connect(mapStateToProps, mapDispatchToProps),
miradorWithPlugins,
);
export default enhance(WindowViewSettings);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment