@@ -16,6 +16,8 @@ import React, {Component, FC} from 'react'
1616import { connect } from 'react-redux'
1717import { getOrg } from 'src/organizations/selectors'
1818
19+ import { getOrg as fetchOrg } from 'src/organizations/apis'
20+
1921import { withRouter , RouteComponentProps } from 'react-router-dom'
2022
2123import { AppState , Organization } from 'src/types'
@@ -142,25 +144,44 @@ const NotFoundOld: FC = () => (
142144)
143145
144146class NotFound extends Component < Props > {
145- componentDidMount ( ) {
147+ state = {
148+ isFetchingOrg : false ,
149+ }
150+
151+ async componentDidMount ( ) {
146152 if ( isFlagEnabled ( 'deepLinking' ) ) {
153+ let org = this . props ?. org
154+
155+ if ( ! org ) {
156+ this . setState ( { isFetchingOrg : true } )
157+ org = await fetchOrg ( )
158+ }
159+
147160 const deepLinkingMap = {
148- '/me/alerts' : `/orgs/${ this . props . org . id } /alerting` ,
149- '/me/billing' : `/orgs/${ this . props . org . id } /billing` ,
150- '/me/dashboards' : `/orgs/${ this . props . org . id } /dashboards-list` ,
151- '/me/notebooks' : `/orgs/${ this . props . org . id } /notebooks` ,
152- '/me/tasks' : `/orgs/${ this . props . org . id } /tasks` ,
153- '/me/usage' : `/orgs/${ this . props . org . id } /usage` ,
161+ '/me/alerts' : `/orgs/${ org . id } /alerting` ,
162+ '/me/billing' : `/orgs/${ org . id } /billing` ,
163+ '/me/dashboards' : `/orgs/${ org . id } /dashboards-list` ,
164+ '/me/notebooks' : `/orgs/${ org . id } /notebooks` ,
165+ '/me/tasks' : `/orgs/${ org . id } /tasks` ,
166+ '/me/usage' : `/orgs/${ org . id } /usage` ,
154167 }
155168
156169 if ( deepLinkingMap . hasOwnProperty ( this . props . location . pathname ) ) {
157170 this . props . history . replace ( deepLinkingMap [ this . props . location . pathname ] )
158171 return
172+ } else {
173+ this . setState ( { isFetchingOrg : false } )
159174 }
160175 }
161176 }
162177
163178 render ( ) {
179+ if ( this . state . isFetchingOrg ) {
180+ // don't render anything if this component is actively fetching org id
181+ // this prevents popping in a 404 page then redirecting
182+ return null
183+ }
184+
164185 if ( isFlagEnabled ( 'newNotFoundPage' ) ) {
165186 return < NotFoundNew />
166187 }
0 commit comments