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: standardize custom fields for policy check #3324

Merged
merged 3 commits into from
Dec 11, 2024
Merged

Conversation

arjunaj5
Copy link
Contributor

@arjunaj5 arjunaj5 commented Dec 10, 2024

Clickup

https://app.clickup.com/t/86cx8ub7w

Code Coverage

Please add code coverage here

UI Preview

Please add screenshots for UI changes

Summary by CodeRabbit

  • New Features

    • Enhanced error handling for policy violations across expense-related components.
    • Added user feedback for successful addition of per diem expenses to reports.
    • Introduced confirmation dialogs for deleting per diem expenses.
  • Improvements

    • Default values for custom properties are now set when empty in expense transactions.
    • Improved handling of connectivity checks before calculating distances in mileage tracking.
    • Enhanced tracking for user interactions during expense creation and editing.

Copy link

coderabbitai bot commented Dec 10, 2024

Walkthrough

The pull request introduces significant enhancements across three components: AddEditExpensePage, AddEditMileagePage, and AddEditPerDiemPage. Key updates include improved validation and error handling for custom properties, ensuring default values are assigned when necessary. The methods for generating transaction objects have been refined to include checks for policy violations and user interactions. New methods have been added for user feedback and confirmation dialogs, contributing to a more robust and user-friendly experience in expense management.

Changes

File Path Change Summary
src/app/fyle/add-edit-expense/add-edit-expense.page.ts - Updated generateTxnFieldsMap, generateEtxnFromFg, and addExpense with enhanced validation and error handling for custom properties and policy violations.
src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts - Modified generateEtxnFromFg, checkPolicyViolation, and getCalculatedDistance to improve handling of custom fields and connectivity checks.
src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts - Enhanced generateEtxnFromFg, addExpense, and deleteExpense with improved error handling and user feedback mechanisms. New method showAddToReportSuccessToast added.
src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts - Updated test setup to include setDefaultValue in CustomFieldsService mock.
src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts - Updated test setup to include setDefaultValue in CustomFieldsService mock.
src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts - Updated test setup to include setDefaultValue in CustomFieldsService mock.

Possibly related PRs

Suggested labels

size/M

Suggested reviewers

  • mvaishnavi
  • Chethan-Fyle

🎉 In the world of expenses, we now shine,
With defaults set, everything's just fine!
Errors handled with a graceful touch,
User feedback, oh, we love it so much!
Rajinikanth style, we conquer the day,
Expense management, come what may! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 0a5eefe and ed38183.

📒 Files selected for processing (6)
  • src/app/fyle/add-edit-expense/add-edit-expense.page.ts (1 hunks)
  • src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts (1 hunks)
  • src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts (1 hunks)
  • src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts (1 hunks)
  • src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts (1 hunks)
  • src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts (1 hunks)
👮 Files not reviewed due to content moderation or server errors (2)
  • src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts
  • src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts
🔇 Additional comments (4)
src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts (1)

1700-1702: 🛠️ Refactor suggestion

⚠️ Potential issue

Macha, reassigning function parameter is not the way of the Superstar!

Thalaivar says, reassigning function parameter is like changing the climax of the movie halfway through. Audience will get confused, no?

Use a local variable instead and keep the story straight.

Apply this diff to fix the issue:

-          if (!customProperty.value) {
-            customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
-          }
+          let updatedCustomProperty = customProperty;
+          if (!customProperty.value) {
+            updatedCustomProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
+          }

Likely invalid or redundant comment.

src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts (1)

2418-2420: 🛠️ Refactor suggestion

⚠️ Potential issue

Dei, reassigning function parameter is not the style of the Superstar!

Thalaivar says, reassigning function parameter is like changing the hero of the movie halfway through. Audience will feel cheated, no?

Use a local variable instead and give a satisfying ending.

Apply this diff to fix the issue:

-          if (!customProperty.value) {
-            customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
-          }
+          let updatedCustomProperty = customProperty;
+          if (!customProperty.value) {
+            updatedCustomProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
+          }

Likely invalid or redundant comment.

src/app/fyle/add-edit-expense/add-edit-expense.page.ts (1)

3521-3523: 🛠️ Refactor suggestion

⚠️ Potential issue

Aye aye aye! Reassigning function parameter is not the style of the Superstar.

Thalaivar says, reassigning function parameter is like changing the climax of the movie at the last minute. Audience will feel cheated, no?

