allow empty values to be set in the auto form (#9198)

This commit is contained in:
Vadim Ogievetsky 2020-01-16 21:06:51 -08:00 committed by Clint Wylie
parent 68ed2a2c8f
commit ab2672514b
2 changed files with 14 additions and 4 deletions

View File

@ -45,6 +45,7 @@ export interface Field<M> {
| 'json'
| 'interval';
defaultValue?: any;
emptyValue?: any;
suggestions?: Functor<M, Suggestion[]>;
placeholder?: string;
min?: number;
@ -99,10 +100,16 @@ export class AutoForm<T extends Record<string, any>> extends React.PureComponent
const { model } = this.props;
if (!model) return;
const newModel =
typeof newValue === 'undefined'
? deepDelete(model, field.name)
: deepSet(model, field.name, newValue);
let newModel: T;
if (typeof newValue === 'undefined') {
if (typeof field.emptyValue === 'undefined') {
newModel = deepDelete(model, field.name);
} else {
newModel = deepSet(model, field.name, field.emptyValue);
}
} else {
newModel = deepSet(model, field.name, newValue);
}
this.modelChange(newModel);
};

View File

@ -180,6 +180,7 @@ export class CoordinatorDynamicConfigDialog extends React.PureComponent<
{
name: 'killDataSourceWhitelist',
type: 'string-array',
emptyValue: [],
info: (
<>
List of dataSources for which kill tasks are sent if property{' '}
@ -191,6 +192,7 @@ export class CoordinatorDynamicConfigDialog extends React.PureComponent<
{
name: 'killPendingSegmentsSkipList',
type: 'string-array',
emptyValue: [],
info: (
<>
List of dataSources for which pendingSegments are NOT cleaned up if property{' '}
@ -259,6 +261,7 @@ export class CoordinatorDynamicConfigDialog extends React.PureComponent<
{
name: 'decommissioningNodes',
type: 'string-array',
emptyValue: [],
info: (
<>
List of historical services to 'decommission'. Coordinator will not assign new