Support item tags, fixes #1258

This commit is contained in:
Alexander Zobnin
2021-08-09 14:57:49 +03:00
parent c6441cccf0
commit 915973829d
15 changed files with 574 additions and 364 deletions

View File

@@ -1,7 +1,7 @@
import _ from 'lodash';
import moment from 'moment';
import * as c from './constants';
import { VariableQuery, VariableQueryTypes } from './types';
import { VariableQuery, VariableQueryTypes, ZBXItemTag } from './types';
import { DataFrame, FieldType, getValueFormats, MappingType, rangeUtil, ValueMapping } from '@grafana/data';
/*
@@ -405,6 +405,21 @@ export function parseTags(tagStr: string): any[] {
return tags;
}
// Parses string representation of tag into the object
export function parseItemTag(tagStr: string): ZBXItemTag {
const itemTag: ZBXItemTag = { tag: '', value: '' };
const tagParts = tagStr.split(': ');
itemTag.tag = tagParts[0];
if (tagParts[1]) {
itemTag.value = tagParts[1];
}
return itemTag;
}
export function itemTagToString(t: ZBXItemTag): string {
return t.value ? `${t.tag}: ${t.value}` : t.tag;
}
export function mustArray(result: any): any[] {
return result || [];
}