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

[UI library] Add toast element #21407

Merged
merged 24 commits into from
May 30, 2024
Merged

Conversation

pls78
Copy link
Member

@pls78 pls78 commented May 24, 2024

Context

  • We want to add a generic Toast element to the UI Library in order to render customizable notifications.

Summary

This PR can be summarized in the following changelog entry:

  • [@yoast/ui-library 0.0.1] Adds a Toast element.

Relevant technical choices:

  • The Notification component has been refactored to use the new Toast element.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

Test the Settings notification
  • Go to Yoast SEO -> Settings

    • change any setting and hit Save changes
    • verify the following notification appears
    Screenshot 2024-05-24 at 12 30 01
    • wait until it closes automatically
    • change another setting, and when the notification appears click on the close button
      • verify the notification closes immediately
  • Go to Yoast SEO -> Settings -> Site connections

    • in the Google input field type &&&& and click on Save changes

    • verify:

      • the following notification appears
      Screenshot 2024-05-24 at 12 32 23
      • the notification stays open until you close it
Test the AI Generator notification
  • With a MySQL client open the wp_usermeta table and search for the tuple where user_id = your user id and meta_key = _yoast_alerts_dismissed

  • if the following string is present in the meta_value field:s:26:"wpseo_premium_ai_generator";b:1;, remove it and update the array length accordingly (or remove the whole meta_value content if you don't care about the notifications you previously dismissed)

  • Activate Yoast SEO Premium

  • Edit a post in the block editor

    • make sure
      • it has little to no content
      • it has a keyphrase
    • Click on Use AI and verify the following notification appears
    Screenshot 2024-05-24 at 12 53 53
    • verify that either clicking on the close or Dismiss button closes the notification
    • click on Use AI again
      • verify the notification is shown again
Test the UI-Library storybook
  • In the terminal got to the wordpress-seo/packages/ui-library directory
    • type yarn storybook: after some time the StoryBook page should appear in your browser
    • go to the Toaster sub-section in the Elements section and verify
      • all the stories ( the Toaster factory, with title, with description and with close button ) render properly
      • you can correctly interact with the toaster

Relevant test scenarios

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Default Block/Gutenberg/Classic/Elementor/other)
  • Changes should be tested on different browsers
  • Changes should be tested on multisite

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

Impact check

This PR affects the following parts of the plugin, which may require extra testing:

  • The above testing instructions cover the possible regressions.

UI changes

  • This PR changes the UI in the plugin. I have added the 'UI change' label to this PR.

Other environments

  • This PR also affects Shopify. I have added a changelog entry starting with [shopify-seo], added test instructions for Shopify and attached the Shopify label to this PR.

Documentation

  • I have written documentation for this change. For example, comments in the Relevant technical choices, comments in the code, documentation on Confluence / shared Google Drive / Yoast developer portal, or other.

Quality assurance

  • I have tested this code to the best of my abilities.
  • During testing, I had activated all plugins that Yoast SEO provides integrations for.
  • I have added unit tests to verify the code works as intended.
  • If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
  • I have written this PR in accordance with my team's definition of done.
  • I have checked that the base branch is correctly set.

Innovation

  • No innovation project is applicable for this PR.
  • This PR falls under an innovation project. I have attached the innovation label.
  • I have added my hours to the WBSO document.

Fixes #21396

@pls78 pls78 added the changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog label May 24, 2024
@pls78 pls78 added this to the 22.9 milestone May 24, 2024
@coveralls
Copy link

coveralls commented May 24, 2024

Pull Request Test Coverage Report for Build fbadf8a8c26ec0a7ccf4470c8e292df90e9afc0a

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 3706 unchanged lines in 106 files lost coverage.
  • Overall coverage decreased (-4.3%) to 48.3%

Files with Coverage Reduction New Missed Lines %
admin/class-option-tabs-formatter.php 1 0.0%
src/actions/configuration/first-time-configuration-action.php 1 91.84%
src/builders/indexable-home-page-builder.php 1 98.0%
src/builders/indexable-term-builder.php 1 99.15%
src/context/meta-tags-context.php 1 28.29%
src/generators/breadcrumbs-generator.php 1 64.23%
src/generators/schema/webpage.php 1 90.32%
src/integrations/blocks/structured-data-blocks.php 1 16.0%
src/integrations/settings-integration.php 1 28.49%
src/integrations/watchers/indexable-ancestor-watcher.php 1 98.41%
Totals Coverage Status
Change from base Build 9092209d55aa5a8e5ebf33e771925ce9dfb32d9e: -4.3%
Covered Lines: 24971
Relevant Lines: 53563

💛 - Coveralls

@pls78 pls78 marked this pull request as ready for review May 24, 2024 11:37
@pls78 pls78 requested a review from a team as a code owner May 24, 2024 11:37
Copy link
Contributor

@mhkuu mhkuu left a comment

Choose a reason for hiding this comment

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

CR: Approved, just one quirk I don't fully understand 😅 See my comment above.

In my commit above I fixed one issue where the 'Close' story did not have right docs. I also updated some strings and fixed some JSDoc 🙌

packages/ui-library/src/elements/toaster/index.js Outdated Show resolved Hide resolved
@enricobattocchi enricobattocchi removed this from the 22.9 milestone May 28, 2024
@Jordi-PV Jordi-PV self-requested a review May 28, 2024 11:13
@mhkuu mhkuu changed the base branch from trunk to release/22.9 May 28, 2024 11:18
@layer components {
.yst-root {

.yst-toast {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big deal, but I would consider placing every CSS rule in a different line for readability. E.g.

.yst-toast {
        @apply
		yst-w-80
		yst-max-w-full
		yst-overflow-y-auto
		yst-p-4
		yst-bg-white
		yst-shadow-lg y
		st-rounded-lg
		yst-ring-1
		yst-ring-black
		yst-ring-opacity-5
		yst-z-20
		yst-pointer-events-auto;
    }

    `.yst-toast--large {
        @apply
              yst-w-96;
    }`

I am also looking at the stylesheets of other elements/components in the UI library, where we also do it this way.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that the general approach is to keep the @apply on the same line as the Tailwind classes when they are a few (like 2 or 3), so I'm updating just the .yst-toast one 🙂

@@ -0,0 +1 @@
The `Toast.Close` subcomponent allows to render a button that closes the toast. It is useful when you want to give the user the ability to close the toast manually.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I would refactor this doc as follow:

The Toast.Close subcomponent renders a Toast with a button to close the toast. This feature is useful when you want to provide the user with the option to manually close the toast notification.

Copy link
Member Author

Choose a reason for hiding this comment

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

Technically the Toast.Close it is a subcomponent of the Toast element, so it renders just the close button. I'd rephrase it as:
The Toast.Close subcomponent renders a button to close the toast. This feature is useful when you want to provide the user with the option to manually close the toast notification.

@@ -0,0 +1 @@
The Toast component is a general-purpose toast element which can be used to implement custom notifications.
Copy link
Contributor

Choose a reason for hiding this comment

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

Here I would describe it as:

The Toast component is a versatile toast element that can be used to implement custom notifications.

Copy link
Member Author

Choose a reason for hiding this comment

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

Counter-proposal 😁 What about:
The Toast element is a versatile toast component that can be used to implement custom notifications.
In the original description I forgot to change component to element, as the Toast is now an element

@@ -0,0 +1 @@
`Toast.Description` can be used to add a description to the toast's content. It can be a list of strings.
Copy link
Contributor

Choose a reason for hiding this comment

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

And in this doc maybe also mention the paragraph option;

The Toast.Description subcomponent allows you to add detailed content to the toast, either as a paragraph or a list of strings.

@pls78 pls78 changed the title [UI library] Add toaster element [UI library] Add toast element May 28, 2024
@Jordi-PV
Copy link
Contributor

Screen.Recording.2024-05-28.at.14.59.16.mov

Nothing relevant for the AI assessment fixes project, but I was testing the Toast subcomponents Toast.Title and Toast.Description in the Storybook, and I noticed that in the Toast.Title when adding the 'children' it changes the content paragraph instead of title, and in the Toast.Description the

    list also changes to a paragraph instead of the array list of elements. 🤔

@pls78
Copy link
Member Author

pls78 commented May 29, 2024

Screen.Recording.2024-05-28.at.14.59.16.mov

Nothing relevant for the AI assessment fixes project, but I was testing the Toast subcomponents Toast.Title and Toast.Description in the Storybook, and I noticed that in the Toast.Title when adding the 'children' it changes the content paragraph instead of title, and in the Toast.Description the

list also changes to a paragraph instead of the array list of elements. 🤔

Yeah, I should have disabled the children control for both Title and Description as they don't make any sense: the user controls what's in there through the title and description props respectively. I have now disabled all the controls for the subcomponents as I didn't find a way to hide just the children one.

@pls78 pls78 merged commit e9c5c12 into release/22.9 May 30, 2024
15 of 16 checks passed
@pls78 pls78 deleted the ui-library-add-toaster-element branch May 30, 2024 09:33
@pls78 pls78 added this to the 22.9 milestone May 30, 2024
@mhkuu mhkuu added changelog: enhancement Needs to be included in the 'Enhancements' category in the changelog and removed changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog labels Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: enhancement Needs to be included in the 'Enhancements' category in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[UI-Library] Refactoring Notification component to use the new Toaster element
6 participants