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

Refs #26729 - replace notifications polling by middleware #7121

Merged

Conversation

Ron-Lavi
Copy link
Member

@Ron-Lavi Ron-Lavi commented Oct 22, 2019

blocked by #7157

@theforeman-bot
Copy link
Member

Issues: #26729

@MariaAga
Copy link
Member

@LaViro tests in Notifications are failing, is it because this is a WIP?

@Ron-Lavi
Copy link
Member Author

Yes, still work in progress @MariaAga thanks

@Ron-Lavi Ron-Lavi force-pushed the replace_notifications_polling branch from 7294372 to 6b81cf4 Compare October 24, 2019 14:09
@coveralls
Copy link

coveralls commented Oct 24, 2019

Coverage Status

Coverage decreased (-0.2%) to 75.254% when pulling f057285 on laviro:replace_notifications_polling into 5e0496a on theforeman:develop.

@Ron-Lavi Ron-Lavi force-pushed the replace_notifications_polling branch from 6b81cf4 to 9f1db56 Compare October 28, 2019 17:01
@Ron-Lavi Ron-Lavi force-pushed the replace_notifications_polling branch 3 times, most recently from 64150cd to e7a636a Compare November 7, 2019 12:51
@Ron-Lavi Ron-Lavi changed the title [WIP] Refs #26729 - replace notifications polling by middleware Refs #26729 - replace notifications polling by middleware Nov 10, 2019
@Ron-Lavi Ron-Lavi force-pushed the replace_notifications_polling branch 2 times, most recently from b6e75ac to afaa43c Compare November 14, 2019 10:54
@Ron-Lavi Ron-Lavi force-pushed the replace_notifications_polling branch from afaa43c to b158331 Compare November 18, 2019 08:12
Copy link
Contributor

@jeremylenz jeremylenz left a 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.

});
dispatch(getNotifications(url));
};
export const startNotificationsPolling = url => ({
Copy link
Contributor

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/stories/docs/APIPollingMiddleware.md Outdated Show resolved Hide resolved
webpack/stories/docs/APIPollingMiddleware.md Outdated Show resolved Hide resolved
webpack/stories/docs/APIPollingMiddleware.md Outdated Show resolved Hide resolved
webpack/stories/docs/intervalMiddleware.md Outdated Show resolved Hide resolved
@Ron-Lavi Ron-Lavi force-pushed the replace_notifications_polling branch from b158331 to 4b29c62 Compare November 20, 2019 18:15
@Ron-Lavi
Copy link
Member Author

thanks @jeremylenz for the review !
updated with the code from #7157,
I appreciate if you could review only the last commit as the first commits are always keep updated by #7157 - if you have comments on the code it is best to comment there, but I will update with your suggestions, thanks again 👍

Copy link
Contributor

@jeremylenz jeremylenz left a 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

@jeremylenz
Copy link
Contributor

@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.

@Ron-Lavi Ron-Lavi force-pushed the replace_notifications_polling branch from 4b29c62 to 8ed2e42 Compare November 21, 2019 09:35
@Ron-Lavi
Copy link
Member Author

Rebased the interval middleware part and it still works the same

@Ron-Lavi Ron-Lavi force-pushed the replace_notifications_polling branch from 8ed2e42 to 61b1b69 Compare November 28, 2019 14:16
Copy link
Member

@amirfefer amirfefer left a 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

Comment on lines 41 to 37
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);
});
Copy link
Member

@amirfefer amirfefer Dec 1, 2019

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?

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 will add it with the other tests refactor in #7138

expect(reducer(stateWithNotifications, action)).toMatchSnapshot();
});

it('Should handle FAILURE', () => {
Copy link
Member

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?

Copy link
Member Author

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 👍

Copy link
Member Author

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 ?

@mmoll mmoll force-pushed the replace_notifications_polling branch from 423068f to f03fe92 Compare January 5, 2020 20:26
@mmoll
Copy link
Contributor

mmoll commented Jan 5, 2020

[test foreman]

@mmoll
Copy link
Contributor

mmoll commented Jan 5, 2020

Integration test failures seem related

@Ron-Lavi Ron-Lavi force-pushed the replace_notifications_polling branch from f03fe92 to c3832e9 Compare January 6, 2020 05:47
@Ron-Lavi
Copy link
Member Author

Ron-Lavi commented Jan 6, 2020

Thanks @mmoll, hope I fixed it.
it seems that the API action structure changed in middleware and caused some errors.

Copy link
Member

@ohadlevy ohadlevy left a 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 = () => {
Copy link
Member

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..)

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 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

Copy link
Member

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?

Copy link
Member Author

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

@Ron-Lavi
Copy link
Member Author

Ron-Lavi commented Jan 6, 2020

@amirfefer can you review again? thanks

Copy link
Member

@amirfefer amirfefer left a 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 = () => {
Copy link
Member

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(() => {
Copy link
Member

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

Copy link
Member Author

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

@Ron-Lavi
Copy link
Member Author

Ron-Lavi commented Jan 8, 2020

rebased

@Ron-Lavi Ron-Lavi force-pushed the replace_notifications_polling branch from a181917 to 0eb500c Compare January 9, 2020 06:01
@mmoll
Copy link
Contributor

mmoll commented Jan 9, 2020

[test katello]

Copy link
Member

@amirfefer amirfefer left a 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

Comment on lines +36 to +43
case SUCCESS:
return state.merge({
notifications: response.notifications,
hasUnreadMessages: hasUnreadMessages(response.notifications),
});
case FAILURE: {
return state.set('error', response);
}
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member Author

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

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 to the third option

replace it by using the interval middleware
@Ron-Lavi Ron-Lavi force-pushed the replace_notifications_polling branch from f057285 to 433797d Compare January 26, 2020 08:35
@Ron-Lavi
Copy link
Member Author

ready for another review :)

Copy link
Contributor

@jeremylenz jeremylenz left a 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

Copy link
Member

@amirfefer amirfefer left a 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 👍

@amirfefer amirfefer merged commit 62a0439 into theforeman:develop Jan 30, 2020
@Ron-Lavi Ron-Lavi deleted the replace_notifications_polling branch February 12, 2020 12:37
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.

9 participants