/* Usage: <%= react_component("DocumentEntitiesSidebar", { document_id: 3, linked_entities: { 'Character' => [], ... } }) %> */ import React from "react" import PropTypes from "prop-types" import DocumentEntityLinkModal from './DocumentEntityLinkModal.js'; import PageLookupSidebar from './PageLookupSidebar.js'; var pluralize = require('pluralize'); class DocumentEntitiesSidebar extends React.Component { constructor(props) { super(props); this.state = { linked_entities: this.props.linked_entities }; } classIcon(class_name) { return window.ContentTypeData[class_name].icon; } classColor(class_name) { return window.ContentTypeData[class_name].color; } componentDidMount() { // We have a setTimeout call here because materializecss's initializer isn't playing well with // the component lifecycle. Calling sidenav() in componentDidMount() produces several graphical // errors (sliding in from the center of the screen, overlapping the doc editor when closed, etc) // so we're just doing this for now instead. // // Implications of this hack: for the first second after mounting this component, a user opening // this component will have it open on the left side of the screen instead of the right side. Then, // when this timeout triggers, the sidebar will close. Reopening it will open it on the right side // of the screen. // // It's also possible some slow computers/internets might have issues that would require longer than // one second of waiting, but in that case we just default to opening this sidenav on the left side // of the screen (default sidenav behavior) instead of the right side. setTimeout(function () { $('#document-entities-right').sidenav({ closeOnClick: true, edge: 'right', draggable: false }); }, 1000); } lookupPage(content_type, content_id) { // console.log('loading page: ' + content_type + ' ' + content_id); this.refs.PageLookupSidebar.loadPage(content_type, content_id); } render () { return ( ); } } DocumentEntitiesSidebar.propTypes = { linked_entities: PropTypes.object.isRequired, link_form_path: PropTypes.string.isRequired }; export default DocumentEntitiesSidebar;