Skip to content

Commit

Permalink
Ensuring group is writable in formatLayersCategories
Browse files Browse the repository at this point in the history
  • Loading branch information
gislawill committed Jul 25, 2024
1 parent acdcbdd commit 52dbd65
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions frontend/src/components/MapView/LeftPanel/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,22 @@ function formatLayersCategories(
const group = mapKeys(key, (_v, k: string) =>
camelCase(k),
) as unknown as MenuGroup;
const visibleLayer =
const mainLayer =
group.layers.find(gl =>
selectedLayers?.some(sl => sl.id === gl.id),
) || group.layers.find(l => l.main);

const staticLayer = LayerDefinitions[visibleLayer?.id as LayerKey];
const layer = { ...staticLayer, group };
const layer = LayerDefinitions[mainLayer?.id as LayerKey];

// Check if layer is frozen or sealed before writing to it, required to prevent a race condition
if (Object.isFrozen(layer)) {
console.error(`Layer ${layer?.id} is frozen and cannot be modified.`);
} else if (Object.isSealed(layer)) {
console.error(`Layer ${layer?.id} is sealed and cannot be modified.`);
} else {
layer.group = group;

Check warning on line 49 in frontend/src/components/MapView/LeftPanel/utils.ts

View workflow job for this annotation

GitHub Actions / frontend_tests (ubuntu-latest)

Unallowed reassignment
}

return layer;
}
return LayerDefinitions[key as LayerKey];
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export class CommonLayerProps {
},
*/
@optional
group?: MenuGroup;
group?: MenuGroup = undefined; // Defaulting to undefined to make sure that the group property is writable

@optional
validity?: Validity; // Include additional dates in the calendar based on the number provided.
Expand Down

0 comments on commit 52dbd65

Please sign in to comment.