-
Notifications
You must be signed in to change notification settings - Fork 4
Re-org Nework to allow user-defined layout and network name: front-end #205
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
Changes from all commits
21e2cc9
1029e7e
6462f29
343997e
786c767
67c520a
75f0969
58ce9a6
ac62945
747daf7
416e5fe
d959680
ce03682
adcfbbc
3b6bc70
60af28d
494998f
6d79611
da129d7
4cb2676
1f5d6ae
e6c2d13
596f5cc
e2ac1ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,14 +3,17 @@ import { useRef, useEffect, useState, useMemo, useCallback } from 'react'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { DeckGL } from '@deck.gl/react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GeoJsonLayer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IconLayer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PointCloudLayer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PolygonLayer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TextLayer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from '@deck.gl/layers'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { DataFilterExtension } from '@deck.gl/extensions'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { DataFilterExtension, PathStyleExtension } from '@deck.gl/extensions'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import positron from 'constants/mapStyles/positron.json'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import no_label from 'constants/mapStyles/positron_nolabel.json'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // eslint-disable-next-line import/no-unresolved | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import triangleFillIcon from 'assets/icons/triangle-fill.svg?url'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import * as turf from '@turf/turf'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import './Map.css'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -220,13 +223,18 @@ const useMapLayers = (onHover = () => {}) => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: mapLayers[name]?.edges, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getLineWidth: (f) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| normalizeLineWidth( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f.properties['peak_mass_flow'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f.properties?.['peak_mass_flow'] ?? 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| min, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| max, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 * scale, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getLineColor: edgeColour, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getDashArray: (f) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f.properties?.['peak_mass_flow'] != null ? [0, 0] : [8, 4], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dashJustified: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dashGapPickable: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extensions: [new PathStyleExtension({ dash: true })], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| updateTriggers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
224
to
238
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainGuard against invalid/missing Right now You can keep the current behavior for valid values while falling back to a safe minimum width for missing/invalid ones by guarding the accessor: - getLineWidth: (f) =>
- normalizeLineWidth(
- f.properties?.['peak_mass_flow'] ?? 0,
- min,
- max,
- 1,
- 7 * scale,
- ),
+ getLineWidth: (f) => {
+ const raw = f.properties?.['peak_mass_flow'];
+ const value = raw != null ? Number(raw) : null;
+
+ // Fall back to minimum width when value is missing/invalid
+ if (value == null || Number.isNaN(value)) {
+ return 1;
+ }
+
+ return normalizeLineWidth(value, min, max, 1, 7 * scale);
+ },The dashed logic ( I'll help verify this review comment. Let me gather information about the code structure and the Length of output: 27 🏁 Script executed: #!/bin/bash
# Look at the broader context of the Map.jsx file around the flagged lines
cat src/features/map/components/Map/Map.jsx | head -280 | tail -100Length of output: 3309 🏁 Script executed: #!/bin/bash
# Find where min and max are computed/set for this specific context
rg -n "min\|max" src/features/map/components/Map/Map.jsx -B3 -A3Length of output: 0 🏁 Script executed: #!/bin/bash
# Check if there are other uses of getLineWidth or normalizeLineWidth in the codebase
rg -n "getLineWidth|normalizeLineWidth" --type=jsx --type=js -C2Length of output: 27 🏁 Script executed: #!/bin/bash
# Look for utility/helper files that might contain normalizeLineWidth
fd -e js -e jsx -e ts -e tsx | xargs rg -l "normalizeLineWidth" 2>/dev/null | head -20Length of output: 39 I need to search more carefully for the function definitions. Let me adjust the approach: Length of output: 1492 🏁 Script executed: #!/bin/bash
# Search for normalizeLineWidth definition without file type restriction
rg -n "normalizeLineWidth" -B2 -A10Length of output: 2037 🏁 Script executed: #!/bin/bash
# Search for getPropertyRange definition
rg -n "getPropertyRange" -B2 -A15Length of output: 2724 🏁 Script executed: #!/bin/bash
# Look for all imports and exports in Map.jsx
grep -n "import\|export\|normalizeLineWidth" src/features/map/components/Map/Map.jsx | head -30Length of output: 1200 🏁 Script executed: #!/bin/bash
# Get the full context of the Map.jsx file - look at top section
head -100 src/features/map/components/Map/Map.jsxLength of output: 2997 Guard against invalid/missing The issue is confirmed. When The suggested fix is appropriate: return a safe minimum width (1) for missing/invalid values instead of normalizing with out-of-range input. - getLineWidth: (f) =>
- normalizeLineWidth(
- f.properties?.['peak_mass_flow'] ?? 0,
- min,
- max,
- 1,
- 7 * scale,
- ),
+ getLineWidth: (f) => {
+ const raw = f.properties?.['peak_mass_flow'];
+ const value = raw != null ? Number(raw) : null;
+
+ // Fall back to minimum width when value is missing/invalid
+ if (value == null || Number.isNaN(value)) {
+ return 1;
+ }
+
+ return normalizeLineWidth(value, min, max, 1, 7 * scale);
+ },📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getLineWidth: [scale, min, max], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -239,23 +247,114 @@ const useMapLayers = (onHover = () => {}) => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _layers.push( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new GeoJsonLayer({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: `${name}-nodes`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: mapLayers[name]?.nodes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getFillColor: (f) => nodeFillColor(f.properties['type']), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getPointRadius: (f) => nodeRadius(f.properties['type']), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getLineColor: (f) => nodeLineColor(f.properties['type']), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getLineWidth: 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| updateTriggers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getPointRadius: [scale], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onHover: onHover, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pickable: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parameters: { depthTest: false }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Partition nodes by type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const nodesData = mapLayers[name]?.nodes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { plantNodes, consumerNodes, noneNodes } = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nodesData?.features ?? [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ).reduce( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (acc, feature) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const type = feature.properties['type']; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (type === 'PLANT') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| acc.plantNodes.push(feature); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (type === 'CONSUMER') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| acc.consumerNodes.push(feature); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| acc.noneNodes.push(feature); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return acc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { plantNodes: [], consumerNodes: [], noneNodes: [] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Add GeoJsonLayer for NONE nodes - rendered first (bottom layer) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (noneNodes.length > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _layers.push( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new GeoJsonLayer({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: `${name}-none-nodes`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'FeatureCollection', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| features: noneNodes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getFillColor: (f) => nodeFillColor(f.properties['type']), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getPointRadius: (f) => nodeRadius(f.properties['type']), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getLineColor: (f) => nodeLineColor(f.properties['type']), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getLineWidth: 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| updateTriggers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getPointRadius: [scale], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onHover: onHover, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pickable: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parameters: { depthTest: false }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Add GeoJsonLayer for CONSUMER nodes - rendered second (above NONE nodes) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (consumerNodes.length > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _layers.push( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new GeoJsonLayer({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: `${name}-consumer-nodes`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'FeatureCollection', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| features: consumerNodes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getFillColor: (f) => nodeFillColor(f.properties['type']), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getPointRadius: (f) => nodeRadius(f.properties['type']), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getLineColor: (f) => nodeLineColor(f.properties['type']), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getLineWidth: 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| updateTriggers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getPointRadius: [scale], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onHover: onHover, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pickable: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parameters: { depthTest: false }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Add IconLayer for plant nodes with triangle icon | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Rendered after other nodes to appear on top | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (plantNodes.length > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Use bright yellow for high visibility and to complement blue/red edges | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const plantColor = [255, 209, 29, 255]; // Bright yellow | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _layers.push( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new IconLayer({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: `${name}-plant-nodes`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: plantNodes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getIcon: () => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| url: triangleFillIcon, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| width: 64, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| height: 64, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| anchorY: 32, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mask: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getPosition: (f) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const coords = f.geometry.coordinates; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Add z-elevation of 3 meters to lift icon above the map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [coords[0], coords[1], 3]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getSize: 10 * scale, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getColor: plantColor, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sizeUnits: 'meters', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sizeMinPixels: 20, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| billboard: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| loadOptions: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| imagebitmap: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| resizeWidth: 64, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| resizeHeight: 64, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| resizeQuality: 'high', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onHover: onHover, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pickable: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| updateTriggers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getSize: [scale], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parameters: { depthTest: false }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (name == DEMAND && mapLayers?.[name]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential edge case: empty array response.
The backward compatibility logic converts legacy array responses to the new format, defaulting to
data[0]. However, if the backend returns an empty array, this would setdefault: undefined.Consider adding a guard:
// Backend can return either array (legacy) or {choices: [...], default: "..."} (new) if (Array.isArray(data)) { - setChoices({ choices: data, default: data[0] }); + setChoices({ choices: data, default: data.length > 0 ? data[0] : null }); } else { setChoices(data); }📝 Committable suggestion
🤖 Prompt for AI Agents