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

nYNAB import - properly handle hidden categories and groups #4294

Merged
merged 11 commits into from
Feb 6, 2025

Conversation

youngcw
Copy link
Member

@youngcw youngcw commented Feb 4, 2025

Pass along YNAB hidden attribute so categories and groups can retain hidden status after migration.

@actual-github-bot actual-github-bot bot changed the title nYNAB import properly handle hidden categories and groups [WIP] nYNAB import properly handle hidden categories and groups Feb 4, 2025
Copy link

netlify bot commented Feb 4, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit b07a7a1
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/67a4cad7513b2200086f9256
😎 Deploy Preview https://deploy-preview-4294.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.

@youngcw youngcw changed the base branch from master to youngcw/fix-nynab-duplicates February 4, 2025 22:50
Copy link
Contributor

github-actions bot commented Feb 4, 2025

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
16 6.81 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
static/js/uk.js 111.11 kB 0%
static/js/nl.js 83.87 kB 0%
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/pt-BR.js 103.29 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/en.js 99.34 kB 0%
static/js/en-GB.js 99.33 kB 0%
static/js/de.js 96.74 kB 0%
static/js/useAccountPreviewTransactions.js 1.69 kB 0%
static/js/AppliedFilters.js 10.52 kB 0%
static/js/narrow.js 84.94 kB 0%
static/js/wide.js 102.8 kB 0%
static/js/ReportRouter.js 1.59 MB 0%
static/js/index.js 4.29 MB 0%

Copy link
Contributor

github-actions bot commented Feb 4, 2025

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.33 MB → 1.33 MB (+66 B) +0.00%
Changeset
File Δ Size
packages/loot-core/src/server/importers/ynab5.ts 📈 +114 B (+0.62%) 17.84 kB → 17.96 kB
packages/loot-core/src/server/api.ts 📈 +30 B (+0.14%) 21.04 kB → 21.07 kB
packages/loot-core/src/server/main.ts 📈 +28 B (+0.04%) 69.5 kB → 69.52 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
kcab.worker.js 1.33 MB → 1.33 MB (+66 B) +0.00%

Smaller

No assets were smaller

Unchanged

No assets were unchanged

"id": "F5751985-3290-41E7-B17F-6DBE979F315D",
"name": "Bills",
"hidden": true,
"deleted": false
Copy link
Member Author

Choose a reason for hiding this comment

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

for testing duplicate groups

"goal_overall_funded": null,
"goal_overall_left": null,
"deleted": false
},
Copy link
Member Author

Choose a reason for hiding this comment

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

for testing duplicate categories

@youngcw youngcw changed the title [WIP] nYNAB import properly handle hidden categories and groups nYNAB import - properly handle hidden categories and groups Feb 4, 2025
matt-fidd
matt-fidd previously approved these changes Feb 6, 2025
Copy link
Contributor

@matt-fidd matt-fidd left a comment

Choose a reason for hiding this comment

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

Workflows are failing because the base branch isn't master, they'll hopefully sort themselves when the other change is merged

Base automatically changed from youngcw/fix-nynab-duplicates to master February 6, 2025 14:36
@youngcw youngcw dismissed matt-fidd’s stale review February 6, 2025 14:36

The base branch was changed.

Copy link
Contributor

coderabbitai bot commented Feb 6, 2025

Walkthrough

This pull request extends the category management functionality by introducing and propagating a hidden property across several system components. In the demo budget JSON file, new category groups and categories are added, with specific entries marked as hidden or visible, including a duplicated category with altered visibility. The server API and database insertion handlers have been updated to accept and process the hidden attribute. Additionally, TypeScript interfaces within the YNAB5 importers have been expanded to include this new property, and the category import logic now incorporates retry mechanisms for creating category groups and categories, appending a count to the name upon failure. Overall, these changes ensure that the hidden state of categories and groups is consistently managed throughout the application.

Possibly related PRs

Suggested labels

:sparkles: Merged

Suggested reviewers

  • youngcw

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/loot-core/src/server/importers/ynab5.ts (2)

85-106: Consider extracting retry logic to a reusable function.

The retry logic is duplicated between category group and category creation. Consider extracting it to a reusable function to improve maintainability and reduce code duplication.

