mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 08:35:43 -06:00
* fix merge conflict * fix betterer * handle new creating annotations * add h5 'or' tag to annotation editor * fix annotation regression looking for tags before target * remove angular annotation partial * change ann tags type to string[] and use TagsInput to create ann * remove GraphiteEventsType, return annotations targets setting 'textEditor': true * fix yarn typecheck errors * add dateTime for yarn fix to tests * fix incorrect merge conflict resolution * fix betterer * making changes for PR approval resolutions * fix prettier issue * fix prettier
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
type LegacyAnnotation = {
|
|
target?: string;
|
|
tags?: string;
|
|
};
|
|
|
|
// this becomes the target in the migrated annotations
|
|
const migrateLegacyAnnotation = (json: LegacyAnnotation) => {
|
|
// return the target annotation
|
|
if (typeof json.target === 'string' && json.target) {
|
|
return {
|
|
fromAnnotations: true,
|
|
target: json.target,
|
|
textEditor: true,
|
|
};
|
|
}
|
|
|
|
// return the tags annotation
|
|
return {
|
|
queryType: 'tags',
|
|
tags: (json.tags || '').split(' '),
|
|
fromAnnotations: true,
|
|
};
|
|
};
|
|
|
|
// eslint-ignore-next-line
|
|
export const prepareAnnotation = (json: any) => {
|
|
// annotation attributes are either 'tags' or 'target'(a graphite query string)
|
|
// because the new annotations will also have a target attribute, {}
|
|
// we need to handle the ambiguous 'target' when migrating legacy annotations
|
|
// so, to migrate legacy annotations
|
|
// we check that target is a string
|
|
// or
|
|
// there is a tags attribute with no target
|
|
const resultingTarget = json.target && typeof json.target !== 'string' ? json.target : migrateLegacyAnnotation(json);
|
|
|
|
json.target = resultingTarget;
|
|
|
|
return json;
|
|
};
|