grafana/public/app/plugins/panel/timeseries/FillBelowToEditor.tsx
Ashley Harrison 06d3c27bc1
Select: Portal menu by default (#48176)
* Remove menuShouldPortal from all <Select /> components

* fix unit tests

* leave menuShouldPortal as an escape hatch

* Fix import order
2022-05-04 15:12:59 +01:00

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);
}}
/>
);
};