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

Develop #698

Merged
merged 9 commits into from
Aug 29, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ function AnalyzeAreasContainer(props) {
layerId: newSelectedOption,
category: newLayerCategory,
});
} else {
layersToToggle = activeLayers.map((l) => ({
layerId: l.title,
}));
}

if (formerSelectedSlug === CLEAR_SELECTIONS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
TERRESTRIAL_GLOBAL,
TERRESTRIAL_REGIONAL,
MARINE,
// DEFAULT_RESOLUTIONS,
DEFAULT_RESOLUTIONS,
} from 'constants/biodiversity-layers-constants';
import { LAYERS_CATEGORIES } from 'constants/mol-layers-configs';

Expand All @@ -15,6 +15,7 @@ export const useSelectLayersOnTabOrResolutionChange = ({
previousSelectedResolutions,
layersToggleConfig,
category,
selectedCategory,
isChecked,
allActiveLayerTitles,
activeLayers,
Expand Down Expand Up @@ -76,10 +77,10 @@ export const useSelectLayersOnTabOrResolutionChange = ({
.filter((l) => l.category === LAYERS_CATEGORIES.BIODIVERSITY)
.map((l) => l.title);
const resolution = selectedResolutions[currentResolutionGroup];
// const defaultResolutionLayers =
// layersToggleConfig[biodiversityLayerVariant][currentResolutionGroup][
// DEFAULT_RESOLUTIONS[currentResolutionGroup]
// ];
const defaultResolutionLayers =
layersToggleConfig[biodiversityLayerVariant][currentResolutionGroup][
DEFAULT_RESOLUTIONS[currentResolutionGroup]
];
const availableLayers =
layersToggleConfig[biodiversityLayerVariant][currentResolutionGroup][
resolution
Expand All @@ -95,17 +96,18 @@ export const useSelectLayersOnTabOrResolutionChange = ({
availableLayers &&
availableLayers.find((layer) => layer.value.includes(layerTaxa));

if (hasMatchingLayer) {
if (hasMatchingLayer && selectedCategory === category) {
// select matching layer on selected variant
handleLayerToggle(hasMatchingLayer);
} else if (availableLayers && layerTaxa !== 'all') {
// select first element if there's no matching layer
handleLayerToggle(availableLayers[0]);
} else if(hasMatchingLayer && category === TERRESTRIAL_GLOBAL){
handleLayerToggle(hasMatchingLayer);
} else if(!hasMatchingLayer && category === TERRESTRIAL_GLOBAL){
if(availableLayers){
handleLayerToggle(availableLayers[0]);
} else {
handleLayerToggle(defaultResolutionLayers[0]);
}
}
// else {
// // select first element if there's no maching resolution
// handleLayerToggle(defaultResolutionLayers[0]);
// }
}, [
biodiversityLayerVariant,
selectedResolutions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ const getGroupedLayerOptions = createSelector(
const getSelectedLayerOption = createSelector(
[getCategoryLayerOptions, getSelectedLayer],
(options, selectedLayer) => {
const allTaxaIndex = options.findIndex(item => item.name === 'all taxa');
const optionsSelectedLayer =
options.find((l) => l.value === selectedLayer) || options[0];
options.find((l) => l.value === selectedLayer) || options[allTaxaIndex] || options[0];
if (!optionsSelectedLayer) return null;

// label is needed for grouped layer option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ function BiodiversityLayerToggle(props) {
setSelectedLayer,
allActiveLayerTitles,
category,
setSelectedCategory,
selectedCategory
} = props;
const locale = useLocale();
const layersToggleConfig = useMemo(() => getLayersToggleConfig(), [locale]);
Expand All @@ -60,6 +62,7 @@ function BiodiversityLayerToggle(props) {
const previousSelectedResolutions = usePrevious(selectedResolutions);

const handleLayerToggle = (option) => {
setSelectedCategory(category);
const layer = layersConfig[option.layer];
if (!allActiveLayerTitles) {
// Add layer to empty selection
Expand Down Expand Up @@ -113,6 +116,7 @@ function BiodiversityLayerToggle(props) {
isChecked,
allActiveLayerTitles,
activeLayers,
selectedCategory,
handleLayerToggle,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function BiodiversitySidebarCardComponent({
const firstStep = onboardingStep === 0;
const { title, description, source } = cardMetadata || {};
const [isOpen, setOpen] = useState(false);
const [selectedCategory, setSelectedCategory] = useState(TERRESTRIAL_GLOBAL);
const handleBoxClick = () => setOpen(!isOpen);

// --- Onboarding
Expand Down Expand Up @@ -115,6 +116,8 @@ function BiodiversitySidebarCardComponent({
activeLayers={activeLayers}
selectedLayer={selectedLayer}
setSelectedLayer={setSelectedLayer}
selectedCategory={selectedCategory}
setSelectedCategory={setSelectedCategory}
selectedResolutions={selectedResolutions}
resolutionOptions={categoryResolutionOptions}
selectedResolutionOption={selectedResolutionOptions[category]}
Expand Down