mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-03 19:36:20 +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';
 | 
			
		||||
 | 
			
		||||
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 = {
 | 
			
		||||
      properties: {
 | 
			
		||||
        enabled: true,
 | 
			
		||||
@ -18,6 +18,31 @@ describe('ADMIN | COMPONENTS | Permissions | utils | updateValues', () => {
 | 
			
		||||
    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', () => {
 | 
			
		||||
    const complexeObject = {
 | 
			
		||||
      conditions: 'test',
 | 
			
		||||
 | 
			
		||||
@ -8,18 +8,18 @@ import isObject from 'lodash/isObject';
 | 
			
		||||
 * of an object.
 | 
			
		||||
 * 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) => {
 | 
			
		||||
    const currentValue = obj[current];
 | 
			
		||||
 | 
			
		||||
    if (current === 'conditions') {
 | 
			
		||||
    if (current === 'conditions' && !isFieldUpdate) {
 | 
			
		||||
      acc[current] = currentValue;
 | 
			
		||||
 | 
			
		||||
      return acc;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (isObject(currentValue)) {
 | 
			
		||||
      return { ...acc, [current]: updateValues(currentValue, valueToSet) };
 | 
			
		||||
      return { ...acc, [current]: updateValues(currentValue, valueToSet, current === 'fields') };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    acc[current] = valueToSet;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user