mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugins: Unset annotation editor variables (#74519)
This commit is contained in:
parent
9770b870e3
commit
5af35f1f3c
@ -99,6 +99,15 @@ export class AnnotationFieldMapper extends PureComponent<Props, State> {
|
|||||||
|
|
||||||
onFieldNameChange = (k: keyof AnnotationEvent, v: SelectableValue<string>) => {
|
onFieldNameChange = (k: keyof AnnotationEvent, v: SelectableValue<string>) => {
|
||||||
const mappings = this.props.mappings || {};
|
const mappings = this.props.mappings || {};
|
||||||
|
|
||||||
|
// in case of clearing the value
|
||||||
|
if (!v) {
|
||||||
|
const newMappings = { ...this.props.mappings };
|
||||||
|
delete newMappings[k];
|
||||||
|
this.props.change(newMappings);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const mapping = mappings[k] || {};
|
const mapping = mappings[k] || {};
|
||||||
|
|
||||||
this.props.change({
|
this.props.change({
|
||||||
@ -114,17 +123,14 @@ export class AnnotationFieldMapper extends PureComponent<Props, State> {
|
|||||||
renderRow(row: AnnotationFieldInfo, mapping: AnnotationEventFieldMapping, first?: AnnotationEvent) {
|
renderRow(row: AnnotationFieldInfo, mapping: AnnotationEventFieldMapping, first?: AnnotationEvent) {
|
||||||
const { fieldNames } = this.state;
|
const { fieldNames } = this.state;
|
||||||
|
|
||||||
let picker = fieldNames;
|
let picker = [...fieldNames];
|
||||||
const current = mapping.value;
|
const current = mapping.value;
|
||||||
let currentValue = fieldNames.find((f) => current === f.value);
|
let currentValue = fieldNames.find((f) => current === f.value);
|
||||||
if (current) {
|
if (current && !currentValue) {
|
||||||
picker = [...fieldNames];
|
picker.push({
|
||||||
if (!currentValue) {
|
label: current,
|
||||||
picker.push({
|
value: current,
|
||||||
label: current,
|
});
|
||||||
value: current,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let value = first ? first[row.key] : '';
|
let value = first ? first[row.key] : '';
|
||||||
@ -139,7 +145,7 @@ export class AnnotationFieldMapper extends PureComponent<Props, State> {
|
|||||||
return (
|
return (
|
||||||
<tr key={row.key}>
|
<tr key={row.key}>
|
||||||
<td>
|
<td>
|
||||||
{row.key}{' '}
|
{row.label || row.key}{' '}
|
||||||
{row.help && (
|
{row.help && (
|
||||||
<Tooltip content={row.help}>
|
<Tooltip content={row.help}>
|
||||||
<Icon name="info-circle" />
|
<Icon name="info-circle" />
|
||||||
@ -166,6 +172,7 @@ export class AnnotationFieldMapper extends PureComponent<Props, State> {
|
|||||||
}}
|
}}
|
||||||
noOptionsMessage="Unknown field names"
|
noOptionsMessage="Unknown field names"
|
||||||
allowCustomValue={true}
|
allowCustomValue={true}
|
||||||
|
isClearable
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td>{`${value}`}</td>
|
<td>{`${value}`}</td>
|
||||||
|
@ -89,7 +89,7 @@ interface AnnotationEventFieldSetter {
|
|||||||
|
|
||||||
export interface AnnotationFieldInfo {
|
export interface AnnotationFieldInfo {
|
||||||
key: keyof AnnotationEvent;
|
key: keyof AnnotationEvent;
|
||||||
|
label?: string;
|
||||||
split?: string;
|
split?: string;
|
||||||
field?: (frame: DataFrame) => Field | undefined;
|
field?: (frame: DataFrame) => Field | undefined;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
@ -103,7 +103,7 @@ export const annotationEventNames: AnnotationFieldInfo[] = [
|
|||||||
field: (frame: DataFrame) => frame.fields.find((f) => f.type === FieldType.time),
|
field: (frame: DataFrame) => frame.fields.find((f) => f.type === FieldType.time),
|
||||||
placeholder: 'time, or the first time field',
|
placeholder: 'time, or the first time field',
|
||||||
},
|
},
|
||||||
{ key: 'timeEnd', help: 'When this field is defined, the annotation will be treated as a range' },
|
{ key: 'timeEnd', label: 'end time', help: 'When this field is defined, the annotation will be treated as a range' },
|
||||||
{
|
{
|
||||||
key: 'title',
|
key: 'title',
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user