Bundle event handlers into a separate structure

This commit is contained in:
Przemek Wiech
2019-05-21 18:27:05 +02:00
parent 2598d35caf
commit dfd58ea8af
2 changed files with 45 additions and 25 deletions

View File

@@ -272,6 +272,26 @@ export class App extends React.Component<RouteComponentProps, {}> {
this.props.history.push(location);
};
private onPrint = () => {
analyticsEvent('print');
this.chartRef && this.chartRef.print();
};
private onDownloadPdf = () => {
analyticsEvent('download_pdf');
this.chartRef && this.chartRef.downloadPdf();
};
private onDownloadPng = () => {
analyticsEvent('download_png');
this.chartRef && this.chartRef.downloadPng();
};
private onDownloadSvg = () => {
analyticsEvent('download_svg');
this.chartRef && this.chartRef.downloadSvg();
};
private renderMainArea = () => {
if (this.state.data && this.state.selection) {
return (
@@ -316,22 +336,12 @@ export class App extends React.Component<RouteComponentProps, {}> {
)
}
standalone={this.state.standalone}
onSelection={this.onSelection}
onPrint={() => {
analyticsEvent('print');
this.chartRef && this.chartRef.print();
}}
onDownloadPdf={() => {
analyticsEvent('download_pdf');
this.chartRef && this.chartRef.downloadPdf();
}}
onDownloadPng={() => {
analyticsEvent('download_png');
this.chartRef && this.chartRef.downloadPng();
}}
onDownloadSvg={() => {
analyticsEvent('download_svg');
this.chartRef && this.chartRef.downloadSvg();
eventHandlers={{
onSelection: this.onSelection,
onPrint: this.onPrint,
onDownloadPdf: this.onDownloadPdf,
onDownloadPng: this.onDownloadPng,
onDownloadSvg: this.onDownloadSvg,
}}
/>
)}