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

* StatPanel: Fix text mode auto logic

* Removed import
This commit is contained in:
Torkel Ödegaard
2020-07-07 10:16:06 +02:00
committed by GitHub
parent 586d26c729
commit c9f22b72e3
3 changed files with 17 additions and 3 deletions
@@ -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,
+2 -1
View File
@@ -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}