From 07215d3b8d96af4e6fa90b55011af3134a9ad3f2 Mon Sep 17 00:00:00 2001 From: Jack Reed <phillipjreed@gmail.com> Date: Thu, 22 Oct 2020 07:18:30 -0600 Subject: [PATCH] Always make sure the annotation side bar button is present --- src/index.js | 3 ++ src/plugins/windowSideBarButtonsPlugin.js | 39 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/plugins/windowSideBarButtonsPlugin.js diff --git a/src/index.js b/src/index.js index c54effa..efa1720 100644 --- a/src/index.js +++ b/src/index.js @@ -2,10 +2,12 @@ import miradorAnnotationPlugin from './plugins/miradorAnnotationPlugin'; import externalStorageAnnotationPlugin from './plugins/externalStorageAnnotationPlugin'; import canvasAnnotationsPlugin from './plugins/canvasAnnotationsPlugin'; import annotationCreationCompanionWindow from './plugins/annotationCreationCompanionWindow'; +import windowSideBarButtonsPlugin from './plugins/windowSideBarButtonsPlugin'; export { miradorAnnotationPlugin, externalStorageAnnotationPlugin, canvasAnnotationsPlugin, annotationCreationCompanionWindow, + windowSideBarButtonsPlugin, }; export default [ @@ -13,4 +15,5 @@ export default [ externalStorageAnnotationPlugin, canvasAnnotationsPlugin, annotationCreationCompanionWindow, + windowSideBarButtonsPlugin, ]; diff --git a/src/plugins/windowSideBarButtonsPlugin.js b/src/plugins/windowSideBarButtonsPlugin.js new file mode 100644 index 0000000..7232f75 --- /dev/null +++ b/src/plugins/windowSideBarButtonsPlugin.js @@ -0,0 +1,39 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; + +/** + * A wrapper plugin that sets hasAnyAnnotations to true so that the annotation + * companion window button is present + */ +class WindowSideBarButtonWrapper extends Component { + /** */ + render() { + const { PluginComponents, TargetComponent, targetProps } = this.props; + targetProps.hasAnyAnnotations = true; + return ( + <TargetComponent + {...targetProps} // eslint-disable-line react/jsx-props-no-spreading + PluginComponents={PluginComponents} + /> + ); + } +} + +WindowSideBarButtonWrapper.propTypes = { + PluginComponents: PropTypes.array, // eslint-disable-line react/forbid-prop-types + TargetComponent: PropTypes.oneOfType([ + PropTypes.func, + PropTypes.node, + ]).isRequired, + targetProps: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types +}; + +WindowSideBarButtonWrapper.defaultProps = { + PluginComponents: [], +}; + +export default { + component: WindowSideBarButtonWrapper, + mode: 'wrap', + target: 'WindowSideBarButtons', +}; -- GitLab