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

feat: support split expense grouping for Xero #1075

Merged

Conversation

JustARatherRidiculouslyLongUsername
Copy link
Contributor

@JustARatherRidiculouslyLongUsername JustARatherRidiculouslyLongUsername commented Nov 15, 2024

Description

Clickup

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

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new option for grouping split expenses in Xero export settings.
    • Added a conditional field for selecting expense grouping based on credit card export type.
  • Enhancements

    • Improved validation rules to include new expense grouping options.
    • Enhanced user interface with additional configuration options for managing expense exports, including a new select field for split expense grouping.

These updates provide users with greater flexibility and control over their expense grouping settings when exporting to Xero.

* feat: add split expense grouping config to xero export settings

* feat: add split expense grouping config to xero clone settings (#1072)
Copy link
Contributor

coderabbitai bot commented Nov 15, 2024

Walkthrough

The changes enhance the xero-export-settings.model.ts file by adding a new property, split_expense_grouping, to the XeroExpenseGroupSettingPost type and updating related methods. The HTML components for cloning and exporting settings were modified to conditionally display new fields for managing split expenses based on specific criteria. The associated TypeScript files were updated to include new properties and methods that support the functionality for handling split expense grouping in the Xero export settings.

Changes

File Change Summary
src/app/core/models/xero/xero-configuration/xero-export-settings.model.ts - Added property split_expense_grouping: SplitExpenseGrouping to XeroExpenseGroupSettingPost.
- Introduced static method getSplitExpenseGroupingOptions().
- Updated mapAPIResponseToFormGroup and constructPayload methods to handle splitExpenseGrouping.
src/app/integrations/xero/xero-onboarding/xero-clone-settings/xero-clone-settings.component.html - Added conditional <div> for grouping split expenses based on creditCardExportType and feature flag.
- Included <app-clone-setting-field> for user selection.
src/app/integrations/xero/xero-onboarding/xero-clone-settings/xero-clone-settings.component.ts - Added properties brandingFeatureConfig and splitExpenseGroupingOptions.
- Imported brandingFeatureConfig and XeroCorporateCreditCardExpensesObject.
src/app/integrations/xero/xero-shared/xero-export-settings/xero-export-settings.component.html - Introduced conditional rendering for <app-configuration-select-field> for split expense grouping based on feature flag and creditCardExportType.
src/app/integrations/xero/xero-shared/xero-export-settings/xero-export-settings.component.ts - Added property readonly XeroCorporateCreditCardExpensesObject and splitExpenseGroupingOptions.
- Imported XeroCorporateCreditCardExpensesObject.

Possibly related PRs

Suggested reviewers

  • DhaaraniCIT
  • ashwin1111

🐇 In the fields where expenses split,
A new grouping option is now a hit!
With flags that guide and choices that gleam,
Xero's settings now fulfill the dream.
So hop along, let’s set it right,
For managing expenses, it’s a delight! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 18d032d and b3c08ae.

📒 Files selected for processing (1)
  • src/app/integrations/xero/xero-onboarding/xero-clone-settings/xero-clone-settings.component.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/app/integrations/xero/xero-onboarding/xero-clone-settings/xero-clone-settings.component.ts

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 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

🧹 Outside diff range and nitpick comments (8)
src/app/integrations/xero/xero-shared/xero-export-settings/xero-export-settings.component.ts (1)

52-53: Add type annotation for better type safety.

Consider adding a type annotation to the splitExpenseGroupingOptions property to maintain consistency with TypeScript best practices.

-  splitExpenseGroupingOptions = XeroExportSettingModel.getSplitExpenseGroupingOptions();
+  splitExpenseGroupingOptions: SelectFormOption[] = XeroExportSettingModel.getSplitExpenseGroupingOptions();
src/app/core/models/xero/xero-configuration/xero-export-settings.model.ts (2)

171-182: Consider adding JSDoc comments for better documentation

The new method follows the established pattern and provides clear options. Consider adding JSDoc comments to document the purpose and return type.

+  /**
+   * Returns the available options for split expense grouping
+   * @returns {SelectFormOption[]} Array of options for configuring how split expenses should be grouped
+   */
   static getSplitExpenseGroupingOptions() {

233-234: Document the default value for split_expense_grouping

The code sets MULTIPLE_LINE_ITEM as the default value for split_expense_grouping. Consider adding a comment explaining why this is the chosen default.

+        // Default to MULTIPLE_LINE_ITEM for split expenses to maintain backward compatibility
         split_expense_grouping: exportSettingsForm.get('splitExpenseGrouping')?.value ? exportSettingsForm.get('splitExpenseGrouping')?.value : SplitExpenseGrouping.MULTIPLE_LINE_ITEM
src/app/integrations/xero/xero-shared/xero-export-settings/xero-export-settings.component.html (2)

193-207: LGTM! Consider enhancing validation feedback.

The implementation of the split expense grouping field follows consistent patterns with other configuration fields and is properly integrated within the form structure. The conditional rendering is appropriate, ensuring the field only appears when relevant.

Consider adding validation messages to provide clear feedback when the field is required but empty. You can add an error message template similar to other mandatory fields in the form:

 <app-configuration-select-field
     [form]="exportSettingForm"
     [isFieldMandatory]="true"
     [showClearIcon]="true"
     [mandatoryErrorListName]="'split expense grouping'"
     [label]="'How should the split expenses be grouped?'"
     [subLabel]="'Choose how expenses should be grouped for split expenses'"
     [options]="splitExpenseGroupingOptions"
     [iconPath]="'question-square-outline'"
     [placeholder]="'Select the split expense grouping type'"
-    [formControllerName]="'splitExpenseGrouping'">
+    [formControllerName]="'splitExpenseGrouping'"
+    [validationErrorMessage]="'Please select how split expenses should be grouped'">
 </app-configuration-select-field>

193-207: Enhance accessibility for the split expense grouping field.

While the implementation follows the standard component pattern, consider these accessibility improvements:

  1. Add ARIA attributes to provide better screen reader support:
 <app-configuration-select-field
     [form]="exportSettingForm"
     [isFieldMandatory]="true"
     [showClearIcon]="true"
     [mandatoryErrorListName]="'split expense grouping'"
+    [ariaLabel]="'Split expense grouping selection'"
+    [ariaDescribedBy]="'split-expense-grouping-description'"
     [label]="'How should the split expenses be grouped?'"
     [subLabel]="'Choose how expenses should be grouped for split expenses'"
     [options]="splitExpenseGroupingOptions"
     [iconPath]="'question-square-outline'"
     [placeholder]="'Select the split expense grouping type'"
     [formControllerName]="'splitExpenseGrouping'">
 </app-configuration-select-field>
  1. Ensure the error state is properly announced to screen readers by implementing appropriate ARIA live regions in the parent component.
src/app/integrations/xero/xero-onboarding/xero-clone-settings/xero-clone-settings.component.ts (2)

11-11: LGTM with a minor suggestion.

The import of XeroCorporateCreditCardExpensesObject is correctly added. Consider splitting this line into multiple lines for better readability if more enums are added in the future.

-import { AppName, ConfigurationCta, ConfigurationWarningEvent, InputType, ToastSeverity, XeroCorporateCreditCardExpensesObject, XeroFyleField } from 'src/app/core/models/enum/enum.model';
+import {
+  AppName,
+  ConfigurationCta,
+  ConfigurationWarningEvent,
+  InputType,
+  ToastSeverity,
+  XeroCorporateCreditCardExpensesObject,
+  XeroFyleField
+} from 'src/app/core/models/enum/enum.model';

43-44: Add type annotations to the new properties.

While the properties are correctly placed and initialized, they're missing TypeScript type annotations. This is inconsistent with TypeScript best practices and could make the code harder to maintain.

-  brandingFeatureConfig = brandingFeatureConfig;
+  brandingFeatureConfig: typeof brandingFeatureConfig = brandingFeatureConfig;

-  splitExpenseGroupingOptions = XeroExportSettingModel.getSplitExpenseGroupingOptions();
+  splitExpenseGroupingOptions: SelectFormOption[] = XeroExportSettingModel.getSplitExpenseGroupingOptions();

-  XeroCorporateCreditCardExpensesObject = XeroCorporateCreditCardExpensesObject;
+  readonly XeroCorporateCreditCardExpensesObject: typeof XeroCorporateCreditCardExpensesObject = XeroCorporateCreditCardExpensesObject;

Also applies to: 65-66, 140-141

src/app/integrations/xero/xero-onboarding/xero-clone-settings/xero-clone-settings.component.html (1)

182-183: Consider simplifying the conditional rendering.

The multi-line condition could be extracted to a component property or method for better readability and maintainability.

-                <div class="clone-setting--field" *ngIf="brandingFeatureConfig.featureFlags.exportSettings.splitExpenseGrouping && 
-                    exportSettingForm.controls.creditCardExportType.value === XeroCorporateCreditCardExpensesObject.BANK_TRANSACTION">
+                <div class="clone-setting--field" *ngIf="shouldShowSplitExpenseGrouping()">

Add this method to your component:

shouldShowSplitExpenseGrouping(): boolean {
  return this.brandingFeatureConfig.featureFlags.exportSettings.splitExpenseGrouping && 
    this.exportSettingForm.controls.creditCardExportType.value === this.XeroCorporateCreditCardExpensesObject.BANK_TRANSACTION;
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5fcb07e and 18d032d.

📒 Files selected for processing (5)
  • src/app/core/models/xero/xero-configuration/xero-export-settings.model.ts (5 hunks)
  • src/app/integrations/xero/xero-onboarding/xero-clone-settings/xero-clone-settings.component.html (1 hunks)
  • src/app/integrations/xero/xero-onboarding/xero-clone-settings/xero-clone-settings.component.ts (4 hunks)
  • src/app/integrations/xero/xero-shared/xero-export-settings/xero-export-settings.component.html (1 hunks)
  • src/app/integrations/xero/xero-shared/xero-export-settings/xero-export-settings.component.ts (3 hunks)
🔇 Additional comments (11)
src/app/integrations/xero/xero-shared/xero-export-settings/xero-export-settings.component.ts (3)

9-9: LGTM!

The import of XeroCorporateCreditCardExpensesObject is properly placed with related enums and follows the established naming pattern.


91-92: LGTM!

The readonly property is properly defined and follows the established pattern for exposing enums to the template.


52-53: Verify related changes for split expense grouping.

The additions look good, but please ensure:

  1. The template file (xero-export-settings.component.html) properly uses these new properties
  2. The form validation in XeroExportSettingModel.getValidators() includes rules for split expense grouping
  3. The constructPayloadAndSave method correctly handles the new split expense grouping option

Also applies to: 91-92

✅ Verification successful

Based on the search results, I can now generate a final response. The code shows that:

  1. The template file properly uses splitExpenseGroupingOptions as evidenced by its presence in xero-export-settings.component.html
  2. The form validation includes split expense grouping in XeroExportSettingModel.getValidators() where it's added to the creditCardExpense validator rules
  3. The constructPayloadAndSave method in xero-export-settings.component.ts correctly handles saving all form values through XeroExportSettingModel.constructPayload(this.exportSettingForm)

All required changes for split expense grouping are properly implemented.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify related changes for split expense grouping implementation

# Check template usage
echo "Checking template usage..."
rg -l "splitExpenseGroupingOptions" --type html

# Check validator implementation
echo "Checking validator implementation..."
rg "getValidators.*split" --type typescript

# Check payload handling
echo "Checking payload construction..."
rg "constructPayload.*split" --type typescript

Length of output: 916


Script:

#!/bin/bash
# Let's try different search patterns and file extensions

# Check validator implementation
echo "Checking validator implementation..."
rg "getValidators" -A 5 -B 5 "*.ts"

# Check payload handling
echo "Checking payload construction..."
rg "constructPayloadAndSave" -A 10 -B 2 "*.ts"

# Check model implementation
echo "Checking model implementation..."
ast-grep --pattern 'class XeroExportSettingModel {
  $$$
  static getValidators() {
    $$$
  }
  $$$
}'

Length of output: 512


Script:

#!/bin/bash
# Let's try without file extension filters since they're causing issues

# Check validator implementation
echo "Checking validator implementation..."
rg "getValidators" -A 5 -B 5

# Check payload handling
echo "Checking payload construction..."
rg "constructPayloadAndSave" -A 10 -B 2

# Check XeroExportSettingModel implementation
echo "Checking XeroExportSettingModel implementation..."
rg "class XeroExportSettingModel" -A 20

Length of output: 108561

src/app/core/models/xero/xero-configuration/xero-export-settings.model.ts (4)

5-5: LGTM: Import statement is correctly updated

The addition of SplitExpenseGrouping to the enum imports is appropriate for the new split expense grouping feature.


187-187: Verify if split expense grouping is intentionally limited to credit card expenses

The validator includes splitExpenseGrouping only in creditCardExpense rules. Let's verify if this is intentional and aligns with the business requirements.

#!/bin/bash
# Search for related test files and business logic
echo "=== Searching for related test files ==="
rg -l "splitExpenseGrouping|split_expense_grouping" "**/*.spec.ts"

echo "=== Searching for business logic documentation ==="
fd -e md | xargs rg -l "split expense"

221-222: Query the purpose of the searchOption form control

The addition of searchOption seems unrelated to the split expense grouping feature. Could you clarify its purpose?

#!/bin/bash
# Search for other occurrences of searchOption
rg "searchOption" --type ts

15-16: Verify backward compatibility of the new required field

The addition of split_expense_grouping as a required field in XeroExpenseGroupSettingPost might affect existing code. Let's verify that all implementations provide this field.

✅ Verification successful

Based on the search results, I can see that the split_expense_grouping field is properly handled in the codebase:

  1. It's included in form initialization with a default value:
splitExpenseGrouping: new FormControl(exportSettings?.expense_group_settings?.split_expense_grouping)
  1. It's included in payload construction with a default value:
split_expense_grouping: exportSettingsForm.get('splitExpenseGrouping')?.value ? exportSettingsForm.get('splitExpenseGrouping')?.value : SplitExpenseGrouping.MULTIPLE_LINE_ITEM
  1. The field is consistently used across different integrations (Xero, QBO, Intacct, etc.) in their export settings forms and models.

No backward compatibility issues with the new required field

The codebase properly handles the split_expense_grouping field by providing a default value of SplitExpenseGrouping.MULTIPLE_LINE_ITEM when constructing the payload. This ensures backward compatibility as existing code will always have a valid value for this required field.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for places where XeroExpenseGroupSettingPost is constructed
rg -l "XeroExpenseGroupSettingPost" | while read -r file; do
  echo "=== $file ==="
  # Show the context where the type is used
  rg -C 5 "XeroExpenseGroupSettingPost" "$file"
done

Length of output: 11302


Script:

#!/bin/bash
# Search for XeroExpenseGroupSettingPost type definition and its usage
ast-grep --pattern 'interface XeroExpenseGroupSettingPost {
  $$$
}'

# Also search for any object creation or type usage
rg -A 5 -B 5 "XeroExpenseGroupSettingPost" --type ts

Length of output: 4137


Script:

#!/bin/bash
# Search for places where XeroExportSettingPost is constructed to see how the expense_group_settings is handled
rg -A 10 -B 10 "new FormGroup\({[^}]*expense_group_settings" --type ts

# Also search for any direct object creation
rg -A 5 -B 5 "expense_group_settings:\s*{" --type ts

Length of output: 387


Script:

#!/bin/bash
# Search for form initialization or object creation related to expense_group_settings
rg -A 5 -B 5 "expense_group_settings" --type ts

# Also look for any test files that might show object construction
rg -A 5 -B 5 "XeroExpenseGroupSettingPost" --type spec.ts

Length of output: 55727

src/app/integrations/xero/xero-shared/xero-export-settings/xero-export-settings.component.html (1)

193-207: Verify form validation and save handling for the new field.

The new split expense grouping field is well-integrated into the form structure, but let's ensure proper handling during form submission.

✅ Verification successful

Based on the comprehensive code analysis, I can now provide a definitive response about the form validation and save handling for the split expense grouping field:

Form validation and save handling are properly implemented

The split expense grouping field is well-integrated into the export settings form with proper:

  1. Form initialization:

    • Added as a FormControl with proper model binding
    • Default value set to MULTIPLE_LINE_ITEM if not specified
  2. Save handling:

    • Included in the payload construction in XeroExportSettingModel
    • Properly mapped to the API format in constructPayload method
    • Has fallback to default value if not specified
  3. Type safety:

    • Uses proper enum SplitExpenseGrouping
    • Consistent implementation across different integrations (Xero, QBO, Intacct)
  4. UI Options:

    • Proper options setup through getSplitExpenseGroupingOptions()
    • Consistent options: Single Line Item and Multiple Line Item
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify form handling implementation for split expense grouping

# Check for form validation handling in component
rg -A 5 "splitExpenseGrouping" --type ts

# Check for proper save/submit handling
rg -A 10 "constructPayloadAndSave|save\(" --type ts

# Look for related test coverage
rg -g "*spec.ts" "splitExpenseGrouping"

Length of output: 188364


Script:

#!/bin/bash
# Check form validation and save handling for split expense grouping in the component
ast-grep --pattern $'class XeroExportSettingModel {
  $$$
  static constructPayload($_, $_) {
    $$$
  }
  $$$
}'

# Look for test coverage specifically around split expense grouping
rg -g "*spec.ts" -B 5 -A 5 "splitExpenseGrouping.*value"

Length of output: 174


Script:

#!/bin/bash
# Check the model and component implementation for split expense grouping
rg -A 10 "class XeroExportSettingModel" --type ts

# Check form handling in the component
rg -A 10 "splitExpenseGrouping.*FormControl" --type ts

# Check payload construction
rg -A 10 "split_expense_grouping.*payload" --type ts

Length of output: 5586


Script:

#!/bin/bash
# Check for split expense grouping in model and payload construction
rg -B 5 -A 15 "split_expense_grouping.*:" --type ts

# Check for enum or type definition related to split expense grouping
rg -B 2 -A 2 "SplitExpenseGrouping" --type ts

# Check component initialization and form setup
rg -B 5 -A 10 "splitExpenseGroupingOptions" --type ts

Length of output: 56048

src/app/integrations/xero/xero-onboarding/xero-clone-settings/xero-clone-settings.component.ts (2)

5-5: LGTM!

The import of brandingFeatureConfig is correctly added to the existing branding imports.


Line range hint 43-141: Verify template usage of the new properties.

Please ensure that these properties are correctly used in the component's template file (xero-clone-settings.component.html).

✅ Verification successful

