FieldNamePicker: support the isClearable option (#63828)

This commit is contained in:
Ryan McKinley 2023-02-28 11:15:30 -08:00 committed by GitHub
parent e643437ee6
commit bc2f68dc56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 8 deletions

View File

@ -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;
}

View File

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

View File

@ -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 = ({