Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getInitialValue(name, props: any = {}) {
const field = this.getField(name);
if (field.type === Array) {
const item = this.getInitialValue(joinName(name, '0'));
const items = Math.max(props.initialCount || 0, field.minCount || 0);
return Array.from({ length: items }, () => item);
}
if (field.type === Object) {
return {};
}
return field.defaultValue;
}
: value.map((item, index) => (
))}
getField(name, returnExtracted = true) {
return joinName(null, name).reduce((definition, next, index, array) => {
if (next === '$' || next === '' + parseInt(next, 10)) {
invariant(
definition.type instanceof graphql.GraphQLList,
'Field not found in schema: "%s"',
name,
);
definition = { type: extractFromNonNull(definition.type.ofType) };
} else if (definition.type && definition.type._fields) {
definition = definition.type._fields[next];
} else {
definition = definition[next];
}
invariant(definition, 'Field not found in schema: "%s"', name);
const isLast = array.length - 1 === index;
: value.map((item: any, index: number) => (
))}
Children.map(props.children, child =>
React.cloneElement(child, {
className: 'col-xs-11',
name: joinName(props.name, child.props.name),
label: null,
}),
)
Children.map(children, child =>
React.cloneElement(child, {
key: index,
label: null,
name: joinName(
name,
child.props.name && child.props.name.replace('$', index),
),
}),
),
: fields.map(key => (
))}
: fields.map(key => (
))}
getInitialValue(name, props: any = {}) {
const type = this.getType(name);
if (type === Array) {
const item = this.getInitialValue(joinName(name, '0'));
const items = props.initialCount || 0;
return Array.from({ length: items }, () => item);
}
if (type === Object) {
return {};
}
const defaultValue = this.getField(name).defaultValue;
return defaultValue === undefined
? this.extras[name] && this.extras[name].initialValue
: defaultValue;
}