Skip to content

fix(ui): a map's text draft, spectral points, dialogs and import follow it when it moves (#2959) - #2975

Merged
jgregoriorincon merged 7 commits into
opengeos:mainfrom
jgregoriorincon:fix/2959-map-state-follows-map
Nov 26, 2026
Merged

jgregoriorincon merged 7 commits into
opengeos:mainfrom
jgregoriorincon:fix/2959-map-state-follows-map

Conversation

@jgregoriorincon

@jgregoriorincon jgregoriorincon commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part 1 of #2959 (the maps). Several pieces of open UI state remembered the active map by its place in the project (active_map) and dropped themselves when it no longer matched. Since #2806 that place changes whenever the map in view is moved (its tab, Move Up/Down, map.move), or another map moves past it, although the map in view is the same one. Each now keeps the map's identity, Map::instance_id() (the one table.rs and readjob.rs already use), and compares it with the map in view:

State Before, after the map in view moved After
Text typed in the Format pane for a map text (graphicformat.rs) the typed text was thrown away and the pane opened again kept, saved to its map
Spectral profile points (spectralui.rs) dropped with "read on … on another map" kept
Define Projection (dialogs.rs) Apply refused: "The active project or map changed" applies to its map
GeoPackage save/discard prompt (dialogs.rs) refused the same way applies to its map
Add From Service import in flight (serviceui.rs) cancelled without a message goes on in its map
Repair Data Source (repairsource.rs) the dialog closed stays open
What the label pane and the Unique Values box keep for a layer: class chosen, searches, the typed expression (labelpane::layer_key) reset, the typed expression lost kept

The dialogs, the import and the repair form share one helper, dialogs::map_key (identity plus name, as they already compared name); Define Projection, the GeoPackage prompt and the repair form keep the project they opened on beside it in one dialogs::MapOwner, whose holds is the one check. A different map, a copy (map.duplicate renews the identity), a deleted or replaced map and a replacement project still refuse or cancel, as before.

No new state: the fields that held an index hold an identity.

Not in this PR:

It reaches the desktop app and the browser build (the same egui code); commands, CLI, Python, scripts, plugins, the assistant, the ribbon and shortcuts, and the phone interface (ui-touch uses none of the changed modules) are untouched, and undo is unchanged.

Testing

  • New tests, each failing on the previous code and passing now:
    • graphicformat::tests::moving_the_map_keeps_the_text_being_typed (the typed text was lost);
    • spectralui::tests::moving_the_map_keeps_the_points (0 points kept, expected 1);
    • define_projection::dialog_applies_after_its_map_is_moved (Apply refused);
    • labelpane::tests::a_layers_state_follows_its_map_when_the_map_moves (the key changed with the map's place), and that a copy is another key;
    • serviceui::tests::an_import_follows_its_map_when_it_moves, on dialogs::map_key (the key changed from (0, "World") to (1, "World")): the same map moved is the same key, another map isn't. The GeoPackage prompt and Repair Data Source compare through this helper and have their own tests:
    • dialogs::tests::the_gpkg_prompt_follows_its_map_when_the_map_moves;
    • repairsource::tests::the_form_follows_its_map_when_the_map_moves (its stale check is now repairsource::gone);
    • serviceui::tests::an_import_in_flight_goes_on_when_its_map_moves runs poll on an import in flight.
      All four fail with the old position-based key.
  • The existing refusals still pass: dialog_rejects_a_different_map_with_the_same_layer_id and dialog_rejects_a_replacement_project_with_the_same_map_and_layer.
  • checks.sh 2959 rustgis-ui-egui: fmt, clippy, nextest (9610 passed), cargo check -p rustgis-web --target wasm32-unknown-unknown, doctests, layers and schema --check all exit 0.

UI evidence

No visible UI change.

Related issue

Part of #2959.

Summary by CodeRabbit

  • Bug Fixes
    • Map-specific dialogs, imports, repair workflows, graphic-format drafts, layer state, and spectral data now stay associated with the correct map when maps are reordered.
    • Actions are prevented from applying to a different map or project if the original target is no longer available.
  • Tests
    • Added coverage for map reordering, map switching, and preserving the correct target across these changes.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The UI now tracks dialog ownership, imports, repair forms, graphic-format drafts, layer UI state, and spectral points by stable map identity rather than project position. Tests cover map movement and cases where switching maps or projects invalidates an operation.

Changes: Map identity in UI workflows

Layer / File(s) Summary
Dialog and import ownership
crates/ui-egui/src/dialogs.rs, crates/ui-egui/src/serviceui.rs, crates/ui-egui/tests/integration/define_projection.rs
Dialogs capture project and map ownership, and imports use a stable map key. Tests cover map movement and ownership changes.
Map-keyed editor and spectral state
crates/ui-egui/src/graphicformat.rs, crates/ui-egui/src/labelpane.rs, crates/ui-egui/src/spectralui.rs
Graphic-format drafts, layer UI keys, and spectral profiles use map instance identity. Tests cover state after map movement.
Repair form ownership
crates/ui-egui/src/repairsource.rs
Repair forms use MapOwner and validate the target layer and tile data. Tests cover map movement and owner changes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • opengeos/RustGIS issue 2959 describes map-position keyed state being lost when a map moves. This PR addresses the listed dialog, import, repair, editor, and spectral behaviors; layout state is deferred.

Suggested reviewers: deniial00, giswqs, elpidioassinaturas

Merge Risk: Minimal · up to 2817a

This change makes map-related UI state follow the same map when its position in the project changes, while refusing or cancelling for different maps and replacement projects. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: map-keyed UI state (text draft, spectral points, dialogs, import) now follows a map when it moves. The changeset matches this. The title covers the main fix, though it…
Description check Passed The description follows the template. It has Summary, Testing, UI evidence, and Related issue sections. The UI evidence section correctly says 'No visible UI change.' The Related issue section says 'P…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: map-keyed UI state (text draft, spectral points, dialogs, import) now follows a map when it moves. The changeset matches this. The title covers the main fix, though it does not list every affected area (labelpane, repairsource), 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 correctly says 'No visible UI change.' The Related issue section says 'Part of #2959.' The Summary and Testing sections are detailed and match the changeset. One minor gap: the template asks for issue closing syntax in Related issue, but this is a partial PR, so 'Part of #2959' fits.

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 hops where map keys stay,
No draft is lost along the way.
A spectral point keeps its place,
A dialog waits with steady grace.
Maps may move; their states remain,
Then switch away, and checks constrain.

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: 40842a79-af58-4d64-a2b1-aab10a9d106d
Commits

Reviewing files that changed from the base of the PR and between c0c5362 and 2817aec.

Files selected for processing: 7

  • crates/ui-egui/src/dialogs.rs
  • crates/ui-egui/src/graphicformat.rs
  • crates/ui-egui/src/labelpane.rs
  • crates/ui-egui/src/repairsource.rs
  • crates/ui-egui/src/serviceui.rs
  • crates/ui-egui/src/spectralui.rs
  • crates/ui-egui/tests/integration/define_projection.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/ui-egui/src/labelpane.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I found no bugs, security issues or AGENTS.md breaks in the changed code. The change swaps the map-place key (active_map index) for Map::instance_id(), and I checked that the swap holds up:

  • Session::map() falls back to the first map and never panics, so the new map_key helper is safe where the old .get() code was.
  • instance_id comes from a process-global atomic counter and is skipped by serde, so it is never saved. Keys that now include it stay session-scoped and cannot leak into a project file.
  • Undo snapshots keep the map's identity, map.duplicate and map.new mint a fresh one, and map.move only reorders, so "same map, moved" and "copy is another map" hold.
  • The old (usize, String) tuples have no other readers. All uses in dialogs.rs, repairsource.rs and serviceui.rs are updated.
  • The change adds no data copies and no commands, so the memory, command-surface and cancellation rules don't apply. Nothing here is UI-thread work, and the code is wasm-neutral.

I did not build or run the tests, since this environment has no shell. The judgments above come from reading the code.

Findings

Bugs

  • None found. Confidence: high that the logic is sound.

Security

  • None.

Performance

  • None. The change adds one String clone per dialog open or per frame in layer_key-style paths, which is negligible.

Quality

  • labelpane.rs:1454: the "copy is another key" assertion passes on the renamed copy alone, so it does not prove that duplicate_map renews the identity. Posted inline. Confidence: high. Category: quality.
  • serviceui.rs test: it covers the "moved map keeps the import" path but not the PR's claim that a deleted or replaced map cancels the import. An extra case would cover that. Confidence: medium. Category: quality.
  • labelpane::layer_key still includes the map name, so a rename resets the label-pane state. The text draft in graphicformat does not include the name and survives a rename. The PR's table implies "kept" for both. This is pre-existing and not a regression, so it's worth documenting rather than fixing here. Confidence: medium. Category: quality.
  • dialogs.rs: Option<(u64, MapKey)> is a nested tuple that is hard to read. A small struct would be clearer. Nit. Category: quality.
  • map_key lives in dialogs but is used by repairsource and serviceui. A home in the map or session module would avoid the cross-module reach. Nit. Category: quality.

AGENTS.md

  • None. The change touches no commands, saved files, expression vocabulary or asset rules.

Earlier concerns left alone: 0. No prior review threads exist on this PR.

Change size

Compared with the base branch (merge base 77c573c to PR head fc1f200).

Measure Value
Files changed 7 (added 0, modified 7, removed 0, renamed 0)
Size before 540.2 KB
Size after 546.6 KB
Total size change +6.3 KB
Path Before After Change
crates/ui-egui/src/graphicformat.rs 14.8 KB 16.6 KB +1.8 KB
crates/ui-egui/src/spectralui.rs 42.8 KB 44.0 KB +1.2 KB
crates/ui-egui/src/labelpane.rs 138.0 KB 139.2 KB +1.2 KB
crates/ui-egui/tests/integration/define_projection.rs 10.4 KB 11.5 KB +1.1 KB
crates/ui-egui/src/serviceui.rs 63.0 KB 63.8 KB +0.9 KB
crates/ui-egui/src/dialogs.rs 256.5 KB 256.5 KB +259 B
crates/ui-egui/src/repairsource.rs 14.8 KB 14.7 KB -51 B

Comment thread crates/ui-egui/src/serviceui.rs Resolved
Comment thread crates/ui-egui/src/labelpane.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Scope: 7 files in crates/ui-egui, moving the map-scoped UI state (Format pane text, spectral points, Define Projection, GeoPackage prompt, Add From Service import, Repair Data Source, label-pane layer state) from the map's index to Map::instance_id(). I checked the identity lifecycle in crates/map/src/lib.rs and the engine: instance_id is process-local and not serialized, snapshots keep it, and copies or new maps renew it (map.new, map.duplicate, offline maps, globe locator, plugin_fetch, circle_edit). With that, moving a map keeps its key, and a copy, a deleted map and a replaced map get a different one. I could not compile or run the tests here (no shell), so this is from reading the code.

Bugs: None found. The key comparisons still refuse the cases the PR says they refuse. The import's poll now continues only when the map in view is the originating map, so the landing code acts on the right map.

Security: None found.

Performance: None significant. dialogs::map_key clones the map name each frame while the Repair Data Source form is open. That is negligible and I did not raise it.

Quality:

  • crates/ui-egui/src/serviceui.rs:687 (confidence: high). The new import test checks only the map_key helper, not poll, so it would not catch a regression in the moved-map import path. The GeoPackage prompt and Repair Data Source have no moved-map test either, as the PR notes. Inline comment posted.
  • crates/ui-egui/src/labelpane.rs:148 (confidence: medium). The map name in layer_key is redundant now that identity is unique, and keeping it means a rename still resets the pane's state, which the PR table doesn't mention. This predates the PR. Inline comment posted.

AGENTS.md: No breaks found. There is no unwrap/expect/panic in non-test code, the changes are not desktop-only so the wasm build is unaffected, and no saved file or command surface changed, so no schema, snapshot or limit file needs updating.

Prior reviews: 1 earlier thread (the weak assert_ne! in the label-pane test). It is outdated, and the test now asserts the identity directly, as that thread asked, so I left it alone. I raised 2 new concerns and skipped 1 already-raised concern.

Change size

Compared with main (merge base 77c573c to PR head e7ee2f9), the whole PR.

Measure Value
Files changed 7 (0 added, 7 modified, 0 removed, 0 renamed)
Size before 540.2 KB
Size after 546.8 KB
Total size change +6.5 KB
Path Before After Change
crates/ui-egui/src/graphicformat.rs 14.8 KB 16.6 KB +1.8 KB
crates/ui-egui/src/labelpane.rs 138.0 KB 139.5 KB +1.4 KB
crates/ui-egui/src/spectralui.rs 42.8 KB 44.0 KB +1.2 KB
crates/ui-egui/tests/integration/define_projection.rs 10.4 KB 11.5 KB +1.1 KB
crates/ui-egui/src/serviceui.rs 63.0 KB 63.8 KB +0.9 KB
crates/ui-egui/src/dialogs.rs 256.5 KB 256.7 KB +259 B
crates/ui-egui/src/repairsource.rs 14.8 KB 14.7 KB −51 B

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2975/
Web app https://preview.rustgis.app/pr-2975/app/
Commit 2817aec

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).

Comment thread crates/ui-egui/src/dialogs.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I found no bugs, security issues, or performance problems in this PR. One readability point is posted inline, and a few nits are grouped below. I could not compile or run the tests (no shell here), so this is a read-only review of the diff and the surrounding code.

Bugs: none found (confidence: high).

  • Map::instance_id is process-local and never serialized. It is renewed on every copy path I found (map.duplicate, offline.open, the layout globe replacement, the items and circle-edit map insertions), and undo snapshots keep it. So a copy never matches its original, and a reopened project gets fresh identities.
  • The spectral restart logic (spectralui.rs 245–260, 289) still restarts on a different map, a rename-free layer change, or a pixel change. The map check now compares identities.
  • The Repair form's gone (repairsource.rs) still closes the form for a different project, a missing layer, or a replaced tile layer.
  • The import poll (serviceui.rs) still cancels on a deleted or replaced map. Since map_key compares identity and name, a same-map move is the only case that now continues.
  • The gesture states the PR leaves index-based (boxedit, circleedit, vertexedit, the map popup) are called out in the PR description as intentional.

Security: none.

Performance: none. map_key clones a short name once per frame while a dialog is open; that is negligible.

Quality:

  • dialogs.rs:33 (posted inline): Option<(u64, MapKey)> nests a tuple and repeats the same project-and-map check in three places (gpkg_owner, the Define Projection Apply closure, repairsource::gone). A small struct would give one definition. Left for the release quality pass.
  • Nit: the new define_projection::dialog_applies_after_its_map_is_moved test repeats the reprojected-point lookup inline, where the file already has a point(...) helper. Also left for the release quality pass.

AGENTS.md: no breaks found. No commands or parameters were added, so the command-surface snapshot is unaffected. No user-visible strings were added. The description covers the surfaces the change reaches, and the new tests fail on the old comparisons.

Prior reviews: 3 earlier concerns left alone, because this head already addresses them. The serviceui test gap now has an_import_in_flight_goes_on_when_its_map_moves and a GeoPackage prompt test. The labelpane doc now says a rename resets layer state. The labelpane copy assertion now compares instance_id directly.

Change size

Compared with the base branch (merge base 77c573c to PR head 81d86ec). Sizes are in KB (1 KB = 1024 B).

Measure Value
Files changed 7 (added 0, modified 7, removed 0, renamed 0)
Size before 540.2 KB
Size after 550.5 KB
Total size change +10.3 KB
Path Before After Change
crates/ui-egui/src/serviceui.rs 63.0 KB 65.3 KB +2.4 KB
crates/ui-egui/src/graphicformat.rs 14.8 KB 16.6 KB +1.8 KB
crates/ui-egui/src/labelpane.rs 138.0 KB 139.5 KB +1.5 KB
crates/ui-egui/src/dialogs.rs 256.5 KB 257.7 KB +1.2 KB
crates/ui-egui/src/repairsource.rs 14.8 KB 15.9 KB +1.2 KB
crates/ui-egui/src/spectralui.rs 42.8 KB 44.0 KB +1.2 KB
crates/ui-egui/tests/integration/define_projection.rs 10.4 KB 11.5 KB +1.1 KB

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Reviewed the whole diff (7 files in crates/ui-egui), checked the callers and the Map::instance_id / renew_instance_id lifecycle in crates/map and crates/engine, and read the new tests. I could not compile or run them here (no shell), so the assertions are checked by reading only.

Bugs: None found. Checked:

  • Map::instance_id is #[serde(skip)], so it is process-local and fresh on load.
  • map.move moves the Map value and keeps its identity.
  • map.duplicate and the other renew paths (navigate.rs, workspace.rs, items.rs) assign a new identity.
  • Undo snapshots keep identity.
  • Session::map() falls back to a OnceLock empty map, so the key is stable when no map exists.
  • The repairsource tiles index is per map, so it stays valid after a move.
  • The Define Projection Apply path still runs on the active map.

Security: None found. No new input parsing, no new commands, no new file or network access.

Performance: None found. The new keys are a u64 plus the name, compared on each frame, which is no costlier than the index-plus-name comparison it replaces.

Quality: Nothing that needs a change in this PR.

  • The prior thread about layer_key resetting on rename is answered: the doc comment now says so.
  • The prior thread about the duplicate-map assertion is resolved: the test now asserts the identity directly.
  • The prior thread about missing in-flight import coverage is resolved: an_import_in_flight_goes_on_when_its_map_moves calls poll.
  • The prior thread about missing GeoPackage and Repair Data Source coverage is resolved: the_gpkg_prompt_follows_its_map_when_the_map_moves and the_form_follows_its_map_when_the_map_moves were added.
  • Low-confidence note, not posted: rename behaviour differs by surface. Labels, spectral points and the text draft keep state across a rename, while the dialogs, the import and Repair refuse or cancel on it, because MapOwner and map_key include the name. The PR body and doc comments describe both, so I see this as deliberate.

AGENTS.md: No breaks found. The new code adds no user-visible literals, so tl! does not apply. No unwrap appears in non-test code. The new code is platform-neutral, so the wasm build is unaffected. The PR body covers the surfaces it reaches.

Concerns left alone: 1 prior concern was left alone because it is still present and already raised: the MapOwner tuple-nesting nit in dialogs.rs, which is deferred to the release quality pass. The other 3 earlier threads are resolved by the new code, so they are not re-raised.

Inline comments: None posted, because no finding met the bar for a comment.

Change size

Compared with main (merge base 77c573c to PR head 2817aec). The table counts files, and the sizes are file sizes in bytes, not diff lines.

Measure Value
Files changed 7 (added 0, modified 7, removed 0, renamed 0)
Size before 540.2 KB
Size after 550.9 KB
Total size change +10.7 KB
File Before After Change
crates/ui-egui/src/serviceui.rs 62.9 KB 65.3 KB +2.4 KB
crates/ui-egui/src/graphicformat.rs 14.8 KB 16.6 KB +1.8 KB
crates/ui-egui/src/dialogs.rs 256.5 KB 258.1 KB +1.6 KB
crates/ui-egui/src/labelpane.rs 138.0 KB 139.5 KB +1.5 KB
crates/ui-egui/src/spectralui.rs 42.8 KB 44.0 KB +1.2 KB
crates/ui-egui/src/repairsource.rs 14.8 KB 15.9 KB +1.1 KB
crates/ui-egui/tests/integration/define_projection.rs 10.4 KB 11.5 KB +1.1 KB

@jgregoriorincon
jgregoriorincon marked this pull request as ready for review November 25, 2026 23:28
Comment thread crates/ui-egui/src/graphicformat.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the full diff, the base AGENTS.md, and the four prior review threads. I also checked the code the PR depends on: Map::instance_id and its renewal sites (navigate.rs duplicate, items.rs, workspace.rs), map.move, Project::map(), and the non-test callers of layer_key, follow_rename and repairsource::gone. I found no crash, unwrap in non-test code, wasm, or layering problem. The prior-review fixes hold in the current code.

Bugs

  • Silent draft loss in graphicformat::save_draft (crates/ui-egui/src/graphicformat.rs:182), pre-existing, medium confidence (~55%). A typed but unsaved text draft is dropped with no notice when another map is in view. The PR changes this line to use identity, so it is raised here. Under AGENTS.md's "Never silent", it should give a notice. Posted as an inline comment, category bug.

Security

  • None found.

Performance

  • None new. dialogs::map_key clones the map name on each frame that serviceui::poll runs. The old active_map did the same, so this is not a regression.

Quality

  • None new. The earlier quality points on this PR were addressed in the code, so I did not repeat them.

AGENTS.md

  • None found. The PR adds no user-visible literals, no unwrap outside tests, and no new command, project field or saved state. The tests use fixed expected values.

Coverage and checks

  • I could not build or run the tests (no shell). The PR reports fmt, clippy, nextest (9610 passed) and the wasm check as passing. I checked the new tests by reading them. They match the behaviour the PR describes.
  • Prior concerns left alone: 4 (the serviceui test gap, the labelpane name-in-key question which the author answered, the duplicate-copy assertion which was fixed, and the MapOwner consolidation which was done).

Change size

Compared: the whole PR against main (merge base 77c573c to PR head 2817aec).

Measure Value
Files changed 7 (0 added, 7 modified, 0 removed, 0 renamed)
Size before 540.2 KB
Size after 550.9 KB
Total size change +10.7 KB
File Before After Change
crates/ui-egui/src/serviceui.rs 63.0 KB 65.3 KB +2.4 KB
crates/ui-egui/src/graphicformat.rs 14.8 KB 16.6 KB +1.8 KB
crates/ui-egui/src/dialogs.rs 256.5 KB 258.1 KB +1.6 KB
crates/ui-egui/src/labelpane.rs 138.0 KB 139.5 KB +1.5 KB
crates/ui-egui/src/spectralui.rs 42.8 KB 44.0 KB +1.2 KB
crates/ui-egui/src/repairsource.rs 14.8 KB 15.9 KB +1.1 KB
crates/ui-egui/tests/integration/define_projection.rs 10.4 KB 11.5 KB +1.1 KB

@jgregoriorincon
jgregoriorincon added this pull request to the merge queue Nov 26, 2026
Merged via the queue into opengeos:main with commit 3163417 Nov 26, 2026
31 checks passed
@jgregoriorincon
jgregoriorincon deleted the fix/2959-map-state-follows-map branch November 26, 2026 00:15
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.

1 participant