Skip to content

Commit

Permalink
Merge pull request #24 from mongabay/feature/MP-173-link-to-trase-but…
Browse files Browse the repository at this point in the history
…ton-implementation

Create trase link
  • Loading branch information
barbara-chaves authored Oct 24, 2023
2 parents 7e7399f + b2c3ef8 commit 7cfb0aa
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 2 deletions.
43 changes: 43 additions & 0 deletions components/tool/trase-link/component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import { TRASE_API } from 'modules/tool/world-map/trase-api.js';
import './style.scss';

const TraseLink = ({ country, commodity, unit, year }) => {
const href = useMemo(() => {
const traseAppUpl = TRASE_API.split('/api')[0];
return `${traseAppUpl}/flows/data-view?toolLayout=1&countries=${country}&commodities=${commodity}&selectedYears=${year}&selectedYears=${year}&selectedResizeBy=${unit}`;
}, [commodity, country, unit, year]);

return (
<div className="c-tool-trase-link">
<a href={href} target="_blank" rel="noreferrer">
<svg
xmlns="http://www.w3.org/2000/svg"
width="19"
height="19"
viewBox="0 0 19 19"
fill="none"
>
<path
d="M9.29762 3.83333H3.125C2.56142 3.83333 2.02091 4.05722 1.6224 4.45573C1.22388 4.85425 1 5.39475 1 5.95833V15.875C1 16.4386 1.22388 16.9791 1.6224 17.3776C2.02091 17.7761 2.56142 18 3.125 18H13.0417C13.6053 18 14.1458 17.7761 14.5443 17.3776C14.9428 16.9791 15.1667 16.4386 15.1667 15.875V9.70238M5.25 13.75L18 1M18 1H13.0417M18 1V5.95833"
stroke="#444242"
strokeWidth="1.61905"
strokeLinecap="square"
/>
</svg>
<span>Check data on Trase</span>
</a>
</div>
);
};

TraseLink.propTypes = {
country: PropTypes.string,
commodity: PropTypes.string,
unit: PropTypes.string,
year: PropTypes.number,
region: PropTypes.string,
};

export default TraseLink;
11 changes: 11 additions & 0 deletions components/tool/trase-link/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { connect } from 'react-redux';

import { traseSelectors } from 'modules/tool';
import Component from './component';

export default connect(state => ({
country: traseSelectors.selectCountry(state),
commodity: traseSelectors.selectCommodity(state),
unit: traseSelectors.selectUnit(state),
year: traseSelectors.selectYear(state),
}))(Component);
19 changes: 19 additions & 0 deletions components/tool/trase-link/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@import 'css/settings';

.c-tool-trase-link {
margin-left: 16px;
margin-top: 32px;
width: 100%;
a {
display: flex;
gap: 12px;
align-items: center;
span {
color: #444242;
font-size: $font-size-m;
font-weight: 600;
text-decoration-line: underline;
text-decoration-color: rgba(black, 0.2);
}
}
}
6 changes: 5 additions & 1 deletion components/tool/world-map/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Attributions from '../attributions';

import WORLD_GEOGRAPHIES from './WORLD.topo.json';
import './style.scss';
import TraseLink from '../trase-link';

class WorldMap extends React.PureComponent {
state = {
Expand Down Expand Up @@ -220,7 +221,10 @@ class WorldMap extends React.PureComponent {
<Lines>{this.renderLines()}</Lines>
</ZoomableGroup>
</ComposableMap>
<Ranking />
<div>
<Ranking />
{!exporting && <TraseLink />}
</div>
</div>
</Tooltip>
<Attributions exporting={exporting} />
Expand Down
2 changes: 1 addition & 1 deletion modules/tool/world-map/trase-api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';

const TRASE_API = 'https://supplychains.trase.earth/api/v3';
export const TRASE_API = 'https://supplychains.trase.earth/api/v3';

export const fetchTraseContexts = () =>
axios.get(`${TRASE_API}/contexts`).then(({ data }) => data?.data ?? []);
Expand Down

0 comments on commit 7cfb0aa

Please sign in to comment.