Skip to content

Commit b61a348

Browse files
committed
[New] add button to download global picture data from the DDW API #485
1 parent a182801 commit b61a348

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

src/components/molecules/ChartShare/index.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Button, Icon, Modal, SemanticICONS } from 'semantic-ui-react';
33
import { black, lightSecondaryColor, white } from '../../theme/semantic';
44
import { getShortURL } from '@devinit/prelude/lib/misc';
55
import glamorous, { Div, Span } from 'glamorous';
6+
import { getWarehouseAPILink } from '../../../utils';
67

78
export const NoBackground = {
89
'& .no-background:hover': {
@@ -79,6 +80,8 @@ export default class ChartShare extends React.Component<Props, State> {
7980
};
8081
constructor(props: Props) {
8182
super(props);
83+
84+
this.stopPropagation = this.stopPropagation.bind(this);
8285
}
8386
public componentDidMount() {
8487
this.createLink(this.props);
@@ -109,17 +112,28 @@ export default class ChartShare extends React.Component<Props, State> {
109112
// tslint:disable jsx-no-lambda
110113
public render() {
111114
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+
}
112120

113121
return (
114122
<Modal
115123
trigger={
116124
<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>
123137
</ButtonWrapper>
124138
}
125139
size="tiny"
@@ -168,4 +182,8 @@ export default class ChartShare extends React.Component<Props, State> {
168182
});
169183
}
170184
}
185+
186+
private stopPropagation(event: React.MouseEvent<HTMLAnchorElement>) {
187+
event.stopPropagation();
188+
}
171189
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ class Map extends React.Component<Props, State> {
144144
<Intro step={ 7 } intro={ howTo.globalPicture.share }>
145145
<Div paddingBottom="2em">
146146
<ChartShare
147-
size="big"
147+
size="medium"
148148
color="black"
149+
fontWeight="normal"
149150
stateToShare={ {
150151
year: this.state.currentYear,
151152
indicator: this.meta.id

src/utils/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export interface PageMeta {
2727
height?: string;
2828
}
2929

30+
export const getWarehouseAPILink = 'http://212.111.41.68:8000';
31+
3032
export const createLinkMeta = (args: PageMetaArgs, obj: MenuItem): PageMeta => {
3133
let title = obj.name;
3234
if (obj.link === '/uganda') {

0 commit comments

Comments
 (0)