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: helper function for dynamic content #1158

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

Conversation

DhaaraniCIT
Copy link
Contributor

@DhaaraniCIT DhaaraniCIT commented Jan 21, 2025

Description

feat: helper function for dynamic content

Clickup

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

Summary by CodeRabbit

  • New Features

    • Added a new brandingCaseConversion method in HelperService to standardize text case transformations across the application.
  • Refactor

    • Updated multiple components to use the new brandingCaseConversion method for consistent text formatting.
    • Simplified conditional logic for branding-related text transformations.
  • Chores

    • Introduced HelperService as a dependency in several components to centralize case conversion logic.

Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Walkthrough

The pull request introduces a new method brandingCaseConversion in the HelperService to standardize text case transformations across multiple components. This method provides a centralized approach to handling text formatting based on brand configurations. The changes span multiple files in the application, replacing inline conditional logic with calls to the new helper method. The modifications aim to improve code readability and maintainability by consolidating branding-related text transformations into a single service.

Changes

File Path Change Summary
src/app/core/services/common/helper.service.ts Added brandingCaseConversion method for handling text case transformations
src/app/integrations/*/netsuite-*/*.component.* Updated to use helperService for label generation
src/app/integrations/*/qbo-*/*.component.html Replaced inline case conversion with helper method calls
src/app/shared/components/configuration/*.component.* Integrated HelperService for consistent text formatting
src/app/shared/components/dashboard/*.component.html Replaced conditional text formatting with helper method
src/app/shared/components/export-log/*.component.* Added HelperService and updated text rendering logic

Suggested Labels

size/L

Suggested Reviewers

  • ashwin1111
  • anishfyle

Poem

🐰 A Rabbit's Ode to Code Refactoring 🧹

With helper methods, we dance and prance,
Transforming text with a magical glance
No more conditionals, complex and wild
Our code now clean, elegant and mild
Branding made simple, with just one call!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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. (Beta)
  • @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/M Medium PR label Jan 21, 2025
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: 2

🧹 Nitpick comments (6)
src/app/core/services/common/helper.service.ts (1)

Line range hint 289-292: Fix typo in method name: 'sentenseCase' → 'sentenceCase'.

The method name contains a typo. Consider renaming it for consistency.

-  sentenseCaseConversion(content: string) {
+  sentenceCaseConversion(content: string) {
src/app/integrations/netsuite/netsuite-shared/netsuite-import-settings/netsuite-custom-segment-dialog/netsuite-custom-segment-dialog.component.ts (1)

76-78: Consider consistent string concatenation style.

While both methods use the helper service correctly, they use different string concatenation styles. Consider using template literals for better readability.

-    return this.helper.sentenseCaseConversion('Enter Transaction Line Field') + ' ID';
+    return `${this.helper.sentenseCaseConversion('Enter Transaction Line Field')} ID`;

Also applies to: 87-89

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

185-185: Consider using template literals for better readability.

While the helper function usage is good, the string concatenation could be improved using template literals.

-[label]=" 'Set the ' + helperService.brandingCaseConversion(exportSettingForm.controls.creditCardExportType.value)  + ' date as'"
+[label]="`Set the ${helperService.brandingCaseConversion(exportSettingForm.controls.creditCardExportType.value)} date as`"

-[placeholder]="'Select the date of the ' + helperService.brandingCaseConversion(exportSettingForm.controls.creditCardExportType.value)"
+[placeholder]="`Select the date of the ${helperService.brandingCaseConversion(exportSettingForm.controls.creditCardExportType.value)}`"

Also applies to: 189-189

src/app/shared/components/configuration/configuration-import-field/configuration-import-field.component.html (1)

41-45: Consider using template literals for better readability.

While the helper function usage is good, the string concatenations could be improved using template literals.

-Import {{ helper.brandingCaseConversion(getDestinationField(expenseField.get('destination_field')?.value)) }} from {{ uiExposedAppName }}
+Import ${helper.brandingCaseConversion(getDestinationField(expenseField.get('destination_field')?.value))} from ${uiExposedAppName}

-The imported {{ helper.brandingCaseConversion(getDestinationField(expenseField.get('destination_field')?.value)) }}
+The imported ${helper.brandingCaseConversion(getDestinationField(expenseField.get('destination_field')?.value))}
src/app/integrations/netsuite/netsuite-shared/netsuite-export-settings/netsuite-export-settings.component.html (1)

309-309: LGTM! Consider extracting the repeated expression.

The changes effectively utilize the new helper function for consistent text formatting. However, since the same expression is used in both label and placeholder, consider extracting it to improve readability.

+<!-- Extract the expression to a variable for better readability -->
+<ng-container #exportTypeText>
+  {{ helperService.brandingCaseConversion(exportSettingForm.get('creditCardExportType')?.value) }}
+</ng-container>

 <app-configuration-select-field
     [form]="exportSettingForm"
     [isFieldMandatory]="true"
     [mandatoryErrorListName]="'export date'"
-    [label]=" 'Set the ' + helperService.brandingCaseConversion(exportSettingForm.get('creditCardExportType')?.value)  + ' date as'"
+    [label]="'Set the ' + exportTypeText + ' date as'"
     [subLabel]="'The selected date will reflect in the corporate card expenses exported to NetSuite.'"
     [options]="cccExpenseGroupingDateOptions"
     [iconPath]="'calendar'"
-    [placeholder]="'Select the date of the ' + helperService.brandingCaseConversion(exportSettingForm.get('creditCardExportType')?.value)"
+    [placeholder]="'Select the date of the ' + exportTypeText"
     [formControllerName]="'creditCardExportDate'">
 </app-configuration-select-field>

Also applies to: 313-313

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

168-168: LGTM! Consider extracting repeated expressions.

The changes effectively utilize the new helper function for consistent text formatting across both reimbursable and credit card sections. However, since the same expressions are used in multiple places, consider extracting them to improve readability.

+<!-- Extract expressions to variables for better readability -->
+<ng-container #reimbursableExportTypeText>
+  {{ helperService.brandingCaseConversion(exportSettingForm.get('reimbursableExportType')?.value) }}
+</ng-container>
+<ng-container #creditCardExportTypeText>
+  {{ helperService.brandingCaseConversion(exportSettingForm.get('creditCardExportType')?.value) }}
+</ng-container>

 <!-- Reimbursable section -->
 <app-configuration-select-field
     [form]="exportSettingForm"
     [isFieldMandatory]="true"
     [mandatoryErrorListName]="'export date'"
-    [label]="'Set the ' + helperService.brandingCaseConversion(exportSettingForm.get('reimbursableExportType')?.value) + ' date as'"
+    [label]="'Set the ' + reimbursableExportTypeText + ' date as'"
     [subLabel]="'The selected type of date will reflect in the expenses exported from ' + brandingConfig.brandName + ' to QuickBooks Online.'"
     [options]="reimbursableExpenseGroupingDateOptions"
-    [placeholder]="'Select the date of the ' + helperService.brandingCaseConversion(exportSettingForm.get('reimbursableExportType')?.value)"
+    [placeholder]="'Select the date of the ' + reimbursableExportTypeText"
     [iconPath]="'calendar'"
     [formControllerName]="'reimbursableExportDate'">
 </app-configuration-select-field>

 <!-- Credit card section -->
 <app-configuration-select-field
     [form]="exportSettingForm"
     [isFieldMandatory]="true"
     [mandatoryErrorListName]="'export date'"
-    [label]=" 'Set the ' + helperService.brandingCaseConversion(exportSettingForm.get('creditCardExportType')?.value)  + ' date as'"
+    [label]="'Set the ' + creditCardExportTypeText + ' date as'"
     [subLabel]="'The selected date will reflect in the corporate card expenses exported to QuickBooks Online.'"
     [options]="cccExpenseGroupingDateOptions"
     [iconPath]="'calendar'"
-    [placeholder]="'Select the date of the ' + helperService.brandingCaseConversion(exportSettingForm.get('creditCardExportType')?.value)"
+    [placeholder]="'Select the date of the ' + creditCardExportTypeText"
     [formControllerName]="'creditCardExportDate'">
 </app-configuration-select-field>

Also applies to: 171-171, 335-335, 339-339

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1d05001 and eb24c02.

📒 Files selected for processing (11)
  • src/app/core/services/common/helper.service.ts (1 hunks)
  • src/app/integrations/netsuite/netsuite-shared/netsuite-export-settings/netsuite-export-settings.component.html (1 hunks)
  • src/app/integrations/netsuite/netsuite-shared/netsuite-import-settings/netsuite-custom-segment-dialog/netsuite-custom-segment-dialog.component.ts (4 hunks)
  • src/app/integrations/qbo/qbo-shared/qbo-export-settings/qbo-export-settings.component.html (2 hunks)
  • src/app/integrations/xero/xero-shared/xero-export-settings/xero-export-settings.component.html (1 hunks)
  • src/app/shared/components/configuration/configuration-import-field/configuration-import-field.component.html (4 hunks)
  • src/app/shared/components/configuration/configuration-select-field/configuration-select-field.component.html (2 hunks)
  • src/app/shared/components/configuration/configuration-select-field/configuration-select-field.component.ts (2 hunks)
  • src/app/shared/components/dashboard/dashboard-error-section/dashboard-error-section.component.html (2 hunks)
  • src/app/shared/components/export-log/export-log-table/export-log-table.component.html (1 hunks)
  • src/app/shared/components/export-log/export-log-table/export-log-table.component.ts (2 hunks)
🔇 Additional comments (9)
src/app/core/services/common/helper.service.ts (1)

304-315: LGTM! The branding case conversion implementation looks good.

The method effectively handles different branding requirements with clear conditional logic.

src/app/shared/components/export-log/export-log-table/export-log-table.component.ts (1)

7-7: LGTM! Clean dependency injection.

The HelperService integration follows Angular's best practices.

Also applies to: 38-39

src/app/integrations/netsuite/netsuite-shared/netsuite-import-settings/netsuite-custom-segment-dialog/netsuite-custom-segment-dialog.component.ts (1)

8-8: LGTM! Clean dependency injection.

The HelperService integration follows Angular's best practices.

Also applies to: 43-45

src/app/shared/components/configuration/configuration-select-field/configuration-select-field.component.ts (1)

19-19: LGTM! Clean dependency injection.

The HelperService integration follows Angular's best practices.

Also applies to: 119-120

src/app/shared/components/export-log/export-log-table/export-log-table.component.html (1)

40-40: LGTM! Consistent use of helper function for case conversion.

The change improves code maintainability by centralizing the text case transformation logic.

src/app/shared/components/dashboard/dashboard-error-section/dashboard-error-section.component.html (1)

20-20: LGTM! Consistent error message formatting.

The changes improve code maintainability by using the helper function for text case transformations in error messages.

Also applies to: 45-45

src/app/shared/components/configuration/configuration-select-field/configuration-select-field.component.html (1)

174-174: LGTM! Consistent case conversion in default fields section.

The changes improve consistency in text case transformations for default fields.

Also applies to: 179-179

src/app/shared/components/configuration/configuration-import-field/configuration-import-field.component.html (1)

132-132: LGTM! Consistent field label formatting.

The changes improve consistency in text case transformations for field labels.

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

168-168: Verify the helper function implementation.

The brandingCaseConversion helper function is used consistently across multiple files. Let's verify its implementation to ensure it handles all possible cases correctly.

Also applies to: 171-171, 309-309, 313-313, 335-335, 339-339

✅ Verification successful

Helper function implementation is correct and consistent.

The brandingCaseConversion function is properly implemented with brand-specific text formatting and is used consistently across the codebase for UI text formatting.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of brandingCaseConversion helper function.

# Test: Search for the function implementation
ast-grep --pattern $'class HelperService {
  $$$
  brandingCaseConversion($$$) {
    $$$
  }
  $$$
}'

# Test: Search for all usages of the function
rg -A 5 'brandingCaseConversion'

Length of output: 15517

</span>
</td>
<td *ngIf="!isDashboardFailed && appName !== AppName.SAGE300 && appName !== AppName.QBD_DIRECT && appName !== AppName.BUSINESS_CENTRAL">
<div>
<button (click)="openUrl(rowData.integrationUrl)" [pTooltip]="brandingConfig.brandId === 'co' ? 'Open in new tab' : 'Open in New Tab'" tooltipPosition="top">
<button (click)="openUrl(rowData.integrationUrl)" [pTooltip]="helper.sentenseCaseConversion('Open in New Tab')" tooltipPosition="top">
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in helper method name.

The method name sentenseCaseConversion contains a typo (missing 'c'). It should be sentenceCaseConversion.

-[pTooltip]="helper.sentenseCaseConversion('Open in New Tab')"
+[pTooltip]="helper.sentenceCaseConversion('Open in New Tab')"

Also applies to: 52-52

@@ -77,15 +77,15 @@ <h5 *ngIf="formControllerName === 'cccExportType' && brandingConfig.brandId ===
[ngStyle]="{'white-space': 'nowrap', 'overflow': 'hidden', 'text-overflow': 'ellipsis', 'max-width': '16rem'}"
[pTooltip]="isOverflowing(textElement) ? option.label : null" tooltipPosition="top">
<span>
{{ brandingConfig.brandId === 'co' ? (option.label | sentenceCase) : (option.label)}}</span>
{{ helper.sentenseCaseConversion(option.label)}}</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in helper method name across dropdown templates.

The method name sentenseCaseConversion contains a typo. It should be sentenceCaseConversion.

-{{ helper.sentenseCaseConversion(option.label)}}
+{{ helper.sentenceCaseConversion(option.label)}}

-{{ helper.sentenseCaseConversion(option.display_name) }}
+{{ helper.sentenceCaseConversion(option.display_name) }}

-{{ helper.sentenseCaseConversion(item.display_name) }}
+{{ helper.sentenceCaseConversion(item.display_name) }}

Also applies to: 88-88, 93-93

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.

1 participant