@@ -3,6 +3,7 @@ import { Button, Icon, Modal, SemanticICONS } from 'semantic-ui-react';
3
3
import { black , lightSecondaryColor , white } from '../../theme/semantic' ;
4
4
import { getShortURL } from '@devinit/prelude/lib/misc' ;
5
5
import glamorous , { Div , Span } from 'glamorous' ;
6
+ import { getWarehouseAPILink } from '../../../utils' ;
6
7
7
8
export const NoBackground = {
8
9
'& .no-background:hover' : {
@@ -79,6 +80,8 @@ export default class ChartShare extends React.Component<Props, State> {
79
80
} ;
80
81
constructor ( props : Props ) {
81
82
super ( props ) ;
83
+
84
+ this . stopPropagation = this . stopPropagation . bind ( this ) ;
82
85
}
83
86
public componentDidMount ( ) {
84
87
this . createLink ( this . props ) ;
@@ -109,17 +112,28 @@ export default class ChartShare extends React.Component<Props, State> {
109
112
// tslint:disable jsx-no-lambda
110
113
public render ( ) {
111
114
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
+ }
112
120
113
121
return (
114
122
< Modal
115
123
trigger = {
116
124
< ButtonWrapper background = { background } hover = { hover } >
117
- < Button className = { className } size = { size } color = { color } >
118
- < Icon name = { iconName || 'share alternate' } />
119
- < Span fontWeight = { fontWeight || 'normal' } fontSize = { fontSize || '1em' } >
120
- { label || 'Share this chart' }
121
- </ Span >
122
- </ Button >
125
+ < Button . Group >
126
+ < Button className = { className } size = { size } color = { color } >
127
+ < Icon name = { iconName || 'share alternate' } />
128
+ < Span fontWeight = { fontWeight || 'normal' } fontSize = { fontSize || '1em' } >
129
+ { label || 'Share this chart' }
130
+ </ Span >
131
+ </ 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 >
136
+ </ Button . Group >
123
137
</ ButtonWrapper >
124
138
}
125
139
size = "tiny"
@@ -168,4 +182,8 @@ export default class ChartShare extends React.Component<Props, State> {
168
182
} ) ;
169
183
}
170
184
}
185
+
186
+ private stopPropagation ( event : React . MouseEvent < HTMLAnchorElement > ) {
187
+ event . stopPropagation ( ) ;
188
+ }
171
189
}
0 commit comments