Skip to content

Commit

Permalink
perf(services): avoid rerenders for progress bars
Browse files Browse the repository at this point in the history
Closes DCOS-51377
  • Loading branch information
Daniel Schmidt committed Apr 9, 2019
1 parent 0ed91c3 commit a03443f
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions plugins/services/src/js/components/ServiceStatusProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,36 @@ interface ServiceStatusProgressBarProps {
service: Service | ServiceTree | Pod;
}

const ServiceProgressBar = React.memo(
({
instancesCount,
runningInstances
}: {
instancesCount: number;
runningInstances: number;
}) => (
<Tooltip
interactive={true}
content={
<div className="tooltip-line-item">
<Plural
render="span"
value={runningInstances}
one={`# instance running out of ${instancesCount}`}
other={`# instances running out of ${instancesCount}`}
/>
</div>
}
>
<ProgressBar
className="status-bar--large staged"
data={ProgressBar.getDataFromValue(runningInstances, "success")}
total={instancesCount}
/>
</Tooltip>
)
);

class ServiceStatusProgressBar extends React.Component<
ServiceStatusProgressBarProps
> {
Expand All @@ -25,23 +55,6 @@ class ServiceStatusProgressBar extends React.Component<
]).isRequired
};

getTooltipContent() {
const { service } = this.props;
const runningInstances = service.getRunningInstancesCount();
const instancesTotal = service.getInstancesCount();

return (
<div className="tooltip-line-item">
<Plural
render="span"
value={runningInstances}
one={`# instance running out of ${instancesTotal}`}
other={`# instances running out of ${instancesTotal}`}
/>
</div>
);
}

render() {
const { service } = this.props;
const instancesCount = service.getInstancesCount();
Expand All @@ -52,18 +65,10 @@ class ServiceStatusProgressBar extends React.Component<
}

return (
<Tooltip interactive={true} content={this.getTooltipContent()}>
<ProgressBar
className="status-bar--large staged"
data={[
{
className: "success",
value: runningInstances
}
]}
total={instancesCount}
/>
</Tooltip>
<ServiceProgressBar
instancesCount={instancesCount}
runningInstances={runningInstances}
/>
);
}
}
Expand Down

0 comments on commit a03443f

Please sign in to comment.