From a4d3f277ea2a8cacfe19d2fd7ce10f23ab0b5eb8 Mon Sep 17 00:00:00 2001 From: Matt Fiddaman Date: Tue, 18 Feb 2025 23:06:00 +0000 Subject: [PATCH] update mapping data for existing synced transactions and always show direction dropdown (#4403) * update sync mapping data for existing transactions on sync * show payment direction dropdown regardless of sample data * note * ignore changes in raw_synced_data --- .../components/banksync/EditSyncAccount.tsx | 23 +-- .../src/components/banksync/FieldMapping.tsx | 173 ++++++++++-------- .../loot-core/src/server/accounts/sync.ts | 13 +- upcoming-release-notes/4403.md | 6 + 4 files changed, 117 insertions(+), 98 deletions(-) create mode 100644 upcoming-release-notes/4403.md diff --git a/packages/desktop-client/src/components/banksync/EditSyncAccount.tsx b/packages/desktop-client/src/components/banksync/EditSyncAccount.tsx index f820d99061b..b13efd362f1 100644 --- a/packages/desktop-client/src/components/banksync/EditSyncAccount.tsx +++ b/packages/desktop-client/src/components/banksync/EditSyncAccount.tsx @@ -179,22 +179,13 @@ export function EditSyncAccount({ account }: EditSyncAccountProps) { Field mapping - {fields.length > 0 ? ( - - ) : ( - - - No transactions found with mappable fields, accounts must have - been synced at least once for this function to be available. - - - )} + Options diff --git a/packages/desktop-client/src/components/banksync/FieldMapping.tsx b/packages/desktop-client/src/components/banksync/FieldMapping.tsx index e4b61f71c32..ddf0975cbcd 100644 --- a/packages/desktop-client/src/components/banksync/FieldMapping.tsx +++ b/packages/desktop-client/src/components/banksync/FieldMapping.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { useTranslation } from 'react-i18next'; +import { Trans, useTranslation } from 'react-i18next'; import { Text } from '@actual-app/components/text'; @@ -65,92 +65,103 @@ export function FieldMapping({ }} /> - - - - - - - {fields.map(field => { - return ( - + {fields.length === 0 ? ( + + + No transactions found with mappable fields, accounts must have been + synced at least once for this function to be available. + + + ) : ( + <> + - - - - - - [field, field])} + value={mapping.get(field.actualField)} + style={{ + width: 290, + }} + onChange={newValue => { + if (newValue) setMapping(field.actualField, newValue); + }} + /> + + + + + + f.field === mapping.get(field.actualField), + )?.example + } + width="flex" + style={{ paddingLeft: '10px', height: '100%', border: 0 }} + /> + + ); + })} + + )} ); } diff --git a/packages/loot-core/src/server/accounts/sync.ts b/packages/loot-core/src/server/accounts/sync.ts index ac2c1dc0ccc..44fac2eeb6d 100644 --- a/packages/loot-core/src/server/accounts/sync.ts +++ b/packages/loot-core/src/server/accounts/sync.ts @@ -474,9 +474,20 @@ export async function reconcileTransactions( imported_payee: trans.imported_payee || null, notes: existing.notes || trans.notes || null, cleared: trans.cleared ?? existing.cleared, + raw_synced_data: + existing.raw_synced_data ?? trans.raw_synced_data ?? null, }; - if (hasFieldsChanged(existing, updates, Object.keys(updates))) { + const fieldsToMarkUpdated = Object.keys(updates).filter(k => { + // do not mark raw_synced_data if it's gone from falsy to falsy + if (!existing.raw_synced_data && !trans.raw_synced_data) { + return k !== 'raw_synced_data'; + } + + return true; + }); + + if (hasFieldsChanged(existing, updates, fieldsToMarkUpdated)) { updated.push({ id: existing.id, ...updates }); if (!existingPayeeMap.has(existing.payee)) { const payee = await db.getPayee(existing.payee); diff --git a/upcoming-release-notes/4403.md b/upcoming-release-notes/4403.md new file mode 100644 index 00000000000..b57e3f0e466 --- /dev/null +++ b/upcoming-release-notes/4403.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [matt-fidd] +--- + +Update bank sync mapping data for existing transactions on sync