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
Branches
Tags
No related merge requests found
import { compose } from 'redux'; import { compose } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import { import {
getCanvasLabel, getCanvasLabel,
getSelectedCanvas, getSelectedCanvas,
...@@ -36,7 +35,6 @@ const mapDispatchToProps = { ...@@ -36,7 +35,6 @@ const mapDispatchToProps = {
const enhance = compose( const enhance = compose(
connect(mapStateToProps, mapDispatchToProps), connect(mapStateToProps, mapDispatchToProps),
miradorWithPlugins,
// further HOC go here // further HOC go here
); );
......
...@@ -3,7 +3,6 @@ import { compose } from 'redux'; ...@@ -3,7 +3,6 @@ import { compose } from 'redux';
import { withTranslation } from 'react-i18next'; import { withTranslation } from 'react-i18next';
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 miradorWithPlugins from '../lib/miradorWithPlugins';
import { WorkspaceAddButton } from '../components/WorkspaceAddButton'; import { WorkspaceAddButton } from '../components/WorkspaceAddButton';
/** /**
...@@ -40,7 +39,6 @@ const enhance = compose( ...@@ -40,7 +39,6 @@ const enhance = compose(
withTranslation(), withTranslation(),
withStyles(styles), withStyles(styles),
connect(mapStateToProps, mapDispatchToProps), connect(mapStateToProps, mapDispatchToProps),
miradorWithPlugins,
); );
export default enhance(WorkspaceAddButton); export default enhance(WorkspaceAddButton);
import miradorWithPlugins from '../lib/miradorWithPlugins';
import { WorkspaceControlPanelButtons } import { WorkspaceControlPanelButtons }
from '../components/WorkspaceControlPanelButtons'; from '../components/WorkspaceControlPanelButtons';
export default miradorWithPlugins(WorkspaceControlPanelButtons); export default WorkspaceControlPanelButtons;
import { compose } from 'redux'; import { compose } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { withTranslation } from 'react-i18next'; import { withTranslation } from 'react-i18next';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import { WorkspaceExport } from '../components/WorkspaceExport'; import { WorkspaceExport } from '../components/WorkspaceExport';
/** /**
...@@ -14,7 +13,6 @@ const mapStateToProps = state => ({ state }); ...@@ -14,7 +13,6 @@ const mapStateToProps = state => ({ state });
const enhance = compose( const enhance = compose(
withTranslation(), withTranslation(),
connect(mapStateToProps, {}), connect(mapStateToProps, {}),
miradorWithPlugins,
); );
export default enhance(WorkspaceExport); export default enhance(WorkspaceExport);
...@@ -2,7 +2,6 @@ import { connect } from 'react-redux'; ...@@ -2,7 +2,6 @@ import { connect } from 'react-redux';
import { compose } from 'redux'; import { compose } from 'redux';
import { withTranslation } from 'react-i18next'; import { withTranslation } from 'react-i18next';
import { withStyles } from '@material-ui/core'; import { withStyles } from '@material-ui/core';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
import { WorkspaceFullScreenButton } import { WorkspaceFullScreenButton }
from '../components/WorkspaceFullScreenButton'; from '../components/WorkspaceFullScreenButton';
...@@ -38,7 +37,6 @@ const enhance = compose( ...@@ -38,7 +37,6 @@ const enhance = compose(
withTranslation(), withTranslation(),
withStyles(styles), withStyles(styles),
connect(mapStateToProps, mapDispatchToProps), connect(mapStateToProps, mapDispatchToProps),
miradorWithPlugins,
); );
export default enhance(WorkspaceFullScreenButton); export default enhance(WorkspaceFullScreenButton);
import { compose } from 'redux'; import { compose } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { withTranslation } from 'react-i18next'; import { withTranslation } from 'react-i18next';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
import { WorkspaceMenu } from '../components/WorkspaceMenu'; import { WorkspaceMenu } from '../components/WorkspaceMenu';
...@@ -27,7 +26,6 @@ const mapStateToProps = state => ({ ...@@ -27,7 +26,6 @@ const mapStateToProps = state => ({
const enhance = compose( const enhance = compose(
withTranslation(), withTranslation(),
connect(mapStateToProps, mapDispatchToProps), connect(mapStateToProps, mapDispatchToProps),
miradorWithPlugins,
); );
export default enhance(WorkspaceMenu); export default enhance(WorkspaceMenu);
import { compose } from 'redux'; import { compose } from 'redux';
import { withTranslation } from 'react-i18next'; import { withTranslation } from 'react-i18next';
import { withStyles } from '@material-ui/core'; import { withStyles } from '@material-ui/core';
import miradorWithPlugins from '../lib/miradorWithPlugins';
import { WorkspaceMenuButton } from '../components/WorkspaceMenuButton'; import { WorkspaceMenuButton } from '../components/WorkspaceMenuButton';
/** /**
...@@ -21,7 +20,6 @@ const styles = theme => ({ ...@@ -21,7 +20,6 @@ const styles = theme => ({
const enhance = compose( const enhance = compose(
withTranslation(), withTranslation(),
withStyles(styles), withStyles(styles),
miradorWithPlugins,
// further HOC // further HOC
); );
......
/**
* componentPlugins - gets window plugins based on a component parent
*/
export default function componentPlugins(componentName, plugins = []) {
// TODO: Figure out how to handle when not running under window. Probably not
// a pressing priority, but relevant for tests
return plugins.map((pluginName) => {
if (window.Mirador.plugins[pluginName]
&& window.Mirador.plugins[pluginName].parent === componentName) {
return window.Mirador.plugins[pluginName];
}
return null;
}).filter(plugin => (plugin !== (undefined || null)));
}
import React, { Component } from 'react';
import { compose } from 'redux';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import componentPlugins from './componentPlugins';
/**
* miradorWithPlugins - renders and returns a component with provided plugins
*
* @param {type} WrappedComponent
*/
export default function miradorWithPlugins(WrappedComponent) {
/**
*/
class ConnectedComponent extends Component {
/**
* constructor -
*/
constructor(props) {
super(props);
this.getPluginParent = this.getPluginParent.bind(this);
}
/**
* pluginParent - access the plugin's "parent"
*/
getPluginParent() {
return this.pluginParent;
}
/**
* render - renders the wrapped component with the plugins.
*/
render() {
const { config } = this.props;
const { plugins } = config;
return (
<>
<WrappedComponent {...this.props} ref={(parent) => { this.pluginParent = parent; }} />
{componentPlugins(WrappedComponent.name, plugins)
.map(component => React.createElement(
connect(component.mapStateToProps, component.mapDispatchToProps)(component.component),
{ key: component.name, ...this.props, pluginParent: this.getPluginParent },
))
}
</>
);
}
}
const wrappedComponentName = WrappedComponent.name || 'Component';
ConnectedComponent.displayName = `miradorWithPlugins(${wrappedComponentName})`;
ConnectedComponent.propTypes = {
config: PropTypes.instanceOf(Object).isRequired,
};
/**
*/
const mapStateToProps = state => ({ config: state.config });
const enhance = compose(
connect(mapStateToProps),
// further HOC go here
);
return enhance(ConnectedComponent);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment