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

[web] Agama core/Section improvements #816

Merged
merged 17 commits into from
Oct 31, 2023
Merged

[web] Agama core/Section improvements #816

merged 17 commits into from
Oct 31, 2023

Conversation

dgdavid
Copy link
Contributor

@dgdavid dgdavid commented Oct 25, 2023

Problem

We've identified a use case where a section without title makes a lot of sense. The introductory sections at the top of the page, which is the case of current Software page at the time of writing.

And probably more use cases will arise.

Solution

To add support for sections without title and take the opportunity for improving the component a little bit and start adding support for a11n.

Additionally, the layout/Icon component has been improved a bit too, for outputting errors to the console instead of the UI and for including the icon name as data attribute of the rendered SVG for easily identify it.

Side effects

As part of this PR jsdom dependency has been updated by using the overrides package.json key because of the use of crypto.randomUUID and a few tests using mocks for windown.location has to be rewritten since it's no longer possible to mock it anymore. See https://github.com/jsdom/jsdom/blob/master/Changelog.md#2100 and jsdom/jsdom#3492 to know more.

In any case, jest-environtment-jsdom is about to update it in the next version, jestjs/jest#13825 (comment). So, we're prepared already.

Testing

  • Adapted unit tests, adding new examples when needed.
  • Tested manually too.

@coveralls
Copy link

coveralls commented Oct 25, 2023

Coverage Status

coverage: 75.232% (+0.04%) from 75.192% when pulling 1ad5f8d on section-no-title into d6d3648 on master.

@dgdavid dgdavid force-pushed the section-no-title branch 4 times, most recently from 7094689 to a61df81 Compare October 31, 2023 09:46
@dgdavid dgdavid marked this pull request as ready for review October 31, 2023 09:51
@@ -149,10 +147,19 @@ const icons = {
*
*/
export default function Icon({ name, className = "", size = 32, ...otherProps }) {
if (!icons[name]) {
console.error(sprintf(_("Icon %s not found!"), name));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOTE: I wonder if worth it adding a process.env.NODE_ENV check for not delivering these console.error in the production build.

Suggested change
console.error(sprintf(_("Icon %s not found!"), name));
process.env.NODE_ENV !== "production" && console.error(sprintf(_("Icon %s not found!"), name));

or even to have a logError util for using it in every place we do a console.error

const logError = (error) => {
  if (process.node.NODE_ENV !== "production") {
    console.error(error);
  }
};
Suggested change
console.error(sprintf(_("Icon %s not found!"), name));
logError(sprintf(_("Icon %s not found!"), name));

Not sure if webpack automatically drop these blocks from the production build. Has to check.

https://webpack.js.org/guides/production/#specify-the-mode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've checked by my own that blocks conditioned to process.env.NODE_ENV !== 'production' are not shipped in the production build. Which is great. So, creating an issue for wrap all console.errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discarded. See #842

Copy link
Contributor

@imobachgs imobachgs left a comment

Choose a reason for hiding this comment

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

It looks good. Thanks!

web/src/components/core/Section.jsx Outdated Show resolved Hide resolved
@imobachgs
Copy link
Contributor

Oh, it looks like you have a conflict to fix (originated after merging #831).

By using aria-label and aria-laballedby attributes.
And set the aria-busy attribute when it's in loading mode.
Trust in the truthy value of props instead of checking if present and
not empty.

See https://developer.mozilla.org/en-US/docs/Glossary/Truthy
Beacuse crypto.randomUUID() was added in version 22.1.0 [1][2] but the
jest-environment-jsdom dependency will be updated with jest v30[3]

[1] jsdom/jsdom#3551
[2] https://github.com/jsdom/jsdom/blob/master/Changelog.md#2210
[3] jestjs/jest#13825 (comment)
Because it's no longer possible to mock some window properties since
jsdom 21.0.0 and it was updated to version 22.1.0 in previous commits.

See https://github.com/jsdom/jsdom/blob/master/Changelog.md#2100 and
jsdom/jsdom#3492
Output the error to the console instead of rendering it in the UI.
Checking the data-icon-name attribute.
@dgdavid dgdavid merged commit 8ef73b0 into master Oct 31, 2023
10 checks passed
@dgdavid dgdavid deleted the section-no-title branch October 31, 2023 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants