GraphNG: Fix PlotLegend field display name being outdated (#32064)

This commit is contained in:
Dominik Prokop 2021-03-17 14:40:30 +01:00 committed by GitHub
parent c8d8dcd067
commit 48f46a597f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
import React, { useCallback } from 'react';
import { DataFrame, DisplayValue, fieldReducers, reduceField } from '@grafana/data';
import { DataFrame, DisplayValue, fieldReducers, getFieldDisplayName, reduceField } from '@grafana/data';
import { UPlotConfigBuilder } from './config/UPlotConfigBuilder';
import { VizLegendItem, VizLegendOptions } from '../VizLegend/types';
import { AxisPlacement } from './config';
@ -55,12 +55,13 @@ export const PlotLegend: React.FC<PlotLegendProps> = ({
}
const field = data[fieldIndex.frameIndex]?.fields[fieldIndex.fieldIndex];
const label = getFieldDisplayName(field, data[fieldIndex.frameIndex]!);
return {
disabled: !seriesConfig.show ?? false,
fieldIndex,
color: seriesConfig.lineColor!,
label: seriesConfig.fieldName,
label,
yAxis: axisPlacement === AxisPlacement.Left ? 1 : 2,
getDisplayValues: () => {
if (!calcs?.length) {
@ -80,6 +81,7 @@ export const PlotLegend: React.FC<PlotLegendProps> = ({
};
});
},
getItemKey: () => `${label}-${fieldIndex.frameIndex}-${fieldIndex.fieldIndex}`,
};
})
.filter((i) => i !== undefined) as VizLegendItem[];