Fix dz errors on change compo

This commit is contained in:
soupette 2019-12-11 17:13:23 +01:00
parent e991f6ec7c
commit fc1cbbd753
2 changed files with 51 additions and 29 deletions

View File

@ -288,6 +288,7 @@ const EditViewDataManagerProvider = ({
type: 'MOVE_COMPONENT_DOWN',
dynamicZoneName,
currentIndex,
shouldCheckErrors: shouldCheckDZErrors(dynamicZoneName),
});
};
const moveComponentUp = (dynamicZoneName, currentIndex) => {
@ -296,6 +297,7 @@ const EditViewDataManagerProvider = ({
type: 'MOVE_COMPONENT_UP',
dynamicZoneName,
currentIndex,
shouldCheckErrors: shouldCheckDZErrors(dynamicZoneName),
});
};
const moveComponentField = (pathToComponent, dragIndex, hoverIndex) => {
@ -323,19 +325,23 @@ const EditViewDataManagerProvider = ({
});
};
const removeComponentFromDynamicZone = (dynamicZoneName, index) => {
emitEvent('removeComponentFromDynamicZone');
const shouldCheckDZErrors = dzName => {
const doesDZHaveError = Object.keys(formErrors).some(
key => key.split('.')[0] === dynamicZoneName
key => key.split('.')[0] === dzName
);
const shouldCheckErrors = !isEmpty(formErrors) && doesDZHaveError;
return shouldCheckErrors;
};
const removeComponentFromDynamicZone = (dynamicZoneName, index) => {
emitEvent('removeComponentFromDynamicZone');
dispatch({
type: 'REMOVE_COMPONENT_FROM_DYNAMIC_ZONE',
dynamicZoneName,
index,
shouldCheckErrors,
shouldCheckErrors: shouldCheckDZErrors(dynamicZoneName),
});
};
const removeComponentFromField = (keys, componentUid) => {

View File

@ -104,31 +104,47 @@ const reducer = (state, action) => {
}
);
case 'MOVE_COMPONENT_UP':
return state.updateIn(['modifiedData', action.dynamicZoneName], list => {
return list
.delete(action.currentIndex)
.insert(
action.currentIndex - 1,
state.getIn([
'modifiedData',
action.dynamicZoneName,
action.currentIndex,
])
);
});
return state
.update('shouldCheckErrors', v => {
if (action.shouldCheckErrors) {
return !v;
}
return v;
})
.updateIn(['modifiedData', action.dynamicZoneName], list => {
return list
.delete(action.currentIndex)
.insert(
action.currentIndex - 1,
state.getIn([
'modifiedData',
action.dynamicZoneName,
action.currentIndex,
])
);
});
case 'MOVE_COMPONENT_DOWN':
return state.updateIn(['modifiedData', action.dynamicZoneName], list => {
return list
.delete(action.currentIndex)
.insert(
action.currentIndex + 1,
state.getIn([
'modifiedData',
action.dynamicZoneName,
action.currentIndex,
])
);
});
return state
.update('shouldCheckErrors', v => {
if (action.shouldCheckErrors) {
return !v;
}
return v;
})
.updateIn(['modifiedData', action.dynamicZoneName], list => {
return list
.delete(action.currentIndex)
.insert(
action.currentIndex + 1,
state.getIn([
'modifiedData',
action.dynamicZoneName,
action.currentIndex,
])
);
});
case 'MOVE_FIELD':
return state.updateIn(['modifiedData', ...action.keys], list => {
return list