Based on the shell script results, I can now generate the final response since I have enough information to verify the template usage.

Template correctly uses all the new properties

The verification shows that:

  • splitExpenseGroupingOptions is properly used in the template with correct binding to form controls and necessary conditions
  • brandingFeatureConfig is used extensively throughout the template for feature flag checks
  • XeroCorporateCreditCardExpensesObject is used correctly in conditional statements for split expense grouping
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check template usage of the new properties

# Check for usage of splitExpenseGroupingOptions
echo "Checking splitExpenseGroupingOptions usage:"
rg -A 3 "splitExpenseGroupingOptions" --type html

# Check for usage of brandingFeatureConfig
echo "Checking brandingFeatureConfig usage:"
rg -A 3 "brandingFeatureConfig" --type html

# Check for usage of XeroCorporateCreditCardExpensesObject
echo "Checking XeroCorporateCreditCardExpensesObject usage:"
rg -A 3 "XeroCorporateCreditCardExpensesObject" --type html

Length of output: 101805

src/app/integrations/xero/xero-onboarding/xero-clone-settings/xero-clone-settings.component.html (1)

184-194: LGTM! The field configuration follows the established pattern.

The new split expense grouping field is well-structured and consistent with other fields in the form:

  • Uses the same app-clone-setting-field component
  • Includes appropriate icon and tooltip
  • Properly configured as a mandatory field
  • Uses consistent naming conventions

Copy link

Unit Test Coverage % values
Statements 35.34% ( 4221 / 11942 )
Branches 28.89% ( 1224 / 4236 )
Functions 27.95% ( 935 / 3345 )
Lines 35.47% ( 4147 / 11689 )

@JustARatherRidiculouslyLongUsername JustARatherRidiculouslyLongUsername merged commit 936b0f3 into master Nov 18, 2024
5 checks passed
JustARatherRidiculouslyLongUsername added a commit that referenced this pull request Nov 19, 2024
* feat: add split expense grouping config to xero export settings

* feat: add split expense grouping config to xero clone settings (#1072)

(cherry picked from commit 936b0f3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M Medium PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants