Skip to content

fix(engine): a legend's lists bind every layer of a name they give - #3622

Merged
jgregoriorincon merged 3 commits into
opengeos:mainfrom
jgregoriorincon:fix/3288-legend-shared-names
Dec 2, 2026
Merged

jgregoriorincon merged 3 commits into
opengeos:mainfrom
jgregoriorincon:fix/3288-legend-shared-names

Conversation

@jgregoriorincon

@jgregoriorincon jgregoriorincon commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A legend's exclude, layerOrder, columnBreaks, labels and classLabels name layers, and the legend applies each name to every layer of the frame's map that has it, in any case. The inputs of layout.addElement and layout.update took only the first of those layers, so an exact approval didn't bind the others.

legend_inputs, which both commands and all five lists go through, now binds every layer of a named name in the frame's map. Map::layer_by_name is unchanged, and so is what a table, chart or colorbar binds, which each read one layer.

Surfaces: the change is in the shared engine, in what layout.addElement and layout.update bind when a plan is approved, so the Assistant, MCP and any other surface that plans these two commands get it, whichever app it runs in. No command, option or tool description changed, and there is nothing to add to the ribbon, shortcuts, command search or any pane. Nothing saved or undone changes.

Testing

  • New tests in crates/engine/src/tests/layout_legend_shared_names.rs: with two layers named Rivers, each of the five lists (and another case of the name) binds both, through both commands; with one, only that layer is bound, a same-named layer in another map isn't, and a call that gives no list binds none. The first test fails without the fix (left: [(2, 4)], right: [(2, 3), (2, 4)]).
  • Local: fmt, clippy, doctests, layers and the schema check pass. The full nextest run: 12302 passed and 8 failed, all outside this diff and failing on this machine without it (7 in rustgis-geolibre and the line_strokes_editor_edits_one_class smoke test, [Bug]: smoke test line_strokes_editor_edits_one_class fails on main #3411). After a last change to one new test, the 62 layout_legend tests, fmt and clippy of rustgis-engine pass again.

UI evidence

No visible UI change.

Related issue

Closes #3288.

Summary by CodeRabbit

  • Bug Fixes
    • Legend selections now include all layers with matching names, including names that differ only by capitalization. This works when the same name appears in multiple legend lists.
    • Layout elements now bind only to matching layers in the active map, and empty layout parameters do not bind any layers.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Code review

Small, focused change: legend_inputs now binds every layer of each name a legend's lists give (case-insensitive), not just the first. I checked the fix against the legend renderer and the other binders, and found no correctness problems.

Bugs

  • None found. The new filter matches what the legend renderer does: render/src/layout/legend.rs applies exclude, layerOrder, columnBreaks and labels with eq_ignore_ascii_case over every layer, so an approval now covers the same layers the legend draws. Confidence: high.

Security

  • None found.

Performance

  • None found. The extra work is names × layers over a small map. Confidence: high.

Quality

  • Inline comment on tests/layout_legend_shared_names.rs (lines 17–22): the named() helper repeats the production filter, so the expected values can drift with the code under test. The len() asserts limit this, and I judged it minor. Confidence: medium.
  • Not raised inline, because it is pre-existing and not changed here: a legend list naming a layer that is not in the map yet is dropped, while Inputs::named (used by tables, charts and the like) records it in future_layers. So a layer a batch adds later isn't bound by the legend. The PR doesn't change this and it may be intended. Confidence: low–medium.

AGENTS.md

  • The PR description doesn't say which surfaces the change reaches (desktop, browser, CLI, Python, phone, ribbon, Assistant and MCP tool descriptions, plugins, undo), as "Reach every surface" asks. It only says "No visible UI change." The change does reach the Assistant and MCP through the approval inputs of layout.addElement and layout.update, so the description should say so. Confidence: high.
  • The other AGENTS.md checks pass: no unwrap in non-test code, the new test has a fixed expected count, no timer waits, no copied code, and both the lossy and clean cases are covered.

Twins checked

  • Table, chart and colorbar binders (frame_layer_name, colorbar_layer): they bind one layer and the PR leaves them unchanged. That is consistent with how they read data.
  • Legend paths in the renderer (exclude, layerOrder, columnBreaks, labels, classLabels): all use case-insensitive matching over every layer, so the binder now agrees with them.
  • terrain bed lookup in render/src/block.rs: deliberately binds only a unique name, a different rule not touched by this PR.
  • No #[cfg(target_arch = "wasm32")] branch is touched.

Prior review threads: none existed, so nothing was left out as already raised.

Change size

Compared with main (merge base d75248d to PR head 9ccc55d), the whole PR.

Measure Value
Files changed 3 (1 added, 2 modified, 0 removed, 0 renamed)
Size before 3.89 MB (4,078,495 B)
Size after 3.89 MB (4,081,607 B)
Total size change +3.0 KB (+3,112 B)
File Before After Change
crates/engine/src/tests.rs 3.87 MB 3.87 MB +81 B
crates/engine/src/cmd/layout/inputs.rs 16.6 KB 16.8 KB +143 B
crates/engine/src/tests/layout_legend_shared_names.rs 0 B 2.8 KB +2.8 KB

Comment thread crates/engine/src/cmd/layout/inputs.rs Resolved
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Code review

I read the diff, the surrounding code (legend_inputs and its two callers, legend_layer, Map::layer_by_name, the policy plan that consumes inputs.layers, and the legend renderer in ui-egui) and the prior review thread. I could not build or run the tests here (no shell), so the findings below come from reading the code.

Bugs

  • None found. Both callers (inputs.rs:133 for layout.addElement and inputs.rs:256 for layout.update) go through legend_inputs. Names reach it as the map's canonical spellings from legend_layer, and eq_ignore_ascii_case matches layer_by_name and the renderer at ui-egui/.../legend.rs:326. Tile-only names bind nothing, as before. Confidence: high.

Security

  • None found. The change only widens the set of layers an approval binds, which makes the approval plan cover more of what the legend touches. Confidence: high.

Performance

  • The new scan is O(names × layers) per list. Each list is capped by MAX_LEGEND_EXCLUDED or MAX_LEGEND_LABELS, and legend_layer already scans the same way. Negligible. Confidence: high.

Quality

  • Same-named layers named by two lists are pushed twice into inputs.layers. Posted as an inline comment on inputs.rs:284 with a contains suggestion, matching edit.rs:100. The new tests use one list per call, so they don't cover this. Confidence: medium.

AGENTS.md

  • "Reach every surface": the staged metadata.json body has no surfaces statement. The PR author's reply in the prior thread says it was added to the description, so this may be a stale snapshot. Please confirm it's in the current PR body. Confidence: low.

Twins checked

  • legend_inputs has two callers, and both are covered.
  • Table, chart and colorbar still bind one layer through Inputs::named. The PR says this is intentional, and I agree it is not a legend list.
  • No other legend-list call site binds layers. The legend_* readers are used for validation and for state only.
  • The overlay tools, layer.add* and project.open*/import* are not touched by this diff.

Prior concerns

  • 1 earlier concern left alone. It was the test-helper quality thread, which the author fixed in 79a211e and which is marked outdated and resolved. Not re-raised.

Change size

Compared with the base branch: the whole PR against main (merge base d75248d to PR head 79a211e).

Measure Value
Files changed 3 (1 added, 2 modified, 0 removed, 0 renamed)
Size before 3.89 MB
Size after 3.89 MB
Total size change +2.9 KB
Path Before After Change
crates/engine/src/tests/layout_legend_shared_names.rs 0 B 2.7 KB +2.7 KB
crates/engine/src/cmd/layout/inputs.rs 16.6 KB 16.8 KB +143 B
crates/engine/src/tests.rs 3.87 MB 3.87 MB +81 B

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

legend_inputs now includes every active-map layer whose name matches a supplied legend selector, without regard to case. Tests cover both legend commands, duplicate names, map scope, and empty selector lists.

Changes: Legend binding

Layer / File(s) Summary
Match selectors to map layers
crates/engine/src/cmd/layout/inputs.rs
legend_inputs walks the active map’s layers and includes each layer whose name matches a selector, case-insensitively. The documentation describes the matching behavior and treats tile-layer names as selector text.
Verify legend command bindings
crates/engine/src/tests.rs, crates/engine/src/tests/layout_legend_shared_names.rs
Tests cover both legend commands with duplicate and case-insensitive names, names repeated across lists, same-named layers in another map, and empty parameters.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related issues

Possibly related PRs

  • opengeos/RustGIS#3213: Adds classLabels overrides; this PR changes how that list binds duplicate layer names.
  • opengeos/RustGIS#1739: Adds the labels list with case-insensitive matching; this PR changes its binding for duplicate names.
  • opengeos/RustGIS#3285: Adds layerOrder; both PRs address how that list binds same-named layers.

Suggested reviewers: elpidioassinaturas, mavrick-f

Merge Risk: Minimal · up to 0cf92

Legend layer-name lists now bind every layer with a matching name in the active map, as the linked issue requests. Tests cover both legend commands, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a legend's lists now bind every layer that shares a name in the frame's map. It matches the summary, the objectives, and the linked issue #3288. It uses the fix(engine…
Description check Passed The description follows the template. It has Summary, Testing, UI evidence, and Related issue sections. The UI evidence section states 'No visible UI change.', which the template allows when no UI cha…
Linked Issues check Passed Issue #3288 requires that every layer reached by a legend's name lists be among the command inputs. At the reviewed head, legend_inputs in crates/engine/src/cmd/layout/inputs.rs walks map.layers…
Out of Scope Changes check Passed The whole-PR change set consists of the legend_inputs change in crates/engine/src/cmd/layout/inputs.rs (with a comment update), the module registration in crates/engine/src/tests.rs, and the new…
Full details: Title check

Explanation

The title names the main change: a legend's lists now bind every layer that shares a name in the frame's map. It matches the summary, the objectives, and the linked issue #3288. It uses the fix(engine) convention and names the affected surface. It is 66 characters, which is acceptable.

Full details: Description check

Explanation

The description follows the template. It has Summary, Testing, UI evidence, and Related issue sections. The UI evidence section states 'No visible UI change.', which the template allows when no UI changes. The Summary explains the cause, the fix, and the scope. The Testing section lists new tests, the expected failure without the fix, and the local check results. The Related issue section links #3288.

Full details: Linked Issues check

Explanation

Issue #3288 requires that every layer reached by a legend's name lists be among the command inputs. At the reviewed head, legend_inputs in crates/engine/src/cmd/layout/inputs.rs walks map.layers and binds each layer whose name matches any supplied selector with eq_ignore_ascii_case. It binds each layer once, so a name shared by two layers binds both. layout.addElement (via element_inputs) and layout.update (via update_inputs) both route the legend's exclude, layerOrder, columnBreaks, labels and classLabels lists through this function. The PR adds crates/engine/src/tests/layout_legend_shared_names.rs (registered in crates/engine/src/tests.rs) covering both commands, duplicate names, a single match, a same-named layer in another map, and a call with no lists. The test file was not read directly. Its coverage rests on the PR description and the change summary. Map::layer_by_name and the single-layer bindings for table, chart and colorbar are unchanged, as the issue requires. The inclusion of columnBreaks goes beyond the issue's four named lists. It is the same bug class, because the legend applies that list to layers by name too.

Full details: Out of Scope Changes check

Explanation

The whole-PR change set consists of the legend_inputs change in crates/engine/src/cmd/layout/inputs.rs (with a comment update), the module registration in crates/engine/src/tests.rs, and the new test module. All of these serve the objective of binding every layer that a legend's name lists reach. The PR states that no command, option, tool description, UI, or saved state changes. The diff was read at the file level only, and the summary reports no other files. No unrelated change was identified.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the layers in a row,
Each matching name now joins the show.
Uppercase, lowercase, all are found,
Only the active map counts around.
The legend lists its layers sound.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: db31f761-1bac-468d-97e2-a85e124f44c1
Commits

Reviewing files that changed from the base of the PR and between d75248d and 0cf923f.

Files selected for processing: 3

  • crates/engine/src/cmd/layout/inputs.rs
  • crates/engine/src/tests.rs
  • crates/engine/src/tests/layout_legend_shared_names.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

Comment thread crates/engine/src/cmd/layout/inputs.rs Resolved
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Code review

I found no bugs, security issues or AGENTS.md breaks in this PR. The change does what the description says: a legend's exclude, layerOrder, columnBreaks, labels and classLabels now bind every layer whose name matches, in any case, instead of only the first one.

Bugs: none found. Confidence: high.

  • The name filter at inputs.rs:284 matches layer_by_name, which uses eq_ignore_ascii_case. It also matches the renderer's exclusion at legend.rs:70.
  • Names reach legend_inputs already resolved by legend_layer, so the trim() fallback in that function doesn't matter here.
  • Both callers (inputs.rs:133, inputs.rs:256) start from an empty Inputs, so layers can't be pushed twice.
  • The walk is over map.layers, so each layer is pushed at most once per call.

Security: none. No input handling or secret handling changed.

Performance: nothing significant. The name chain is re-walked per layer, which costs little at legend list sizes (the one nit I posted inline).

Quality:

  • Inline nit at inputs.rs:284: collect the names once before filtering. Confidence: high that it's valid; it's a readability point only.
  • The new tests in layout_legend_shared_names.rs cover the two-list case (line 95), the case-insensitive case, the layer-in-another-map case, and the empty-input case.
  • I didn't run the tests; this review has no build or test tool. I checked the helpers they use exist (renew_instance_id on Map and Layer, and layer.rename, which accepts duplicate names).

AGENTS.md: no breaks. No command or parameter changed, so command-surface.txt is unaffected. No project fields or schema changed. The change adds no layer copies. The "Reach every surface" note in the PR description is accurate.

Twins checked: the only callers of legend_inputs are the two commands in the diff. The table, chart and colorbar paths (inputs.rs:20, 125, 128, 235, 242, 249) still bind one layer on purpose, as the PR says. The publication code (publication/mod.rs:365) and the raster notices (legend.rs:111) already use the same case-insensitive rule. I did not trace the layout.import and report.existingTemplate paths beyond confirming they don't call legend_inputs.

Prior review threads: I left 2 earlier concerns alone.

  • The thread saying a layer named by two lists is pushed twice (inputs.rs:285) doesn't match the current code, which does one pass. The existing test at line 95 also checks that case.
  • The thread about the test helper repeating the production filter is resolved by commit 79a211e.

Change size

Compared: the whole PR against main (merge base d75248d to PR head 0cf923f).

Files changed Added Modified Removed Renamed Size before Size after Total size change
3 1 2 0 0 3.89 MB 3.89 MB +3.1 KB
Path Size before Size after Size change
crates/engine/src/tests/layout_legend_shared_names.rs 0 B 2.8 KB +2.8 KB
crates/engine/src/cmd/layout/inputs.rs 16.6 KB 16.8 KB +235 B
crates/engine/src/tests.rs 3.87 MB 3.87 MB +81 B

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3622/
Web app https://preview.rustgis.app/pr-3622/app/
Commit 0cf923f

GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the preview label (once per commit).

@jgregoriorincon
jgregoriorincon marked this pull request as ready for review December 2, 2026 19:58
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Code review

I found no bugs, security issues or AGENTS.md breaks in this PR, and posted no inline comments. The change is small: legend_inputs now binds every map layer whose name matches one of a legend's five lists, case-insensitively, instead of one layer per name. It is covered by two new tests.

Bugs: none found. I checked that:

  • The eq_ignore_ascii_case match agrees with how the renderer applies exclude, layerOrder, columnBreaks and labels (crates/render/src/layout/legend.rs).
  • All five lists resolve names through legend_layer first, so the names reaching legend_inputs are already in the map's spelling. A name the map lacks is refused before binding, as the author's reply says.
  • The duplicate-push case from the earlier thread is fixed in 0cf923f. The walk over map layers binds each layer once, and the exclude + labels case in the new test covers it.
  • table, chart and colorbar still bind a single layer, which is intended.

Security: none found.

Performance: none. The cost is layers × names over in-memory metadata, and only ids are pushed.

Quality (low confidence, not raised as a comment):

  • inputs.layers now comes out in map order, not in the order the names were given. The tests sort before comparing, so nothing checks this. I did not verify whether the approval text the user sees depends on that order.

Prior review threads (4 in total): I left all of them alone. Two were fixed in the head commit: the duplicate push, and the test helper that repeated the production filter. The collect-names nit on the filter is still open, but the author answered it and the code there hasn't changed, so I did not post it again.

AGENTS.md: the change stays within the rules. It needs no schema or command-surface update, and the PR description states which surfaces it reaches.

Change size

Compared with main (merge base d75248d to PR head 0cf923f), the whole PR.

Measure Value
Files changed 3 (1 added, 2 modified, 0 removed, 0 renamed)
Size before 3.89 MB
Size after 3.89 MB
Total size change +3.1 KB
Path Before After Change
crates/engine/src/tests/layout_legend_shared_names.rs 0 B 2.8 KB +2.8 KB
crates/engine/src/cmd/layout/inputs.rs 16.6 KB 16.8 KB +235 B
crates/engine/src/tests.rs 3.87 MB 3.87 MB +81 B

@jgregoriorincon
jgregoriorincon added this pull request to the merge queue Dec 2, 2026
Merged via the queue into opengeos:main with commit 8f1c5ec Dec 2, 2026
31 checks passed
@jgregoriorincon
jgregoriorincon deleted the fix/3288-legend-shared-names branch December 2, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: A legend binds only the first of the layers that share a name it lists

1 participant