Skip to content

frontend: replace hardcoded [0]/[1] panel indices in CompareV2 metrics selection #13270

@manaswinidas

Description

@manaswinidas

Problem

MetricsDropdown.tsx and CompareV2.tsx hardcode [0] and [1] array indices to address the two comparison panels. There is no runtime guard if selectedArtifacts.length < 2, so any future change to the panel count (or a bug in the parent) would cause a silent crash.

Affected locations:

  • frontend/src/components/viewers/MetricsDropdown.tsx — 6 occurrences (selectedArtifacts[0], selectedArtifacts[1], selectedArtifactsForDisplay[0], selectedArtifactsForDisplay[1])
  • frontend/src/pages/CompareV2.tsxgetVerifiedTwoPanelSelection indexes [0]/[1], and createSelectedArtifactArray(2) seeds the magic number in 3 places

Suggested fix

  • Extract the panel count into a named constant (e.g. COMPARE_PANEL_COUNT = 2).
  • Derive the dropdown layout from the array length rather than hardcoded indices where possible.
  • Add a runtime assertion or early return if selectedArtifacts.length doesn't match the expected count.

Context

Spotted during review of #13256. Pre-existing issue, not introduced by that PR.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions