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 {
}
}
componentDidMount = () => this.fetchData()
componentDidMount = () => this.fetchTableData()
componentDidUpdate = prevProps => {
if (prevProps.routeProps.location !== this.props.routeProps.location) {
this.fetchData()
// handle the case when the TABLE tab was not originally active
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 = ''
const base = 'http://ldf.fi/mmm'
const locationArr = this.props.routeProps.location.pathname.split('/')
......@@ -131,7 +134,7 @@ class InstanceHomePage extends React.Component {
render = () => {
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 (
<div className={classes.root}>
<PerspectiveTabs
......@@ -144,13 +147,14 @@ class InstanceHomePage extends React.Component {
<div className={classes.spinnerContainer}>
<CircularProgress style={{ color: purple[500] }} thickness={5} />
</div>}
{!hasData &&
{!hasTableData &&
<>
<Typography variant='h6'>
No data found for id: <span style={{ fontStyle: 'italic' }}>{this.state.localID}</span>
</Typography>
</>}
{hasData &&
{/* make sure that tableData exists before rendering any components */}
{hasTableData &&
<>
<Route
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