Skip to content

Commit 756af61

Browse files
review
1 parent 63ff213 commit 756af61

File tree

3 files changed

+2
-23
lines changed

3 files changed

+2
-23
lines changed

packages/core/src/components/fields/MultiSchemaField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class AnyOfField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
123123
const oldOption = selectedOption >= 0 ? retrievedOptions[selectedOption] : undefined;
124124

125125
let newFormData = schemaUtils.sanitizeDataForNewSchema(newOption, oldOption, formData);
126-
if (newFormData && newOption) {
126+
if (newOption) {
127127
// Call getDefaultFormState to make sure defaults are populated on change. Pass "excludeObjectChildren"
128128
// so that only the root objects themselves are created without adding undefined children properties
129129
newFormData = schemaUtils.getDefaultFormState(newOption, newFormData, 'excludeObjectChildren') as T;

packages/utils/src/schema/sanitizeDataForNewSchema.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ const NO_VALUE = Symbol('no Value');
5151
* - For each element in the `data` recursively sanitize the data, stopping at `maxItems` if specified
5252
* - Otherwise, just return the `data` removing any values after `maxItems` if it is set
5353
* - If the type of the old and new schema `items` are booleans of the same value, return `data` as is
54-
* - If the new schema contains a default value then:
55-
* - return the default value. We expect this to be a scalar value
5654
* - Otherwise return `undefined`
5755
*
5856
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
@@ -62,8 +60,7 @@ const NO_VALUE = Symbol('no Value');
6260
* @param [data={}] - The form data associated with the schema, defaulting to an empty object when undefined
6361
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
6462
* @returns - The new form data, with all the fields uniquely associated with the old schema set
65-
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties
66-
* and doesn't provide a default value
63+
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
6764
*/
6865
export default function sanitizeDataForNewSchema<
6966
T = any,
@@ -237,12 +234,5 @@ export default function sanitizeDataForNewSchema<
237234
}
238235
// Also probably want to deal with `prefixItems` as tuples with the latest 2020 draft
239236
}
240-
// Schema contains a single scalar value
241-
else {
242-
const newDefaultValue = get(newSchema, 'default');
243-
if (newDefaultValue !== undefined) {
244-
newFormData = newDefaultValue;
245-
}
246-
}
247237
return newFormData as T;
248238
}

packages/utils/test/schema/sanitizeDataForNewSchemaTest.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -483,16 +483,5 @@ export default function sanitizeDataForNewSchemaTest(testValidator: TestValidato
483483
};
484484
expect(schemaUtils.sanitizeDataForNewSchema(newSchema, oldSchema, ['qwerty', 'asdfg'])).toEqual({});
485485
});
486-
487-
it('returns default value when new schema is a scalar schema', () => {
488-
const oldSchema: RJSFSchema = {
489-
type: 'string',
490-
};
491-
const newSchema: RJSFSchema = {
492-
type: 'boolean',
493-
default: true,
494-
};
495-
expect(schemaUtils.sanitizeDataForNewSchema(newSchema, oldSchema, 'oldValue')).toEqual(true);
496-
});
497486
});
498487
}

0 commit comments

Comments
 (0)