@@ -5,6 +5,7 @@ import React from 'react'
55import PT from 'prop-types'
66import _ from 'lodash'
77import uncontrollable from 'uncontrollable'
8+ import { withRouter } from 'react-router-dom'
89
910import { formatNumberWithCommas } from '../../../helpers/format'
1011import { getPhaseActualData } from '../../../helpers/projectHelper'
@@ -22,7 +23,6 @@ import ProductTimelineContainer from '../containers/ProductTimelineContainer'
2223import NotificationsReader from '../../../components/NotificationsReader'
2324import { phaseFeedHOC } from '../containers/PhaseFeedHOC'
2425import spinnerWhileLoading from '../../../components/LoadingSpinner'
25- import { scrollToHash } from '../../../components/ScrollToAnchors'
2626
2727const enhance = spinnerWhileLoading ( props => ! props . processing )
2828const EnhancedEditProjectForm = enhance ( EditProjectForm )
@@ -130,23 +130,28 @@ class ProjectStage extends React.Component{
130130 expandProjectPhase ( phase . id , tab )
131131 }
132132
133- componentDidUpdate ( ) {
134- const { phaseState } = this . props
135- if ( _ . get ( phaseState , 'isExpanded' ) ) {
136- const scrollTo = window . location . hash ? window . location . hash . substring ( 1 ) : null
137- if ( scrollTo ) {
138- scrollToHash ( scrollTo )
139- }
140- }
133+ componentDidMount ( ) {
134+ ! _ . isEmpty ( this . props . location . hash ) && this . handleUrlHash ( this . props )
141135 }
142136
143- componentWillReceiveProps ( nextProps ) {
144- const { feedId, commentId, phase, phaseState, expandProjectPhase } = this . props
145- const { feed } = nextProps
146- if ( ! _ . get ( phaseState , 'isExpanded' ) && feed && ( feed . id === parseInt ( feedId ) || feed . postIds . includes ( parseInt ( commentId ) ) ) ) {
147- expandProjectPhase ( phase . id , 'posts' )
137+ componentDidUpdate ( prevProps ) {
138+ const { location } = this . props
139+ if ( ! _ . isEmpty ( location . hash ) && location . hash !== prevProps . location . hash ) {
140+ this . handleUrlHash ( this . props )
148141 }
142+ }
143+
144+ // expand a phase if necessary depending on the url hash
145+ handleUrlHash ( props ) {
146+ const { expandProjectPhase, phase, location } = props
149147
148+ const hashParts = _ . split ( location . hash . substring ( 1 ) , '-' )
149+ const phaseId = hashParts [ 0 ] === 'phase' ? parseInt ( hashParts [ 1 ] , 10 ) : null
150+
151+ if ( phaseId && phase . id === phaseId ) {
152+ const tab = hashParts [ 2 ]
153+ expandProjectPhase ( phaseId , tab )
154+ }
150155 }
151156
152157 render ( ) {
@@ -169,6 +174,7 @@ class ProjectStage extends React.Component{
169174 collapseProjectPhase,
170175 expandProjectPhase,
171176 commentAnchorPrefix,
177+ isLoading,
172178
173179 // comes from phaseFeedHOC
174180 currentUser,
@@ -253,6 +259,8 @@ class ProjectStage extends React.Component{
253259 projectMembers = { projectMembers }
254260 onSaveMessage = { onSaveMessage }
255261 commentAnchorPrefix = { commentAnchorPrefix }
262+ phaseId = { phase . id }
263+ isLoading = { isLoading }
256264 />
257265 ) }
258266
@@ -278,6 +286,7 @@ class ProjectStage extends React.Component{
278286 removeAttachment = { this . removeProductAttachment }
279287 attachmentsStorePath = { attachmentsStorePath }
280288 canManageAttachments = { ! ! currentMemberRole }
289+ disableAutoScrolling
281290 />
282291 </ div >
283292 }
@@ -311,7 +320,7 @@ ProjectStage.propTypes = {
311320 commentAnchorPrefix : PT . string ,
312321}
313322
314- const ProjectStageUncontrollable = uncontrollable ( ProjectStage , {
323+ const ProjectStageUncontrollable = uncontrollable ( withRouter ( ProjectStage ) , {
315324 activeTab : 'onTabClick' ,
316325} )
317326
0 commit comments