Skip to content

Conversation

@patrickelectric
Copy link
Member

@patrickelectric patrickelectric commented Jan 22, 2026

Summary by Sourcery

Add a USB section to the system information view to display connected USB devices organized by bus and hierarchy.

New Features:

  • Introduce a USB tab in the system information page alongside existing system, process, network, and kernel sections.
  • Add a USB devices view that fetches USB information from the backend and presents it as a searchable, categorized tree by bus and port path, with device details and status indicators.

Enhancements:

  • Define TypeScript types for USB devices and responses used by the system information frontend.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 22, 2026

Reviewer's Guide

Adds a new USB tab to the System Information view that periodically fetches USB device data from the backend, groups devices by USB bus, builds a hierarchical tree per bus, and renders it with rich metadata, icons, and search filtering.

Sequence diagram for periodic USB device fetching and rendering

sequenceDiagram
  actor User
  participant SystemInformationView
  participant Usb
  participant back_axios
  participant BackendAPI as SystemInformationBackend

  User->>SystemInformationView: Open system information page
  SystemInformationView->>Usb: Render when page value is usb
  activate Usb
  Usb->>Usb: mounted()
  Usb->>Usb: fetchUsb()
  Usb->>back_axios: GET /system-information/usb (timeout 10s)
  activate back_axios
  back_axios->>BackendAPI: Forward request
  BackendAPI-->>back_axios: UsbDevicesResponse (devices[])
  back_axios-->>Usb: response.data.devices
  deactivate back_axios
  Usb->>Usb: devices = response.data.devices
  Usb->>Usb: compute buses and treeItems
  Usb-->>User: Render USB buses with treeview
  deactivate Usb

  loop Every 5 seconds
    Usb->>Usb: fetchUsb()
    Usb->>back_axios: GET /system-information/usb
    alt Success
      back_axios-->>Usb: UsbDevicesResponse
      Usb->>Usb: Update devices and treeItems
      Usb-->>User: Refresh USB tree display
    else Error and backend online
      back_axios-->>Usb: Error
      Usb->>Usb: Set error message and stop loading
      Usb-->>User: Show error alert
    end
  end

  User-->>SystemInformationView: Navigate away from USB tab
  SystemInformationView-->>Usb: Destroy component
  Usb->>Usb: beforeDestroy() clearInterval(timer)
Loading

Class diagram for USB system information data structures and component

classDiagram
  class UsbDevice {
    +number vid
    +number pid
    +string | null serial_number
    +string | null manufacturer
    +string | null product
    +string port_path
    +number bus_number
    +number device_address
    +number device_class
    +number device_subclass
    +number device_protocol
    +string usb_version
    +string speed
    +number num_configurations
  }

  class UsbDevicesResponse {
    +UsbDevice[] devices
  }

  class UsbTreeNode {
    +UsbDevice device
    +UsbTreeNode[] children
    +number depth
    +number | null portNumber
  }

  class TreeItem {
    +string id
    +string name
    +TreeItem[] children
    +number deviceClass
    +number deviceSubclass
    +number deviceProtocol
    +string | null manufacturer
    +string | null serial
    +string vidPid
    +string usbVersion
    +string speed
    +string portPath
    +number address
  }

  class UsbBus {
    +number busNumber
    +UsbDevice | null rootHub
    +TreeItem[] treeItems
  }

  class Usb {
    <<VueComponent>>
    +UsbDevice[] devices
    +boolean loading
    +string | null error
    +number timer
    +string search
    +UsbBus[] buses
    +UsbBus[] filteredBuses
    +mounted() void
    +beforeDestroy() void
    +fetchUsb() Promise~void~
    +deviceToTreeItem(device UsbDevice) TreeItem
    +buildTreeItems(devices UsbDevice[]) TreeItem[]
    +getParentPath(portPath string) string
    +countDevices(items TreeItem[]) number
    +hasMatchingDevice(items TreeItem[]) boolean
    +isSearchMatch(item TreeItem) boolean
    +filterTree(item TreeItem, search string) boolean
    +getDeviceIcon(item TreeItem) string
    +getDeviceIconColor(item TreeItem) string
    +getDeviceTypeTooltip(deviceClass number) string
    +getSpeedColor(speed string | undefined) string
    +getSpeedLabel(speed string | undefined) string
    +getAllNodeIds(items TreeItem[]) string[]
  }

  Usb "*" o-- "*" UsbDevice : uses_devices
  Usb "*" o-- "*" UsbBus : groups_into
  UsbBus "1" o-- "1" UsbDevice : rootHub
  UsbBus "1" o-- "1" TreeItem : root_tree
  TreeItem "1" o-- "*" TreeItem : children
  UsbTreeNode "1" o-- "*" UsbTreeNode : children
  UsbTreeNode "1" --> "1" UsbDevice : wraps
  UsbDevicesResponse "1" o-- "*" UsbDevice : contains
