[v9.3.x] Prometheus: Fix exception being thrown when toggling visibility in explore (#60162)

Prometheus: Fix exception being thrown when toggling visibility in explore (#60159)

fix error being thrown when frameIndex is out of bounds of dataframe

(cherry picked from commit b0f8e803a1)

Co-authored-by: Galen Kistler <109082771+gtk-grafana@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)
2022-12-12 15:03:04 +01:00
committed by GitHub
co-authored by Galen Kistler
parent 2bbab19dd4
commit 2b220ad0cb
@@ -119,8 +119,8 @@ export const getVisibleLabels = (config: UPlotConfigBuilder, frames: DataFrame[]
const fieldIndex = plotInstance.props?.dataFrameFieldIndex?.fieldIndex;
if (frameIndex !== undefined && fieldIndex !== undefined) {
const field = frames[frameIndex].fields[fieldIndex];
if (field.labels) {
const field = frames[frameIndex]?.fields[fieldIndex];
if (field?.labels) {
// Note that this may be an empty object in the case of a metric being rendered with no labels
visibleLabels.push({
labels: field.labels,