Skip to content

Commit 08bd249

Browse files
review
1 parent 7182576 commit 08bd249

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
@@ -44,8 +44,6 @@ const NO_VALUE = Symbol('no Value');
4444
* - For each element in the `data` recursively sanitize the data, stopping at `maxItems` if specified
4545
* - Otherwise, just return the `data` removing any values after `maxItems` if it is set
4646
* - If the type of the old and new schema `items` are booleans of the same value, return `data` as is
47-
* - If the new schema contains a default value then:
48-
* - return the default value. We expect this to be a scalar value
4947
* - Otherwise return `undefined`
5048
*
5149
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
@@ -54,8 +52,7 @@ const NO_VALUE = Symbol('no Value');
5452
* @param [oldSchema] - The old schema from which the data originated
5553
* @param [data={}] - The form data associated with the schema, defaulting to an empty object when undefined
5654
* @returns - The new form data, with all the fields uniquely associated with the old schema set
57-
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties
58-
* and doesn't provide a default value
55+
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
5956
*/
6057
export default function sanitizeDataForNewSchema<
6158
T = any,
@@ -196,12 +193,5 @@ export default function sanitizeDataForNewSchema<
196193
}
197194
// Also probably want to deal with `prefixItems` as tuples with the latest 2020 draft
198195
}
199-
// Schema contains a single scalar value
200-
else {
201-
const newDefaultValue = get(newSchema, 'default');
202-
if (newDefaultValue !== undefined) {
203-
newFormData = newDefaultValue;
204-
}
205-
}
206196
return newFormData as T;
207197
}

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)