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: Milestone 6: Dashboard > Tasks display exact amount #3361

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

SahilK-027
Copy link
Contributor

@SahilK-027 SahilK-027 commented Dec 17, 2024

Important

This is the feature branch.
This PR contains all the approved child PRs ✅

Clickup

clickup link

Summary by CodeRabbit

  • New Features

    • Introduced ExactCurrencyPipe for more precise currency formatting across various components and services.
    • Enhanced layout and visibility logic in the tasks-card component for improved user experience.
  • Bug Fixes

    • Adjusted test cases to reflect updated currency formats and ensure accurate display of task information.
  • Style

    • Updated styles for various elements in the tasks-card component, including font sizes and padding for a more consistent look.
  • Documentation

    • Added ExactCurrencyPipe to the SharedModule for broader application use.

Copy link

coderabbitai bot commented Dec 17, 2024

Walkthrough

In a spectacular display of precision, this pull request transforms the monetary landscape of our application! The changes sweep across multiple files, focusing on currency representation and task-related mock data. We've upgraded our currency handling with the ExactCurrencyPipe, replacing the previous humanized approach with a more surgical precision in financial formatting. The modifications touch task samples, service logic, and component styling, creating a harmonious symphony of exact monetary representation.

Changes

File Change Summary
src/app/core/mock-data/task.data.ts Updated multiple task sample constants with precise monetary values
src/app/core/services/tasks.service.spec.ts Replaced HumanizeCurrencyPipe with ExactCurrencyPipe in test suite
src/app/core/services/tasks.service.ts Integrated ExactCurrencyPipe for currency transformations
src/app/fyle/dashboard/tasks/tasks-card/tasks-card.component.* Refined layout, styling, and rendering logic for task cards
src/app/shared/shared.module.ts Added ExactCurrencyPipe as a provider

Suggested Reviewers

  • Dimple16
  • Chethan-Fyle
  • arjunaj5

Possibly Related PRs

Poem

Behold, the numbers dance with might,
Precision strikes like lightning bright! 💥
Currencies align, no more disguise,
Exact as Rajini's stylish eyes! 💸
Mock data bows to decimal's reign! 🌟


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.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cb9cd69 and 6c60697.

📒 Files selected for processing (7)
  • src/app/core/mock-data/task.data.ts (7 hunks)
  • src/app/core/services/tasks.service.spec.ts (23 hunks)
  • src/app/core/services/tasks.service.ts (8 hunks)
  • src/app/fyle/dashboard/tasks/tasks-card/tasks-card.component.html (2 hunks)
  • src/app/fyle/dashboard/tasks/tasks-card/tasks-card.component.scss (4 hunks)
  • src/app/fyle/dashboard/tasks/tasks-card/tasks-card.component.spec.ts (2 hunks)
  • src/app/shared/shared.module.ts (1 hunks)
🔇 Additional comments (3)
src/app/fyle/dashboard/tasks/tasks-card/tasks-card.component.scss (1)

11-11: 🧹 Nitpick (assertive)

Mind it! Font sizes might be too small for comfortable reading, macha!

Reducing all icon sizes to 20px uniformly might affect visibility. Consider maintaining slightly larger sizes for critical icons like warnings (24px).

Let me check the accessibility guidelines for you:

Also applies to: 18-18, 28-28, 35-35

src/app/core/services/tasks.service.spec.ts (2)

5-5: Mind it! The test setup is perfect, just like my style!

The ExactCurrencyPipe is properly imported and configured in the test environment with all the necessary spy objects and providers.

Also applies to: 84-84, 106-106, 125-128, 190-190


209-214: Kabali says these currency pipe changes are spot on!

The test cases have been systematically updated to use ExactCurrencyPipe with proper parameters and expectations. The changes maintain consistent test coverage across all scenarios.

Also applies to: 225-230, 260-265, 280-285, 302-307, 319-324, 343-348, 375-380, 950-959, 1021-1033

Comment on lines 42 to +46

