Skip to content

Commit

Permalink
feat: implement and use forest type button
Browse files Browse the repository at this point in the history
  • Loading branch information
friedjoff committed Apr 28, 2020
1 parent 8bd8961 commit 556a209
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 34 deletions.
10 changes: 2 additions & 8 deletions src/components/EcogramPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { List, Popup } from 'semantic-ui-react';
import { info } from 'lib/src';

import Button from './Button';

const { REACT_APP_VECTOR_TILES_ENDPOINT } = process.env;
const endpoint = `${REACT_APP_VECTOR_TILES_ENDPOINT}/forest-type`;
import ForestTypeButton from './ForestTypeButton';

function EcogramPopup({ target, forestTypes, onClose, selectForestType }) {
const { t, i18n } = useTranslation();
Expand All @@ -18,11 +16,7 @@ function EcogramPopup({ target, forestTypes, onClose, selectForestType }) {
<List>
{forestTypes.map((f) => (
<List.Item style={{ whiteSpace: 'nowrap' }}>
<Button
active
icon="file pdf"
onClick={() => window.open(`${endpoint}/${f}.pdf`, '_blank')}
/>
<ForestTypeButton code={f} />
<Button active onClick={() => selectForestType(f)}>
{f} - {info('forestType', f)[i18n.language]}
</Button>
Expand Down
28 changes: 28 additions & 0 deletions src/components/ForestTypeButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import PropTypes from 'prop-types';
import React from 'react';

import Button from './Button';

const { REACT_APP_VECTOR_TILES_ENDPOINT } = process.env;
const endpoint = `${REACT_APP_VECTOR_TILES_ENDPOINT}/forest-type`;

function ForestTypeButton({ code, ...props }) {
return (
<Button
active
icon="file pdf"
onClick={(e) => {
e.stopPropagation();
window.open(`${endpoint}/${code}.pdf`, '_blank');
}}
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
/>
);
}

ForestTypeButton.propTypes = {
code: PropTypes.string.isRequired,
};

export default ForestTypeButton;
39 changes: 13 additions & 26 deletions src/components/LocationResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import { info } from 'lib/src';

import Dropdown from './Dropdown';
import Ecogram from './Ecogram';
import ForestTypeButton from './ForestTypeButton';
import { setFormLocation } from '../store/actions';
import styles from './LocationResult.module.css';

const otherForestTypeGroups = ['special', 'volatile', 'riverside', 'pioneer'];

function LocationResult() {
const dispatch = useDispatch();
const { t, i18n } = useTranslation();
Expand Down Expand Up @@ -47,31 +46,19 @@ function LocationResult() {
<Dropdown
search
label={t('forestType.group.other')}
options={forestTypes.other.map((key) => ({
key,
content: (
<>
<ForestTypeButton code={key} compact />
{key} - {info('forestType', key)[i18n.language]}
</>
),
text: `${key} - ${info('forestType', key)[i18n.language]}`,
value: key,
}))}
value={formLocation.forestType}
>
<Dropdown.Menu>
{otherForestTypeGroups
.map((group) => (
<>
<Dropdown.Header content={t(`forestType.group.${group}`)} />
{forestTypes[group].map((key) => {
const label = info('forestType', key)[i18n.language];
const text = label ? `${key} - ${label}` : key;
return (
<Dropdown.Item
text={text}
value={key}
onClick={(e, { value: forestType }) =>
selectForestType(forestType)
}
/>
);
})}
</>
))
.reduce((ttft, ft) => ttft.concat(ft), [])}
</Dropdown.Menu>
</Dropdown>
/>
)}
</Form>
) : null;
Expand Down
9 changes: 9 additions & 0 deletions src/components/ProjectionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { info } from 'lib/src';

import ChoiceButton from './ChoiceButton';
import Dropdown from './Dropdown';
import ForestTypeButton from './ForestTypeButton';
import { setFormLocation } from '../store/actions';
import styles from './ProjectionForm.module.css';

Expand All @@ -19,6 +20,14 @@ const getButtonOptions = (type, lng) => (key) => ({
});
const getDropdownOptions = (type, lng, includeKey = false) => (key) => ({
key,
content: includeKey ? (
<>
<ForestTypeButton code={key} compact />
{key} - {info(type, key)[lng]}
</>
) : (
info(type, key)[lng]
),
text: includeKey ? `${key} - ${info(type, key)[lng]}` : info(type, key)[lng],
value: key,
});
Expand Down

0 comments on commit 556a209

Please sign in to comment.