Loading

File-Level Changes

Change Details Files
Extend SystemInformationView to expose a new USB section.
  • Register the Usb component in the SystemInformationView component list.
  • Render the Usb panel when the selected page value is 'usb'.
  • Add a new navigation entry for USB with an mdi-usb icon in the system information sidebar.
core/frontend/src/views/SystemInformationView.vue
Introduce a Usb system-information panel that fetches and displays USB devices as a searchable, hierarchical tree grouped by bus.
  • Create a Usb.vue component that loads USB device data from the /system-information/usb backend endpoint using back_axios with periodic polling and backend-offline handling.
  • Derive UsbBus structures by grouping devices by bus_number, identifying the root hub per bus (port_path ending in '-0'), and building a parent/child tree based on parsed port_path relationships.
  • Render each bus in a Vuetify card with host controller info, a speed chip, a v-treeview showing all devices expanded, per-node speed chips, VID:PID/manufacturer/serial/port-path metadata with tooltips, and a footer summarizing device count.
  • Implement search across device name, manufacturer, serial, VID:PID, and port path; filter buses and tree items accordingly; and highlight exact matches in the tree labels.
  • Map USB class codes (and some subclass/protocol/name heuristics) to icons and human-readable tooltips, and derive speed label/color chips from the device speed string (e.g., Super/High/Full/Low).
  • Manage component lifecycle with a mounted polling interval and beforeDestroy cleanup, and style the USB tree, cards, and search-match highlighting with scoped CSS.
core/frontend/src/components/system-information/Usb.vue
Define typed USB system information models for frontend use.
  • Add a UsbDevice interface describing fields returned from the backend (identifiers, topology, class codes, version, speed).
  • Add a UsbDevicesResponse interface representing the USB devices API response envelope.
  • Add a UsbTreeNode interface for potential tree representations built from UsbDevice structures.
core/frontend/src/types/system-information/usb.ts

Possibly linked issues

  • #(unknown): PR adds a USB tab to system information, displaying detected USB devices as requested by the issue.

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

@patrickelectric patrickelectric marked this pull request as ready for review January 22, 2026 16:23
Copy link

@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 2 issues, and left some high level feedback:

  • The search-related helpers (hasMatchingDevice, isSearchMatch, and filterTree) all duplicate very similar matching logic; consider extracting a shared predicate function to reduce repetition and keep the search behavior consistent in one place.
  • In fetchUsb, when isBackendOffline(err) is true the method returns without updating loading, which can leave the UI in a perpetual loading state; it may be worth explicitly clearing loading in that branch or otherwise signaling the offline state to the user.
  • The getAllNodeIds(bus.treeItems) call is recomputed on every render and passed directly to v-treeview's open prop; if the device list grows large, consider caching these IDs per bus (e.g., via a computed property) to avoid repeated deep traversal of the tree on each update.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The search-related helpers (`hasMatchingDevice`, `isSearchMatch`, and `filterTree`) all duplicate very similar matching logic; consider extracting a shared predicate function to reduce repetition and keep the search behavior consistent in one place.
