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

Notification scripts update #92

Merged
merged 71 commits into from
Jan 19, 2023
Merged

Notification scripts update #92

merged 71 commits into from
Jan 19, 2023

Conversation

erikyo
Copy link
Collaborator

@erikyo erikyo commented Jun 14, 2022

Since the previous version has all hub notifications hardcoded and the hub could not be tested, I created a react component and a redux store controller to handle notifications multiple destinations. The component has a context (formerly called location), which subscribes to notifications from its context and receives updates from it.

Then notifyController was rebuilt with all the previous functionality (add, remove, clearAll) and, in addition, a function was added to retrieve the api (it currently reads a false response from a json file).

Actually we have two main components: Notification and NotificationArea, the latter depending on context displays the array of Notification with diffent styles and options (for example at the moment the hub is set to display two lists of notifications, the current week's and previous week notices. This is not yet customizable but it would be nice if we can provide some filters (by type, by plugin etc as mentioned in PR #84)

We have a rest-api endpoint (thanks @Sephsekla!) but we need to decide how the component fetches data from the database, what arguments it passes to it, and the strategy for updating the data in the reducer.

a brief story of what is changed with this PR:

  • Adopted the @wordpress/components in order to comply to wordpress design standards
  • Adopted the @wordpress/data to dispatch notifications to all components that request them
  • The old function addNotify has been added to window.wp.notify (the js/api was located there)
    https://github.com/erikyo/wp-notify/blob/443873fc9e93cdbe83e92df64ff1708de85b4b4f/src/scripts/wp-notify.js#L50
  • When you test this PR remember to update the timestamp in the json file and this way moment.js will tell you how much time has passed in a textual way ("an hour ago", "few second ago", "a week ago" and so on)
  • Adds the storybook and an initial component setup
  • Fixes some a11y related issues (mainly now the hub is operable via keyboard)
  • UI: the vertical padding of dash notifications should be a little smaller now on horizontal monitors with low vertical resolutions, because now it depends on the height of the screen
  • Settings table updated (Accessibility: settings checkbox labels are not unique #110)

Copy link
Collaborator

@Sephsekla Sephsekla left a comment

Choose a reason for hiding this comment

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

@erikyo thanks for all your hard work here! I've added a few comments but in general this has massively pushed things forward.

As a general note I'd like to do some work on modularisation and comments in particular, but I think it would make more sense to get this merged and then we can chip away at any updates in smaller PRs (since this is pretty huge at this point).

@bacoords @jonathanbossenger what are your thoughts? Should we go ahead with a merge so we can work against develop again?

includes/demo.php Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/scripts/components/noticeImage.js Outdated Show resolved Hide resolved
import { delay } from '../utils';

// Notice class method.
export default class Notice extends Component {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this have to be a class? Or could it just be const or function? It's not got any class-specific logic or anything.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For certain things I have always preferred to create a class whereas I use functional components more often for component elements, this one has also a method (onDismiss) and I guess more may be added in the future..
In this way the component is also more prone to being extended (not that it would be impossible otherwise)

src/scripts/components/notification.js Outdated Show resolved Hide resolved
this.props.additionalClassName,
].filter( Boolean );

return (
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is good, but it is a bit of a massive thing 😅

Maybe not now, but it would be good to split it up slightly, so something like this for each of the individual conditional components.

const dashboardActions = () => <something>Some buttons</something>

return (
  <div>
    { (location === 'dashboard') && dashboardActions }
  </div>
)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Following this idea I also created a component for the actions (ok+dismiss button), but I was wondering if it would be a good idea to do the same for the title/text. What do you think?

src/styles/notify/notification-hub.scss Outdated Show resolved Hide resolved
src/styles/notify/notification-hub.scss Outdated Show resolved Hide resolved
@erikyo erikyo requested a review from Sephsekla October 8, 2022 16:46
Copy link
Collaborator

@Sephsekla Sephsekla left a comment

Choose a reason for hiding this comment

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

👍 We can definitely iterate on this, but for now (once conflicts are resolved) I'd be in favour of getting this merged so we can move to smaller PRs against develop (since a lot of the progress is still only in this branch.

erikyo and others added 26 commits December 21, 2022 17:20
Better code splitting
Enqueue the notify script after wp-components and wp-i18n has been loaded
updates dependencies
rearrange code
…imbly style the border since it would now be a bit complex to do

added more jsdocs
…ss#108)

not 100% sure if it is wai compliant
we need to create the shortcut for action (space?) / delete (del ?) etc.
https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_roving_tabindex
…ive, but need an empty alt attribute to prevent screen readers from attempting to interpret them. (addresses WordPress#107)
focus / active single hub notification
Co-authored-by: Joe Bailey-Roberts <[email protected]>
Co-authored-by: Joe Bailey-Roberts <[email protected]>
@erikyo
Copy link
Collaborator Author

erikyo commented Jan 7, 2023

since 989c918 checks are failing since i've removed the rules exclusions in the phpcs configuration file.

I think if we want use the WP-standards we can't pick and choose the ones we like or don't like and that since it's only loaded the ruleset of core and doc we should follow it.

@Sephsekla
Copy link
Collaborator

since 989c918 checks are failing since i've removed the rules exclusions in the phpcs configuration file.

I think if we want use the WP-standards we can't pick and choose the ones we like or don't like and that since it's only loaded the ruleset of core and doc we should follow it.

@erikyo for now can you just revert the phpcs config change? While I agree that it's a change worth making, I'd prefer to make it in its own followup PR. It's a little outside the scope of JS scripts update, and ideally something to handle separately rather than delaying merging this into develop.

@erikyo erikyo requested a review from Sephsekla January 18, 2023 15:36
@erikyo erikyo marked this pull request as ready for review January 18, 2023 17:00
Copy link
Collaborator

@Sephsekla Sephsekla left a comment

Choose a reason for hiding this comment

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

💥 Awesome stuff!

Re: the changes to the json file, I think this is fine for now, although I'd like to get the ball rolling again on the schema discussion and finalise this before we go much further.

There's a lot in here and probably a few things that could be tweaked, but for now I'd be in favour of merging this and iterating on things in smaller PRs going forward.

Copy link
Collaborator

@Sephsekla Sephsekla left a comment

Choose a reason for hiding this comment

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

🥳

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.

2 participants