-
Notifications
You must be signed in to change notification settings - Fork 0
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: fix payload and display of dynamic fields in xero clone settings #1074
fix: fix payload and display of dynamic fields in xero clone settings #1074
Conversation
Problem: Dynamic fields that use destination attributes were unusable in Xero clone settings Cause: Export settings and clone settings use different formats to store destination attributes. However, the same methods were used to ingest data and build the payload Solution: Patch the values in clone settings - while setting the default form values and while building the payload
WalkthroughThe pull request introduces modifications to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
There was a problem hiding this 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 (1)
src/app/core/models/xero/xero-configuration/clone-setting.model.ts (1)
29-31
: Consider adding null checks for general_mappings.While the code safely accesses form control values using optional chaining, it assumes
general_mappings
exists in the payload objects. Consider adding null checks or initialization.- exportSettingPayload.general_mappings.bank_account = exportSettingForm.get('bankAccount')?.value; - importSettingPayload.general_mappings.default_tax_code = importSettingForm.get('defaultTaxCode')?.value; - advancedSettingPayload.general_mappings.payment_account = advancedSettingForm.get('billPaymentAccount')?.value; + if (exportSettingPayload.general_mappings) { + exportSettingPayload.general_mappings.bank_account = exportSettingForm.get('bankAccount')?.value; + } + if (importSettingPayload.general_mappings) { + importSettingPayload.general_mappings.default_tax_code = importSettingForm.get('defaultTaxCode')?.value; + } + if (advancedSettingPayload.general_mappings) { + advancedSettingPayload.general_mappings.payment_account = advancedSettingForm.get('billPaymentAccount')?.value; + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
src/app/core/models/xero/xero-configuration/clone-setting.model.ts
(1 hunks)src/app/integrations/xero/xero-onboarding/xero-clone-settings/xero-clone-settings.component.ts
(1 hunks)
🔇 Additional comments (3)
src/app/core/models/xero/xero-configuration/clone-setting.model.ts (2)
27-28
: LGTM! Clear explanation of the formatting strategy.
The comment effectively explains why values are left unformatted here, making it clear that formatting happens during component initialization specifically for clone settings.
29-31
: Verify the form control names and mapping fields.
The implementation correctly assigns unformatted values from form controls to their respective general mappings. However, let's verify that these field names match across the codebase.
✅ Verification successful
Form control names and mapping fields are correctly implemented
The verification shows consistent usage across the codebase:
- Form control names (
bankAccount
,defaultTaxCode
,billPaymentAccount
) match in both component templates and model definitions - General mapping fields (
bank_account
,default_tax_code
,payment_account
) are consistently used in the models - Values are properly formatted using
ExportSettingModel.formatGeneralMappingPayload
before assignment
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify consistency of form control names and mapping fields
# Check form control names in component templates
echo "Checking form control names in templates..."
rg -A 2 "formControlName=['\"]?(bankAccount|defaultTaxCode|billPaymentAccount)['\"]?"
# Check general_mappings field names in models and interfaces
echo "Checking general_mappings field names..."
rg -A 2 "(bank_account|default_tax_code|payment_account).*general_mappings"
# Check ExportSettingModel.formatGeneralMappingPayload usage
echo "Checking formatting method usage..."
ast-grep --pattern 'ExportSettingModel.formatGeneralMappingPayload'
Length of output: 8378
src/app/integrations/xero/xero-onboarding/xero-clone-settings/xero-clone-settings.component.ts (1)
368-380
: Verify edge cases in destination attribute conversion
The conversion logic looks correct for transforming destination attributes to default destination attributes. However, there are a few considerations:
- The null check using optional chaining is good, but we should also handle undefined values explicitly.
- Consider extracting this conversion logic into a separate method for better readability and reusability.
Consider refactoring to:
- // Convert field values from destination attributes to *default* destination attributes
- const controls = [
- this.exportSettingForm.get('bankAccount'),
- this.importSettingForm.get('defaultTaxCode'),
- this.advancedSettingForm.get('billPaymentAccount')
- ];
-
- for (const control of controls) {
- const fullDestinationAttribute: DestinationAttribute | null = control?.value;
- control?.setValue(
- fullDestinationAttribute && ExportSettingModel.formatGeneralMappingPayload(fullDestinationAttribute)
- );
- }
+ private convertDestinationAttributes(): void {
+ const controls = [
+ this.exportSettingForm.get('bankAccount'),
+ this.importSettingForm.get('defaultTaxCode'),
+ this.advancedSettingForm.get('billPaymentAccount')
+ ];
+
+ for (const control of controls) {
+ if (!control) {
+ continue;
+ }
+
+ const fullDestinationAttribute: DestinationAttribute | undefined | null = control.value;
+ control.setValue(
+ fullDestinationAttribute ? ExportSettingModel.formatGeneralMappingPayload(fullDestinationAttribute) : null
+ );
+ }
+ }
+
+ this.convertDestinationAttributes();
Let's verify the usage of ExportSettingModel.formatGeneralMappingPayload
:
✅ Verification successful
Based on the search results, I can now generate the final response since I have enough context about the usage of formatGeneralMappingPayload
across the codebase.
The destination attribute conversion logic is correctly implemented
The conversion logic in the code is consistent with how formatGeneralMappingPayload
is used throughout the codebase:
- It's consistently used to transform
DestinationAttribute
toDefaultDestinationAttribute
format - The same pattern is followed in other components (QBO, NetSuite) for similar form controls
- The null check using optional chaining aligns with other implementations
The current implementation is safe and follows the established patterns in the codebase. The refactoring suggestion in the review comment, while good for readability, isn't strictly necessary as the current code is already aligned with the codebase conventions.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if formatGeneralMappingPayload is used consistently across the codebase
# Expected: The method should be used in similar conversion scenarios
rg "formatGeneralMappingPayload" -A 3 -B 3
Length of output: 23120
Description
Problem: Dynamic fields that use destination attributes were unusable in Xero clone settings
Cause: Export settings and clone settings use different formats to store destination attributes. However, the same methods were used to ingest data and build the payload
Solution: Patch the values in clone settings - while setting the default form values and while building the payload
Clickup
app.clickup.com
Summary by CodeRabbit
New Features
Bug Fixes