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: initialize chart of accounts multiselect when there is no api response #1110

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

JustARatherRidiculouslyLongUsername
Copy link
Contributor

@JustARatherRidiculouslyLongUsername JustARatherRidiculouslyLongUsername commented Dec 11, 2024

app.clickup.com

Summary by CodeRabbit

  • Bug Fixes
    • Improved null safety for accessing the charts of accounts property in the import settings.

Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Walkthrough

The changes involve a modification to the BusinessCentralImportSettingsModel class within the business-central-import-settings.model.ts file. The update specifically enhances null safety in the mapAPIResponseToFormGroup static method by changing the way the charts_of_accounts property is accessed. The new implementation ensures that both importSettings and import_settings are checked for null or undefined values before accessing charts_of_accounts.

Changes

File Change Summary
src/app/core/models/business-central/business-central-configuration/business-central-import-settings.model.ts Updated mapAPIResponseToFormGroup method to enhance null safety for charts_of_accounts access.

Possibly related PRs

  • feat: add multiselect to choose types of accounts to import #1099: This PR modifies the BusinessCentralImportSettingsModel class in the same file, specifically adding a new property charts_of_accounts and updating the mapAPIResponseToFormGroup method, which is closely related to the changes made in the main PR regarding the handling of the charts_of_accounts property for null safety.

Suggested labels

size/S

Suggested reviewers

  • ashwin1111
  • DhaaraniCIT

Poem

In the code where rabbits hop,
Nulls were lurking, but now they stop.
With checks in place, so safe and sound,
Our charts of accounts are now well-found!
Hooray for changes, let’s give a cheer,
For safer coding, we hold dear! 🐰✨


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. (Experiment)
  • @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.

@github-actions github-actions bot added the size/XS Extra Small PR label Dec 11, 2024
@JustARatherRidiculouslyLongUsername JustARatherRidiculouslyLongUsername added the deploy Triggers deployment of active branch to Staging label Dec 11, 2024
Copy link

Unit Test Coverage % values
Statements 34.05% ( 4200 / 12334 )
Branches 27.67% ( 1209 / 4369 )
Functions 26.69% ( 922 / 3454 )
Lines 34.21% ( 4132 / 12078 )

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

🧹 Outside diff range and nitpick comments (2)
src/app/core/models/business-central/business-central-configuration/business-central-import-settings.model.ts (2)

29-29: Consider simplifying the nested ternary expression.

The current implementation could be made more readable by using nullish coalescing and extracting the default value.

-            chartOfAccountTypes: new FormControl(importSettings?.import_settings?.charts_of_accounts ? importSettings?.import_settings?.charts_of_accounts : ['Expense']),
+            const DEFAULT_CHART_OF_ACCOUNT_TYPE = ['Expense'];
+            chartOfAccountTypes: new FormControl(importSettings?.import_settings?.charts_of_accounts ?? DEFAULT_CHART_OF_ACCOUNT_TYPE),

29-29: Consider centralizing default values.

The default chart of accounts type ('Expense') appears in both the form initialization and getChartOfAccountTypesList(). Consider creating a constants file to maintain these values in one place.

This would improve maintainability and ensure consistency across the application. Example structure:

// business-central.constants.ts
export const BUSINESS_CENTRAL_DEFAULTS = {
  CHART_OF_ACCOUNTS: {
    DEFAULT_TYPE: 'Expense',
    TYPES: ['Expense', 'Assets', 'Income', 'Equity', 'Liabilities', 'Others', 'Cost of Goods Sold']
  }
};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6175642 and 4e52fd3.

📒 Files selected for processing (1)
  • src/app/core/models/business-central/business-central-configuration/business-central-import-settings.model.ts (1 hunks)
🔇 Additional comments (2)
src/app/core/models/business-central/business-central-configuration/business-central-import-settings.model.ts (2)

29-29: LGTM! Null safety improvement implemented correctly.

The additional null check for import_settings prevents potential runtime errors when the API response is empty or malformed.


29-29: Verify the impact on dependent components.

Let's ensure this initialization change doesn't affect components that consume this form control.

✅ Verification successful

The initialization change is safe and consistent with the codebase

The verification shows that:

  1. The form control chartOfAccountTypes is properly bound to a multi-select component in the template
  2. The default value ['Expense'] aligns with the UI's behavior where "Expense" is disabled and pre-selected
  3. The model correctly maps between the form control and the API property charts_of_accounts
  4. The initialization handles both undefined and defined cases appropriately
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for components using chartOfAccountTypes
echo "Searching for components using chartOfAccountTypes..."
rg -l "chartOfAccountTypes" --type ts

# Search for template files that might bind to this control
echo "Searching for template bindings..."
rg -l "chartOfAccountTypes" --type html

# Look for any tests that might need updating
echo "Searching for related test files..."
rg -l "chartOfAccountTypes.*FormControl" --type spec

Length of output: 2526


Script:

#!/bin/bash
# Let's check the actual usage of chartOfAccountTypes in the components
echo "Checking Business Central import settings component implementation..."
rg -A 5 "chartOfAccountTypes" src/app/integrations/business-central/business-central-shared/business-central-import-settings/business-central-import-settings.component.ts

echo "Checking Business Central import settings template..."
cat src/app/integrations/business-central/business-central-shared/business-central-import-settings/business-central-import-settings.component.html

echo "Checking Business Central import settings model usage..."
rg -A 5 "charts_of_accounts" src/app/core/models/business-central/business-central-configuration/business-central-import-settings.model.ts

Length of output: 7752

@Ashutosh619-sudo Ashutosh619-sudo merged commit ceef58c into bc-beta-bugfixes Dec 11, 2024
8 checks passed
JustARatherRidiculouslyLongUsername added a commit that referenced this pull request Dec 12, 2024
* fix: initialize chart of accounts multiselect when there is no api response (#1110)

* fix: remove the posted at date option for ccc expenses grouped by report (#1105)

* fix: update login error flow and fix redirect url (#1117)

* fix: restrict JE modules to group by expense only (#1113)

* fix: restrict JE modules to group by expense only

* fix: add a default bank account field for CCC expenses (#1114)

* fix: remove validation temporarily (#1111)

* fix: add a default bank account field for CCC expenses

* fix: add missing options to bank accounts on page init

* fix: dynamic content for xero customize settings (#1112)

* fix: update sublabel key to avoid build fail (#1116)

* fix: Prod fixes of QBD direct (#1118)

* fix bugs (#1119)

* refactor: capitalization

* fix: only ccc exports not being saved (#1121)

---------

Co-authored-by: Ashwin Thanaraj <[email protected]>
Co-authored-by: Nilesh Pant <[email protected]>
Co-authored-by: Dhaarani <[email protected]>
Co-authored-by: Anish Kr Singh <[email protected]>

---------

Co-authored-by: Ashwin Thanaraj <[email protected]>
Co-authored-by: Nilesh Pant <[email protected]>
Co-authored-by: Dhaarani <[email protected]>
Co-authored-by: Anish Kr Singh <[email protected]>

---------

Co-authored-by: Ashwin Thanaraj <[email protected]>
Co-authored-by: Nilesh Pant <[email protected]>
Co-authored-by: Dhaarani <[email protected]>
Co-authored-by: Anish Kr Singh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deploy Triggers deployment of active branch to Staging size/XS Extra Small PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants