Files
Ashley Harrison 47f8717149 React: Use new JSX transform (#88802)
* update eslint, tsconfig + esbuild to handle new jsx transform

* remove thing that breaks the new jsx transform

* remove react imports

* adjust grafana-icons build

* is this the correct syntax?

* try this

* well this was much easier than expected...

* change grafana-plugin-configs webpack config

* fixes

* fix lockfile

* fix 2 more violations

* use path.resolve instead of require.resolve

* remove react import

* fix react imports

* more fixes

* remove React import

* remove import React from docs

* remove another react import
2024-06-25 12:43:47 +01:00

64 lines
1.9 KiB
TypeScript

import { css } from '@emotion/css';
import { useState } from 'react';
import { GrafanaTheme2, QueryEditorProps } from '@grafana/data';
import { Box, InlineField, Input, TagsInput, useStyles2 } from '@grafana/ui';
import { GraphiteDatasource } from '../datasource';
import { GraphiteQuery, GraphiteOptions } from '../types';
export const AnnotationEditor = (props: QueryEditorProps<GraphiteDatasource, GraphiteQuery, GraphiteOptions>) => {
const { query, onChange } = props;
const [target, setTarget] = useState<string>(query.target ?? '');
const [tags, setTags] = useState<string[]>(query.tags ?? []);
const updateValue = <K extends keyof GraphiteQuery, V extends GraphiteQuery[K]>(key: K, val: V) => {
if (key === 'tags') {
onChange({
...query,
[key]: val,
fromAnnotations: true,
queryType: key,
});
} else {
onChange({
...query,
[key]: val,
fromAnnotations: true,
textEditor: true,
});
}
};
const onTagsChange = (tagsInput: string[]) => {
setTags(tagsInput);
updateValue('tags', tagsInput);
};
const styles = useStyles2(getStyles);
return (
<Box marginBottom={5}>
<InlineField label="Graphite Query" labelWidth={24} grow>
<Input
value={target}
onChange={(e) => setTarget(e.currentTarget.value || '')}
onBlur={() => updateValue('target', target)}
placeholder="Example: statsd.application.counters.*.count"
/>
</InlineField>
<h5 className={styles.heading}>Or</h5>
<InlineField label="Graphite events tags" labelWidth={24}>
<TagsInput id="tags-input" width={50} tags={tags} onChange={onTagsChange} placeholder="Example: event_tag" />
</InlineField>
</Box>
);
};
const getStyles = (theme: GrafanaTheme2) => ({
heading: css({
fontSize: theme.typography.body.fontSize,
marginBottom: theme.spacing(1),
}),
});