@@ -62,6 +62,7 @@ export interface Props {
62
62
background ?: boolean ;
63
63
hover ?: boolean ;
64
64
stateToShare ?: StateToShare ;
65
+ download ?: boolean ;
65
66
}
66
67
67
68
export interface State {
@@ -109,14 +110,9 @@ export default class ChartShare extends React.Component<Props, State> {
109
110
110
111
return this . setState ( { link : shortURL } ) ;
111
112
}
112
- // tslint:disable jsx-no-lambda
113
+ // tslint:disable jsx-no-lambda
113
114
public render ( ) {
114
115
const { className, size, color, label, background, hover, fontSize, iconName, fontWeight } = this . props ;
115
- let url = '' ;
116
- if ( this . props . stateToShare && this . props . stateToShare . indicator ) {
117
- const indicator = this . props . stateToShare . indicator . split ( '.' ) [ 1 ] . replace ( / - / g, '_' ) ;
118
- url = `${ getWarehouseAPILink } /single_table?indicator=${ indicator } &format=csv` ;
119
- }
120
116
121
117
return (
122
118
< Modal
@@ -129,10 +125,7 @@ export default class ChartShare extends React.Component<Props, State> {
129
125
{ label || 'Share this chart' }
130
126
</ Span >
131
127
</ Button >
132
- < a href = { url } className = "ui medium button" onClick = { this . stopPropagation } >
133
- < i aria-hidden = "true" className = "download alternate icon" />
134
- Download Data
135
- </ a >
128
+ { this . renderDownloadButton ( ) }
136
129
</ Button . Group >
137
130
</ ButtonWrapper >
138
131
}
@@ -174,6 +167,25 @@ export default class ChartShare extends React.Component<Props, State> {
174
167
</ Modal > ) ;
175
168
}
176
169
170
+ private renderDownloadButton ( ) {
171
+ if ( this . props . download ) {
172
+ let url = '' ;
173
+ if ( this . props . stateToShare && this . props . stateToShare . indicator ) {
174
+ const indicator = this . props . stateToShare . indicator . split ( '.' ) [ 1 ] . replace ( / - / g, '_' ) ;
175
+ url = `${ getWarehouseAPILink } /single_table?indicator=${ indicator } &format=csv` ;
176
+ }
177
+
178
+ return (
179
+ < a href = { url } className = "ui medium button" onClick = { this . stopPropagation } >
180
+ < i aria-hidden = "true" className = "download alternate icon" />
181
+ Download Data
182
+ </ a >
183
+ ) ;
184
+ }
185
+
186
+ return null ;
187
+ }
188
+
177
189
private updateShareAnalytics ( source : 'facebook' | 'twitter' | 'mail' ) {
178
190
if ( ( window as any ) . gtag ) {
179
191
( window as any ) . gtag ( 'event' , 'share' , {
0 commit comments