Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{items.map((item, index) => {
// This is largely copied from the default ArrayField
const itemSchema = this.getItemSchema(index);
const itemIdPrefix = `${idSchema.$id}_${index}`;
const itemIdSchema = toIdSchema(itemSchema, itemIdPrefix, definitions);
const isLast = items.length === (index + 1);
const isEditing = this.state.editing[index];
const notLastOrMultipleRows = !isLast || items.length > 1;
if (isReviewMode ? isEditing : isLast || isEditing) {
return (
<div>
<element name="{`table_${itemIdPrefix}`}/">
<div>
<div>
{isLast && items.length > 1 && uiSchema['ui:options'].itemName
? <h5>New {uiSchema['ui:options'].itemName}</h5>
: null}
<div>
</div></div></div></element></div>
{items.map((item, index) => {
// This is largely copied from the default ArrayField
const itemSchema = this.getItemSchema(index);
const itemIdPrefix = `${idSchema.$id}_${index}`;
const itemIdSchema = toIdSchema(
itemSchema,
itemIdPrefix,
definitions,
);
const isLast = items.length === index + 1;
const isEditing = this.state.editing[index];
const notLastOrMultipleRows = !isLast || items.length > 1;
if (isReviewMode ? isEditing : isLast || isEditing) {
return (
<div></div>
* startInEdit - Either a function or a value that will be evaluated as truthy or not
* If a function is used, it's passed the formData and expects a boolean return value
* volatileData - If this is truthy, the component pattern changes slightly so only completely new
* data can be entered, but not edited.
* This is useful for bank account information.
* reviewTitle - The title shown on the review card. Defaults to ui:title
* editTitle - The title shown on the edit card. Defaults to ui:title
* itemName - The name of the set of data in the card. This shows up on the "New X" button if
* volatileData is set to true.
*/
export default class ReviewCardField extends React.Component {
static defaultProps = {
uiSchema: {},
errorSchema: {},
idSchema: {},
registry: getDefaultRegistry(),
required: false,
disabled: false,
readonly: false,
};
constructor(props) {
super(props);
// Throw an error if there’s no viewComponent (should be React component)
if (
typeof get('ui:options.viewComponent', this.props.uiSchema) !== 'function'
) {
throw new Error(
`No viewComponent found in uiSchema for ReviewCardField ${
this.props.idSchema.$id
}.`,
import get from '../../../../platform/utilities/data/get';
import omit from '../../../../platform/utilities/data/omit';
/**
* Displays a review card if the information inside is valid.
*
* For use on a schema of type 'object' or 'array'.
* Intended to wrap objects or arrays to avoid duplicate functionality here.
*/
export default class ReviewCardField extends React.Component {
static defaultProps = {
uiSchema: {},
errorSchema: {},
idSchema: {},
registry: getDefaultRegistry(),
required: false,
disabled: false,
readonly: false,
}
constructor(props) {
super(props);
// Throw an error if there’s no viewComponent (should be React component)
if (typeof get('ui:options.viewComponent', this.props.uiSchema) !== 'function') {
throw new Error(`No viewComponent found in uiSchema for ReviewCardField ${this.props.idSchema.$id}.`);
}
const acceptedTypes = ['object', 'array'];
if (!acceptedTypes.includes(this.props.schema.type)) {
* startInEdit - Either a function or a value that will be evaluated as truthy or not
* If a function is used, it's passed the formData and expects a boolean return value
* volatileData - If this is truthy, the component pattern changes slightly so only completely new
* data can be entered, but not edited.
* This is useful for bank account information.
* reviewTitle - The title shown on the review card. Defaults to ui:title
* editTitle - The title shown on the edit card. Defaults to ui:title
* itemName - The name of the set of data in the card. This shows up on the "New X" button if
* volatileData is set to true.
*/
export default class ReviewCardField extends React.Component {
static defaultProps = {
uiSchema: {},
errorSchema: {},
idSchema: {},
registry: getDefaultRegistry(),
required: false,
disabled: false,
readonly: false,
};
constructor(props) {
super(props);
// Throw an error if there’s no viewComponent (should be React component)
if (
typeof get('ui:options.viewComponent', this.props.uiSchema) !== 'function'
) {
throw new Error(
`No viewComponent found in uiSchema for ReviewCardField ${
this.props.idSchema.$id
}.`,
this.setState(newState, () => {
const newFormData = this.props.formData.concat(getDefaultFormState(this.props.schema.additionalItems, undefined, this.props.registry.definitions) || {});
this.props.onChange(newFormData);
this.scrollToRow(`${this.props.idSchema.$id}_${lastIndex + 1}`);
});
} else {
return (value) => {
const formData = Object.keys(this.props.formData || {}).length
? this.props.formData
: getDefaultFormState(this.props.schema, undefined, this.props.registry.definitions);
this.props.onChange(set(name, value, formData));
};
}
componentDidMount() {
const { schema, formData = [], registry } = this.props;
if (schema.minItems > 0 && formData.length === 0) {
this.props.onChange(Array(schema.minItems).fill(
getDefaultFormState(schema.additionalItems, undefined, registry.definitions)
));
}
}
return value => {
const formData = Object.keys(this.props.formData || {}).length
? this.props.formData
: getDefaultFormState(
this.props.schema,
undefined,
this.props.registry.definitions,
);
this.props.onChange(set(name, value, formData));
};
}
function setupFormData(data, schema, uiSchema) {
const schemaWithItemsCorrected = updateItemsSchema(schema);
return updateSchemaAndData(
schemaWithItemsCorrected,
uiSchema,
getDefaultFormState(schemaWithItemsCorrected, data, {}),
);
}