From c9bfb467d72eaad6708e9bdf6ceaed109ee71411 Mon Sep 17 00:00:00 2001 From: Christoph Anderson <37236531+lupusA@users.noreply.github.com> Date: Thu, 14 Sep 2023 21:56:13 +0200 Subject: [PATCH] fix(ui): Fixed error while rendering source table (#188) * Fixed error while rendering. Setting the state is not allowed there. * No double call of setState() needed --------- Co-authored-by: Christoph Anderson --- src/App.jsx | 13 ++++++------- src/SourcesTable.jsx | 20 ++++++++------------ 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index fcf7551..cf3410d 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -64,14 +64,13 @@ export default class App extends Component { } fetchTaskSummary() { - if( ! this.state.isFetching ) - { + if (!this.state.isFetching) { this.setState({ isFetching: true }); - axios.get('/api/v1/tasks-summary').then(result => { - this.setState({ isFetching: false, runningTaskCount: result.data["RUNNING"] || 0 }); - }).catch(error => { - this.setState({ isFetching: false, runningTaskCount: -1 }); - }); + axios.get('/api/v1/tasks-summary').then(result => { + this.setState({ isFetching: false, runningTaskCount: result.data["RUNNING"] || 0 }); + }).catch(error => { + this.setState({ isFetching: false, runningTaskCount: -1 }); + }); } } diff --git a/src/SourcesTable.jsx b/src/SourcesTable.jsx index 6aefb10..db3ebe0 100644 --- a/src/SourcesTable.jsx +++ b/src/SourcesTable.jsx @@ -43,7 +43,8 @@ export class SourcesTable extends Component { } componentDidMount() { - this.setState({ isLoading: true }); + const { defaultSnapshotViewAll } = this.context; + this.setState({ isLoading: true, selectedOwner: defaultSnapshotViewAll ? allSnapshots : localSnapshots }); this.fetchSourcesWithoutSpinner(); this.interval = window.setInterval(this.fetchSourcesWithoutSpinner, 3000); } @@ -53,7 +54,7 @@ export class SourcesTable extends Component { } fetchSourcesWithoutSpinner() { - if( ! this.state.isFetching ){ + if (!this.state.isFetching) { this.setState({ isFetching: true, }); @@ -78,14 +79,12 @@ export class SourcesTable extends Component { } } - selectOwner(h) { + selectOwner(owner) { const { setDefaultSnapshotViewAll } = this.context; - this.setState({ - selectedOwner: h, - }); - if (h === localSnapshots) { + this.setState({ selectedOwner: owner }); + if (owner === localSnapshots) { setDefaultSnapshotViewAll(false); - } else if (h === allSnapshots) { + } else if (owner === allSnapshots) { setDefaultSnapshotViewAll(true); } } @@ -217,16 +216,13 @@ export class SourcesTable extends Component { render() { let { sources, isLoading, error } = this.state; - const { bytesStringBase2, defaultSnapshotViewAll } = this.context + const { bytesStringBase2 } = this.context if (error) { return

{error.message}

; } if (isLoading) { return ; } - if (this.state.selectedOwner == null) { - this.setState({ selectedOwner: defaultSnapshotViewAll ? allSnapshots : localSnapshots}) - } let uniqueOwners = sources.reduce((a, d) => { const owner = ownerName(d.source);