Skip to content

A local-first personal finance app

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

Vincenzo Di Biase300ddc631186
diff --git a/packages/desktop-client/src/components/modals/EditRuleModal.jsx b/packages/desktop-client/src/components/modals/EditRuleModal.jsx
index 0ddd6fd8de..ddcb0499e7 100644
--- a/packages/desktop-client/src/components/modals/EditRuleModal.jsx
+++ b/packages/desktop-client/src/components/modals/EditRuleModal.jsx
@@ -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(),
};
}
diff --git a/upcoming-release-notes/3607.md b/upcoming-release-notes/3607.md
new file mode 100644
index 0000000000..61ea0349d6
--- /dev/null
+++ b/upcoming-release-notes/3607.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [attyluccio]
+---
+
+Fixes Rule Conditions Removal