Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/blocks/plugins/conditions/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { __ } from '@wordpress/i18n';

import { isEmpty } from 'lodash';
import { cloneDeep, isEmpty } from 'lodash';

import {
BaseControl,
Expand Down Expand Up @@ -389,15 +389,15 @@ const Edit = ({
}, [ attributes.otterConditions ]);

const addGroup = () => {
const otterConditions = [ ...( attributes.otterConditions || []) ];
const otterConditions = cloneDeep( attributes.otterConditions || [] );
const newGroupIndex = otterConditions.length; // Use the index of the new group
otterConditions.push([{}]);
setAttributes({ otterConditions });
Comment on lines 391 to 395
setOpenTabs(prev => new Set(prev).add(newGroupIndex));
};

const removeGroup = n => {
let otterConditions = [ ...attributes.otterConditions ];
let otterConditions = cloneDeep( attributes.otterConditions );
otterConditions.splice( n, 1 );

if ( ! Boolean( otterConditions.length ) ) {
Expand All @@ -408,13 +408,13 @@ const Edit = ({
};

const addNewCondition = index => {
const otterConditions = [ ...attributes.otterConditions ];
const otterConditions = cloneDeep( attributes.otterConditions );
otterConditions[ index ].push({});
setAttributes({ otterConditions });
};

const removeCondition = ( index, key ) => {
const otterConditions = [ ...attributes.otterConditions ];
const otterConditions = cloneDeep( attributes.otterConditions );
otterConditions[ index ].splice( key, 1 );

if ( 0 === otterConditions[ index ]) {
Expand All @@ -427,7 +427,7 @@ const Edit = ({
const changeCondition = ( value, index, key ) => {
window.oTrk?.set( `condition-type_${attributes?.id ?? name}_${index}_${key}`, { groupID: attributes?.id ?? name, feature: 'condition', featureComponent: 'condition-type', featureValue: value });

const otterConditions = [ ...attributes.otterConditions ];
const otterConditions = cloneDeep( attributes.otterConditions );

const attrs = applyFilters( 'otter.blockConditions.defaults', {}, value );

Expand Down Expand Up @@ -460,19 +460,19 @@ const Edit = ({
* @param {string} type The type of the condition.
*/
const changeArrayValue = ( value, index, key, type ) => {
const otterConditions = [ ...attributes.otterConditions ];
const otterConditions = cloneDeep( attributes.otterConditions );
otterConditions[ index ][ key ][ type ] = value;
setAttributes({ otterConditions });
};

const changeVisibility = ( value, index, key ) => {
const otterConditions = [ ...attributes.otterConditions ];
const otterConditions = cloneDeep( attributes.otterConditions );
otterConditions[ index ][ key ].visibility = 'true' === value ? true : false;
setAttributes({ otterConditions });
};

const changeValue = ( value, index, key, field ) => {
const otterConditions = [ ...attributes.otterConditions ];
const otterConditions = cloneDeep( attributes.otterConditions );
if ( null !== value ) {
otterConditions[ index ][ key ][ field ] = value;
} else {
Expand All @@ -490,7 +490,7 @@ const Edit = ({
* @param {string} type The type of the condition.
*/
const toggleValueInArray = ( value, index, key, type ) => {
const otterConditions = [ ...attributes.otterConditions ];
const otterConditions = cloneDeep( attributes.otterConditions );
if ( otterConditions[ index ][ key ][ type ]?.includes( value ) ) {
otterConditions[ index ][ key ][ type ] = otterConditions[ index ][ key ][ type ].filter( v => v !== value );
} else {
Expand Down
Loading