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

[TypeScript] More specific types on budget table components #4524

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

joel-jeremy
Copy link
Contributor

@joel-jeremy joel-jeremy commented Mar 3, 2025

@actual-github-bot actual-github-bot bot changed the title [TypeScript] More specific types on budget table components [WIP] [TypeScript] More specific types on budget table components Mar 3, 2025
@joel-jeremy joel-jeremy changed the title [WIP] [TypeScript] More specific types on budget table components [TypeScript] More specific types on budget table components Mar 3, 2025
Copy link

netlify bot commented Mar 3, 2025

Deploy Preview for actualbudget ready!

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

netlify bot commented Mar 3, 2025

Deploy Preview for actualbudget ready!

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

coderabbitai bot commented Mar 3, 2025

Walkthrough

This pull request updates several type definitions across multiple components in the desktop client. The changes replace manually defined and generic types with specific types derived from the CategoryEntity and CategoryGroupEntity interfaces from the loot-core/types/models module. In particular, properties and function parameters that were previously typed as string or inline object types are now strictly typed using CategoryEntity['id'] or the CategoryGroupEntity type. These adjustments improve type safety and enforce consistency by ensuring that all identifiers and related data structures match the centralized type definitions.

Possibly related PRs

Suggested reviewers

  • MikesGlitch
  • matt-fidd
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
  • @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

github-actions bot commented Mar 3, 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
18 8.05 MB → 8.05 MB (-6 B) -0.00%
Changeset
File Δ Size
src/components/budget/SidebarGroup.tsx 📉 -6 B (-0.09%) 6.41 kB → 6.41 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 5.33 MB → 5.33 MB (-6 B) -0.00%

Unchanged

Asset File Size % Changed
static/js/en.js 103.63 kB 0%
static/js/en-GB.js 96.59 kB 0%
static/js/es.js 58.26 kB 0%
static/js/de.js 112.69 kB 0%
static/js/workbox-window.prod.es5.js 5.69 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/BackgroundImage.js 122.29 kB 0%
static/js/fr.js 113.61 kB 0%
static/js/uk.js 111.11 kB 0%
static/js/nl.js 95.56 kB 0%
static/js/pt-BR.js 110.57 kB 0%
static/js/useAccountPreviewTransactions.js 1.69 kB 0%
static/js/narrow.js 86.26 kB 0%
static/js/AppliedFilters.js 10.8 kB 0%
static/js/wide.js 103.68 kB 0%
static/js/ReportRouter.js 1.59 MB 0%

Copy link
Contributor

github-actions bot commented Mar 3, 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.34 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.34 MB 0%

Copy link

netlify bot commented Mar 3, 2025

Deploy Preview for actualbudget ready!

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

@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 (1)
packages/desktop-client/src/components/budget/SidebarCategory.tsx (1)

35-35: Improved type safety with CategoryEntity ID usage.

The change from string to CategoryEntity['id'] makes the code more type-safe by ensuring that only valid category IDs can be passed to this function.

