Skip to content

Commit 8a1492e

Browse files
committed
[Fix] make download button on ChartShare optional #485
1 parent 786ebcd commit 8a1492e

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/components/molecules/ChartShare/index.tsx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export interface Props {
6262
background?: boolean;
6363
hover?: boolean;
6464
stateToShare?: StateToShare;
65+
download?: boolean;
6566
}
6667

6768
export interface State {
@@ -109,14 +110,9 @@ export default class ChartShare extends React.Component<Props, State> {
109110

110111
return this.setState({ link: shortURL });
111112
}
112-
// tslint:disable jsx-no-lambda
113+
// tslint:disable jsx-no-lambda
113114
public render() {
114115
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-
}
120116

121117
return (
122118
<Modal
@@ -129,10 +125,7 @@ export default class ChartShare extends React.Component<Props, State> {
129125
{ label || 'Share this chart' }
130126
</Span>
131127
</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() }
136129
</Button.Group>
137130
</ButtonWrapper>
138131
}
@@ -174,6 +167,25 @@ export default class ChartShare extends React.Component<Props, State> {
174167
</Modal>);
175168
}
176169

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+
177189
private updateShareAnalytics(source: 'facebook' | 'twitter' | 'mail') {
178190
if ((window as any).gtag) {
179191
(window as any).gtag('event', 'share', {

src/components/molecules/Maps/Map/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class Map extends React.Component<Props, State> {
151151
year: this.state.currentYear,
152152
indicator: this.meta.id
153153
} }
154+
download
154155
/>
155156
</Div>
156157
</Intro>

0 commit comments

Comments
 (0)