Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('works with empty strings', () => {
expect(joinName('', 'a', 'b')).toBe('a.b');
expect(joinName('a', '', 'b')).toBe('a.b');
expect(joinName('a', 'b', '')).toBe('a.b');
});
it('works with partials', () => {
expect(joinName('a', 'b.c.d')).toBe('a.b.c.d');
expect(joinName('a.b', 'c.d')).toBe('a.b.c.d');
expect(joinName('a.b.c', 'd')).toBe('a.b.c.d');
expect(joinName(null, 'a', 'b.c.d')).toEqual(['a', 'b', 'c', 'd']);
expect(joinName(null, 'a.b', 'c.d')).toEqual(['a', 'b', 'c', 'd']);
expect(joinName(null, 'a.b.c', 'd')).toEqual(['a', 'b', 'c', 'd']);
});
});
it('works with empty strings', () => {
expect(joinName('', 'a', 'b')).toBe('a.b');
expect(joinName('a', '', 'b')).toBe('a.b');
expect(joinName('a', 'b', '')).toBe('a.b');
});
it('works with partials', () => {
expect(joinName('a', 'b.c.d')).toBe('a.b.c.d');
expect(joinName('a.b', 'c.d')).toBe('a.b.c.d');
expect(joinName('a.b.c', 'd')).toBe('a.b.c.d');
expect(joinName(null, 'a', 'b.c.d')).toEqual(['a', 'b', 'c', 'd']);
expect(joinName(null, 'a.b', 'c.d')).toEqual(['a', 'b', 'c', 'd']);
expect(joinName(null, 'a.b.c', 'd')).toEqual(['a', 'b', 'c', 'd']);
});
});
it('works with partials', () => {
expect(joinName('a', 'b.c.d')).toBe('a.b.c.d');
expect(joinName('a.b', 'c.d')).toBe('a.b.c.d');
expect(joinName('a.b.c', 'd')).toBe('a.b.c.d');
expect(joinName(null, 'a', 'b.c.d')).toEqual(['a', 'b', 'c', 'd']);
expect(joinName(null, 'a.b', 'c.d')).toEqual(['a', 'b', 'c', 'd']);
expect(joinName(null, 'a.b.c', 'd')).toEqual(['a', 'b', 'c', 'd']);
});
});
getInitialValue(name, props: any = {}) {
const { default: _default, type: _type } = this.getField(name);
const {
default: defaultValue = _default !== undefined
? _default
: get(this.schema.default, name),
type = _type
} = this._compiledSchema[name];
if (defaultValue !== undefined) return cloneDeep(defaultValue);
if (type === 'array') {
const item = this.getInitialValue(joinName(name, '0'));
const items = props.initialCount || 0;
return Array(items).fill(item);
}
if (type === 'object') return {};
return undefined;
}
: value.map((item, index) => (
))}
,
Children.map(props.children, child =>
React.cloneElement(child, {
name: joinName(props.name, child.props.name),
label: null,
style: {
margin: 0,
...child.props.style
}
})
)
getField(name) {
return joinName(null, name).reduce((definition, next, nextIndex, array) => {
const previous = joinName(array.slice(0, nextIndex));
const isRequired = (
definition.required ||
(this._compiledSchema[previous] || {}).required ||
[]
).includes(next);
const _key = joinName(previous, next);
const _definition = this._compiledSchema[_key] || {};
if (next === '$' || next === '' + parseInt(next, 10)) {
invariant(
definition.type === 'array',
'Field not found in schema: "%s"',
name
);
: fields.map(key => (
))}