Skip to content

Commit

Permalink
Merge pull request #191 from resource-watch/feature/explore-embed-fix
Browse files Browse the repository at this point in the history
Explore embed fix
  • Loading branch information
Miguel Barrenechea Sánchez authored Jan 19, 2018
2 parents c8a314e + 9efbaa4 commit c379a3d
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Icon from 'components/ui/Icon';

import './legend-actions-style.scss';

export const LegendActions = ({ layerSpec, onOpacity, onVisibility, onInfo, onClose }) => (
export const LegendActions = ({ layerSpec, onOpacity, onVisibility, onMultiLayer, onInfo, onClose }) => (
<div className="c-legend-actions">
<LegendOpacitySelector
layerSpec={layerSpec}
Expand All @@ -17,6 +17,7 @@ export const LegendActions = ({ layerSpec, onOpacity, onVisibility, onInfo, onCl
{layerSpec.provider !== 'nexgddp' && layerSpec.layers.length > 1 &&
<LegendMultiLayerSelector
layerSpec={layerSpec}
onMultiLayer={onMultiLayer}
/>
}

Expand Down Expand Up @@ -52,14 +53,16 @@ LegendActions.propTypes = {
onOpacity: PropTypes.func,
onVisibility: PropTypes.func,
onInfo: PropTypes.func,
onClose: PropTypes.func
onClose: PropTypes.func,
onMultiLayer: PropTypes.func
};

LegendActions.defaultProps = {
onOpacity: () => {},
onVisibility: () => {},
onInfo: () => {},
onClose: () => {}
onClose: () => {},
onMultiLayer: () => {}
};

export default LegendActions;
20 changes: 15 additions & 5 deletions app/scripts/components/legend/legend-component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ import './legend-style.scss';

class Legend extends PureComponent {
getLegendToolbar() {
const { layerSpec } = this.props;
if (layerSpec.provider === 'nexgddp') return (<LegendNexGDDPToolbar layerSpec={layerSpec} />);
const { layerSpec, onMultiLayer } = this.props;
if (layerSpec.provider === 'nexgddp') {
return (
<LegendNexGDDPToolbar
layerSpec={layerSpec}
onMultiLayer={onMultiLayer}
/>
);
}
return null;
}

render() {
const { layerSpec, onOpacity, onVisibility, onClose, onInfo } = this.props;
const { layerSpec, onOpacity, onVisibility, onClose, onMultiLayer, onInfo } = this.props;
const { name, legendConfig } = layerSpec;
const { type, unit } = legendConfig;

Expand All @@ -31,6 +38,7 @@ class Legend extends PureComponent {
onVisibility={onVisibility}
onInfo={onInfo}
onClose={onClose}
onMultiLayer={onMultiLayer}
/>}
</div>
{this.props.toolbar && this.getLegendToolbar()}
Expand All @@ -51,7 +59,8 @@ Legend.propTypes = {
onOpacity: PropTypes.func,
onVisibility: PropTypes.func,
onInfo: PropTypes.func,
onClose: PropTypes.func
onClose: PropTypes.func,
onMultiLayer: PropTypes.func
};

Legend.defaultProps = {
Expand All @@ -60,7 +69,8 @@ Legend.defaultProps = {
updateOpacity: () => {},
onVisibility: () => {},
onInfo: () => {},
onClose: () => {}
onClose: () => {},
onMultiLayer: () => {}
};

export default Legend;
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class LegendControl extends React.PureComponent {
}

render() {
const { layersSpec, datasetsSpec, position, sortable, onOpacity, onVisibility, onClose, onInfo } = this.props;
const { layersSpec, datasetsSpec, position, sortable, onOpacity, onVisibility, onClose, onInfo, onMultiLayer } = this.props;
const { collapsed } = this.state;

return (
Expand Down Expand Up @@ -58,6 +58,7 @@ export class LegendControl extends React.PureComponent {
onVisibility={onVisibility}
onInfo={onInfo}
onClose={onClose}
onMultiLayer={onMultiLayer}
/> }

{ (datasetsSpec && datasetsSpec.length > 0) &&
Expand All @@ -78,7 +79,8 @@ LegendControl.propTypes = {
onOpacity: PropTypes.func,
onVisibility: PropTypes.func,
onInfo: PropTypes.func,
onClose: PropTypes.func
onClose: PropTypes.func,
onMultiLayer: PropTypes.func
};

LegendControl.defaultProps = {
Expand All @@ -91,7 +93,8 @@ LegendControl.defaultProps = {
onOpacity: () => {},
onVisibility: () => {},
onInfo: () => {},
onClose: () => {}
onClose: () => {},
onMultiLayer: () => {}
};

export default LegendControl;
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import PropTypes from 'prop-types';
import Legend from '../../legend-component';
import './legend-list-item.scss';

const LegendListItem = ({ value, onOpacity, onVisibility, onClose, onInfo }) => (
const LegendListItem = ({ value, onOpacity, onVisibility, onClose, onInfo, onMultiLayer }) => (
<li className="c-legend-list-item">
<Legend layerSpec={value} onOpacity={onOpacity} onVisibility={onVisibility} onInfo={onInfo} onClose={onClose} />
<Legend layerSpec={value} onOpacity={onOpacity} onVisibility={onVisibility} onInfo={onInfo} onClose={onClose} onMultiLayer={onMultiLayer} />
</li>
);

Expand All @@ -14,14 +14,16 @@ LegendListItem.propTypes = {
onOpacity: PropTypes.func,
onVisibility: PropTypes.func,
onInfo: PropTypes.func,
onClose: PropTypes.func
onClose: PropTypes.func,
onMultiLayer: PropTypes.func
};

LegendListItem.defaultProps = {
onOpacity: () => {},
onVisibility: () => {},
onInfo: () => {},
onClose: () => {}
onClose: () => {},
onMultiLayer: () => {}
};

export default LegendListItem;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const SortableItem = SortableElement(props => (
</div>
));

const SortableLegendList = SortableContainer(({ items, onOpacity, onVisibility, onClose, onInfo }) => (
const SortableLegendList = SortableContainer(({ items, onOpacity, onVisibility, onClose, onInfo, onMultiLayer }) => (
<ul>
{items.map((value, index) => (
<SortableItem
Expand All @@ -30,6 +30,7 @@ const SortableLegendList = SortableContainer(({ items, onOpacity, onVisibility,
onVisibility={onVisibility}
onInfo={onInfo}
onClose={onClose}
onMultiLayer={onMultiLayer}
/>
))}
</ul>
Expand All @@ -55,7 +56,7 @@ class LegendList extends React.PureComponent {
}

render() {
const { sortable, onOpacity, onVisibility, onClose, onInfo } = this.props;
const { sortable, onOpacity, onVisibility, onClose, onInfo, onMultiLayer } = this.props;
const { items } = this.state;

if (sortable) {
Expand All @@ -73,6 +74,7 @@ class LegendList extends React.PureComponent {
onVisibility={onVisibility}
onInfo={onInfo}
onClose={onClose}
onMultiLayer={onMultiLayer}
/>
</div>
);
Expand All @@ -97,15 +99,17 @@ LegendList.propTypes = {
onOpacity: PropTypes.func,
onVisibility: PropTypes.func,
onInfo: PropTypes.func,
onClose: PropTypes.func
onClose: PropTypes.func,
onMultiLayer: PropTypes.func
};

LegendList.defaultProps = {
onOpacity: () => {},
onVisibility: () => {},
onSortChange: () => {},
onInfo: () => {},
onClose: () => {}
onClose: () => {},
onMultiLayer: () => {}
};

export default LegendList;
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { connect } from 'react-redux';
import * as exploreActions from 'pages/explore/explore-actions';

import Component from './legend-multi-layer-selector-component';

const mapStateToProps = null;

export default connect(mapStateToProps, exploreActions)(Component);
export default Component;
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LegendMultiLayerSelector extends Component {
}

onChangeLayer(layer) {
this.props.setMultiActiveLayer({
this.props.onMultiLayer({
layerId: layer.id,
id: layer.dataset
});
Expand Down Expand Up @@ -92,7 +92,7 @@ class LegendMultiLayerSelector extends Component {

LegendMultiLayerSelector.propTypes = {
layerSpec: PropTypes.object,
setMultiActiveLayer: PropTypes.func
onMultiLayer: PropTypes.func
};

export default LegendMultiLayerSelector;
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { connect } from 'react-redux';
import * as exploreActions from 'pages/explore/explore-actions';

import Component from './legend-nexgddp-toolbar-component';

const mapStateToProps = null;

export default connect(mapStateToProps, exploreActions)(Component);
export default Component;
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ class LegendNexGDDPToolbar extends PureComponent {
onResolutionChange(temporalResolution) {
this.setState({ temporalResolution }, () => {
this.updatingPeriods();
this.props.setMultiActiveLayer({ ...this.state, id: this.props.layerSpec.dataset });
this.props.onMultiLayer({ ...this.state, id: this.props.layerSpec.dataset });
});
}

onPeriodChange(period) {
this.setState({ period }, () => {
this.props.setMultiActiveLayer({ ...this.state, id: this.props.layerSpec.dataset });
this.props.onMultiLayer({ ...this.state, id: this.props.layerSpec.dataset });
});
}

onScenarioChange(scenario) {
this.setState({ scenario }, () => {
this.props.setMultiActiveLayer({ ...this.state, id: this.props.layerSpec.dataset });
this.props.onMultiLayer({ ...this.state, id: this.props.layerSpec.dataset });
});
}

Expand Down Expand Up @@ -137,7 +137,7 @@ class LegendNexGDDPToolbar extends PureComponent {

LegendNexGDDPToolbar.propTypes = {
layerSpec: PropTypes.object,
setMultiActiveLayer: PropTypes.func
onMultiLayer: PropTypes.func
};

export default LegendNexGDDPToolbar;
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ import { createSelector } from 'reselect';

import selectElementsFromTree from 'helpers/dropdown-tree';

const data = state => state.explorePage.datasetFilters.data;
const filters = state => state.explorePage.datasetFilters.filters;
const data = state => state.exploreEmbedPage.datasetFilters.data;
const filters = state => state.exploreEmbedPage.datasetFilters.filters;
const originalData = state => state.exploreEmbedPage.datasetFilters.originalData;

const getFilterStatus = (_data, _filters) => {
const getFilterStatus = (_data, _filters, _originalData) => {
if (!Object.keys(_data).length) return {};
if (!Object.keys(_filters).length) return _data;
if (!Object.keys(_filters).length) return { ..._originalData };

const data = _data;
const newData = _data;

Object.keys(_filters).map((filterKey) => {
const filterValues = _filters[filterKey];
const dataTree = _data[filterKey] || [];
const dataTree = newData[filterKey] || [];

dataTree.forEach(child => selectElementsFromTree(child, filterValues));
});

return data;
return newData;
};

export default createSelector(data, filters, getFilterStatus);
export default createSelector(data, filters, originalData, getFilterStatus);
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ import { Component, createElement } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';

import * as exploreActions from 'pages/explore/explore-actions';
import * as exploreActions from 'pages/explore-embed/explore-embed-actions';
import reducers, { initialState } from 'pages/explore/explore-dataset-filters/explore-dataset-filters-reducer';

import ExploreDatasetFiltersComponent from 'pages/explore/explore-dataset-filters/explore-dataset-filters-component';
import getFilterStatus from './explore-dataset-filters-selectors';

const mapStateToProps = state => ({
data: getFilterStatus(state)
data: state.explorePage.datasetFilters.data
});

class ExploreDatasetFiltersContainer extends Component {
componentWillMount() {
this.props.getFiltersData();
if (!Object.keys(this.props.data).length) this.props.getFiltersData();
}

render() {
Expand All @@ -25,7 +24,8 @@ class ExploreDatasetFiltersContainer extends Component {
}

ExploreDatasetFiltersContainer.propTypes = {
getFiltersData: PropTypes.func
getFiltersData: PropTypes.func,
data: PropTypes.object
};

export { exploreActions, reducers, initialState };
Expand Down
Loading

0 comments on commit c379a3d

Please sign in to comment.