+async function createWithRetry<T>(
+  name: string,
+  createFn: (name: string) => Promise<T>,
+  maxRetries: number = 10
+): Promise<T> {
+  let count = 1;
+  const origName = name;
+  
+  while (true) {
+    try {
+      return await createFn(name);
+    } catch (e) {
+      if (count >= maxRetries) {
+        throw Error(e.message);
+      }
+      name = origName + '-' + count.toString();
+      count++;
+    }
+  }
+}

 // Usage in createCategoryGroup
-let run = true;
-const MAX_RETRY = 10;
-let count = 1;
-const origName = group.name;
-while (run) {
-  try {
-    groupId = await actual.createCategoryGroup({
-      name: group.name,
-      is_income: false,
-      hidden: group.hidden,
-    });
-    entityIdMap.set(group.id, groupId);
-    run = false;
-  } catch (e) {
-    group.name = origName + '-' + count.toString();
-    count += 1;
-    if (count >= MAX_RETRY) {
-      run = false;
-      throw Error(e.message);
-    }
-  }
-}
+groupId = await createWithRetry(
+  group.name,
+  async (name) => {
+    const id = await actual.createCategoryGroup({
+      name,
+      is_income: false,
+      hidden: group.hidden,
+    });
+    entityIdMap.set(group.id, id);
+    return id;
+  }
+);

133-154: Add logging for retry attempts.

Consider adding logging to help track retry attempts during category creation. This will be valuable for debugging import issues.

+import { logger } from '../logger';

 // In retry logic
 } catch (e) {
+  logger.debug(
+    `Retry ${count} for category "${origName}": ${e.message}`
+  );
   cat.name = origName + '-' + count.toString();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e8b4a75 and 0295e96.

⛔ Files ignored due to path filters (2)
  • upcoming-release-notes/4293.md is excluded by !**/*.md
  • upcoming-release-notes/4294.md is excluded by !**/*.md
📒 Files selected for processing (6)
  • packages/desktop-client/e2e/data/ynab5-demo-budget.json (3 hunks)
  • packages/loot-core/src/server/api.ts (1 hunks)
  • packages/loot-core/src/server/importers/ynab5-types.d.ts (1 hunks)
  • packages/loot-core/src/server/importers/ynab5.ts (2 hunks)
  • packages/loot-core/src/server/main.ts (1 hunks)
  • packages/loot-core/src/types/server-handlers.d.ts (1 hunks)
🔇 Additional comments (9)
packages/loot-core/src/server/importers/ynab5-types.d.ts (1)

33-33: LGTM! Type definitions for hidden property added correctly.

The addition of the hidden boolean property to both CategoryGroup and Category interfaces aligns with the PR objective of preserving hidden status during YNAB import.

Also applies to: 41-41

packages/loot-core/src/types/server-handlers.d.ts (1)

96-96: LGTM! Server handler type updated correctly.

The addition of the optional hidden property to the category-group-create handler's argument type is consistent with the YNAB import requirements.

packages/loot-core/src/server/importers/ynab5.ts (1)

82-82: LGTM! Hidden Categories group exclusion added.

The addition of Hidden Categories to the excluded groups list is correct and aligns with the PR objective.

Also applies to: 82-82

packages/loot-core/src/server/api.ts (1)

631-634: LGTM! API handler updated correctly.

The addition of the hidden property to the category group creation handler is consistent with the type definitions and YNAB import requirements.

packages/loot-core/src/server/main.ts (1)

371-383: LGTM! The changes properly handle hidden category groups.

The handler now correctly accepts and propagates the hidden property when creating category groups, which is essential for preserving the visibility state during YNAB imports.

packages/desktop-client/e2e/data/ynab5-demo-budget.json (4)

169-174: LGTM! Good test case for hidden category groups.

The test data includes a hidden category group that shares a name with an existing visible group, providing good coverage for both the hidden property and duplicate name handling.


177-199: LGTM! Good test case for category visibility independence.

The test data verifies that a category's visibility is independent of its parent group's visibility by including a visible category under a hidden group.


273-296: LGTM! Good test case for hidden categories under visible groups.

The test data verifies that categories can be hidden independently of their parent group's visibility by including a hidden category under a visible group.


633-656: LGTM! Good test case for duplicate categories with different visibility.

The test data includes a hidden category that shares a name with an existing visible category, providing good coverage for both the hidden property and duplicate name handling.

@youngcw youngcw requested a review from matt-fidd February 6, 2025 14:45
@youngcw youngcw merged commit 7096d00 into master Feb 6, 2025
20 checks passed
@youngcw youngcw deleted the youngcw/nynab-handle-hidden branch February 6, 2025 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants