Annotations: Add custom label for custom values in builtin annotations (#36691)

This commit is contained in:
Maria Alexandra
2021-07-13 13:30:07 +02:00
committed by GitHub
parent 702fd1cad9
commit da7f5864f5
2 changed files with 6 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ export interface TermCount {
export interface Props { export interface Props {
allowCustomValue?: boolean; allowCustomValue?: boolean;
formatCreateLabel?: (input: string) => string;
/** Do not show selected values inside Select. Useful when the values need to be shown in some other components */ /** Do not show selected values inside Select. Useful when the values need to be shown in some other components */
hideValues?: boolean; hideValues?: boolean;
inputId?: string; inputId?: string;
@@ -33,6 +34,7 @@ const filterOption = (option: any, searchQuery: string) => {
export const TagFilter: FC<Props> = ({ export const TagFilter: FC<Props> = ({
allowCustomValue = false, allowCustomValue = false,
formatCreateLabel,
hideValues, hideValues,
inputId, inputId,
isClearable, isClearable,
@@ -65,6 +67,7 @@ export const TagFilter: FC<Props> = ({
const selectOptions = { const selectOptions = {
allowCustomValue, allowCustomValue,
formatCreateLabel,
defaultOptions: true, defaultOptions: true,
filterOption, filterOption,
getOptionLabel: (i: any) => i.label, getOptionLabel: (i: any) => i.label,

View File

@@ -65,6 +65,8 @@ export default function AnnotationQueryEditor({ query, onChange }: Props) {
tags, tags,
}); });
const onFormatCreateLabel = (input: string) => `Use custom value: ${input}`;
return ( return (
<FieldSet className={styles.container}> <FieldSet className={styles.container}>
<Field label="Filter by"> <Field label="Filter by">
@@ -92,6 +94,7 @@ export default function AnnotationQueryEditor({ query, onChange }: Props) {
<Field label="Tags" description={tagsTooltipContent}> <Field label="Tags" description={tagsTooltipContent}>
<TagFilter <TagFilter
allowCustomValue allowCustomValue
formatCreateLabel={onFormatCreateLabel}
inputId="grafana-annotations__tags" inputId="grafana-annotations__tags"
onChange={onTagsChange} onChange={onTagsChange}
tagOptions={getAnnotationTags} tagOptions={getAnnotationTags}