Skip to content

Commit

Permalink
fix(ui): Fixed error while rendering source table (#188)
Browse files Browse the repository at this point in the history
* Fixed error while rendering. Setting the state is
not allowed there.

* No double call of setState() needed

---------

Co-authored-by: Christoph Anderson <[email protected]>
  • Loading branch information
lupusA and lupusA authored Sep 14, 2023
1 parent 6e931fd commit c9bfb46
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
13 changes: 6 additions & 7 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
}
}

Expand Down
20 changes: 8 additions & 12 deletions src/SourcesTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -53,7 +54,7 @@ export class SourcesTable extends Component {
}

fetchSourcesWithoutSpinner() {
if( ! this.state.isFetching ){
if (!this.state.isFetching) {
this.setState({
isFetching: true,
});
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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 <p>{error.message}</p>;
}
if (isLoading) {
return <Spinner animation="border" variant="primary" />;
}
if (this.state.selectedOwner == null) {
this.setState({ selectedOwner: defaultSnapshotViewAll ? allSnapshots : localSnapshots})
}
let uniqueOwners = sources.reduce((a, d) => {
const owner = ownerName(d.source);

Expand Down

0 comments on commit c9bfb46

Please sign in to comment.