- In `fetchUsb`, when `isBackendOffline(err)` is true the method returns without updating `loading`, which can leave the UI in a perpetual loading state; it may be worth explicitly clearing `loading` in that branch or otherwise signaling the offline state to the user.
- The `getAllNodeIds(bus.treeItems)` call is recomputed on every render and passed directly to `v-treeview`'s `open` prop; if the device list grows large, consider caching these IDs per bus (e.g., via a computed property) to avoid repeated deep traversal of the tree on each update.

## Individual Comments

### Comment 1
<location> `core/frontend/src/components/system-information/Usb.vue:326-335` </location>
<code_context>
+    clearInterval(this.timer)
+  },
+  methods: {
+    async fetchUsb(): Promise<void> {
+      try {
+        const response = await back_axios({
+          method: 'get',
+          url: '/system-information/usb',
+          timeout: 10000,
+        })
+        this.devices = response.data.devices
+        this.loading = false
+        this.error = null
+      } catch (err: unknown) {
+        if (isBackendOffline(err)) return
+        this.error = `Failed to fetch USB devices: ${err instanceof Error ? err.message : 'Unknown error'}`
+        this.loading = false
</code_context>

<issue_to_address>
**issue (bug_risk):** Loading state is never cleared when the backend is offline, leaving the view stuck in a spinner state.

When `isBackendOffline(err)` is true, `fetchUsb` returns without clearing `loading`, so an initial offline request leaves the UI stuck in a spinner with no message. In the offline branch, explicitly set `loading = false` and optionally surface a non-error offline/ informational state so the UI can render a stable view.
</issue_to_address>

### Comment 2
<location> `core/frontend/src/components/system-information/Usb.vue:423-432` </location>
<code_context>
+      }
+      return false
+    },
+    isSearchMatch(item: TreeItem): boolean {
+      if (!this.search) return false
+      const searchLower = this.search.toLowerCase()
+      return (
+        item.name.toLowerCase().includes(searchLower)
+        || item.manufacturer?.toLowerCase().includes(searchLower)
+        || item.serial?.toLowerCase().includes(searchLower)
+        || item.vidPid.toLowerCase().includes(searchLower)
+      )
+    },
</code_context>

<issue_to_address>
**suggestion:** Search highlighting and filtering use slightly different criteria, which can produce confusing UX.

`filterTree`/`hasMatchingDevice` search includes `item.portPath`, but `isSearchMatch` does not. As a result, an item may appear in filtered results (matched by port path) without the `search-match` highlight. Either add `portPath` to `isSearchMatch` or restrict both to the same set of fields so filtering and highlighting stay consistent.

```suggestion
    isSearchMatch(item: TreeItem): boolean {
      if (!this.search) return false
      const searchLower = this.search.toLowerCase()
      return (
        item.name.toLowerCase().includes(searchLower)
        || item.manufacturer?.toLowerCase().includes(searchLower)
        || item.serial?.toLowerCase().includes(searchLower)
        || item.vidPid.toLowerCase().includes(searchLower)
        || item.portPath.toLowerCase().includes(searchLower)
      )
    },
```
</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.

Comment on lines +326 to +182
async fetchUsb(): Promise<void> {
try {
const response = await back_axios({
method: 'get',
url: '/system-information/usb',
timeout: 10000,
})
this.devices = response.data.devices
this.loading = false
this.error = null
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Loading state is never cleared when the backend is offline, leaving the view stuck in a spinner state.

When isBackendOffline(err) is true, fetchUsb returns without clearing loading, so an initial offline request leaves the UI stuck in a spinner with no message. In the offline branch, explicitly set loading = false and optionally surface a non-error offline/ informational state so the UI can render a stable view.

Copy link
Member

@joaoantoniocardoso joaoantoniocardoso left a comment

Choose a reason for hiding this comment

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

As I mentioned in the meeting, it's working here and the code looks okay, but I can't test it with USB hubs, which would be interesting to see how the UI behaves.

Speaking of UI, although BlueOS already has some variability in terms of style, this one seems to be adding an entirely new style:

Image

@patrickelectric
Copy link
Member Author

As I mentioned in the meeting, it's working here and the code looks okay, but I can't test it with USB hubs, which would be interesting to see how the UI behaves.

Speaking of UI, although BlueOS already has some variability in terms of style, this one seems to be adding an entirely new style:

Image

I'm not sure if I follow.

  • The hub information is already in the screenshot.
  • The color pallet and components are already the ones that we use in BlueOS.

@joaoantoniocardoso
Copy link
Member

joaoantoniocardoso commented Feb 2, 2026

As I mentioned in the meeting, it's working here and the code looks okay, but I can't test it with USB hubs, which would be interesting to see how the UI behaves.
Speaking of UI, although BlueOS already has some variability in terms of style, this one seems to be adding an entirely new style:
Image

I'm not sure if I follow.

* The hub information is already in the screenshot.

* The color pallet and components are already the ones that we use in BlueOS.

HUBs:

I meant that I couldn't test adding an external hub to see how it behaves. The internal hub is what's being shown in the image, as you noticed.

UI:

The colors might be the same, but the style is not: on the left, we have monochromatic, flat-outlined "cards" packed with information, on the right, they are lean and simple dark cards with a bluey top accent. These are two different visual styles/languages, and the one on the right is the most widely used in the software.

@patrickelectric
Copy link
Member Author

As I mentioned in the meeting, it's working here and the code looks okay, but I can't test it with USB hubs, which would be interesting to see how the UI behaves.
Speaking of UI, although BlueOS already has some variability in terms of style, this one seems to be adding an entirely new style:
Image

I'm not sure if I follow.

* The hub information is already in the screenshot.

* The color pallet and components are already the ones that we use in BlueOS.

HUBs:

I meant that I couldn't test adding an external hub to see how it behaves. The internal hub is what's being shown in the image, as you noticed.

UI:

The colors might be the same, but the style is not: on the left, we have monochromatic, flat-outlined "cards" packed with information, on the right, they are lean and simple dark cards with a bluey top accent. These are two different visual styles/languages, and the one on the right is the most widely used in the software.

I'm open to suggestion on UI.

@joaoantoniocardoso
Copy link
Member

I'm open to suggestion on UI.

Here you are:

  • first, no outlined or the custom border radius, no special colors;
  • in general, we avoid custom css, as it tends to make the UI/UX diverge; we only use custom css when we need to solve some edge/special case, and it doesn't look like it is the case;
  • copy the search bar from core/frontend/src/components/system-information/Processes.vue
  • for the content, copy the style from core/frontend/src/components/system-information/NetworkCard.vue and/or core/frontend/src/components/system-information/SystemConditionCard.vue. The major difference seems to be whether we use an accent on the top or not;
  • the three goes then, inside a v-card-text using v-list-item using vuetify pa-0, tex--secondary, no custom stuff.

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
@patrickelectric
Copy link
Member Author

I'm open to suggestion on UI.

Here you are:

  • first, no outlined or the custom border radius, no special colors;
  • in general, we avoid custom css, as it tends to make the UI/UX diverge; we only use custom css when we need to solve some edge/special case, and it doesn't look like it is the case;
  • copy the search bar from core/frontend/src/components/system-information/Processes.vue
  • for the content, copy the style from core/frontend/src/components/system-information/NetworkCard.vue and/or core/frontend/src/components/system-information/SystemConditionCard.vue. The major difference seems to be whether we use an accent on the top or not;
  • the three goes then, inside a v-card-text using v-list-item using vuetify pa-0, tex--secondary, no custom stuff.

check now

image

Copy link
Member

@joaoantoniocardoso joaoantoniocardoso left a comment

Choose a reason for hiding this comment

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

great!

@joaoantoniocardoso joaoantoniocardoso merged commit 35d4fc1 into bluerobotics:master Feb 6, 2026
7 checks passed
@ES-Alexander ES-Alexander added the docs-needed Change needs to be documented label Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-needed Change needs to be documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants