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: add more decimal places to CurrencyInput #33686

Conversation

AnnaHariprasad5123
Copy link
Contributor

@AnnaHariprasad5123 AnnaHariprasad5123 commented May 23, 2024

Hi CWatson,

What's in this PR?

  • Added extra decimal labels to the CurrencyInput in both the JsonForm and CurrencyInput Widgets.
  • Added logic related to additional decimal places.

Fixes #33361

Thank you.

/ok-to-test tags="@tag.CurrencyInput"

Copy link
Contributor

coderabbitai bot commented May 23, 2024

Walkthrough

Walkthrough

The changes introduce enhanced functionality to the CurrencyInputWidget by allowing users to specify up to 6 decimal places. This includes renaming the formatCurrencyNumber function to limitDecimalValue, updating test cases, and expanding the options available in the CurrencyInputWidget and JSONFormWidget to support additional decimal precision.

Changes

File Path Change Summary
app/client/src/widgets/CurrencyInputWidget/component/utilities.test.ts Renamed test case from formatCurrencyNumber to limitDecimalValue and updated test cases to cover various precision levels (3 to 6 decimal places).
app/client/src/widgets/CurrencyInputWidget/component/utilities.ts Renamed formatCurrencyNumber to limitDecimalValue and updated it to handle additional decimal precision cases (3 to 6 decimal places).
app/client/src/widgets/CurrencyInputWidget/widget/index.tsx Added options with labels and values from 3 to 6 in the list for decimal precision.
app/client/src/widgets/JSONFormWidget/widget/propertyConfig/properties/input.ts Expanded PROPERTIES object to include additional options with labels and values ranging from 3 to 6 for decimal precision.

Sequence Diagram(s) (Beta)

No sequence diagrams are generated as the changes are primarily functional enhancements without significant modifications to control flow.

Assessment against linked issues

Objective Addressed Explanation
Allow selection of 3 to 6 decimal places in CurrencyInputWidget (Issue #33361)
Update test cases to reflect new decimal precision options (Issue #33361)
Ensure JSONFormWidget supports additional decimal precision (Issue #33361)

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 19bcbbd and 28d44fa.
Files selected for processing (4)
  • app/client/src/widgets/CurrencyInputWidget/component/utilities.test.ts (2 hunks)
  • app/client/src/widgets/CurrencyInputWidget/component/utilities.ts (1 hunks)
  • app/client/src/widgets/CurrencyInputWidget/widget/index.tsx (2 hunks)
  • app/client/src/widgets/JSONFormWidget/widget/propertyConfig/properties/input.ts (1 hunks)
Additional Context Used
Biome (50)
app/client/src/widgets/CurrencyInputWidget/component/utilities.test.ts (7)

27-34: Prefer for...of instead of forEach.


36-36: Unexpected any. Specify a different type.


36-44: Prefer for...of instead of forEach.


47-87: Prefer for...of instead of forEach.


89-117: Prefer for...of instead of forEach.


137-147: Prefer for...of instead of forEach.


149-159: Prefer for...of instead of forEach.

app/client/src/widgets/CurrencyInputWidget/component/utilities.ts (8)

24-24: This default parameter should follow the last required parameter or should be a required parameter.


56-56: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.


63-65: This else clause can be omitted because previous branches break early.


77-77: Template literals are preferred over string concatenation.


78-78: Template literals are preferred over string concatenation.


35-35: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.


46-46: Reassigning a function parameter is confusing.


75-75: Use Number.parseFloat instead of the equivalent global.

app/client/src/widgets/CurrencyInputWidget/widget/index.tsx (15)

52-52: Unexpected any. Specify a different type.


54-54: Unexpected any. Specify a different type.


93-93: Unexpected any. Specify a different type.


94-94: Declare variables separately


94-94: This variable implicitly has the any type.


309-309: Do not use template literals if interpolation and special-character handling are not needed.


411-411: Using super in a static context can be confusing.


416-416: Using super in a static context can be confusing.


426-426: Unexpected any. Specify a different type.


427-427: Using super in a static context can be confusing.


434-434: Using super in a static context can be confusing.


502-502: Change to an optional chain.


536-536: Template literals are preferred over string concatenation.


1-1: All these imports are only used as types.


483-483: Use Number.parseFloat instead of the equivalent global.

app/client/src/widgets/JSONFormWidget/widget/propertyConfig/properties/input.ts (20)

14-14: Unexpected any. Specify a different type.


16-16: Unexpected any. Specify a different type.


17-17: Unexpected any. Specify a different type.


110-110: Unexpected any. Specify a different type.


112-112: Unexpected any. Specify a different type.


113-113: Unexpected any. Specify a different type.


129-157: This else clause can be omitted because previous branches break early.


140-157: This else clause can be omitted because previous branches break early.


151-157: This else clause can be omitted because previous branches break early.


161-161: Unexpected any. Specify a different type.


163-163: Unexpected any. Specify a different type.


164-164: Unexpected any. Specify a different type.


180-208: This else clause can be omitted because previous branches break early.


191-208: This else clause can be omitted because previous branches break early.


202-208: This else clause can be omitted because previous branches break early.


229-229: Do not use template literals if interpolation and special-character handling are not needed.


254-254: Do not use template literals if interpolation and special-character handling are not needed.


430-430: Do not use template literals if interpolation and special-character handling are not needed.


453-453: Do not use template literals if interpolation and special-character handling are not needed.


121-121: Reassigning a function parameter is confusing.

Additional comments not posted (3)
app/client/src/widgets/CurrencyInputWidget/component/utilities.test.ts (1)

100-111: Ensure the new test cases for limitDecimalValue correctly handle 3 to 6 decimal places.

app/client/src/widgets/JSONFormWidget/widget/propertyConfig/properties/input.ts (1)

344-359: The addition of decimal options from 3 to 6 in the decimalsInCurrency property aligns with the PR objectives.

app/client/src/widgets/CurrencyInputWidget/widget/index.tsx (1)

361-376: The addition of decimal options from 3 to 6 in the decimals property aligns with the PR objectives and enhances the widget's functionality.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 full the 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@AnnaHariprasad5123
Copy link
Contributor Author

Merge request for #33361

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 (3)
app/client/src/widgets/CurrencyInputWidget/component/utilities.ts (1)

52-65: The extension to handle up to 6 decimal places in limitDecimalValue is implemented correctly.

Consider adding a comment explaining why these specific cases (3 to 6) were added, as it might help future maintainers understand the context better.

app/client/src/widgets/CurrencyInputWidget/component/utilities.test.ts (1)

44-71: The test cases for limitDecimalValue covering decimal places from 3 to 6 are comprehensive and correctly validate the functionality.

Consider adding a comment explaining the choice of test values, especially for edge cases, to aid future maintainers.

app/client/src/widgets/JSONFormWidget/widget/propertyConfig/properties/input.ts (1)

344-359: The addition of decimal place options from 3 to 6 in the PROPERTIES object is implemented correctly and aligns with the PR's objectives.

Consider adding a comment explaining the rationale behind these specific decimal options to help future maintainers understand the choice.

jsartisan
jsartisan previously approved these changes May 24, 2024
].forEach((d) => {
expect(formatCurrencyNumber(d[0] as number, d[1] as string)).toBe(d[2]);
expect(limitDecimalValue(d[0] as number, d[1] as string)).toBe(d[2]);
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems wrong. You edited the wrong it block.

Copy link
Contributor

Choose a reason for hiding this comment

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

@AnnaHariprasad5123 You need to update the it block for limitDecimalValue instead of overriding the it block for formatCurrencyNumber

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My mistake, I will correct it.

@jsartisan jsartisan dismissed their stale review May 24, 2024 12:10

instead of commenting, I accidentally clicked on approve button.

@jsartisan
Copy link
Contributor

@AnnaHariprasad5123 can you check my comments?

@AnnaHariprasad5123 AnnaHariprasad5123 force-pushed the Issue-#33361/Feat-Additional-decimal branch from 6fa07a2 to 19bcbbd Compare May 24, 2024 12:43
@AnnaHariprasad5123
Copy link
Contributor Author

Hi @jsartisan Could you check this once.

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

Outside diff range and nitpick comments (1)
app/client/src/widgets/CurrencyInputWidget/component/utilities.ts (1)

Line range hint 75-75: Replace parseFloat with Number.parseFloat for consistency and clarity.

- return parseFloat(
+ return Number.parseFloat(

jsartisan
jsartisan previously approved these changes May 27, 2024
@AnnaHariprasad5123
Copy link
Contributor Author

Hi @jsartisan Good morning, Please merge my pull request at your earliest convenience.

@jsartisan jsartisan dismissed their stale review May 28, 2024 08:14

Has a missing thing.

@jsartisan
Copy link
Contributor

@AnnaHariprasad5123 I just ran the PR on my local. Found a tiny problem. Validation need sot be updated.
CleanShot 2024-05-28 at 13 42 46@2x

@AnnaHariprasad5123 AnnaHariprasad5123 force-pushed the Issue-#33361/Feat-Additional-decimal branch from 19bcbbd to 28d44fa Compare May 28, 2024 11:49
@AnnaHariprasad5123
Copy link
Contributor Author

Sorry about that, Could you check again @jsartisan

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

Comment on lines +63 to +65
} else {
return decimalValueArray[0];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This else clause can be omitted because previous branches break early.

if (decimalValueArray.length > 1) {
  return (
    decimalValueArray[0] +
    decimalSeperator +
    decimalValueArray[1].slice(0, decimals)
  );
}
- else {
-   return decimalValueArray[0];
- }

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.

Suggested change
} else {
return decimalValueArray[0];
}
if (decimalValueArray.length > 1) {
return (
decimalValueArray[0] +
decimalSeperator +
decimalValueArray[1].slice(0, decimals)
);
}
return decimalValueArray[0];

Comment on lines +52 to +65
case 3:
case 4:
case 5:
case 6:
const decimalValueArray = value.split(decimalSeperator);
return (
decimalValueArray[0] +
decimalSeperator +
decimalValueArray[1].slice(0, decimals)
);
if (decimalValueArray.length > 1) {
return (
decimalValueArray[0] +
decimalSeperator +
decimalValueArray[1].slice(0, decimals)
);
} else {
return decimalValueArray[0];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor the limitDecimalValue function to improve scope handling and control flow.

case 6:
  {
    const decimalValueArray = value.split(decimalSeperator);
    if (decimalValueArray.length > 1) {
      return (
        decimalValueArray[0] +
        decimalSeperator +
        decimalValueArray[1].slice(0, decimals)
      );
    }
    return decimalValueArray[0];
  }

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.

Suggested change
case 3:
case 4:
case 5:
case 6:
const decimalValueArray = value.split(decimalSeperator);
return (
decimalValueArray[0] +
decimalSeperator +
decimalValueArray[1].slice(0, decimals)
);
if (decimalValueArray.length > 1) {
return (
decimalValueArray[0] +
decimalSeperator +
decimalValueArray[1].slice(0, decimals)
);
} else {
return decimalValueArray[0];
}
case 3:
case 4:
case 5:
case 6:
{
const decimalValueArray = value.split(decimalSeperator);
if (decimalValueArray.length > 1) {
return (
decimalValueArray[0] +
decimalSeperator +
decimalValueArray[1].slice(0, decimals)
);
}
return decimalValueArray[0];
}

case 3:
case 4:
case 5:
case 6:
const decimalValueArray = value.split(decimalSeperator);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrap the decimalValueArray declaration in a block to restrict its access to the switch clause.

case 6:
  {
+   {
      const decimalValueArray = value.split(decimalSeperator);
      if (decimalValueArray.length > 1) {
        return (
          decimalValueArray[0] +
          decimalSeperator +
          decimalValueArray[1].slice(0, decimals)
        );
      }
      return decimalValueArray[0];
+   }
  }

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.

Suggested change
const decimalValueArray = value.split(decimalSeperator);
case 6:
{
{
const decimalValueArray = value.split(decimalSeperator);
if (decimalValueArray.length > 1) {
return (
decimalValueArray[0] +
decimalSeperator +
decimalValueArray[1].slice(0, decimals)
);
}
return decimalValueArray[0];
}
}

@jsartisan jsartisan added the ok-to-test Required label for CI label May 29, 2024
@KelvinOm KelvinOm added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels May 29, 2024
@KelvinOm KelvinOm merged commit a94019e into appsmithorg:release May 30, 2024
21 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Additional decimal
3 participants