mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* Remove menuShouldPortal from all <Select /> components * fix unit tests * leave menuShouldPortal as an escape hatch * Fix import order
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import React, { useMemo } from 'react';
|
|
|
|
import { FieldOverrideEditorProps, FieldType, getFieldDisplayName, SelectableValue } from '@grafana/data';
|
|
import { Select } from '@grafana/ui';
|
|
|
|
export const FillBellowToEditor: React.FC<FieldOverrideEditorProps<string, any>> = ({ value, context, onChange }) => {
|
|
const names = useMemo(() => {
|
|
const names: Array<SelectableValue<string>> = [];
|
|
if (context.data.length) {
|
|
for (const frame of context.data) {
|
|
for (const field of frame.fields) {
|
|
if (field.type === FieldType.number) {
|
|
const label = getFieldDisplayName(field, frame, context.data);
|
|
names.push({
|
|
label,
|
|
value: label,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return names;
|
|
}, [context]);
|
|
|
|
const current = useMemo(() => {
|
|
const found = names.find((v) => v.value === value);
|
|
if (found) {
|
|
return found;
|
|
}
|
|
if (value) {
|
|
return {
|
|
label: value,
|
|
value,
|
|
};
|
|
}
|
|
return undefined;
|
|
}, [names, value]);
|
|
|
|
return (
|
|
<Select
|
|
options={names}
|
|
value={current}
|
|
onChange={(v) => {
|
|
onChange(v.value);
|
|
}}
|
|
/>
|
|
);
|
|
};
|