mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
MatcherUI: show field name even when not found in results (#33102)
This commit is contained in:
parent
6271777ec6
commit
98789e7ed9
@ -6,7 +6,7 @@ import { Select } from '../Select/Select';
|
||||
export const FieldNameMatcherEditor = memo<MatcherUIProps<string>>((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<string>) => {
|
||||
@ -46,11 +46,18 @@ const useFieldDisplayNames = (data: DataFrame[]): Set<string> => {
|
||||
}, [data]);
|
||||
};
|
||||
|
||||
const useSelectOptions = (displayNames: Set<string>): Array<SelectableValue<string>> => {
|
||||
const useSelectOptions = (displayNames: Set<string>, currentName: string): Array<SelectableValue<string>> => {
|
||||
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]);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user