OptionsUI: add standard field name picker (#36732)

This commit is contained in:
Ryan McKinley
2021-07-14 11:54:58 -07:00
committed by GitHub
parent 2f595fa144
commit 6d87b26d6c
6 changed files with 140 additions and 11 deletions

View File

@@ -1,4 +1,5 @@
import { DataLink, FieldOverrideContext, SelectableValue, ThresholdsConfig, ValueMapping } from '../../types';
import { ComponentType } from 'react';
import { DataLink, Field, FieldOverrideContext, SelectableValue, ThresholdsConfig, ValueMapping } from '../../types';
export const identityOverrideProcessor = <T>(value: T, _context: FieldOverrideContext, _settings: any) => {
return value;
@@ -158,3 +159,27 @@ export interface StatsPickerConfigSettings {
*/
defaultStat?: string;
}
interface FieldNamePickerInfoProps {
name?: string;
field?: Field;
}
export interface FieldNamePickerConfigSettings {
/**
* Function is a predicate, to test each element of the array.
* Return a value that coerces to true to keep the field, or to false otherwise.
*/
filter?: (field: Field) => boolean;
/**
* Show this text when no values are found
*/
noFieldsMessage?: string;
/**
* When a field is selected, this component can show aditional
* information, including validation etc
*/
info?: ComponentType<FieldNamePickerInfoProps> | null;
}

View File

@@ -15,6 +15,7 @@ import {
identityOverrideProcessor,
UnitFieldConfigSettings,
unitOverrideProcessor,
FieldNamePickerConfigSettings,
} from '../field';
/**
@@ -235,4 +236,14 @@ export class PanelOptionsEditorBuilder<TOptions> extends OptionsUIRegistryBuilde
editor: standardEditorsRegistry.get('unit').editor as any,
});
}
addFieldNamePicker<TSettings = any>(
config: PanelOptionsEditorConfig<TOptions, TSettings & FieldNamePickerConfigSettings, string>
): this {
return this.addCustomEditor({
...config,
id: config.path,
editor: standardEditorsRegistry.get('field-name').editor as any,
});
}
}