Skip to content
Snippets Groups Projects
Commit 09ff2832 authored by esikkala's avatar esikkala
Browse files

InstanceHomePage: fix componentDidUpdate

parent 97fc15cb
No related branches found
No related tags found
No related merge requests found
...@@ -46,15 +46,18 @@ class InstanceHomePage extends React.Component { ...@@ -46,15 +46,18 @@ class InstanceHomePage extends React.Component {
} }
} }
componentDidMount = () => this.fetchData() componentDidMount = () => this.fetchTableData()
componentDidUpdate = prevProps => { componentDidUpdate = prevProps => {
if (prevProps.routeProps.location !== this.props.routeProps.location) { // handle the case when the TABLE tab was not originally active
this.fetchData() const prevPathname = prevProps.routeProps.location.pathname
const currentPathname = this.props.routeProps.location.pathname
if (prevPathname !== currentPathname && currentPathname.endsWith('table')) {
this.fetchTableData()
} }
} }
fetchData = () => { fetchTableData = () => {
let uri = '' let uri = ''
const base = 'http://ldf.fi/mmm' const base = 'http://ldf.fi/mmm'
const locationArr = this.props.routeProps.location.pathname.split('/') const locationArr = this.props.routeProps.location.pathname.split('/')
...@@ -131,7 +134,7 @@ class InstanceHomePage extends React.Component { ...@@ -131,7 +134,7 @@ class InstanceHomePage extends React.Component {
render = () => { render = () => {
const { classes, tableData, isLoading, resultClass, rootUrl } = this.props const { classes, tableData, isLoading, resultClass, rootUrl } = this.props
const hasData = tableData !== null && Object.values(tableData).length >= 1 const hasTableData = tableData !== null && Object.values(tableData).length >= 1
return ( return (
<div className={classes.root}> <div className={classes.root}>
<PerspectiveTabs <PerspectiveTabs
...@@ -144,13 +147,14 @@ class InstanceHomePage extends React.Component { ...@@ -144,13 +147,14 @@ class InstanceHomePage extends React.Component {
<div className={classes.spinnerContainer}> <div className={classes.spinnerContainer}>
<CircularProgress style={{ color: purple[500] }} thickness={5} /> <CircularProgress style={{ color: purple[500] }} thickness={5} />
</div>} </div>}
{!hasData && {!hasTableData &&
<> <>
<Typography variant='h6'> <Typography variant='h6'>
No data found for id: <span style={{ fontStyle: 'italic' }}>{this.state.localID}</span> No data found for id: <span style={{ fontStyle: 'italic' }}>{this.state.localID}</span>
</Typography> </Typography>
</>} </>}
{hasData && {/* make sure that tableData exists before rendering any components */}
{hasTableData &&
<> <>
<Route <Route
exact path={`${rootUrl}/${resultClass}/page/${this.state.localID}`} exact path={`${rootUrl}/${resultClass}/page/${this.state.localID}`}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment