From d6b3b680cb6322030aa7651fe46ebe0d5c91f8da Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Sun, 25 Jun 2017 23:06:28 -0700 Subject: [PATCH] Logic to force sidebar link update --- .../SidebarCollection/SidebarCollection.js | 26 ++++++++++--------- .../components/SidebarLink/SidebarLink.js | 23 +++++++++++----- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/frontend/components/Layout/components/SidebarCollection/SidebarCollection.js b/frontend/components/Layout/components/SidebarCollection/SidebarCollection.js index 3247bd495..828221186 100644 --- a/frontend/components/Layout/components/SidebarCollection/SidebarCollection.js +++ b/frontend/components/Layout/components/SidebarCollection/SidebarCollection.js @@ -20,18 +20,20 @@ class SidebarCollection extends React.Component { renderDocuments(documentList) { const { document } = this.props; - return documentList.map(doc => ( - - - {doc.title} - - {} - {(document.pathToDocument.includes(doc.id) || document.id === doc.id) && - - {doc.children && this.renderDocuments(doc.children)} - } - - )); + if (document) { + return documentList.map(doc => ( + + + {doc.title} + + {(document.pathToDocument.includes(doc.id) || + document.id === doc.id) && + + {doc.children && this.renderDocuments(doc.children)} + } + + )); + } } render() { diff --git a/frontend/components/Layout/components/SidebarLink/SidebarLink.js b/frontend/components/Layout/components/SidebarLink/SidebarLink.js index 73543635f..df60708c4 100644 --- a/frontend/components/Layout/components/SidebarLink/SidebarLink.js +++ b/frontend/components/Layout/components/SidebarLink/SidebarLink.js @@ -1,7 +1,7 @@ // @flow import React from 'react'; import { observer } from 'mobx-react'; -import { NavLink } from 'react-router-dom'; +import { NavLink, withRouter } from 'react-router-dom'; import { Flex } from 'reflexbox'; import styled from 'styled-components'; @@ -9,11 +9,20 @@ const activeStyle = { color: '#000000', }; -const SidebarLink = observer(props => ( - - - -)); +@observer class SidebarLink extends React.Component { + shouldComponentUpdate(nextProps) { + // Navlink is having issues updating, forcing update on URL changes + return this.props.match !== nextProps.match; + } + + render() { + return ( + + + + ); + } +} const LinkContainer = styled(Flex)` padding: 5px 0; @@ -23,4 +32,4 @@ const LinkContainer = styled(Flex)` } `; -export default SidebarLink; +export default withRouter(SidebarLink);