Fixes #3585 - Fixes Rule Conditions Removal (#3607)

This commit is contained in:
Vincenzo Di Biase
2024-10-12 18:49:01 +02:00
committed by GitHub
parent 05dda5f9d7
commit 300ddc6311
2 changed files with 23 additions and 4 deletions

View File

@@ -231,7 +231,15 @@ function ConditionEditor({
onDelete,
onAdd,
}) {
const { field: originalField, op, value, type, options, error } = condition;
const {
field: originalField,
op,
value,
type,
options,
error,
inputKey,
} = condition;
let field = originalField;
if (field === 'amount' && options) {
@@ -246,6 +254,7 @@ function ConditionEditor({
if (type === 'number' && op === 'isbetween') {
valueEditor = (
<BetweenAmountInput
key={inputKey}
defaultValue={value}
onChange={v => onChange('value', v)}
/>
@@ -253,6 +262,7 @@ function ConditionEditor({
} else {
valueEditor = (
<GenericInput
key={inputKey}
field={field}
type={type}
value={value}
@@ -547,7 +557,7 @@ function StageButton({ selected, children, style, onSelect }) {
}
function newInput(item) {
return { ...item, inputKey: '' + Math.random() };
return { ...item, inputKey: uuid() };
}
function ConditionsList({
@@ -579,6 +589,7 @@ function ConditionsList({
field,
op: 'is',
value: null,
inputKey: uuid(),
});
onChangeConditions(copy);
}
@@ -742,7 +753,7 @@ const conditionFields = [
export function EditRuleModal({ defaultRule, onSave: originalOnSave }) {
const [conditions, setConditions] = useState(
defaultRule.conditions.map(parse),
defaultRule.conditions.map(parse).map(c => ({ ...c, inputKey: uuid() })),
);
const [actionSplits, setActionSplits] = useState(() => {
const parsedActions = defaultRule.actions.map(parse);
@@ -750,7 +761,7 @@ export function EditRuleModal({ defaultRule, onSave: originalOnSave }) {
(acc, action) => {
const splitIndex = action.options?.splitIndex ?? 0;
acc[splitIndex] = acc[splitIndex] ?? { id: uuid(), actions: [] };
acc[splitIndex].actions.push(action);
acc[splitIndex].actions.push({ ...action, inputKey: uuid() });
return acc;
},
// The pre-split group is always there
@@ -821,6 +832,7 @@ export function EditRuleModal({ defaultRule, onSave: originalOnSave }) {
op: 'set-split-amount',
options: { method: 'remainder', splitIndex },
value: null,
inputKey: uuid(),
};
} else {
const fieldsArray = splitIndex === 0 ? actionFields : splitActionFields;
@@ -835,6 +847,7 @@ export function EditRuleModal({ defaultRule, onSave: originalOnSave }) {
op: 'set',
value: null,
options: { splitIndex },
inputKey: uuid(),
};
}

View File

@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [attyluccio]
---
Fixes Rule Conditions Removal