&--cta-row {
padding-top: 17px;
padding-top: 11px;
max-width: fit-content;
display: flex;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Style! The CTA row needs some breathing space, boss!

The padding adjustments make the layout too tight. Consider:

  • Maintaining some minimal padding for touch targets
  • Ensuring proper spacing between icon and text
  &--cta-row {
    padding-top: 11px;
    max-width: fit-content;
    display: flex;
+   gap: 8px;

    &-icon {
      color: $black;
      font-size: 14px;
-     padding: 0;
+     padding: 0 4px;
    }
  }

Also applies to: 50-52

@@ -2,7 +2,7 @@
<div class="task--card">
<ion-grid>
<ion-row class="task--row" (click)="taskCtaClicked(task)" [ngClass]="{ 'pb-0': showReportAutoSubmissionInfo }">
<ion-col size="1" class="task--icon-col">
<ion-col size="0.75" class="task--icon-col">
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

The layout structure needs more power! Let me show you how!

The current structure with nested rows and columns could be simplified:

-<ion-col size="0.75" class="task--icon-col">
+<ion-col size="1" class="task--icon-col">
   <ion-row>
-    <ion-col class="task--icon-col">
     <ion-icon
       class="task--icon"
       [ngClass]="..."
       [src]="..."
     ></ion-icon>
-    </ion-col>
   </ion-row>
 </ion-col>

Also applies to: 22-28

{{ task.subheader }}
</ion-col>
</ion-row>
<ion-row class="ion-justify-content-between task--cta-row">
<ion-col size="11" *ngFor="let cta of task.ctas" class="task--cta">
<ion-row class="ion-justify-contant-start task--cta-row">
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ey! There's a typo in your class name that even my signature style can't fix!

ion-justify-contant-start should be ion-justify-content-start. This typo could break your layout, partner!

-<ion-row class="ion-justify-contant-start task--cta-row">
+<ion-row class="ion-justify-content-start task--cta-row">
📝 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
<ion-row class="ion-justify-contant-start task--cta-row">
<ion-row class="ion-justify-content-start task--cta-row">

Comment on lines +86 to +91
it('should display the correct header and amount for the first task', () => {
const taskHeader = getElementBySelector(fixture, '.task--header');
expect(getTextContent(taskHeader)).toContain('Complete');

const taskSubheader = getElementBySelector(fixture, '.task--subheader');
expect(getTextContent(taskSubheader)).toContain('13 expenses worth ₹142.26K can be added to a report');
const taskAmount = getElementBySelector(fixture, '.task--amount');
expect(getTextContent(taskAmount)).toContain('14200.26');
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Your tests are strong like me, but let's make them stronger!

Add more test cases to verify:

  1. Currency symbol display
  2. Different amount formats
  3. Hidden amount scenarios
it('should display currency symbol correctly', () => {
  component.currencySymbol$ = of('$');
  fixture.detectChanges();
  const amountElement = getElementBySelector(fixture, '.task--amount-currency');
  expect(getTextContent(amountElement)).toContain('$');
});

it('should handle hidden amounts correctly', () => {
  component.task.hideAmount = true;
  fixture.detectChanges();
  const amountElement = getElementBySelector(fixture, '.task--amount');
  expect(amountElement).toBeNull();
});

@@ -18,10 +18,10 @@ export const draftExpenseTaskSample = deepFreeze({
});

export const draftExpenseTaskSample2 = deepFreeze({
amount: '132.57B',
amount: '76234.47',
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Mind-blowing changes, but let's make the test data more realistic, macha!

The mock data has some concerns that need your attention:

  1. Some amounts are unrealistically large (e.g. ₹5,177,243,929.65)
  2. Decimal precision is inconsistent across different samples

Consider:

  1. Using more realistic amount ranges that match production scenarios
  2. Maintaining consistent decimal places (preferably 2) across all amounts
  3. Using round numbers where possible to improve readability of test data

Also applies to: 24-24, 49-49, 52-52, 63-63, 66-66, 77-77, 80-80, 105-105, 108-108, 119-119, 122-122, 133-133, 136-136

@@ -418,6 +418,6 @@ import { ExactCurrencyPipe } from './pipes/exact-currency.pipe';
DashboardOptInComponent,
MobileNumberCardComponent,
],
providers: [DecimalPipe, DatePipe, HumanizeCurrencyPipe, ImagePicker, FyCurrencyPipe, ReportState],
providers: [DecimalPipe, DatePipe, HumanizeCurrencyPipe, ImagePicker, FyCurrencyPipe, ReportState, ExactCurrencyPipe],
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Style-ah deprecate the old pipe, thalaiva!

Since we're moving to exact currency display, consider deprecating HumanizeCurrencyPipe to prevent confusion and maintain consistency.

  1. Add @Deprecated decorator to HumanizeCurrencyPipe
  2. Add documentation comment explaining the migration to ExactCurrencyPipe
  3. Plan for removal in future versions

@@ -43,6 +44,7 @@ export class TasksService {
constructor(
private reportService: ReportService,
private humanizeCurrency: HumanizeCurrencyPipe,
private exactCurrency: ExactCurrencyPipe,
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Punch dialogue: Let's add some documentation, boss!

The ExactCurrencyPipe injection lacks documentation about its purpose and configuration.

Add JSDoc comment explaining the pipe's usage:

/** 
 * ExactCurrencyPipe for precise currency formatting
 * Always used with skipSymbol: true as currency symbol is handled separately
 */
private exactCurrency: ExactCurrencyPipe,

Comment on lines +696 to +700
amount: this.exactCurrency.transform({
value: aggregate.total_amount,
currencyCode: homeCurrency,
skipSymbol: true,
}),
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Mind it! Let's reduce the code duplication, thalaiva!

The transform options object is repeated across multiple methods with the same configuration.

Create a private method to handle the currency transformation:

private transformCurrency(value: number, currencyCode: string): string {
  return this.exactCurrency.transform({
    value,
    currencyCode,
    skipSymbol: true
  });
}

Then use it across all methods:

-amount: this.exactCurrency.transform({
-  value: aggregate.totalAmount,
-  currencyCode: homeCurrency,
-  skipSymbol: true,
-}),
+amount: this.transformCurrency(aggregate.totalAmount, homeCurrency),

Also applies to: 734-738, 760-764, 789-793, 821-825, 852-856

@@ -684,14 +686,18 @@
}

getAmountString(amount: number, currency: string): string {
return amount > 0 ? ` worth ${this.humanizeCurrency.transform(amount, currency)} ` : '';
return amount > 0 ? ` worth ${this.exactCurrency.transform({ value: amount, currencyCode: currency })} ` : '';
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Superstar move on the getAmountString method!

The implementation is clean but differs from other transform calls by not using skipSymbol: true. This inconsistency could lead to formatting differences.

Add skipSymbol: true to match other transform calls:

-    return amount > 0 ? ` worth ${this.exactCurrency.transform({ value: amount, currencyCode: currency })} ` : '';
+    return amount > 0 ? ` worth ${this.exactCurrency.transform({ value: amount, currencyCode: currency, skipSymbol: true })} ` : '';
📝 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
return amount > 0 ? ` worth ${this.exactCurrency.transform({ value: amount, currencyCode: currency })} ` : '';
return amount > 0 ? ` worth ${this.exactCurrency.transform({ value: amount, currencyCode: currency, skipSymbol: true })} ` : '';

Comment on lines +663 to +666
exactCurrencyPipe.transform
.withArgs({ value: totalCount, currencyCode: homeCurrency, skipSymbol: true })
.and.returnValue('339.00');
exactCurrencyPipe.transform.withArgs({ value: totalCount, currencyCode: homeCurrency }).and.returnValue('₹339.00');
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Aiyyo! There's a small confusion in the test expectations, machan!

The test is using the wrong value for currency transformation. It's using totalCount instead of a proper amount value, which could lead to incorrect test results.

Apply this fix:

-    const totalCount = incompleteStats.data.count;
-    exactCurrencyPipe.transform
-      .withArgs({ value: totalCount, currencyCode: homeCurrency, skipSymbol: true })
-      .and.returnValue('339.00');
-    exactCurrencyPipe.transform.withArgs({ value: totalCount, currencyCode: homeCurrency }).and.returnValue('₹339.00');
+    const totalAmount = incompleteStats.data.total_amount;
+    exactCurrencyPipe.transform
+      .withArgs({ value: totalAmount, currencyCode: homeCurrency, skipSymbol: true })
+      .and.returnValue('339.00');
+    exactCurrencyPipe.transform.withArgs({ value: totalAmount, currencyCode: homeCurrency }).and.returnValue('₹339.00');

Committable suggestion skipped: line range outside the PR's diff.

@SahilK-027 SahilK-027 changed the base branch from master to Q4-DISPLAY-EXACT-AMOUNT December 19, 2024 09:21
@SahilK-027 SahilK-027 merged commit fee5b22 into Q4-DISPLAY-EXACT-AMOUNT Dec 19, 2024
14 checks passed
Copy link

Unit Test Coverage % values
Statements 95.98% ( 19312 / 20120 )
Branches 91.1% ( 10664 / 11705 )
Functions 94.25% ( 5744 / 6094 )
Lines 96.02% ( 18441 / 19205 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L Large PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants