# Original User Request ## Initial Request — 2026-09-19T16:23:52Z This is a single self-contained fix; keep it small and focused. Implement station deselection and symmetric tab jumping behavior in the IMGW Climate Explorer Shiny application, replicating the behavior from the HungaroMet reference implementation. Working directory: /Users/alexandrudumitrescu/Documents/clima/2026/imgw Integrity mode: demo ## Reference Resources - Reference implementation: `/Users/alexandrudumitrescu/Documents/clima/2026/hungaromet` (notably `sections/server_hungaromet.R` lines 234–300, `sections/ui_hungaromet.R`, `www/app.js`, and `tests/stress_test_m2_m3_challenger_1_gen2.R`). - Target codebase: `/Users/alexandrudumitrescu/Documents/clima/2026/imgw` (`server.R`, `ui.R`, `www/app.js`, `www/styles.css`). ## Requirements ### R1. Symmetric Tab Navigation & Jumping - Selecting a station (via map point click, dropdown search, or station table double-click) must select the station and switch the active navigation tab to the **Dashboard** (`bslib::nav_select("main_nav", "Dashboard")`). - Deselecting a station while actively on the **Dashboard** tab must switch the navigation tab back to **Map View** (`bslib::nav_select("main_nav", "Map View")`). - Deselection triggered by dataset or temporal resolution changes must support silent clearing (`jump_to_map = FALSE`), keeping the current view intact. ### R2. Centralized Deselection State & Map Reset - Implement a centralized `clear_station_selection(jump_to_map = TRUE)` handler in `server.R` that: 1. Clears `current_station_uid(NULL)` and resets station fetch error state. 2. Resets the station search/dropdown input to empty / "All". 3. Removes the MapLibre highlighted selection layer (`clear_layer("selected-highlight")`). 4. Smoothly resets map viewport bounds back to Poland overview extent (`c(14.1, 49.0, 24.1, 54.9)` or center `c(19.1451, 51.9194)`, zoom 5.5). 5. Navigates from Dashboard to Map View if `jump_to_map = TRUE`. ### R3. Interactive Deselection Affordances - **Map Floating Chip**: Display a floating chip badge on the Map View when a station is selected, showing station name, ID, elevation, and an interactive "Deselect Esc" button (`clear_station_chip`). - **Sidebar Deselect Button**: Display an action button in the sidebar (`clear_station_sidebar`) whenever a station is selected. - **Global Esc Shortcut**: Listen for `Escape`/`Esc` keydown in `www/app.js` during the capture phase, closing any open MapLibre popups, blurring active focus, and signaling `esc_clear_station` to Shiny. Guard against triggering if loading overlay is active or a modal dialog is open. - **Home Button Reset**: Ensure clicking the map Home button (`zoom_home`) invokes `clear_station_selection()`. - **Dropdown Reset**: Clearing the station dropdown or selecting "All" invokes `clear_station_selection(jump_to_map = TRUE)`. ### R4. Automated Verification Test Suite - Provide an automated test script (`tests/test_deselection_and_jumping.R`) using `shiny::testServer` that tests: 1. Station selection switches `main_nav` to "Dashboard". 2. `clear_station_sidebar` clears selection and switches `main_nav` back to "Map View". 3. `clear_station_chip` clears selection and switches `main_nav` back to "Map View". 4. `esc_clear_station` clears selection and switches `main_nav` back to "Map View". 5. Selecting "All" or empty on `station_selector` clears selection and switches `main_nav` back to "Map View". 6. `zoom_home` clears selection. 7. Inactive / `jump_to_map = FALSE` clears selection without modifying `main_nav`. 8. Syntax and server load checks (`Rscript test_server_load.R`) succeed without warnings or errors. ## Acceptance Criteria ### Tab Jumping & Selection - [ ] Selecting a station from map click, table double-click, or dropdown updates `current_station_uid` and sets `input$main_nav` to "Dashboard". - [ ] Deselecting an active station while `input$main_nav == "Dashboard"` sets `input$main_nav` to "Map View". - [ ] Deselecting when `jump_to_map = FALSE` does not change `input$main_nav`. ### Deselection UI & Interactions - [ ] A floating chip (`station_chip_ui`) appears over the Map View whenever a station is active and disappears when deselected. - [ ] Clicking the chip's Deselect button triggers `clear_station_selection(jump_to_map = TRUE)`. - [ ] Sidebar displays a "Deselect Station (Esc)" button when a station is active, and clicking it triggers deselection. - [ ] Pressing `Esc` anywhere in the app triggers `esc_clear_station` without interfering with modals or the freeze overlay. - [ ] Clicking the Home button (`zoom_home`) clears the station selection and resets map bounds. - [ ] Changing `station_selector` to empty / "All" clears the station selection. ### Code Quality & Docker Sync - [ ] No `logical(0)` errors in reactive conditionals (adhering to user rules: `!is.null(...) && length(...) > 0`). - [ ] Any newly introduced dependencies are checked against `Dockerfile`. - [ ] The automated test suite (`Rscript tests/test_deselection_and_jumping.R`) runs to completion with exit code 0 and all assertions passing.