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 [saving, setSaving] = useState(false);
|
||||
|
||||
// Build a sensible default rule from the transaction context
|
||||
const merchantMatch = tx.effective_merchant || tx.description;
|
||||
// Build a sensible default rule from the transaction context.
|
||||
// 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 =
|
||||
field === "category"
|
||||
? `${merchantMatch} → ${formatCategory(newValue)}`
|
||||
: `Rename ${tx.effective_merchant || tx.description} → ${newValue}`;
|
||||
? `${conditionValue} → ${formatCategory(newValue)}`
|
||||
: `Rename ${conditionValue} → ${newValue}`;
|
||||
|
||||
const conditions = [
|
||||
{
|
||||
field: "description",
|
||||
operator: "contains",
|
||||
value: (tx.effective_merchant || tx.description).split(" ")[0] ?? "",
|
||||
},
|
||||
];
|
||||
const conditions = [{ field: conditionField, operator: conditionOperator, value: conditionValue }];
|
||||
const actions =
|
||||
field === "category"
|
||||
? { set_category: newValue }
|
||||
@@ -118,7 +117,7 @@ function SaveAsRulePrompt({
|
||||
Automatically apply this {field === "category" ? "category" : "merchant name"} to future matching transactions.
|
||||
</p>
|
||||
<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>
|
||||
<span className="text-zinc-500">Then</span>{" "}
|
||||
{field === "category"
|
||||
|
||||
Reference in New Issue
Block a user