import * as React from 'react'; import { Schema, SchemaProps } from './Schema'; import { ArrayClosingLabel, ArrayOpenningLabel } from '../../common-elements'; import styled from '../../styled-components'; import { humanizeConstraints } from '../../utils'; import { TypeName } from '../../common-elements/fields'; import { ObjectSchema } from './ObjectSchema'; const PaddedSchema = styled.div` padding-left: ${({ theme }) => theme.spacing.unit * 2}px; padding-top: ${({ theme }) => theme.spacing.unit * 2}px; `; export class ArraySchema extends React.PureComponent { render() { const schema = this.props.schema; const itemsSchema = schema.items; const fieldParentsName = this.props.fieldParentsName; const minMaxItems = schema.minItems === undefined && schema.maxItems === undefined ? '' : `(${humanizeConstraints(schema)})`; const updatedParentsArray = fieldParentsName ? [...fieldParentsName.slice(0, -1), fieldParentsName[fieldParentsName.length - 1] + '[]'] : fieldParentsName; if (schema.fields) { return ( ); } if (schema.displayType && !itemsSchema && !minMaxItems.length) { return (
{schema.displayType}
); } return (
Array {minMaxItems}
); } }