fix(rules): save-as-rule uses full merchant name with equals, not first description word
This commit is contained in:
@@ -86,20 +86,19 @@ function SaveAsRulePrompt({
|
|||||||
const createRule = useCreateRule();
|
const createRule = useCreateRule();
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
|
|
||||||
// Build a sensible default rule from the transaction context
|
// Build a sensible default rule from the transaction context.
|
||||||
const merchantMatch = tx.effective_merchant || tx.description;
|
// Prefer merchant_normalized (full name, exact match) over a partial description word.
|
||||||
|
const hasMerchant = !!tx.effective_merchant;
|
||||||
|
const conditionField = hasMerchant ? "merchant_normalized" : "description";
|
||||||
|
const conditionOperator = hasMerchant ? "equals" : "contains";
|
||||||
|
const conditionValue = hasMerchant ? tx.effective_merchant : tx.description;
|
||||||
|
|
||||||
const defaultName =
|
const defaultName =
|
||||||
field === "category"
|
field === "category"
|
||||||
? `${merchantMatch} → ${formatCategory(newValue)}`
|
? `${conditionValue} → ${formatCategory(newValue)}`
|
||||||
: `Rename ${tx.effective_merchant || tx.description} → ${newValue}`;
|
: `Rename ${conditionValue} → ${newValue}`;
|
||||||
|
|
||||||
const conditions = [
|
const conditions = [{ field: conditionField, operator: conditionOperator, value: conditionValue }];
|
||||||
{
|
|
||||||
field: "description",
|
|
||||||
operator: "contains",
|
|
||||||
value: (tx.effective_merchant || tx.description).split(" ")[0] ?? "",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
const actions =
|
const actions =
|
||||||
field === "category"
|
field === "category"
|
||||||
? { set_category: newValue }
|
? { set_category: newValue }
|
||||||
@@ -118,7 +117,7 @@ function SaveAsRulePrompt({
|
|||||||
Automatically apply this {field === "category" ? "category" : "merchant name"} to future matching transactions.
|
Automatically apply this {field === "category" ? "category" : "merchant name"} to future matching transactions.
|
||||||
</p>
|
</p>
|
||||||
<div className="bg-zinc-900 rounded-lg px-3 py-2 text-xs text-zinc-300 mb-3 space-y-1">
|
<div className="bg-zinc-900 rounded-lg px-3 py-2 text-xs text-zinc-300 mb-3 space-y-1">
|
||||||
<p><span className="text-zinc-500">If</span> description contains <span className="text-white">"{conditions[0].value}"</span></p>
|
<p><span className="text-zinc-500">If</span> {conditionField === "merchant_normalized" ? "merchant" : "description"} {conditionOperator} <span className="text-white">"{conditionValue}"</span></p>
|
||||||
<p>
|
<p>
|
||||||
<span className="text-zinc-500">Then</span>{" "}
|
<span className="text-zinc-500">Then</span>{" "}
|
||||||
{field === "category"
|
{field === "category"
|
||||||
|
|||||||
Reference in New Issue
Block a user