From 98789e7ed982f21b824f12d445d04c8689e0b2b6 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Mon, 19 Apr 2021 00:02:58 -0700 Subject: [PATCH] MatcherUI: show field name even when not found in results (#33102) --- .../MatchersUI/FieldNameMatcherEditor.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/grafana-ui/src/components/MatchersUI/FieldNameMatcherEditor.tsx b/packages/grafana-ui/src/components/MatchersUI/FieldNameMatcherEditor.tsx index 8f96c020350..1d67ddccc3f 100644 --- a/packages/grafana-ui/src/components/MatchersUI/FieldNameMatcherEditor.tsx +++ b/packages/grafana-ui/src/components/MatchersUI/FieldNameMatcherEditor.tsx @@ -6,7 +6,7 @@ import { Select } from '../Select/Select'; export const FieldNameMatcherEditor = memo>((props) => { const { data, options, onChange: onChangeFromProps } = props; const names = useFieldDisplayNames(data); - const selectOptions = useSelectOptions(names); + const selectOptions = useSelectOptions(names, options); const onChange = useCallback( (selection: SelectableValue) => { @@ -46,11 +46,18 @@ const useFieldDisplayNames = (data: DataFrame[]): Set => { }, [data]); }; -const useSelectOptions = (displayNames: Set): Array> => { +const useSelectOptions = (displayNames: Set, currentName: string): Array> => { return useMemo(() => { - return Array.from(displayNames).map((n) => ({ + const vals = Array.from(displayNames).map((n) => ({ value: n, label: n, })); - }, [displayNames]); + if (currentName && !displayNames.has(currentName)) { + vals.push({ + value: currentName, + label: `${currentName} (not found)`, + }); + } + return vals; + }, [displayNames, currentName]); };