This is a good improvement that enforces type safety. The function signature now explicitly states that it expects a category ID from a CategoryEntity, making the code more self-documenting and preventing potential type mismatches.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5ebbff4 and 0bd7a51.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/4524.md is excluded by !**/*.md
📒 Files selected for processing (6)
  • packages/desktop-client/src/components/budget/IncomeCategory.tsx (1 hunks)
  • packages/desktop-client/src/components/budget/IncomeGroup.tsx (1 hunks)
  • packages/desktop-client/src/components/budget/SidebarCategory.tsx (1 hunks)
  • packages/desktop-client/src/components/budget/SidebarGroup.tsx (3 hunks)
  • packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (4 hunks)
  • packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: Wait for Netlify build to finish
  • GitHub Check: Analyze
🔇 Additional comments (23)
packages/desktop-client/src/components/budget/SidebarCategory.tsx (1)

37-37: Appropriate type narrowing for Promise-based deletion.

Using CategoryEntity['id'] instead of string enhances type safety for this asynchronous operation.

This change correctly aligns the parameter type with its usage. Since the component receives a category prop of type CategoryEntity, ensuring that all functions using its ID are properly typed improves consistency and prevents potential errors.

packages/desktop-client/src/components/budget/IncomeCategory.tsx (3)

21-21: Type refinement improves object property safety.

The editingCell property now correctly uses CategoryEntity['id'] for its id field, ensuring type consistency across the component.

This provides stronger type guarantees when checking if a cell is being edited, making the code more robust against type-related bugs.


24-24: Enhanced type safety for month editing operations.

The onEditMonth callback type signature now properly uses the specific category ID type.

This change ensures that the function is called with the correct ID type, which is especially important when propagating events up through the component hierarchy.


30-30: Proper typing for activity tracking function.

Using the proper category ID type for onShowActivity improves type safety.

This change ensures that only legitimate category IDs can be passed to the activity tracking functionality, preventing potential runtime errors due to type mismatches.

packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx (5)

22-25: Proper type imports enhance component type safety.

Adding explicit imports for CategoryEntity and CategoryGroupEntity types provides a foundation for more specific type definitions throughout the file.

These imports are a key part of the PR's goal to improve type specificity in budget table components, enabling the subsequent type improvements.


141-141: Added explicit type for the group property.

Changing from an inline object type to CategoryGroupEntity provides a more robust and maintainable type definition.

Using the imported type instead of an inline definition ensures type consistency across the codebase and provides better type checking and IDE support.


201-201: Type-specific category definition.

Replacing an inline object type with CategoryEntity improves type safety and documentation.

This change ensures that the component receives a properly typed category object with all the expected properties, making the code more maintainable and less prone to errors.


203-203: Enhanced function signature for editing.

The onEdit callback now uses the more specific CategoryEntity['id'] type for the id parameter.

This properly constrains the types of values that can be passed to this function, aligning with how it's used throughout the component.


205-205: Type-safe activity tracking.

The onShowActivity function now explicitly requires a CategoryEntity['id'] rather than any string.

This improvement ensures that only valid category IDs can be used to show activity, preventing potential runtime errors.

packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (7)

20-23: Added structured type imports for budget entities.

Importing the specific entity types from the models module provides a foundation for better type safety throughout the file.

These imports enable the type enhancements found throughout the rest of the file, bringing consistency with the project's type system.


138-138: Enhanced group property type definition.

Using CategoryGroupEntity instead of an inline type improves type safety and consistency.

This change ensures the component properly handles group objects with all the expected properties defined in the centralized type definition.


196-196: Improved category property typing.

Replacing an inline object type with CategoryEntity enhances type checking and documentation.

This change ensures that the component expects a properly structured category object, making the code more robust against potential type errors.


198-198: Type-safe editing function signature.

The onEdit callback now correctly uses CategoryEntity['id'] for the ID parameter.

This ensures type consistency when editing categories, preventing potential type mismatches between the expected and actual parameter types.


200-200: Type-specific activity tracking.

The onShowActivity function now requires a properly typed category ID.

This change improves type safety by ensuring that only valid category IDs can be used to trigger activity displays.


490-490: Enhanced income category property typing.

Using the CategoryEntity type for the category property in IncomeCategoryMonthProps improves type safety.

This change ensures consistent typing across all components that deal with categories, making the code more maintainable.


493-493: Type-safe activity tracking for income categories.

The onShowActivity function signature now properly uses CategoryEntity['id'].

This change improves type safety and maintains consistency with the other component types in the file.

packages/desktop-client/src/components/budget/IncomeGroup.tsx (3)

4-5: Good modular type import!

The addition of the CategoryGroupEntity type import from the central models file promotes type consistency across the codebase.


13-14: Great type enhancement for improved type safety!

Replacing the manually defined structure with the CategoryGroupEntity type eliminates potential inconsistencies and ensures the component respects the canonical type definition. The change to the editingCell property properly uses indexed access type CategoryGroupEntity['id'] to ensure type coherence between the ID and the entity itself.


17-21: Consistent parameter typing across callbacks!

The function signatures now properly leverage CategoryGroupEntity['id'] for all ID-related parameters and the complete CategoryGroupEntity type for the onSave callback. This ensures type safety throughout all interactions with category groups.

packages/desktop-client/src/components/budget/SidebarGroup.tsx (4)

12-16: Well-structured type imports!

The import statement correctly uses the type keyword for TypeScript type-only imports, which is a best practice as it prevents type definitions from being included in the runtime bundle.


26-27: Excellent type enhancement!

Replacing the manually defined structure with the CategoryGroupEntity type improves type safety and maintainability by ensuring the component adheres to the canonical type definition.


32-41: Comprehensive callback type refinement!

All callback functions now properly use the specific entity ID types:

  • onEdit, onDelete, and onToggleCollapse correctly use CategoryGroupEntity['id']
  • onSave accepts the complete CategoryGroupEntity object
  • onApplyBudgetTemplatesInGroup properly uses an array of CategoryEntity['id']
  • onShowNewCategory correctly uses CategoryGroupEntity['id']

This approach ensures type safety and consistency across all callback interactions.


141-142: Type-safe category ID mapping!

The implementation correctly maps category IDs using the properly typed entity structure, maintaining type safety throughout the component's logic.

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.

1 participant