Skip to content

Commit

Permalink
fix(dashboard): Prevent char overflow when displaying chart descripti…
Browse files Browse the repository at this point in the history
…on (apache#14467)

* Force refresh the chart on toggle display description

* Use forceUpdate instead of forceRefresh

* Instead of forceUpdate, add a state for desciption height

Co-authored-by: Ajay Mancheery <ajaymancheery@Ajays-MacBook-Pro.local>
  • Loading branch information
2 people authored and cccs-RyanS committed Dec 17, 2021
1 parent b5539d9 commit 47cf57f
Showing 1 changed file with 15 additions and 7 deletions.
Expand Up @@ -101,6 +101,7 @@ export default class Chart extends React.Component {
this.state = {
width: props.width,
height: props.height,
descriptionHeight: 0,
};

this.changeFilter = this.changeFilter.bind(this);
Expand All @@ -120,7 +121,8 @@ export default class Chart extends React.Component {
// which improves performance significantly
if (
nextState.width !== this.state.width ||
nextState.height !== this.state.height
nextState.height !== this.state.height ||
nextState.descriptionHeight !== this.state.descriptionHeight
) {
return true;
}
Expand Down Expand Up @@ -164,14 +166,20 @@ export default class Chart extends React.Component {
clearTimeout(this.resizeTimeout);
}

componentDidUpdate(prevProps) {
if (this.props.isExpanded !== prevProps.isExpanded) {
const descriptionHeight =
this.props.isExpanded && this.descriptionRef
? this.descriptionRef.offsetHeight
: 0;
// eslint-disable-next-line react/no-did-update-set-state
this.setState({ descriptionHeight });
}
}

getChartHeight() {
const headerHeight = this.getHeaderHeight();
const descriptionHeight =
this.props.isExpanded && this.descriptionRef
? this.descriptionRef.offsetHeight
: 0;

return this.state.height - headerHeight - descriptionHeight;
return this.state.height - headerHeight - this.state.descriptionHeight;
}

getHeaderHeight() {
Expand Down

0 comments on commit 47cf57f

Please sign in to comment.