Merge branch 'develop' into features/webhooks

This commit is contained in:
Alexandre BODIN 2020-01-20 17:21:14 +01:00 committed by GitHub
commit 1d05cc01b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 86 additions and 47 deletions

View File

@ -20,6 +20,7 @@ const FieldComponent = ({
icon, icon,
isFromDynamicZone, isFromDynamicZone,
isRepeatable, isRepeatable,
isNested,
label, label,
max, max,
min, min,
@ -87,6 +88,7 @@ const FieldComponent = ({
componentUid={componentUid} componentUid={componentUid}
fields={displayedFields} fields={displayedFields}
isFromDynamicZone={isFromDynamicZone} isFromDynamicZone={isFromDynamicZone}
isNested={isNested}
max={max} max={max}
min={min} min={min}
name={name} name={name}
@ -102,6 +104,7 @@ FieldComponent.defaultProps = {
icon: 'smile', icon: 'smile',
isFromDynamicZone: false, isFromDynamicZone: false,
isRepeatable: false, isRepeatable: false,
isNested: false,
max: Infinity, max: Infinity,
min: -Infinity, min: -Infinity,
}; };
@ -112,6 +115,7 @@ FieldComponent.propTypes = {
icon: PropTypes.string, icon: PropTypes.string,
isFromDynamicZone: PropTypes.bool, isFromDynamicZone: PropTypes.bool,
isRepeatable: PropTypes.bool, isRepeatable: PropTypes.bool,
isNested: PropTypes.bool,
label: PropTypes.string.isRequired, label: PropTypes.string.isRequired,
max: PropTypes.number, max: PropTypes.number,
min: PropTypes.number, min: PropTypes.number,

View File

@ -150,7 +150,7 @@ const BannerWrapper = styled.button`
} }
if (hasErrors) { if (hasErrors) {
fill = '#FAA684'; fill = '#F64D0A';
trashFill = '#F64D0A'; trashFill = '#F64D0A';
} }

View File

@ -35,6 +35,7 @@ const DraggedItem = ({
modifiedData, modifiedData,
moveComponentField, moveComponentField,
removeRepeatableField, removeRepeatableField,
triggerFormValidation,
} = useDataManager(); } = useDataManager();
const { setIsDraggingComponent, unsetIsDraggingComponent } = useEditView(); const { setIsDraggingComponent, unsetIsDraggingComponent } = useEditView();
const mainField = get(schema, ['settings', 'mainField'], 'id'); const mainField = get(schema, ['settings', 'mainField'], 'id');
@ -127,6 +128,8 @@ const DraggedItem = ({
end: () => { end: () => {
// Enable the relations select to fire requests // Enable the relations select to fire requests
unsetIsDraggingComponent(); unsetIsDraggingComponent();
// Update the errors
triggerFormValidation();
}, },
collect: monitor => ({ collect: monitor => ({
isDragging: monitor.isDragging(), isDragging: monitor.isDragging(),
@ -171,50 +174,53 @@ const DraggedItem = ({
ref={refs} ref={refs}
/> />
<Collapse isOpen={isOpen} style={{ backgroundColor: '#FAFAFB' }}> <Collapse isOpen={isOpen} style={{ backgroundColor: '#FAFAFB' }}>
<FormWrapper hasErrors={hasErrors} isOpen={isOpen}> {!isDragging && (
{fields.map((fieldRow, key) => { <FormWrapper hasErrors={hasErrors} isOpen={isOpen}>
return ( {fields.map((fieldRow, key) => {
<div className="row" key={key}> return (
{fieldRow.map(field => { <div className="row" key={key}>
const currentField = getField(field.name); {fieldRow.map(field => {
const isComponent = const currentField = getField(field.name);
get(currentField, 'type', '') === 'component'; const isComponent =
const keys = `${componentFieldName}.${field.name}`; get(currentField, 'type', '') === 'component';
const keys = `${componentFieldName}.${field.name}`;
if (isComponent) { if (isComponent) {
const componentUid = currentField.component; const componentUid = currentField.component;
const metas = getMeta(field.name); const metas = getMeta(field.name);
return (
<FieldComponent
componentUid={componentUid}
isRepeatable={currentField.repeatable}
key={field.name}
label={metas.label}
isNested
name={keys}
max={currentField.max}
min={currentField.min}
/>
);
}
return ( return (
<FieldComponent <div key={field.name} className={`col-${field.size}`}>
componentUid={componentUid} <Inputs
isRepeatable={currentField.repeatable} autoFocus={false}
key={field.name} keys={keys}
label={metas.label} layout={schema}
name={keys} name={field.name}
max={currentField.max} onChange={() => {}}
min={currentField.min} onBlur={hasErrors ? checkFormErrors : null}
/> />
</div>
); );
} })}
</div>
return ( );
<div key={field.name} className={`col-${field.size}`}> })}
<Inputs </FormWrapper>
autoFocus={false} )}
keys={keys}
layout={schema}
name={field.name}
onChange={() => {}}
onBlur={hasErrors ? checkFormErrors : null}
/>
</div>
);
})}
</div>
);
})}
</FormWrapper>
</Collapse> </Collapse>
</> </>
); );

View File

@ -1,7 +1,7 @@
import React, { useReducer } from 'react'; import React, { useReducer } from 'react';
import { useDrop } from 'react-dnd'; import { useDrop } from 'react-dnd';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { get } from 'lodash'; import { get, take } from 'lodash';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import { ErrorMessage } from '@buffetjs/styles'; import { ErrorMessage } from '@buffetjs/styles';
import pluginId from '../../pluginId'; import pluginId from '../../pluginId';
@ -18,6 +18,7 @@ const RepeatableComponent = ({
componentValue, componentValue,
componentValueLength, componentValueLength,
fields, fields,
isNested,
max, max,
min, min,
name, name,
@ -28,7 +29,7 @@ const RepeatableComponent = ({
const componentErrorKeys = Object.keys(formErrors) const componentErrorKeys = Object.keys(formErrors)
.filter(errorKey => { .filter(errorKey => {
return errorKey.split('.')[0] === name; return take(errorKey.split('.'), isNested ? 3 : 1).join('.') === name;
}) })
.map(errorKey => { .map(errorKey => {
return errorKey return errorKey
@ -75,7 +76,7 @@ const RepeatableComponent = ({
const doesPreviousFieldContainErrorsAndIsOpen = const doesPreviousFieldContainErrorsAndIsOpen =
componentErrorKeys.includes(`${name}.${index - 1}`) && componentErrorKeys.includes(`${name}.${index - 1}`) &&
index !== 0 && index !== 0 &&
collapses[index - 1].isOpen === false; get(collapses, [index - 1, 'isOpen'], false) === false;
const hasErrors = componentErrorKeys.includes(componentFieldName); const hasErrors = componentErrorKeys.includes(componentFieldName);
return ( return (
@ -88,8 +89,8 @@ const RepeatableComponent = ({
hasErrors={hasErrors} hasErrors={hasErrors}
hasMinError={hasMinError} hasMinError={hasMinError}
isFirst={index === 0} isFirst={index === 0}
isOpen={collapses[index].isOpen} isOpen={get(collapses, [index, 'isOpen'], false)}
key={collapses[index]._temp__id} key={get(collapses, [index, '_temp__id'], null)}
onClickToggle={() => { onClickToggle={() => {
// Close all other collapses and open the selected one // Close all other collapses and open the selected one
toggleCollapses(index); toggleCollapses(index);
@ -107,6 +108,7 @@ const RepeatableComponent = ({
hoverIndex, hoverIndex,
}); });
}} }}
parentName={name}
schema={schema} schema={schema}
toggleCollapses={toggleCollapses} toggleCollapses={toggleCollapses}
/> />
@ -162,6 +164,7 @@ RepeatableComponent.defaultProps = {
componentValue: null, componentValue: null,
componentValueLength: 0, componentValueLength: 0,
fields: [], fields: [],
isNested: false,
max: Infinity, max: Infinity,
min: -Infinity, min: -Infinity,
}; };
@ -171,6 +174,7 @@ RepeatableComponent.propTypes = {
componentValue: PropTypes.oneOfType([PropTypes.array, PropTypes.object]), componentValue: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
componentValueLength: PropTypes.number, componentValueLength: PropTypes.number,
fields: PropTypes.array, fields: PropTypes.array,
isNested: PropTypes.bool,
max: PropTypes.number, max: PropTypes.number,
min: PropTypes.number, min: PropTypes.number,
name: PropTypes.string.isRequired, name: PropTypes.string.isRequired,

View File

@ -411,6 +411,11 @@ const EditViewDataManagerProvider = ({
setIsSubmitting, setIsSubmitting,
shouldShowLoadingState, shouldShowLoadingState,
slug, slug,
triggerFormValidation: () => {
dispatch({
type: 'TRIGGER_FORM_VALIDATION',
});
},
}} }}
> >
{showLoader ? ( {showLoader ? (

View File

@ -187,7 +187,17 @@ const reducer = (state, action) => {
case 'REMOVE_REPEATABLE_FIELD': { case 'REMOVE_REPEATABLE_FIELD': {
const componentPathToRemove = ['modifiedData', ...action.keys]; const componentPathToRemove = ['modifiedData', ...action.keys];
return state.deleteIn(componentPathToRemove); return state
.update('shouldCheckErrors', v => {
const hasErrors = state.get('formErrors').keySeq().size > 0;
if (hasErrors) {
return !v;
}
return v;
})
.deleteIn(componentPathToRemove);
} }
case 'REMOVE_RELATION': case 'REMOVE_RELATION':
@ -223,6 +233,16 @@ const reducer = (state, action) => {
case 'SUBMIT_SUCCESS': case 'SUBMIT_SUCCESS':
case 'DELETE_SUCCEEDED': case 'DELETE_SUCCEEDED':
return state.update('initialData', () => state.get('modifiedData')); return state.update('initialData', () => state.get('modifiedData'));
case 'TRIGGER_FORM_VALIDATION':
return state.update('shouldCheckErrors', v => {
const hasErrors = state.get('formErrors').keySeq().size > 0;
if (hasErrors) {
return !v;
}
return v;
});
default: default:
return state; return state;
} }