Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(map): legend layers order fixes [EP-2851, EP-2852] #170

Merged
merged 2 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/earth-map/src/components/layers/Layers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import InfiniteList from 'components/infinite-list';
import ListItem from 'components/list-item';
import SearchBox from 'components/searchbox';
import SidebarLayoutSearch from 'components/sidebar/sidebar-layout-search';
import { debounce } from 'lodash';
import { debounce, sortBy } from 'lodash';
import { EPanels } from 'modules/sidebar/model';
import React from 'react';
import React, { useEffect, useState } from 'react';

import './styles.scss';

Expand Down Expand Up @@ -92,11 +92,14 @@ const Layers = (props: IProps) => {
} = props;

const { loading, search, listActive, nextPageCursor } = layers;

const hasSearchTerm = !!search.search;
const showX = hasSearchTerm;
const showFilter = !selected || panelExpanded;
const showBack = selected && panelExpanded;

const sortedLayers = sortBy(listActive, 'name');

const handleChange = (e) => {
const newValue = e.target.value;
setLayersSearch({ search: newValue });
Expand Down Expand Up @@ -177,7 +180,7 @@ const Layers = (props: IProps) => {
deselect all
</a>
</div>
{listActive.map((layer) => {
{sortedLayers.map((layer) => {
return (
<ListItem
active={true}
Expand Down
15 changes: 12 additions & 3 deletions packages/earth-map/src/modules/layers/reducers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default {
const layer = payload;
const newActiveLayers = listActive.find((x) => x.slug === layer.slug)
? listActive.filter((x) => x.slug !== layer.slug)
: [...listActive, layer];
: [layer, ...listActive];

return {
...state,
Expand All @@ -58,12 +58,21 @@ export default {
};
},
[actions.setLayerOrder]: (state, { payload }) => {
const { active } = state;
const { active, listActive } = state;
const { datasetIds } = payload;

const activeFiltered = active.filter((a) => !datasetIds.includes(a));

return { ...state, active: [...datasetIds, ...activeFiltered] };
const activeSlugs = [...datasetIds, ...activeFiltered];
const listActiveFiltered = activeSlugs.map((slug: string) =>
listActive.find((layer) => layer.slug === slug)
);

return {
...state,
active: activeSlugs,
listActive: listActiveFiltered,
};
},
[actions.setLayerOpacity]: (state, { payload }) => {
const oldSettings = state.settings;
Expand Down