mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
FieldNamePicker: support the isClearable option (#63828)
This commit is contained in:
parent
e643437ee6
commit
bc2f68dc56
@ -195,4 +195,7 @@ export interface FieldNamePickerConfigSettings {
|
||||
* Placeholder text to display when nothing is selected.
|
||||
*/
|
||||
placeholderText?: string;
|
||||
|
||||
/** When set to false, the value can not be removed */
|
||||
isClearable?: boolean;
|
||||
}
|
||||
|
@ -6,13 +6,10 @@ import { Select } from '../Select/Select';
|
||||
|
||||
import { useFieldDisplayNames, useSelectOptions, frameHasName } from './utils';
|
||||
|
||||
type Props = StandardEditorProps<string, FieldNamePickerConfigSettings>;
|
||||
|
||||
// Pick a field name out of the fields
|
||||
export const FieldNamePicker: React.FC<StandardEditorProps<string, FieldNamePickerConfigSettings>> = ({
|
||||
value,
|
||||
onChange,
|
||||
context,
|
||||
item,
|
||||
}) => {
|
||||
export const FieldNamePicker = ({ value, onChange, context, item }: Props) => {
|
||||
const settings: FieldNamePickerConfigSettings = item.settings ?? {};
|
||||
const names = useFieldDisplayNames(context.data, settings?.filter);
|
||||
const selectOptions = useSelectOptions(names, value);
|
||||
@ -37,7 +34,7 @@ export const FieldNamePicker: React.FC<StandardEditorProps<string, FieldNamePick
|
||||
onChange={onSelectChange}
|
||||
noOptionsMessage={settings.noFieldsMessage}
|
||||
width={settings.width}
|
||||
isClearable={true}
|
||||
isClearable={settings.isClearable !== false}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
@ -18,7 +18,7 @@ import { Button, InlineField, InlineFieldRow, Input, Select } from '@grafana/ui'
|
||||
import { FieldNamePicker } from '@grafana/ui/src/components/MatchersUI/FieldNamePicker';
|
||||
|
||||
const fieldNamePickerSettings: StandardEditorsRegistryItem<string, FieldNamePickerConfigSettings> = {
|
||||
settings: { width: 24 },
|
||||
settings: { width: 24, isClearable: false },
|
||||
} as any;
|
||||
|
||||
export const ConvertFieldTypeTransformerEditor = ({
|
||||
|
Loading…
Reference in New Issue
Block a user