-
Notifications
You must be signed in to change notification settings - Fork 987
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
Refs #26729 - replace notifications polling by middleware #7121
Refs #26729 - replace notifications polling by middleware #7121
Conversation
Issues: #26729 |
@LaViro tests in Notifications are failing, is it because this is a WIP? |
Yes, still work in progress @MariaAga thanks |
7294372
to
6b81cf4
Compare
6b81cf4
to
9f1db56
Compare
64150cd
to
e7a636a
Compare
b6e75ac
to
afaa43c
Compare
afaa43c
to
b158331
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @LaViro! Tested and seems to work as intended. I really like the way you've implemented it, by adding the START_INTERVAL
and STOP_INTERVAL
actions as basic "infrastructure," but then simplifying things for the developer's most common use case by adding the polling
key that just does it for you. And that way, the documentation can be opinionated and thus easy to follow. I left some suggestions & nitpicks below.
webpack/assets/javascripts/react_app/components/notifications/notifications.test.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/redux/API/APIMiddleware.js
Outdated
Show resolved
Hide resolved
}); | ||
dispatch(getNotifications(url)); | ||
}; | ||
export const startNotificationsPolling = url => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the diff of this file and loving how much simpler the middleware solution makes it ❤️
webpack/assets/javascripts/react_app/redux/middlewares/IntervalMiddleware/IntervalActions.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/redux/reducers/notifications/index.js
Outdated
Show resolved
Hide resolved
b158331
to
4b29c62
Compare
thanks @jeremylenz for the review ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed again but didn't really see any new changes except the notifications polling actions, which look fine to me
webpack/assets/javascripts/react_app/redux/actions/notifications/index.js
Outdated
Show resolved
Hide resolved
@LaViro Something to consider-- For the review phase, you could temporarily change the PR on Github so it's comparing with your other branch, rather than comparing with master. Then we would only see the relevant changes and there may be less confusion when reviewing. |
4b29c62
to
8ed2e42
Compare
Rebased the interval middleware part and it still works the same |
8ed2e42
to
61b1b69
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work! removes a lot of redundant code 👍
I left a few inline comments
it('full flow', () => { | ||
const wrapper = mount( | ||
<Notifications data={componentMountData} store={generateStore()} /> | ||
); | ||
wrapper.find('.fa-bell').simulate('click'); | ||
expect(wrapper.find('.panel-group')).toHaveLength(1); | ||
wrapper.find('.panel-group .panel-heading').simulate('click'); | ||
expect(wrapper.find('.unread')).toHaveLength(1); | ||
wrapper.find('.unread').simulate('click'); | ||
expect(wrapper.find('.unread')).toHaveLength(0); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't we need a full flow test in the integration test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add it with the other tests refactor in #7138
webpack/assets/javascripts/react_app/redux/reducers/notifications/index.js
Outdated
Show resolved
Hide resolved
expect(reducer(stateWithNotifications, action)).toMatchSnapshot(); | ||
}); | ||
|
||
it('Should handle FAILURE', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using testReducerSnapshotWithFixtures
from our testsHelper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
originally I thought to add it in #7138, though I see no problem adding it here 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seem a lot of work to update the convention of all tests,
which is a little bit out of the scope of this PR, would it be ok to change it in #7138 ?
61b1b69
to
65de757
Compare
423068f
to
f03fe92
Compare
[test foreman] |
Integration test failures seem related |
f03fe92
to
c3832e9
Compare
Thanks @mmoll, hope I fixed it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor comments inline
@@ -0,0 +1,3 @@ | |||
export const redirectToLogin = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: why is this a notification thing? redirect to login can happen on session timeout regardless of notification (could be triggered by any api call..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, things like that should be handled by the API middleware,
this was a method which was used before in the notifications component.
I wanted to add this feature as a small PR after #7222 will get merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why waiting for another PR? this can be moved easily as you mention to our API middleware
does #7222 block this by any means?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opened #7337
it is blocked by #7222 since that PR refactors almost every file of the API middleware,
@amirfefer waiting also for your PR #7186 to use the connected-react-router
instead of window.replace
webpack/assets/javascripts/react_app/redux/reducers/notifications/index.js
Outdated
Show resolved
Hide resolved
@amirfefer can you review again? thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @LaViro ! Looks great 👍
few inline comments
@@ -0,0 +1,3 @@ | |||
export const redirectToLogin = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why waiting for another PR? this can be moved easily as you mention to our API middleware
does #7222 block this by any means?
expect(global.location.replace).toBeCalled(); | ||
const testHelper = configureIntegrationHelper(); | ||
const wrapper = testHelper.mount(<Notifications {...notificationProps} />); | ||
setTimeout(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it necessary? there are some other async testing techniques than using setTimeOut
, i.e for timers jest has useFakeTimers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I tried to use the different jest mock timers but it seem to destroy also the API response so sadly the notification component doesn't get updated..
The setTimeout solution seem to work and there is no regression on the testing time period.
Please feel free to try and adjust this test and see what I mean
webpack/assets/javascripts/react_app/redux/actions/notifications/index.js
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/redux/actions/notifications/notifications.test.js
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/redux/actions/notifications/notifications.test.js
Show resolved
Hide resolved
acea028
to
a181917
Compare
rebased |
a181917
to
0eb500c
Compare
[test katello] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @LaViro ! Tested and works as expected 👍
just a few nitpicks
case SUCCESS: | ||
return state.merge({ | ||
notifications: response.notifications, | ||
hasUnreadMessages: hasUnreadMessages(response.notifications), | ||
}); | ||
case FAILURE: { | ||
return state.set('error', response); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it make sense to use API reducer here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a bit tricky, since the notifications are consumed also on other cases in this reducer,
and the provided state doesn't give access to the API reducer, a workaround I can do is to use getState()
from the action and use a selector to retrieve the notifications data.
what do you think about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another option is to move the logic to selectors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
third option is to wait for all types of API operations to be supported - #7261
and replace all of the notifications actions with API calls.
the API calls will update the API reducer anyway and only than we won't need those cases in the reducer. imo that would be the best option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 to the third option
webpack/assets/javascripts/react_app/components/notifications/notifications.test.js
Show resolved
Hide resolved
0eb500c
to
f057285
Compare
replace it by using the interval middleware
f057285
to
433797d
Compare
ready for another review :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work @LaViro 😄
Tested again and works as expected. ACK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @LaViro ! great update 👍
blocked by #7157