mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 09:26:43 -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>) => {
|
||||
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] || {};
|
||||
|
||||
this.props.change({
|
||||
@ -114,17 +123,14 @@ export class AnnotationFieldMapper extends PureComponent<Props, State> {
|
||||
renderRow(row: AnnotationFieldInfo, mapping: AnnotationEventFieldMapping, first?: AnnotationEvent) {
|
||||
const { fieldNames } = this.state;
|
||||
|
||||
let picker = fieldNames;
|
||||
let picker = [...fieldNames];
|
||||
const current = mapping.value;
|
||||
let currentValue = fieldNames.find((f) => current === f.value);
|
||||
if (current) {
|
||||
picker = [...fieldNames];
|
||||
if (!currentValue) {
|
||||
picker.push({
|
||||
label: current,
|
||||
value: current,
|
||||
});
|
||||
}
|
||||
if (current && !currentValue) {
|
||||
picker.push({
|
||||
label: current,
|
||||
value: current,
|
||||
});
|
||||
}
|
||||
|
||||
let value = first ? first[row.key] : '';
|
||||
@ -139,7 +145,7 @@ export class AnnotationFieldMapper extends PureComponent<Props, State> {
|
||||
return (
|
||||
<tr key={row.key}>
|
||||
<td>
|
||||
{row.key}{' '}
|
||||
{row.label || row.key}{' '}
|
||||
{row.help && (
|
||||
<Tooltip content={row.help}>
|
||||
<Icon name="info-circle" />
|
||||
@ -166,6 +172,7 @@ export class AnnotationFieldMapper extends PureComponent<Props, State> {
|
||||
}}
|
||||
noOptionsMessage="Unknown field names"
|
||||
allowCustomValue={true}
|
||||
isClearable
|
||||
/>
|
||||
</td>
|
||||
<td>{`${value}`}</td>
|
||||
|
@ -89,7 +89,7 @@ interface AnnotationEventFieldSetter {
|
||||
|
||||
export interface AnnotationFieldInfo {
|
||||
key: keyof AnnotationEvent;
|
||||
|
||||
label?: string;
|
||||
split?: string;
|
||||
field?: (frame: DataFrame) => Field | undefined;
|
||||
placeholder?: string;
|
||||
@ -103,7 +103,7 @@ export const annotationEventNames: AnnotationFieldInfo[] = [
|
||||
field: (frame: DataFrame) => frame.fields.find((f) => f.type === FieldType.time),
|
||||
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',
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user