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 drawer #6644

Merged
merged 34 commits into from
Feb 17, 2020
Merged

Notification drawer #6644

merged 34 commits into from
Feb 17, 2020

Conversation

fhlavac
Copy link
Contributor

@fhlavac fhlavac commented Jan 30, 2020

Notification drawer → React

  • rewritten notification drawer into React
  • rewritten toast notifications into React
  • created tests for notification-reducer, notification-drawer, notifications-actions, toast-list
  • updated top navbar tests to reflect state management changes in the notification drawer
  • deleted the old Angular implementation

drawer

A number of all user's notifications is now fetched using a separate API request since data GET request returns a wrong COUNT - it should be fixed after ManageIQ/manageiq-api#726

I'm not sure about displaying all the necessary attributes in toast notifications (especially the link).
@skateman, could you please check it?

@fhlavac
Copy link
Contributor Author

fhlavac commented Jan 30, 2020

@miq-bot add_reviewer @skateman

@miq-bot
Copy link
Member

miq-bot commented Jan 30, 2020

@fhlavac Cannot add the following reviewer because they are not recognized: skateman Hyperkid123 martinpovolny

@fhlavac
Copy link
Contributor Author

fhlavac commented Jan 30, 2020

@miq-bot add_reviewer @Hyperkid123

@fhlavac
Copy link
Contributor Author

fhlavac commented Jan 30, 2020

@miq-bot add_reviewer @martinpovolny

@miq-bot miq-bot requested a review from martinpovolny January 30, 2020 13:16
@Hyperkid123
Copy link
Contributor

@fhlavac to fix the Travis issues. You will have to delete tests for the old angular controllers. Also, there is a problem with dates in your snapshots. I think an update should be good enough. If it won't help just remove the snapshot.

@skateman
Copy link
Member

I like it even without looking at the code, my only concern is if the kebab context menu things are working as they used to work in the old implemenation.

@Hyperkid123
Copy link
Contributor

@skateman do we know how they suppose to work? Can the session thing be deleted?

Copy link
Contributor

@Hyperkid123 Hyperkid123 left a comment

Choose a reason for hiding this comment

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

So this is what I have found so far.

const [isPanelExpanded, setPanelExpanded] = useState(true);
const unreadCount = useSelector(({ notificationReducer: { unreadCount } }) => unreadCount);
const notifications = useSelector(({ notificationReducer: { notifications } }) => notifications);
const totalNotificationsCount = useSelector(({ notificationReducer: { totalNotificationsCount } }) => totalNotificationsCount);
Copy link
Contributor

Choose a reason for hiding this comment

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

useSelector can be used for multiple values. You don't need to call the hook each time you need something from the state.

const { isDrawerVisible, unreadCount } = useSelector(({ notificationReducer: { isDrawerVisible, unreadCount } }) => ({ isDrawerVisible, unreadCount )});

All state variables should probably use only one useSelector if possible.

const ToastList = () => {
const dispatch = useDispatch();
const toastNotifications = useSelector(({ notificationReducer: { toastNotifications } }) => toastNotifications);
const notificationTimerDelay = 8000;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would define this constant outside of the component. If you leave it is at is, it will create a new variable for each notification which uses slightly more memory. It's not a big deal but its a good practice.

className="nav-item-iconic drawer-pf-trigger-icon"
title={`${unreadCount} ${__('unread notifications')}`}
onClick={() => {
dispatch({ type: '@@notifications/toggleDrawerVisibility' });
Copy link
Contributor

Choose a reason for hiding this comment

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

You should move this string to a constant somewhere.

"type": "success",
"unread": true
}
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing newline at the end of the file

"seen": false,
"href": "http://localhost:3000/api/notifications/10000000017255"
}]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

^^

package.json Outdated
@@ -63,7 +63,7 @@
"moment-strftime": "~0.5.0",
"moment-timezone": "~0.5.21",
"numeral": "~2.0.6",
"patternfly": "~3.59.1",
"patternfly": "~3.59.4",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you revert it back to the original version? I think this upgrade did not help anything.

@skateman
Copy link
Member

@skateman do we know how they suppose to work? Can the session thing be deleted?

What do you mean?

const {
isDrawerVisible, unreadCount, notifications, totalNotificationsCount, maxNotifications,
} = useSelector(({
notificationReducer: {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a lot of extra code duplications. If you have a use case like this, when you are basically consuming the whole state, you can just return the whole object and destruct it only in one place:

const {
    isDrawerVisible, unreadCount, notifications, totalNotificationsCount, maxNotifications,
  } = useSelector(({ notificationReducer }) => notificationReducer)

dispatch(toggleMaxNotifications())
}
>
{ maxNotifications ? __('Show all (may take a while)') : __(`Show only the first ${maxNotificationsConstant}`)}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not going to work. Get text translation (the __() function) does not work with es6 template strings. You should use sprintf if you want to use variables in translations.

__(`Show only the first ${maxNotificationsConstant}`) => sprintf(__(Show only the first %s'), maxNotificationsConstant)

const Notifications = () => {
const dispatch = useDispatch();
const isDrawerVisible = useSelector(({ notificationReducer: { isDrawerVisible } }) => isDrawerVisible);
const unreadCount = useSelector(({ notificationReducer: { unreadCount } }) => unreadCount);
Copy link
Contributor

Choose a reason for hiding this comment

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

^^ use only one useSelector

};

export default connect(mapStateToProps)(Notifications);
export default (Notifications);
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for extra brackets

maxNotifications,
};

beforeEach(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

empty setup and clean callbacks

@fhlavac fhlavac force-pushed the notification-drawer branch from b2e5c95 to f0101d0 Compare February 4, 2020 09:02
@fhlavac fhlavac changed the title Notification drawer [WIP]Notification drawer Feb 4, 2020
@miq-bot miq-bot added the wip label Feb 4, 2020
@fhlavac fhlavac changed the title [WIP]Notification drawer Notification drawer Feb 4, 2020
@fhlavac fhlavac closed this Feb 4, 2020
@fhlavac fhlavac reopened this Feb 4, 2020
@miq-bot miq-bot removed the wip label Feb 4, 2020
@skateman
Copy link
Member

skateman commented Feb 4, 2020

Toasts aren't supposed to be shown when the drawer is open, because they can cover the drawer itself where the redundant information:
Screenshot from 2020-02-04 11-41-02

@fhlavac fhlavac force-pushed the notification-drawer branch from f0101d0 to 64426f5 Compare February 4, 2020 11:09
@fhlavac
Copy link
Contributor Author

fhlavac commented Feb 4, 2020

Toasts aren't supposed to be shown when the drawer is open, because they can cover the drawer itself where the redundant information:

@skateman Displaying both doesn't make sense but in the angular implementation drawer and toast notifications were displayed at the same time as well... maybe it is a bug...

<Drawer.Title
title={drawerTitle}
onCloseClick={() => dispatch(toggleDrawerVisibility())}
onExpandClick={() => { setDrawerExpanded(!isDrawerExpanded); }}
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for extra block around one-line function.

onExpandClick={() => setDrawerExpanded(!isDrawerExpanded)}

<a
id="eventsExpander"
className={classnames({ collapsed: !isPanelExpanded })}
onClick={() => { setPanelExpanded(!isPanelExpanded); }}
Copy link
Contributor

Choose a reason for hiding this comment

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

^^

@fhlavac fhlavac force-pushed the notification-drawer branch from 64426f5 to 8f5f961 Compare February 4, 2020 12:28
Copy link
Contributor

@Hyperkid123 Hyperkid123 left a comment

Choose a reason for hiding this comment

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

@skateman is the functionality OK?

@skateman
Copy link
Member

skateman commented Feb 4, 2020

Yeah, except of the toasts, but we can address that in a future PR. There are multiple possible refactoring points in the area.

Copy link
Member

@skateman skateman left a comment

Choose a reason for hiding this comment

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

The Seal of Approval

@fhlavac
Copy link
Contributor Author

fhlavac commented Feb 6, 2020

@miq-bot add_reviewer @himdel

@miq-bot miq-bot requested a review from himdel February 6, 2020 13:47
@fhlavac fhlavac force-pushed the notification-drawer branch from 8f5f961 to 88664a3 Compare February 10, 2020 11:15
@miq-bot
Copy link
Member

miq-bot commented Feb 10, 2020

Checked commits fhlavac/manageiq-ui-classic@4f6059b~...88664a3 with ruby 2.5.5, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
0 files checked, 0 offenses detected
Everything looks fine. 🍰

@himdel himdel self-assigned this Feb 17, 2020
@h-kataria h-kataria assigned h-kataria and unassigned himdel Feb 17, 2020
@h-kataria h-kataria added this to the Sprint 130 Ending Feb 17, 2020 milestone Feb 17, 2020
@h-kataria h-kataria merged commit d56553d into ManageIQ:master Feb 17, 2020
@@ -64,3 +65,5 @@ miqOptimizationInit();

import * as move from '../helpers/move.js';
ManageIQ.move = move;

ManageIQ.redux.store.dispatch(initNotifications(true));
Copy link
Contributor

@himdel himdel Feb 18, 2020

Choose a reason for hiding this comment

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

This is causing an API request on the login screen, causing a browser login popup.

EDIT: fixing in #6689

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants