Plugins: Unset annotation editor variables (#74519)

This commit is contained in:
Hugo Kiyodi Oshiro 2023-09-14 14:23:17 +02:00 committed by GitHub
parent 9770b870e3
commit 5af35f1f3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 12 deletions

View File

@ -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>

View File

@ -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',
},