mirror of https://github.com/grafana/grafana
OpenTsdb: migrate annotations from angular to react (#53856)
* remove annotation angular dependency and migrate annotations * add nullish coalescing operator * remove annotations angular partial * make annotation queries code and errors more readable * handle the betterer issue with '^ Unexpected any. Specify a different type' at top of file * run precommits * run prettierpull/54298/head^2
parent
2db6a199b8
commit
20d0aa9904
@ -0,0 +1,45 @@ |
||||
import React, { useState } from 'react'; |
||||
|
||||
import { QueryEditorProps } from '@grafana/data'; |
||||
import { InlineFormLabel, Input, InlineSwitch } from '@grafana/ui'; |
||||
|
||||
import OpenTsDatasource from '../datasource'; |
||||
import { OpenTsdbQuery, OpenTsdbOptions } from '../types'; |
||||
|
||||
export const AnnotationEditor = (props: QueryEditorProps<OpenTsDatasource, OpenTsdbQuery, OpenTsdbOptions>) => { |
||||
const { query, onChange } = props; |
||||
const [target, setTarget] = useState<string>(query.target ?? ''); |
||||
const [isGlobal, setIsGlobal] = useState<boolean>(query.isGlobal ?? false); |
||||
|
||||
const updateValue = <K extends keyof OpenTsdbQuery, V extends OpenTsdbQuery[K]>(key: K, val: V) => { |
||||
onChange({ |
||||
...query, |
||||
[key]: val, |
||||
fromAnnotations: true, |
||||
}); |
||||
}; |
||||
|
||||
const updateIsGlobal = (isGlobal: boolean) => { |
||||
isGlobal = !isGlobal; |
||||
setIsGlobal(isGlobal); |
||||
updateValue('isGlobal', isGlobal); |
||||
}; |
||||
|
||||
return ( |
||||
<div className="gf-form-group"> |
||||
<div className="gf-form"> |
||||
<InlineFormLabel width={12}>OpenTSDB metrics query</InlineFormLabel> |
||||
<Input |
||||
value={target} |
||||
onChange={(e) => setTarget(e.currentTarget.value ?? '')} |
||||
onBlur={() => updateValue('target', target)} |
||||
placeholder="events.eventname" |
||||
/> |
||||
</div> |
||||
<div className="gf-form"> |
||||
<InlineFormLabel width={12}>Show Global Annotations?</InlineFormLabel> |
||||
<InlineSwitch value={isGlobal} onChange={(e) => updateIsGlobal(isGlobal)} /> |
||||
</div> |
||||
</div> |
||||
); |
||||
}; |
@ -0,0 +1,23 @@ |
||||
import { LegacyAnnotation } from './types'; |
||||
|
||||
// this becomes the target in the migrated annotations
|
||||
const migrateLegacyAnnotation = (json: LegacyAnnotation) => { |
||||
// return the target annotation
|
||||
const annotation: LegacyAnnotation = { |
||||
fromAnnotations: true, |
||||
target: json.target ?? '', |
||||
name: json.name ?? '', |
||||
isGlobal: json.isGlobal ?? false, |
||||
}; |
||||
|
||||
return annotation; |
||||
}; |
||||
|
||||
// eslint-ignore-next-line
|
||||
export const prepareAnnotation = (json: any) => { |
||||
const resultingTarget = json.target && typeof json.target !== 'string' ? json.target : migrateLegacyAnnotation(json); |
||||
|
||||
json.target = resultingTarget; |
||||
|
||||
return json; |
||||
}; |
@ -1,7 +0,0 @@ |
||||
<div class="gf-form-group"> |
||||
<div class="gf-form"> |
||||
<span class="gf-form-label width-13">OpenTSDB metrics query</span> |
||||
<input type="text" class="gf-form-input" ng-model='ctrl.annotation.target' placeholder="events.eventname"></input> |
||||
</div> |
||||
<gf-form-switch class="gf-form" label="Show Global Annotations?" checked="ctrl.annotation.isGlobal" switch-class="max-width-6" label-class="width-13"></gf-form-switch> |
||||
</div> |
Loading…
Reference in new issue