Skip to content

Commit

Permalink
Variant was not properly saved
Browse files Browse the repository at this point in the history
As reported by #34 `undefined` is not saved in Grafana - so the panel was not properly working after saving/reloading it.

This commit fixes this.
  • Loading branch information
derjust committed Nov 24, 2020
1 parent 743a01b commit b885a23
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/ButtonPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { PureComponent } from 'react';
import { Button, IconName } from '@grafana/ui';
import { Button, IconName, ButtonVariant } from '@grafana/ui';
import { PanelProps } from '@grafana/data';
import { getTemplateSrv } from '@grafana/runtime';
import { ButtonPanelOptions, ButtonPanelState } from 'types';
Expand Down Expand Up @@ -131,7 +131,7 @@ export class ButtonPanel extends PureComponent<Props, ButtonPanelState> {
}
};
const customStyle = () => {
if (this.props.options.variant === undefined) {
if (this.props.options.variant === 'custom') {
return {
// Resaet Grafana defaults
background: 'none',
Expand All @@ -144,6 +144,13 @@ export class ButtonPanel extends PureComponent<Props, ButtonPanelState> {
return {};
}
};
const variant = () : ButtonVariant | undefined => {
if (this.props.options.variant === 'custom') {
return undefined;
} else {
return this.props.options.variant as ButtonVariant;
}
}
const buttonText = () => {
return interpolateVariables(this.props.options.text);
};
Expand All @@ -155,7 +162,7 @@ export class ButtonPanel extends PureComponent<Props, ButtonPanelState> {
return (
<div className={getOrientation()}>
<Button
variant={this.props.options.variant}
variant={variant()}
title={this.state.response}
size="lg"
className={apiStateClassName()}
Expand Down
6 changes: 3 additions & 3 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const plugin = new PanelPlugin<ButtonPanelOptions>(ButtonPanel).setPanelO
label: 'Link',
},
{
value: undefined,
value: 'custom',
label: 'Custom',
},
],
Expand All @@ -118,7 +118,7 @@ export const plugin = new PanelPlugin<ButtonPanelOptions>(ButtonPanel).setPanelO
settings: {
disableNamedColors: true,
},
showIf: config => config.variant === undefined,
showIf: config => config.variant == 'custom',
})
.addColorPicker({
path: 'backgroundColor',
Expand All @@ -127,7 +127,7 @@ export const plugin = new PanelPlugin<ButtonPanelOptions>(ButtonPanel).setPanelO
settings: {
disableNamedColors: true,
},
showIf: config => config.variant === undefined,
showIf: config => config.variant == 'custom',
})
.addRadio({
path: 'orientation',
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface ButtonPanelOptions {
params: Array<[string, string]>;

text: string;
variant: ButtonVariant | undefined;
variant: ButtonVariant | 'custom';
foregroundColor?: string;
backgroundColor?: string;
icon?: IconName;
Expand Down

0 comments on commit b885a23

Please sign in to comment.