Skip to content

Commit dde0497

Browse files
authored
Merge pull request #3325 from Vizzuality/feature/embed-buttons-and-footer
Feature/embed buttons and footer
2 parents 26449d8 + f990a8a commit dde0497

File tree

17 files changed

+144
-51
lines changed

17 files changed

+144
-51
lines changed

app/javascript/components/button/button-styles.scss

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ $button-height: rem(40px);
1616
color: $white;
1717
cursor: pointer;
1818
transition: background-color 150ms ease-out;
19+
text-decoration: none;
1920

2021
&:hover {
2122
background-color: darken($green-gfw, 10%);

app/javascript/pages/country/widget/components/widget-header/widget-header-component.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ class WidgetHeader extends PureComponent {
107107
{widgetSize !== 'small' && !isDeviceTouch && 'SHOW ON MAP'}
108108
</Button>
109109
)}
110-
{!embed &&
111-
settingsConfig &&
110+
{settingsConfig &&
112111
!isEmpty(settingsConfig.options) && (
113112
<Tooltip
114113
theme="light"

app/javascript/pages/country/widget/components/widget-header/widget-header.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { connect } from 'react-redux';
2-
import compact from 'lodash/compact';
32
import moment from 'moment';
43

54
import shareActions from 'components/share/share-actions';
@@ -17,9 +16,10 @@ const actions = {
1716

1817
const mapStateToProps = ({ location, modalMeta }, ownProps) => {
1918
const { locationNames, widget, title, settingsConfig } = ownProps;
20-
const locationUrl = compact(
21-
Object.keys(location.payload).map(key => location.payload[key])
22-
).join('/');
19+
const locationUrl = `${location.payload.country}${
20+
location.payload.region ? `/${location.payload.region}` : ''
21+
}${location.payload.subRegion ? `/${location.payload.subRegion}` : ''}`;
22+
2323
const embedUrl = `${
2424
window.location.origin
2525
}/country/embed/${widget}/${locationUrl}${
@@ -42,11 +42,13 @@ const mapStateToProps = ({ location, modalMeta }, ownProps) => {
4242
subtitle: `${title} in ${
4343
locationNames.current ? locationNames.current.label : ''
4444
}`,
45-
shareUrl: `http://${window.location.host}${window.location.pathname}?${
46-
location && location.category && location.query.category
47-
? `category=${location.query.category}&`
45+
shareUrl: `http://${
46+
window.location.host
47+
}/country/${locationUrl}?widget=${widget}${
48+
location.query && location.query[widget]
49+
? `&${widget}=${location.query[widget]}`
4850
: ''
49-
}${`widget=${widget}`}#${widget}`,
51+
}#${widget}`,
5052
embedUrl,
5153
embedSettings:
5254
settingsConfig.config.size === 'small'

app/javascript/pages/country/widget/components/widget-horizontal-bar-chart/custom-tick-component.jsx

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { format } from 'd3-format';
4+
import Link from 'redux-first-router-link';
45

56
const CustomTick = ({ x, y, index, yAxisDotFill, data, settings }) => {
6-
const { region, path, rank, total } = data[index];
7+
const { region, path, rank, total, extLink } = data[index];
78
const { page, pageSize } = settings;
89
const number = rank || index + 1 + pageSize * page;
910
return (
@@ -19,10 +20,17 @@ const CustomTick = ({ x, y, index, yAxisDotFill, data, settings }) => {
1920
{number}
2021
</text>
2122
<text x="8" y="-16" textAnchor="start" fontSize="12px" fill="#555555">
22-
<a href={path}>
23-
{region} - {format('.1f')(total)}%{' '}
24-
{index === 0 ? 'are plantations' : ''}
25-
</a>
23+
{extLink ? (
24+
<a href={path} target="_blank" rel="noopener nofollower">
25+
{region} - {format('.1f')(total)}%{' '}
26+
{index === 0 ? 'are plantations' : ''}
27+
</a>
28+
) : (
29+
<Link to={path}>
30+
{region} - {format('.1f')(total)}%{' '}
31+
{index === 0 ? 'are plantations' : ''}
32+
</Link>
33+
)}
2634
</text>
2735
</g>
2836
);

app/javascript/pages/country/widget/components/widget-numbered-list/widget-numbered-list-component.jsx

+30-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class WidgetNumberedList extends PureComponent {
1414
data,
1515
settings,
1616
handlePageChange,
17-
linksDisabled
17+
linksDisabled,
18+
linksExt
1819
} = this.props;
1920
const { page, pageSize, unit, unitFormat } = settings;
2021
const pageData = pageSize
@@ -25,12 +26,9 @@ class WidgetNumberedList extends PureComponent {
2526
<div className={`c-widget-numbered-list ${className}`}>
2627
<ul className="list">
2728
{data.length > 0 &&
28-
pageData.map((item, index) => (
29-
<li key={`${item.label}-${item.id}`}>
30-
<Link
31-
className={`list-item ${linksDisabled ? 'disabled' : ''}`}
32-
to={item.path}
33-
>
29+
pageData.map((item, index) => {
30+
const linkContent = (
31+
<div className="list-item">
3432
<div className="item-label">
3533
<div
3634
className="item-bubble"
@@ -46,9 +44,29 @@ class WidgetNumberedList extends PureComponent {
4644
: format(item.value < 1 ? '.2f' : '.3s')(item.value)}
4745
{unit}
4846
</div>
49-
</Link>
50-
</li>
51-
))}
47+
</div>
48+
);
49+
return (
50+
<li key={`${item.label}-${item.id}`}>
51+
{linksExt ? (
52+
<a
53+
href={`http://${window.location.host}${item.path}`}
54+
target="_blank"
55+
rel="noopener nofollower"
56+
>
57+
{linkContent}
58+
</a>
59+
) : (
60+
<Link
61+
className={`${linksDisabled ? 'disabled' : ''}`}
62+
to={item.path}
63+
>
64+
{linkContent}
65+
</Link>
66+
)}
67+
</li>
68+
);
69+
})}
5270
</ul>
5371
{handlePageChange &&
5472
data.length > settings.pageSize && (
@@ -68,7 +86,8 @@ WidgetNumberedList.propTypes = {
6886
settings: PropTypes.object.isRequired,
6987
handlePageChange: PropTypes.func,
7088
className: PropTypes.string,
71-
linksDisabled: PropTypes.bool
89+
linksDisabled: PropTypes.bool,
90+
linksExt: PropTypes.bool
7291
};
7392

7493
export default WidgetNumberedList;

app/javascript/pages/country/widget/widget-component.jsx

+30-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import isEmpty from 'lodash/isEmpty';
66

77
import Loader from 'components/loader/loader';
88
import NoContent from 'components/no-content';
9+
import Button from 'components/button';
910
import WidgetHeader from 'pages/country/widget/components/widget-header';
1011
import WidgetSettingsStatement from 'pages/country/widget/components/widget-settings-statement';
1112

@@ -81,18 +82,20 @@ class Widget extends PureComponent {
8182
settingsConfig.settings &&
8283
settingsConfig.settings.layers &&
8384
settingsConfig.settings.layers.length;
84-
85+
const onMap = active && haveMapLayers;
8586
return (
8687
<div
8788
className={`c-widget ${settingsConfig.config.size || ''}`}
88-
style={
89-
active && haveMapLayers
90-
? {
91-
borderColor: highlightColor,
92-
boxShadow: `0 0px 0px 1px ${highlightColor}`
93-
}
94-
: {}
95-
}
89+
style={{
90+
...(!!onMap && {
91+
borderColor: highlightColor,
92+
boxShadow: `0 0px 0px 1px ${highlightColor}`
93+
}),
94+
...(!!embed && {
95+
border: 0,
96+
borderRadius: 0
97+
})
98+
}}
9699
id={widget}
97100
>
98101
<WidgetHeader
@@ -126,6 +129,24 @@ class Widget extends PureComponent {
126129
{!error && <WidgetComponent {...this.props} {...settingsConfig} />}
127130
</div>
128131
<WidgetSettingsStatement settings={settingsConfig.settings} />
132+
{embed &&
133+
(!query || (query && !query.hideGfw)) && (
134+
<div className="embed-footer">
135+
<p>For more info</p>
136+
<Button
137+
className="embed-btn"
138+
extLink={`http://globalforestwatch.org/country/${
139+
location.country
140+
}${location.region ? `/${location.region}` : ''}${
141+
location.subRegion ? `/${location.subRegion}` : ''
142+
}?widget=${widget}${
143+
query && query[widget] ? `&${widget}=${query[widget]}` : ''
144+
}#${widget}`}
145+
>
146+
EXPLORE ON GFW
147+
</Button>
148+
</div>
149+
)}
129150
</div>
130151
);
131152
}

app/javascript/pages/country/widget/widget-styles.scss

+18
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,22 @@
2828
position: relative;
2929
height: 100%;
3030
}
31+
32+
.embed-footer {
33+
border-top: solid 1px $border;
34+
display: flex;
35+
justify-content: flex-end;
36+
align-items: center;
37+
padding-top: rem(20px);
38+
margin-top: rem(20px);
39+
40+
p {
41+
opacity: 0.7;
42+
}
43+
}
44+
45+
.embed-btn {
46+
width: rem(160px);
47+
margin-left: rem(10px);
48+
}
3149
}

app/javascript/pages/country/widget/widgets/widget-economic-impact/widget-economic-impact-component.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ import './widget-economic-impact-styles.scss';
1010

1111
class WidgetEconomicImpact extends PureComponent {
1212
render() {
13-
const { chartData, chartConfig, rankData, sentence, settings } = this.props;
13+
const {
14+
chartData,
15+
chartConfig,
16+
rankData,
17+
sentence,
18+
settings,
19+
embed
20+
} = this.props;
1421

1522
return (
1623
<div className="c-widget-economic-impact">
@@ -35,6 +42,7 @@ class WidgetEconomicImpact extends PureComponent {
3542
? value => formatUSD(value)
3643
: null
3744
}}
45+
linkExt={embed}
3846
/>
3947
)}
4048
</div>
@@ -48,7 +56,8 @@ WidgetEconomicImpact.propTypes = {
4856
chartConfig: PropTypes.object,
4957
rankData: PropTypes.array,
5058
sentence: PropTypes.string,
51-
settings: PropTypes.object
59+
settings: PropTypes.object,
60+
embed: PropTypes.bool
5261
};
5362

5463
export default WidgetEconomicImpact;

app/javascript/pages/country/widget/widgets/widget-fao-deforestation/widget-fao-deforestation-component.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class WidgetFAODeforestation extends PureComponent {
1919
className="locations-list"
2020
data={data}
2121
settings={settings}
22-
linksDisabled={embed}
22+
linksExt={embed}
2323
/>
2424
)}
2525
</div>

app/javascript/pages/country/widget/widgets/widget-fao-reforestation/widget-fao-reforestation-component.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class WidgetFAOReforestation extends PureComponent {
1919
className="locations-list"
2020
data={data}
2121
settings={settings}
22-
linksDisabled={embed}
22+
linkExt={embed}
2323
/>
2424
)}
2525
</div>

app/javascript/pages/country/widget/widgets/widget-gain-located/widget-gain-located-component.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class WidgetGainLocated extends PureComponent {
2020
data={data}
2121
settings={settings}
2222
handlePageChange={handlePageChange}
23-
linksDisabled={embed}
23+
linksExt={embed}
2424
/>
2525
)}
2626
</div>

app/javascript/pages/country/widget/widgets/widget-loss-located/widget-loss-located-component.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class WidgetLossLocated extends PureComponent {
2020
data={data}
2121
settings={settings}
2222
handlePageChange={handlePageChange}
23-
linksDisabled={embed}
23+
linksExt={embed}
2424
/>
2525
)}
2626
</div>

app/javascript/pages/country/widget/widgets/widget-ranked-plantations/widget-ranked-plantations-selectors.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const getLocation = state => state.location || null;
1515
const getLocationsMeta = state => state.meta || null;
1616
const getLocationNames = state => state.locationNames || null;
1717
const getColors = state => state.colors || null;
18+
const getEmbed = state => state.embed || null;
1819

1920
const getPlanationKeys = createSelector(
2021
[getPlantations],
@@ -23,8 +24,15 @@ const getPlanationKeys = createSelector(
2324
);
2425

2526
export const chartData = createSelector(
26-
[getPlantations, getExtent, getPlanationKeys, getLocationsMeta, getLocation],
27-
(plantations, extent, plantationKeys, meta, location) => {
27+
[
28+
getPlantations,
29+
getExtent,
30+
getPlanationKeys,
31+
getLocationsMeta,
32+
getLocation,
33+
getEmbed
34+
],
35+
(plantations, extent, plantationKeys, meta, location, embed) => {
2836
if (isEmpty(plantations) || isEmpty(meta) || isEmpty(extent)) return null;
2937
const groupedByRegion = groupBy(plantations, 'region');
3038
const regionData = Object.keys(groupedByRegion).map(r => {
@@ -46,13 +54,17 @@ export const chartData = createSelector(
4654
yKeys[key] = pPercentage || 0;
4755
yKeys[`${key} label`] = key;
4856
});
57+
4958
return {
5059
region: regionLabel && regionLabel.label,
5160
...yKeys,
5261
total: totalRegionPlantations / totalArea * 100,
53-
path: `/country/${location.payload.country}/${
62+
path: `${embed ? `http://${window.location.host}` : ''}/country/${
63+
location.payload.country
64+
}/${
5465
location.payload.region ? `${location.payload.region}/` : ''
55-
}${regionId}${location.search ? `?${location.search}` : ''}`
66+
}${regionId}${location.search ? `?${location.search}` : ''}`,
67+
extLink: embed
5668
};
5769
});
5870
const dataParsed = sortByKey(regionData, 'total', true);

app/javascript/pages/country/widget/widgets/widget-ranked-plantations/widget-ranked-plantations.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const mapStateToProps = (
2626
settings,
2727
location,
2828
locationNames,
29-
colors
29+
colors,
30+
embed: ownProps.embed
3031
};
3132
return {
3233
data: chartData(selectorData),

app/javascript/pages/country/widget/widgets/widget-tree-gain/widget-tree-gain-component.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import './widget-tree-gain-styles.scss';
88

99
class WidgetTreeCoverGain extends PureComponent {
1010
render() {
11-
const { data, sentence, settings } = this.props;
11+
const { data, sentence, settings, embed } = this.props;
1212

1313
return (
1414
<div className="c-widget-tree-cover-gain">
@@ -19,7 +19,7 @@ class WidgetTreeCoverGain extends PureComponent {
1919
className="ranking-list"
2020
data={data}
2121
settings={settings}
22-
handlePageChange={() => {}}
22+
linksExt={embed}
2323
/>
2424
</div>
2525
)}
@@ -31,7 +31,8 @@ class WidgetTreeCoverGain extends PureComponent {
3131
WidgetTreeCoverGain.propTypes = {
3232
data: PropTypes.array,
3333
settings: PropTypes.object.isRequired,
34-
sentence: PropTypes.string
34+
sentence: PropTypes.string,
35+
embed: PropTypes.bool
3536
};
3637

3738
export default WidgetTreeCoverGain;

0 commit comments

Comments
 (0)