StatPanel: Fix stat panel display name not showing when explicitly set (#26616)

* StatPanel: Fix stat panel display name now showing when explicitly set

* StatPanel: Updarted auto mode to also take panel title into consideration

* fixed test
pull/26636/head
Torkel Ödegaard 5 years ago committed by GitHub
parent cfac143244
commit cbe1d7b08c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/grafana-data/src/types/panel.ts
  2. 1
      public/app/features/dashboard/dashgrid/PanelChrome.tsx
  3. 1
      public/app/plugins/panel/bargauge/BarGaugePanel.test.tsx
  4. 15
      public/app/plugins/panel/stat/StatPanel.tsx

@ -69,6 +69,8 @@ export interface PanelProps<T = any> {
onChangeTimeRange: (timeRange: AbsoluteTimeRange) => void;
/** @internal */
renderCounter: number;
/** Panel title */
title: string;
}
export interface PanelEditorProps<T = any> {

@ -273,6 +273,7 @@ export class PanelChrome extends PureComponent<Props, State> {
<PanelComponent
id={panel.id}
data={data}
title={panel.title}
timeRange={timeRange}
timeZone={this.props.dashboard.getTimezone()}
options={panelOptions}

@ -84,6 +84,7 @@ function createBarGaugePanelWithData(data: PanelData): ReactWrapper<PanelProps<B
timeRange={timeRange}
timeZone={'utc'}
options={options}
title="hello"
fieldConfig={fieldConfig}
onFieldConfigChange={() => {}}
onOptionsChange={() => {}}

@ -6,6 +6,7 @@ import {
DataLinksContextMenu,
VizRepeater,
VizRepeaterRenderValueProps,
BigValueTextMode,
} from '@grafana/ui';
import {
DisplayValueAlignmentFactors,
@ -53,7 +54,7 @@ export class StatPanel extends PureComponent<PanelProps<StatPanelOptions>> {
colorMode={options.colorMode}
graphMode={options.graphMode}
justifyMode={options.justifyMode}
textMode={options.textMode}
textMode={this.getTextMode()}
alignmentFactors={alignmentFactors}
width={width}
height={height}
@ -63,6 +64,18 @@ export class StatPanel extends PureComponent<PanelProps<StatPanelOptions>> {
/>
);
};
getTextMode() {
const { options, fieldConfig, title } = this.props;
// If we have manually set displayName or panel title switch text mode to value and name
if (options.textMode === BigValueTextMode.Auto && (fieldConfig.defaults.displayName || !title)) {
return BigValueTextMode.ValueAndName;
}
return options.textMode;
}
renderValue = (valueProps: VizRepeaterRenderValueProps<FieldDisplay, DisplayValueAlignmentFactors>): JSX.Element => {
const { value } = valueProps;
const { getLinks, hasLinks } = value;

Loading…
Cancel
Save