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: allow multiple lines in alert component #36126

Conversation

saiprabhu-dandanayak
Copy link
Contributor

@saiprabhu-dandanayak saiprabhu-dandanayak commented Sep 5, 2024

Description

Fixes : #30851

I have raised this pr in-order to allow multiple lines in alert message

Screenshots

passing \n in the message

Screenshot from 2024-09-05 13-51-43

unable to parse \n

Screenshot from 2024-09-05 13-50-06

After issue is resolved

Screenshot from 2024-09-05 13-55-01

Cypress Testing video

Button_showAlert_multiline_message_spec.ts.mp4

Summary by CodeRabbit

  • New Features

    • Introduced a new styled component StyledPre for enhanced formatting in toast notifications.
    • Enhanced the Toast component to better render content, improving readability by preserving whitespace and formatting.
    • Added automated tests for the button widget's alert functionality, ensuring correct display of messages with newline characters.
  • Bug Fixes

    • Improved the display of alert messages in toast notifications, ensuring they respect original formatting.

Copy link
Contributor

coderabbitai bot commented Sep 5, 2024

Walkthrough

The changes introduce a new styled component, StyledPre, to the Toast component for improved text formatting. The rendering of content in the Toast component is updated to utilize this new styled component, enhancing the display of formatted text. Additionally, a new Cypress test file is added to validate the functionality of a button widget that triggers alerts with multiline messages, ensuring proper handling of newline characters.

Changes

Files Change Summary
.../Toast/Toast.styles.tsx
.../Toast/Toast.tsx
Adds a new styled component StyledPre and updates the Toast component to render content using StyledPre.
.../Button/Button_showAlert_multiline_message_spec.ts Introduces automated tests for the showAlert function in a button widget, focusing on newline handling in alert messages.

Poem

In the realm of code, changes arise,
With buttons that alert and toast that complies.
New tests are born, with care they are spun,
Formatting preserved, making readability fun!
So here's to the updates, both clever and bright,
Enhancing our tools, bringing joy to our sight! 🎉


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.

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.

@saiprabhu-dandanayak saiprabhu-dandanayak changed the title ✨ feat: allow multiple lines in alert component feat: allow multiple lines in alert component Sep 5, 2024
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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 65eb854 and 22a53c4.

Files selected for processing (2)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/Button/Button_showAlert_multiline_message_spec..ts (1 hunks)
  • app/client/packages/design-system/ads/src/Toast/Toast.tsx (1 hunks)
Additional context used
Path-based instructions (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Button/Button_showAlert_multiline_message_spec..ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
Additional comments not posted (2)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Button/Button_showAlert_multiline_message_spec..ts (1)

1-6: Review of imports and object structure.

The imports are structured well, and it's good to see that you're using a centralized object repository for your test elements, which is a best practice in maintaining scalable and maintainable test code. Keep up the good work!

app/client/packages/design-system/ads/src/Toast/Toast.tsx (1)

42-42: Excellent use of <pre> for preserving message formatting.

The addition of the <pre> tag with font: 'inherit' is a clever choice, ensuring that multiline content is displayed correctly while maintaining the inherited font styles. This change effectively addresses the issue of displaying multiline alerts by preserving the formatting and spacing of the content, which is crucial for readability, especially when displaying code snippets or detailed error messages.

Comment on lines 8 to 24
describe(
"Tests for showAlert message with newline characters in the alert message",
{ tags: ["@tag.Widget", "@tag.Button"] },
() => {
before("Login to the app and navigate to the workspace", function () {
entityExplorer.DragDropWidgetNVerify(draggableWidgets.BUTTON);
});

it("Verify showAlert message renders correctly with newline characters", () => {
propPane.EnterJSContext("onClick", "showAlert(`sai\n\nprabhu`)");
agHelper.ClickButton("Submit");
cy.wait(500);
cy.get('.Toastify', { timeout: 1000 })
.should('have.text', 'sai\n\nprabhu');
});
},
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Review of test structure and logic.

The structure of your test suite is clear and well-organized. The use of tags to categorize the tests is a good practice as it aids in selective test execution and reporting. However, I have a few points to address:

  1. Avoid using cy.wait(): Using cy.wait(500) at line 19 is generally discouraged as it introduces potential flakiness and makes the tests slower. Instead, consider using Cypress's built-in wait mechanisms that wait for specific conditions.
  2. Selector Best Practices: At line 20, you're using a class selector .Toastify. It's recommended to use data attributes for selectors to make the tests more robust against changes in styling or structure.
  3. Assertion Improvement: The assertion at line 21 checks for exact text, which is good. However, consider enhancing this to check for the presence of newline characters explicitly if that's critical to the test's intent.

Here are some suggestions to improve your test:

  • Replace cy.wait(500) with a more deterministic wait condition.
  • Use a data attribute for the .Toastify selector.
  • Ensure the assertion explicitly checks for the presence and correct rendering of newline characters.
- cy.wait(500);
+ cy.get('.Toastify', { timeout: 1000 }).should('be.visible');

- cy.get('.Toastify', { timeout: 1000 })
+ cy.get('[data-cy="toast-message"]', { timeout: 1000 })

- .should('have.text', 'sai\n\nprabhu');
+ .should('include.text', 'sai')
+ .and('include.text', 'prabhu');

Committable suggestion was skipped due to low confidence.

@saiprabhu-dandanayak
Copy link
Contributor Author

@appsmithorg/query-js-pod , Please review this pr if you have enough bandwidth.
Thanks in advance.

@rishabhrathod01
Copy link
Contributor

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Sep 5, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10716935421.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36126.
recreate: .

@rishabhrathod01
Copy link
Contributor

@saiprabhu-dandanayak Could you please fix the lint and prettier checks that are failing for the PR?

Copy link

github-actions bot commented Sep 5, 2024

Deploy-Preview-URL: https://ce-36126.dp.appsmith.com

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 22a53c4 and fc26810.

Files selected for processing (2)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/Button/Button_showAlert_multiline_message_spec..ts (1 hunks)
  • app/client/packages/design-system/ads/src/Toast/Toast.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/Button/Button_showAlert_multiline_message_spec..ts
  • app/client/packages/design-system/ads/src/Toast/Toast.tsx

@saiprabhu-dandanayak
Copy link
Contributor Author

saiprabhu-dandanayak commented Sep 6, 2024

Hi @rishabhrathod01 , fixed the lint and prettier checks , could you pls check ??

@saiprabhu-dandanayak
Copy link
Contributor Author

Hi @rishabhrathod01 , if you have enough bandwidth , can you pls review this pr , i would be happy to work on comments if any.
Thanks in advance.

@NilanshBansal NilanshBansal added Query & JS Pod Issues related to the query & JS Pod Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. Community Contributor Meant to track issues that are assigned to external contributors Integrations Pod labels Sep 19, 2024
@NilanshBansal
Copy link
Contributor

@carinanfonseca can you please check the design changes here

@carinanfonseca
Copy link
Contributor

carinanfonseca commented Sep 20, 2024

hello @saiprabhu-dandanayak
thank you for your contribution.

It makes sense to recognize the \n when we are in JS mode, but in non-JS mode, a user shouldn't be expected to use \n to create a new line. In that mode, pressing 'Enter' in the text area itself should work, like this:
Screenshot 2024-09-20 at 14 57 56

Additionally, the spacing between the first and second lines doesn't look correct. It should follow the regular spacing, like this:
Screenshot 2024-09-20 at 15 21 02

let me know if this is possible. I am happy to answer any questions.

@saiprabhu-dandanayak
Copy link
Contributor Author

Hi @carinanfonseca , the screenshot i have added in PR description have double \n , so the spacing is more and even in non-JS mode if we provide Enter it will work as expected , In non-JS mode even if we provide \n it is being resolved automatically.
Please let me know this is expected behaviour or not.

@rishabhrathod01
Copy link
Contributor

@saiprabhu-dandanayak could you fix the storybook checks that are failing for the PR?

@saiprabhu-dandanayak
Copy link
Contributor Author

Hi @rishabhrathod01 , The error is showing it lacks Project token and i am not sure how to fix this.
Any suggestions would be helpfull.
Thank You.

@rishabhrathod01
Copy link
Contributor

@saiprabhu-dandanayak you could ignore the storybook failure for now. The Appsmith team will forward the designs for the Toast UI to be implemented here.

cc: @carinanfonseca

@rishabhrathod01
Copy link
Contributor

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11011491433.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36126.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-36126.dp.appsmith.com

@rishabhrathod01
Copy link
Contributor

@saiprabhu-dandanayak could merge the latest release branch to the PR? Will need trigger the workflow again.

Copy link
Contributor

@rishabhrathod01 rishabhrathod01 left a comment

Choose a reason for hiding this comment

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

Code changes look good. Will need to create duplicate PRs for the cypress test run.

@saiprabhu-dandanayak
Copy link
Contributor Author

Hi @rishabhrathod01 , took recent pull from release branch and updated the source branch , pls check.
Thank you.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fc26810 and dff3b4c.

Files selected for processing (1)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/Button/Button_showAlert_multiline_message_spec.ts (1 hunks)
Additional context used
Path-based instructions (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Button/Button_showAlert_multiline_message_spec.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
Additional comments not posted (3)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Button/Button_showAlert_multiline_message_spec.ts (3)

1-6: Good job with the imports, class!

You've correctly imported the necessary helper functions from ObjectsCore. This shows good organization and adherence to best practices in our Cypress tests.


8-14: Excellent work on setting up the test suite, students!

Your describe block is well-structured with an appropriate description and tags. The before hook efficiently sets up the test environment by dragging and dropping a button widget. Keep up the good work!


1-26: Overall assessment of your work, class:

You've done a commendable job creating this test file! It's focused, well-structured, and effectively tests the multiline alert functionality. Here's a summary of your performance:

  1. Excellent use of helper functions and proper test setup.
  2. Good adherence to most Cypress best practices.
  3. Clear and descriptive test case.

To further improve:

  1. Implement the suggestions from the previous comment to align fully with our coding guidelines.
  2. Consider adding more assertions to thoroughly validate the alert's appearance and behavior.

Keep up the great work, and remember: practice makes perfect in the world of testing!

@rishabhrathod01 rishabhrathod01 self-assigned this Sep 24, 2024
@rishabhrathod01
Copy link
Contributor

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 (2)
app/client/packages/design-system/ads/src/Toast/Toast.tsx (2)

43-43: Excellent work on implementing the styled component!

You've successfully wrapped the content in a StyledPre component. This is a great improvement that will allow for better formatting of multi-line messages. However, let's make one small adjustment to improve readability:

Consider removing the extra space inside the StyledPre component:

-        <StyledPre> {content}</StyledPre>
+        <StyledPre>{content}</StyledPre>

This will ensure that there's no unintended leading space in your formatted content.


43-43: Let's add a helpful note for future reference!

Class, while our StyledPre component will likely preserve newline characters, it would be beneficial to add a comment explaining this behavior. This will help other developers understand the purpose of this change.

Consider adding a comment above the StyledPre component:

+        {/* StyledPre preserves newline characters (\n) in the content */}
         <StyledPre>{content}</StyledPre>

This small addition will make your code more informative and easier to maintain in the future. Remember, clear documentation is key to good coding practices!

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 79e48f0 and 2ffb3bd.

📒 Files selected for processing (2)
  • app/client/packages/design-system/ads/src/Toast/Toast.styles.tsx (1 hunks)
  • app/client/packages/design-system/ads/src/Toast/Toast.tsx (2 hunks)
🔇 Additional comments not posted (2)
app/client/packages/design-system/ads/src/Toast/Toast.tsx (1)

7-7: Very good, class! Let's examine the import statement.

I see you've added StyledButton and StyledPre to your imports. This is a step in the right direction for using styled components in your Toast. Well done!

app/client/packages/design-system/ads/src/Toast/Toast.styles.tsx (1)

67-69: Class, let's examine this new addition to our code!

Excellent work on introducing the StyledPre component! This new styled <pre> element will be instrumental in displaying multiline text in our alert messages. By using font: inherit;, we ensure that the text maintains visual consistency with its surroundings.

Remember, children, in web development, <pre> stands for "preformatted text." It's like a special notebook that keeps all the spaces and line breaks exactly as we write them. This will be perfect for our multiline alert messages!

@rishabhrathod01
Copy link
Contributor

rishabhrathod01 commented Sep 30, 2024

Test has passed for the shadow PR - #36514

This PR is safe to merge once the EE counterpart passes all the tests

Copy link
Contributor

@rishabhrathod01 rishabhrathod01 left a comment

Choose a reason for hiding this comment

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

Changes look good to me.

Both CE and EE shadow PR ci-test run has passed.
CE - #36514
EE - https://github.com/appsmithorg/appsmith-ee/pull/5218

Contributor made linting and prettier changes after that and the lint check has passed for the same.

This PR is ready to be merged.

@nerbos nerbos merged commit a6c109b into appsmithorg:release Sep 30, 2024
17 of 20 checks passed
albinAppsmith added a commit that referenced this pull request Oct 1, 2024
## Description

There was an extra space infront of toast content which cause cypress
failures. This PR address that issue.

PR cause this issue: #36126

Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11121364189>
> Commit: a114bff
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11121364189&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Tue, 01 Oct 2024 09:28:44 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Chores**
	- Minor formatting adjustments made to the Toast component.
- Added a TODO comment regarding future accessibility features for
toasts.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
albinAppsmith added a commit that referenced this pull request Oct 2, 2024
@albinAppsmith
Copy link
Collaborator

@saiprabhu-dandanayak We are reverting this PR since it is causing below issues.

  1. There was a white space in front of the content which was fixed by fix: Release blocker: toast with whitespace #36629
  2. Content is not getting wrapped. [Bug]: All the toast error seems to be broken #36642
  3. While running this change in storybook, the toast is expanded in height.
    Screenshot 2024-10-02 at 10 49 09

albinAppsmith added a commit that referenced this pull request Oct 2, 2024
Reverts #36629
Reverts #36126

Reverting this PR since it is causing multiple issues in toast and we
are reverting the original PR caused this issue.

## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11138591480>
> Commit: 598a1d3
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11138591480&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Wed, 02 Oct 2024 07:27:39 UTC
<!-- end of auto-generated comment: Cypress test results  -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a new styled button component for enhanced toast
notifications.
- Updated toast styling with customizable properties for better visual
presentation.
- **Bug Fixes**
- Simplified toast body structure by removing unnecessary components,
ensuring content displays correctly.
- **Chores**
- Removed outdated end-to-end test file for button widget alert
functionality.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contributor Meant to track issues that are assigned to external contributors Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. Integrations Pod Query & JS Pod Issues related to the query & JS Pod
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Allow multiple lines in showAlert message
6 participants