Skip to content

frontend: fix compass priority ordering and drag behavior#3874

Merged
patrickelectric merged 1 commit intobluerobotics:masterfrom
Williangalvani:compass_fix
Apr 13, 2026
Merged

frontend: fix compass priority ordering and drag behavior#3874
patrickelectric merged 1 commit intobluerobotics:masterfrom
Williangalvani:compass_fix

Conversation

@Williangalvani
Copy link
Copy Markdown
Member

@Williangalvani Williangalvani commented Apr 13, 2026

Load initial compass order from COMPASS_PRIO*_ID parameters instead of COMPASS_DEV_ID name order. Only write PRIO_ID params on user drag interactions, not on page load. Fix tab content to follow reordered list using deviceIdNumber for correct parameter mapping, and select the drop position after reordering.

fix #3873

Summary by Sourcery

Align compass configuration UI with compass priority parameters and correct behavior when reordering devices.

Bug Fixes:

  • Load initial compass ordering from COMPASS_PRIO*_ID parameters so the UI reflects configured priorities.
  • Ensure compass priority parameters are only updated after user drag interactions rather than on initial render.
  • Bind compass settings tabs and parameter controls to the reordered compass list using deviceIdNumber for consistent mapping.
  • Maintain the selected tab on the newly dropped compass after drag-and-drop reordering.

Enhancements:

  • Display compass device ID alongside the device name in the compass settings panel.

Load initial compass order from COMPASS_PRIO*_ID parameters instead of
COMPASS_DEV_ID name order. Only write PRIO_ID params on user drag
interactions, not on page load. Fix tab content to follow reordered
list using deviceIdNumber for correct parameter mapping, and select
the drop position after reordering.

Made-with: Cursor
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 13, 2026

Reviewer's Guide

This PR changes the compass setup UI to initialize and persist compass priority based on COMPASS_PRIO*_ID parameters, ensures the detail tabs follow the reordered list using deviceIdNumber-based indexing, and only writes priority parameters in response to explicit drag-and-drop interactions while keeping the active tab aligned to the dropped position.

Sequence diagram for compass drag-and-drop priority update

sequenceDiagram
  actor User
  participant CompassSetupUI
  participant Draggable
  participant AutopilotData

  User->>CompassSetupUI: Drag compass tab handle
  CompassSetupUI->>Draggable: Initialize drag operation
  Draggable-->>Draggable: Reorder reordered_compasses
  Draggable-->>CompassSetupUI: end(evt)
  CompassSetupUI->>CompassSetupUI: onDragEnd(evt)
  CompassSetupUI->>CompassSetupUI: $nextTick
  CompassSetupUI-->>CompassSetupUI: applyCompassPriority()
  loop For each compass in reordered_compasses
    CompassSetupUI->>AutopilotData: parameter(COMPASS_PRIOi_ID)
    AutopilotData-->>CompassSetupUI: Parameter
    CompassSetupUI->>AutopilotData: setParamValue(Parameter, compass.paramValue)
  end
  CompassSetupUI-->>CompassSetupUI: tab = evt.newIndex
  CompassSetupUI-->>User: Active tab follows dropped compass
Loading

Class diagram for ArdupilotMavlinkCompassSetup compass priority logic

classDiagram
  class ArdupilotMavlinkCompassSetup {
    +number tab
    +Compass[] compasses
    +Compass[] reordered_compasses
    +Parameter edited_param
    +mounted()
    +onDragEnd(evt)
    +applyCompassPriority()
    +openParameterEditor(parameter)
    +printParam(parameter)
  }

  class Compass {
    +number deviceIdNumber
    +string deviceName
    +number paramValue
  }

  class Parameter {
    +string name
    +number value
  }

  class AutopilotData {
    +parameter(name) Parameter
    +setParamValue(parameter, value) void
  }

  ArdupilotMavlinkCompassSetup "*" o-- "*" Compass : displays
  ArdupilotMavlinkCompassSetup "*" --> "*" Parameter : uses
  ArdupilotMavlinkCompassSetup --> AutopilotData : reads_writes_priority

  ArdupilotMavlinkCompassSetup : mounted() loads COMPASS_PRIO_ID order
  ArdupilotMavlinkCompassSetup : reordered_compasses sorted by priority
  ArdupilotMavlinkCompassSetup : onDragEnd(evt) calls applyCompassPriority()
  ArdupilotMavlinkCompassSetup : applyCompassPriority() updates COMPASS_PRIO_ID
  ArdupilotMavlinkCompassSetup : UI indexing uses Compass.deviceIdNumber
Loading

File-Level Changes

Change Details Files
Initialize compass ordering from COMPASS_PRIO*_ID parameters instead of the original compasses array order.
  • On mount, read COMPASS_PRIO1_ID..COMPASS_PRIO3_ID via autopilot_data.parameter and build a priority order array.
  • Sort a copy of the compasses list into reordered_compasses based on their paramValue position in the priority order, pushing non-priority compasses to the end.
core/frontend/src/components/vehiclesetup/configuration/compass/ArdupilotMavlinkCompassSetup.vue
Update drag-and-drop handling so that compass priority parameters are written only on user drag end and the selected tab follows the dropped item.
  • Add @EnD="onDragEnd" to the draggable component bound to reordered_compasses.
  • Introduce onDragEnd that, after the DOM updates, applies compass priorities and sets the active tab index to the newIndex from the drag event.
  • Move priority-param writing logic from a watcher on reordered_compasses into a dedicated applyCompassPriority method invoked only from onDragEnd.
core/frontend/src/components/vehiclesetup/configuration/compass/ArdupilotMavlinkCompassSetup.vue
Align tab content and parameter indexing with the reordered compasses using deviceIdNumber-based indices.
  • Change v-tab-item loop to iterate over reordered_compasses instead of the original compasses array, using compass.deviceIdNumber as the key.
  • Update bindings for compass_use_param, compass_extern_param, and compass_orient_param to use compass.deviceIdNumber - 1 as the index, matching parameter arrays to physical compass IDs.
  • Pass compass.deviceIdNumber to the compass-params component as the index prop and enhance the title to show device name and ID/paramValue.?
core/frontend/src/components/vehiclesetup/configuration/compass/ArdupilotMavlinkCompassSetup.vue

Assessment against linked issues

Issue Objective Addressed Explanation
#3873 Ensure compass reorder is persisted and correctly restored when the component remounts (e.g., after reboot), by basing UI order on COMPASS_PRIO*_ID parameters rather than raw device order.
#3873 Fix compass drag-and-drop behavior so that priority parameters are only updated on user drag actions and the tab/content mapping correctly follows the reordered list.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • All array accesses now use compass.deviceIdNumber - 1 as an index; consider centralizing this mapping in a small helper (with bounds checking) to avoid duplicated logic and potential off‑by‑one errors if deviceIdNumber assumptions change.
  • The PRIO slots are hardcoded as [1, 2, 3] in mounted; if the number of priority slots can change or differ between firmware versions, consider deriving this list dynamically (e.g., by probing available COMPASS_PRIO*_ID parameters) or defining a shared constant.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- All array accesses now use `compass.deviceIdNumber - 1` as an index; consider centralizing this mapping in a small helper (with bounds checking) to avoid duplicated logic and potential off‑by‑one errors if `deviceIdNumber` assumptions change.
- The PRIO slots are hardcoded as `[1, 2, 3]` in `mounted`; if the number of priority slots can change or differ between firmware versions, consider deriving this list dynamically (e.g., by probing available `COMPASS_PRIO*_ID` parameters) or defining a shared constant.

## Individual Comments

### Comment 1
<location path="core/frontend/src/components/vehiclesetup/configuration/compass/ArdupilotMavlinkCompassSetup.vue" line_range="174" />
<code_context>
                     <br />

-                    <template v-if="compass_extern_param[index]?.value ?? 0 === 0">
+                    <template v-if="compass_extern_param[compass.deviceIdNumber - 1]?.value ?? 0 === 0">
                       <b>Mounting Rotation:</b>
-                      <v-btn class="ml-4" fab x-small @click="openParameterEditor(compass_orient_param[index])">
</code_context>
<issue_to_address>
**issue (bug_risk):** The `??` and `===` precedence likely makes this condition always treat the fallback as `true` instead of comparing the numeric value to zero.

This is parsed as `(compass_extern_param[...]?.value) ?? (0 === 0)`, i.e. effectively `?? true`. So whenever the left side is `null`/`undefined`, the condition is always `true`. If you want “treat undefined as 0, then compare to 0”, it should be `(compass_extern_param[compass.deviceIdNumber - 1]?.value ?? 0) === 0` instead.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@patrickelectric patrickelectric merged commit 9f3fa28 into bluerobotics:master Apr 13, 2026
7 checks passed
@patrickelectric patrickelectric deleted the compass_fix branch April 13, 2026 19:23
@patrickelectric
Copy link
Copy Markdown
Member

@Williangalvani do we need to cherry-pick to 1.4 ?

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: Compass reordering gets un-done when the component remounts

2 participants