Use a local variable instead and give a satisfying ending.

Apply this diff to fix the issue:

-          if (!customProperty.value) {
-            customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
-          }
+          let updatedCustomProperty = customProperty;
+          if (!customProperty.value) {
+            updatedCustomProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
+          }

Likely invalid or redundant comment.

src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts (1)

60-63: Mind it! The CustomFieldsService spy has leveled up.

Thalaivar says, the CustomFieldsService spy has gained a new power - setDefaultValue. This will help it play its role better in the grand testing saga.


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 10, 2024
Copy link

@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: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 5c80494 and 0a5eefe.

📒 Files selected for processing (3)
  • src/app/fyle/add-edit-expense/add-edit-expense.page.ts (1 hunks)
  • src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts (1 hunks)
  • src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts

[error] 1701-1701: Reassigning a function parameter is confusing.

The parameter is declared here:

Use a local variable instead.

(lint/style/noParameterAssign)

src/app/fyle/add-edit-expense/add-edit-expense.page.ts

[error] 3522-3522: Reassigning a function parameter is confusing.

The parameter is declared here:

Use a local variable instead.

(lint/style/noParameterAssign)

src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts

[error] 2419-2419: Reassigning a function parameter is confusing.

The parameter is declared here:

Use a local variable instead.

(lint/style/noParameterAssign)

Comment on lines 1700 to 1702
if (!customProperty.value) {
customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Mind it! Reassigning function parameter is not cool.

Macha, reassigning function parameter is like changing the rules of the game midway. Not fair, no?

Use a local variable instead and keep the game clean.

Apply this diff to fix the issue:

-          if (!customProperty.value) {
-            customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
-          }
+          let updatedCustomProperty = customProperty;
+          if (!customProperty.value) {
+            updatedCustomProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
+          }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!customProperty.value) {
customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
}
let updatedCustomProperty = customProperty;
if (!customProperty.value) {
updatedCustomProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 1701-1701: Reassigning a function parameter is confusing.

The parameter is declared here:

Use a local variable instead.

(lint/style/noParameterAssign)

Comment on lines 2418 to 2420
if (!customProperty.value) {
customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Tch tch tch! Reassigning function parameter is not the way to go.

Macha, reassigning function parameter is like changing the hero of the movie halfway through. Audience will get confused, no?

Use a local variable instead and keep the story straight.

Apply this diff to fix the issue:

-          if (!customProperty.value) {
-            customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
-          }
+          let updatedCustomProperty = customProperty;
+          if (!customProperty.value) {
+            updatedCustomProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
+          }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!customProperty.value) {
customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
}
let updatedCustomProperty = customProperty;
if (!customProperty.value) {
updatedCustomProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 2419-2419: Reassigning a function parameter is confusing.

The parameter is declared here:

Use a local variable instead.

(lint/style/noParameterAssign)

Comment on lines 3521 to 3523
if (!customProperty.value) {
customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Aye aye aye! Reassigning function parameter is not the style.

Macha, reassigning function parameter is like changing the climax of the movie at the last minute. Audience will feel cheated, no?

Use a local variable instead and give a satisfying ending.

Apply this diff to fix the issue:

-          if (!customProperty.value) {
-            customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
-          }
+          let updatedCustomProperty = customProperty;
+          if (!customProperty.value) {
+            updatedCustomProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
+          }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!customProperty.value) {
customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
}
let updatedCustomProperty = customProperty;
if (!customProperty.value) {
updatedCustomProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type);
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 3522-3522: Reassigning a function parameter is confusing.

The parameter is declared here:

Use a local variable instead.

(lint/style/noParameterAssign)

@github-actions github-actions bot added size/S Small PR and removed size/XS Extra Small PR labels Dec 10, 2024
@arjunaj5 arjunaj5 requested a review from mvaishnavi December 10, 2024 15:31
Copy link

Unit Test Coverage % values
Statements 96.01% ( 19266 / 20066 )
Branches 91.14% ( 10659 / 11695 )
Functions 94.35% ( 5747 / 6091 )
Lines 96.05% ( 18396 / 19152 )

@arjunaj5 arjunaj5 merged commit 4f2d424 into master Dec 11, 2024
6 checks passed
@mvaishnavi mvaishnavi removed their request for review December 11, 2024 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/S Small PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants