Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CSV import not matching category is (nothing) rules #2790

Merged
merged 4 commits into from
Jun 3, 2024

Conversation

matt-fidd
Copy link
Contributor

Fixes #2052

@Maxiimeeb was correct in the issue that the root cause of this is the fact that the csv import passes new transactions down the stack with { category: undefined } if the category is not set in the CSV.

The eval function in the Condition class has a guard that fails the rule if the value it's checking is strictly equal to undefined.

if (fieldValue === undefined) {
return false;
}

This change takes one of the two possible approaches, which is to pass null as the category if unset instead of undefined. parseCategoryFields already does this so it makes sense just to use its return value.

function parseCategoryFields(trans, categories) {
let match = null;
categories.forEach(category => {
if (category.id === trans.category) {
return null;
}
if (category.name === trans.category) {
match = category.id;
}
});
return match;
}

The other way this could be fixed is to amend the guard condition to pick up any nullish values and return accordingly straight away but I'm not sure if this approach would be in line with existing conventions throughout the project for usage of null and undefined.

-    if (fieldValue === undefined) {
-      return false;
-    }
+ if (fieldValue == null) {
+   return this.value == null && this.op === 'is';
+ }

Copy link

netlify bot commented May 22, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit f08b58f
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/665a43ed4871870008a37f5e
😎 Deploy Preview https://deploy-preview-2790.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented May 22, 2024

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
9 4.72 MB → 4.72 MB (-43 B) -0.00%
Changeset
File Δ Size
src/components/modals/ImportTransactions.jsx 📉 -43 B (-0.11%) 38.51 kB → 38.47 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

Asset File Size % Changed
static/js/index.js 3 MB → 3 MB (-43 B) -0.00%

Unchanged

Asset File Size % Changed
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/usePreviewTransactions.js 790 B 0%
static/js/AppliedFilters.js 20.41 kB 0%
static/js/narrow.js 59.97 kB 0%
static/js/wide.js 263.11 kB 0%
static/js/ReportRouter.js 1.23 MB 0%

Copy link
Contributor

github-actions bot commented May 22, 2024

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.2 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.js 1.2 MB 0%

@trafico-bot trafico-bot bot added the 🚧 WIP label May 22, 2024
@matt-fidd matt-fidd changed the title [WIP] Fix CSV import not matching category is (nothing) rules Fix CSV import not matching category is (nothing) rules May 22, 2024
Copy link
Contributor

@twk3 twk3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks to be working well.

I also double-confirmed that this doesn't result in manual transactions loosing their category when being reconciled with an import that matches.

@twk3 twk3 merged commit 6220aad into actualbudget:master Jun 3, 2024
19 checks passed
@trafico-bot trafico-bot bot added ✅ Approved ✨ Merged Pull Request has been merged successfully and removed 🔍 Ready for Review ✨ Merged Pull Request has been merged successfully labels Jun 3, 2024
@matt-fidd matt-fidd deleted the csv-category branch June 20, 2024 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Emty category rule is not aplying on imported data (CSV, QFX)
2 participants