Skip to content
Snippets Groups Projects
Commit 38ccf333 authored by Lutz Helm's avatar Lutz Helm
Browse files

Fix code style issues

parent de35a2ce
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ import miradorAnnotationPlugin from '../src/plugins/miradorAnnotationPlugin'; ...@@ -7,6 +7,7 @@ import miradorAnnotationPlugin from '../src/plugins/miradorAnnotationPlugin';
function createWrapper(props) { function createWrapper(props) {
return shallow( return shallow(
<miradorAnnotationPlugin.component <miradorAnnotationPlugin.component
canvases={[]}
config={{}} config={{}}
TargetComponent="<div>hello</div>" TargetComponent="<div>hello</div>"
targetProps={{}} targetProps={{}}
......
...@@ -3,76 +3,86 @@ import Dialog from '@material-ui/core/Dialog'; ...@@ -3,76 +3,86 @@ import Dialog from '@material-ui/core/Dialog';
import DialogContent from '@material-ui/core/DialogContent'; import DialogContent from '@material-ui/core/DialogContent';
import DialogTitle from '@material-ui/core/DialogTitle'; import DialogTitle from '@material-ui/core/DialogTitle';
import GetAppIcon from '@material-ui/icons/GetApp'; import GetAppIcon from '@material-ui/icons/GetApp';
import List from '@material-ui/core/List' import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem' import ListItem from '@material-ui/core/ListItem';
import ListItemIcon from '@material-ui/core/ListItemIcon' import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText' import ListItemText from '@material-ui/core/ListItemText';
import Typography from '@material-ui/core/Typography'; import Typography from '@material-ui/core/Typography';
import PropTypes, { bool } from 'prop-types'; import PropTypes, { bool } from 'prop-types';
/** */
export class AnnotationDownloadDialog extends Component { export class AnnotationDownloadDialog extends Component {
/** */
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
downloadLinks: [], downloadLinks: [],
} };
this.closeDialog = this.closeDialog.bind(this);
} }
/** */
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
const { canvases, config, open } = this.props; const { canvases, config, open } = this.props;
const { open: prevOpen } = prevProps || {}; const { open: prevOpen } = prevProps || {};
if (prevOpen !== open && open) { if (prevOpen !== open && open) {
/** */
const reducer = async (acc, canvas) => { const reducer = async (acc, canvas) => {
const store = config.annotation.adapter(canvas.id); const store = config.annotation.adapter(canvas.id);
const _acc = await acc; const resolvedAcc = await acc;
const content = await store.all(); const content = await store.all();
if (content if (content) {
) { // eslint-disable-next-line no-underscore-dangle
const label = canvas.__jsonld.label || canvas.id; const label = canvas.__jsonld.label || canvas.id;
const data = new Blob([JSON.stringify(content)], { type: 'application/json' }) const data = new Blob([JSON.stringify(content)], { type: 'application/json' });
const url = window.URL.createObjectURL(data); const url = window.URL.createObjectURL(data);
return [..._acc, { return [...resolvedAcc, {
id: content.id || content['@id'],
canvasId: canvas.id, canvasId: canvas.id,
id: content.id || content['@id'],
label, label,
url, url,
}] }];
}
return _acc;
} }
return resolvedAcc;
};
if (canvases && canvases.length > 0) { if (canvases && canvases.length > 0) {
canvases.reduce(reducer, []).then(downloadLinks => { canvases.reduce(reducer, []).then((downloadLinks) => {
this.setState({ downloadLinks }) this.setState({ downloadLinks });
}); });
} else {
this.setState({ downloadLinks: [] });
} }
} }
if (prevOpen !== open && !open) {
this.setState({ downloadLinks: [] });
} }
/** */
closeDialog() {
const { handleClose } = this.props;
this.setState({ downloadLinks: [] });
handleClose();
} }
/** */
render() { render() {
const { canvases, config, handleClose, open } = this.props; const { handleClose, open } = this.props;
const { downloadLinks } = this.state;
return ( return (
<Dialog <Dialog
aria-labelledby="annotation-download-dialog-title" aria-labelledby="annotation-download-dialog-title"
id="annotation-download-dialog" id="annotation-download-dialog"
onClose={handleClose} onClose={handleClose}
onEscapeKeyDown={handleClose} onEscapeKeyDown={this.closeDialog}
open={open} open={open}
> >
<DialogTitle id="annotation-download-dialog-title" disableTypography> <DialogTitle id="annotation-download-dialog-title" disableTypography>
<Typography variant="h2">Download Annotations</Typography> <Typography variant="h2">Download Annotations</Typography>
</DialogTitle> </DialogTitle>
<DialogContent> <DialogContent>
{ this.state.downloadLinks === undefined || this.state.downloadLinks.length === 0 ? ( { downloadLinks === undefined || downloadLinks.length === 0 ? (
<Typography variant="body1">No annotations stored yet.</Typography> <Typography variant="body1">No annotations stored yet.</Typography>
) : ( ) : (
<List> <List>
{this.state.downloadLinks.map(dl => ( { downloadLinks.map((dl) => (
<ListItem button <ListItem
button
component="a" component="a"
key={dl.canvasId} key={dl.canvasId}
aria-label={`Download annotations for ${dl.label}`} aria-label={`Download annotations for ${dl.label}`}
...@@ -84,7 +94,7 @@ export class AnnotationDownloadDialog extends Component { ...@@ -84,7 +94,7 @@ export class AnnotationDownloadDialog extends Component {
<GetAppIcon /> <GetAppIcon />
</ListItemIcon> </ListItemIcon>
<ListItemText> <ListItemText>
Download annotations for {dl.label} {`Download annotations for canvas "${dl.label}"`}
</ListItemText> </ListItemText>
</ListItem> </ListItem>
))} ))}
...@@ -92,19 +102,19 @@ export class AnnotationDownloadDialog extends Component { ...@@ -92,19 +102,19 @@ export class AnnotationDownloadDialog extends Component {
)} )}
</DialogContent> </DialogContent>
</Dialog> </Dialog>
) );
} }
} }
AnnotationDownloadDialog.propTypes = { AnnotationDownloadDialog.propTypes = {
canvases: PropTypes.arrayOf( canvases: PropTypes.arrayOf(
PropTypes.shape({ id: PropTypes.string, index: PropTypes.number }), PropTypes.shape({ id: PropTypes.string, index: PropTypes.number }),
), ).isRequired,
config: PropTypes.shape({ config: PropTypes.shape({
annotation: PropTypes.shape({ annotation: PropTypes.shape({
adapter: PropTypes.func, adapter: PropTypes.func,
}), }),
}), }).isRequired,
handleClose: PropTypes.func.isRequired, handleClose: PropTypes.func.isRequired,
open: bool.isRequired, open: bool.isRequired,
} };
...@@ -30,17 +30,22 @@ class MiradorAnnotation extends Component { ...@@ -30,17 +30,22 @@ class MiradorAnnotation extends Component {
}); });
} }
/** */
toggleCanvasDownloadDialog(e) { toggleCanvasDownloadDialog(e) {
const { annotationDownloadDialogOpen } = this.state;
const newState = { const newState = {
annotationDownloadDialogOpen: !this.state.annotationDownloadDialogOpen, annotationDownloadDialogOpen: !annotationDownloadDialogOpen,
} };
this.setState(newState); this.setState(newState);
} }
/** */ /** */
render() { render() {
const { canvases, config, TargetComponent, targetProps } = this.props; const {
const showAnnotationDownloadDialog = config.annotation && config.annotation.downloadCanvasAnnotations; canvases, config, TargetComponent, targetProps,
} = this.props;
const { annotationDownloadDialogOpen } = this.state;
const showDownloadDialog = config.annotation && config.annotation.downloadCanvasAnnotations;
return ( return (
<div> <div>
<TargetComponent <TargetComponent
...@@ -53,7 +58,7 @@ class MiradorAnnotation extends Component { ...@@ -53,7 +58,7 @@ class MiradorAnnotation extends Component {
> >
<AddBoxIcon /> <AddBoxIcon />
</MiradorMenuButton> </MiradorMenuButton>
{ showAnnotationDownloadDialog && ( { showDownloadDialog && (
<MiradorMenuButton <MiradorMenuButton
aria-label="Download annotation page for canvas" aria-label="Download annotation page for canvas"
onClick={this.toggleCanvasDownloadDialog} onClick={this.toggleCanvasDownloadDialog}
...@@ -62,12 +67,12 @@ class MiradorAnnotation extends Component { ...@@ -62,12 +67,12 @@ class MiradorAnnotation extends Component {
<GetAppIcon /> <GetAppIcon />
</MiradorMenuButton> </MiradorMenuButton>
)} )}
{ showAnnotationDownloadDialog && ( { showDownloadDialog && (
<AnnotationDownloadDialog <AnnotationDownloadDialog
canvases={canvases} canvases={canvases}
config={config} config={config}
handleClose={this.toggleCanvasDownloadDialog} handleClose={this.toggleCanvasDownloadDialog}
open={this.state.annotationDownloadDialogOpen} open={annotationDownloadDialogOpen}
/> />
)} )}
</div> </div>
...@@ -79,13 +84,13 @@ MiradorAnnotation.propTypes = { ...@@ -79,13 +84,13 @@ MiradorAnnotation.propTypes = {
addCompanionWindow: PropTypes.func.isRequired, addCompanionWindow: PropTypes.func.isRequired,
canvases: PropTypes.arrayOf( canvases: PropTypes.arrayOf(
PropTypes.shape({ id: PropTypes.string, index: PropTypes.number }), PropTypes.shape({ id: PropTypes.string, index: PropTypes.number }),
), ).isRequired,
config: PropTypes.shape({ config: PropTypes.shape({
annotation: PropTypes.shape({ annotation: PropTypes.shape({
adapter: PropTypes.func, adapter: PropTypes.func,
downloadCanvasAnnotations: PropTypes.bool, downloadCanvasAnnotations: PropTypes.bool,
}), }),
}), }).isRequired,
TargetComponent: PropTypes.oneOfType([ TargetComponent: PropTypes.oneOfType([
PropTypes.func, PropTypes.func,
PropTypes.node, PropTypes.node,
...@@ -100,12 +105,11 @@ const mapDispatchToProps = (dispatch, props) => ({ ...@@ -100,12 +105,11 @@ const mapDispatchToProps = (dispatch, props) => ({
), ),
}); });
const mapStateToProps = function mapStateToProps(state, { targetProps: { windowId } }) { /** */
return { const mapStateToProps = (state, { targetProps: { windowId } }) => ({
canvases: getVisibleCanvases(state, { windowId }), canvases: getVisibleCanvases(state, { windowId }),
config: state.config, config: state.config,
}; });
}
export default { export default {
component: MiradorAnnotation, component: MiradorAnnotation,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment