mirror of
https://github.com/strapi/strapi.git
synced 2025-11-09 22:59:14 +00:00
Merge pull request #16418 from GitStartHQ/fix/condition-fields-break-checkbox
This commit is contained in:
commit
e3af28c527
@ -1,7 +1,7 @@
|
|||||||
import updateValues from '../updateValues';
|
import updateValues from '../updateValues';
|
||||||
|
|
||||||
describe('ADMIN | COMPONENTS | Permissions | utils | updateValues', () => {
|
describe('ADMIN | COMPONENTS | Permissions | utils | updateValues', () => {
|
||||||
it('should not the conditions values of given object', () => {
|
it('should not update the conditions values of given object', () => {
|
||||||
const simpleObject = {
|
const simpleObject = {
|
||||||
properties: {
|
properties: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
@ -18,6 +18,31 @@ describe('ADMIN | COMPONENTS | Permissions | utils | updateValues', () => {
|
|||||||
expect(updateValues(simpleObject, false)).toEqual(expected);
|
expect(updateValues(simpleObject, false)).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should update the conditions values if they are fields names', () => {
|
||||||
|
const simpleObject = {
|
||||||
|
conditions: 'test',
|
||||||
|
properties: {
|
||||||
|
fields: {
|
||||||
|
description: false,
|
||||||
|
restaurant: false,
|
||||||
|
conditions: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const expected = {
|
||||||
|
conditions: 'test',
|
||||||
|
properties: {
|
||||||
|
fields: {
|
||||||
|
description: true,
|
||||||
|
restaurant: true,
|
||||||
|
conditions: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(updateValues(simpleObject, true)).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
it('set the leafs of an object with the second argument passed to the function', () => {
|
it('set the leafs of an object with the second argument passed to the function', () => {
|
||||||
const complexeObject = {
|
const complexeObject = {
|
||||||
conditions: 'test',
|
conditions: 'test',
|
||||||
|
|||||||
@ -8,18 +8,18 @@ import isObject from 'lodash/isObject';
|
|||||||
* of an object.
|
* of an object.
|
||||||
* This utility is very helpful when dealing with parent<>children checkboxes
|
* This utility is very helpful when dealing with parent<>children checkboxes
|
||||||
*/
|
*/
|
||||||
const updateValues = (obj, valueToSet) => {
|
const updateValues = (obj, valueToSet, isFieldUpdate = false) => {
|
||||||
return Object.keys(obj).reduce((acc, current) => {
|
return Object.keys(obj).reduce((acc, current) => {
|
||||||
const currentValue = obj[current];
|
const currentValue = obj[current];
|
||||||
|
|
||||||
if (current === 'conditions') {
|
if (current === 'conditions' && !isFieldUpdate) {
|
||||||
acc[current] = currentValue;
|
acc[current] = currentValue;
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isObject(currentValue)) {
|
if (isObject(currentValue)) {
|
||||||
return { ...acc, [current]: updateValues(currentValue, valueToSet) };
|
return { ...acc, [current]: updateValues(currentValue, valueToSet, current === 'fields') };
|
||||||
}
|
}
|
||||||
|
|
||||||
acc[current] = valueToSet;
|
acc[current] = valueToSet;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user