Commit c9f22b72 by Torkel Ödegaard Committed by GitHub

StatPanel: Fixes issue with name showing for single series / field results (#26070)

* StatPanel: Fix text mode auto logic

* Removed import
parent 586d26c7
......@@ -55,6 +55,12 @@ export interface Props extends Themeable {
justifyMode?: BigValueJustifyMode;
alignmentFactors?: DisplayValueAlignmentFactors;
textMode?: BigValueTextMode;
/**
* If part of a series of stat panes, this is the total number.
* Used by BigValueTextMode.Auto text mode.
*/
count?: number;
}
export class BigValue extends PureComponent<Props> {
......
......@@ -463,12 +463,18 @@ export interface BigValueTextValues extends DisplayValue {
}
function getTextValues(props: Props): BigValueTextValues {
const { textMode: nameAndValue, value, alignmentFactors } = props;
const { value, alignmentFactors, count } = props;
let { textMode } = props;
const titleToAlignTo = alignmentFactors ? alignmentFactors.title : value.title;
const valueToAlignTo = formattedValueToString(alignmentFactors ? alignmentFactors : value);
switch (nameAndValue) {
// In the auto case we only show title if this big value is part of more panes (count > 1)
if (textMode === BigValueTextMode.Auto && (count ?? 1) === 1) {
textMode = BigValueTextMode.Value;
}
switch (textMode) {
case BigValueTextMode.Name:
return {
...value,
......@@ -498,6 +504,7 @@ function getTextValues(props: Props): BigValueTextValues {
valueToAlignTo: '1',
tooltip: `Name: ${value.title}\nValue: ${formattedValueToString(value)}`,
};
case BigValueTextMode.ValueAndName:
default:
return {
...value,
......
......@@ -26,7 +26,7 @@ export class StatPanel extends PureComponent<PanelProps<StatPanelOptions>> {
menuProps: DataLinksContextMenuApi
): JSX.Element => {
const { timeRange, options } = this.props;
const { value, alignmentFactors, width, height } = valueProps;
const { value, alignmentFactors, width, height, count } = valueProps;
const { openMenu, targetClassName } = menuProps;
let sparkline: BigValueSparkline | undefined;
......@@ -48,6 +48,7 @@ export class StatPanel extends PureComponent<PanelProps<StatPanelOptions>> {
return (
<BigValue
value={value.display}
count={count}
sparkline={sparkline}
colorMode={options.colorMode}
graphMode={options.graphMode}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment