-
Notifications
You must be signed in to change notification settings - Fork 284
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
Fixes #25957 - Subscription page UI loading fixes #7954
Conversation
Parts of the subscription page are not loading during certain workflows and it is making duplicate API requests on load
Issues: #25957 |
Updates in this PR: Pass just the id into
|
Here is what I believe to be the cause of the original issue linked to this PR, the subs and manifest aren't visible on page load. I was able to recreate this by logging in as a user without a default organization, navigating to subscriptions, and choosing an org from the dropdown |
There is a lot in this PR (even if its not a huge diff), please ask questions about any of the confusing parts, I'm also open to alternate solutions. 👂 |
I have to update tests, the one thing I'm stuck on is the
I think I'll have to break out |
ping @waldenraines and @sharvit for review please 🙏 |
|
||
changeCurrentOrgaziation(encodeURIComponent(`${id}-${item}`)).then(() => | ||
changeCurrentOrgaziation(`${id}`).then(() => |
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.
Maybe it's a good time to correct the method name to 'changeCurrentOrganization' !
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! I meant to do this and forgot. I'll update!
@@ -69,7 +68,10 @@ class SubscriptionsPage extends Component { | |||
} | |||
} | |||
|
|||
if (!isEqual(organization, prevProps.organization)) { | |||
// remove the loading attribute so the action isn't called when org starts loading | |||
const { loading: _cloading, ...currentOrgInfo } = organization; |
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.
what are _cloading
and _ploading
?
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 am removing the loading
attribute from the object. to do this, I'm assigning it to a variable and pulling the rest of the object to another variable currentOrgInfo
. If I just use loading
, I can't use loading
again in the next line since its a const, so I added 'c' and 'p' and then '_' to signify its not being used.
Definitely open to suggestions here, I don't love these names either 🤢
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.
Got it. Had to play in the repl but it makes sense. Very interesting syntax!
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.
what about:
const getOrgInfo = (org) => {
const { loading, ...info } = org;
return info;
};
const currentOrgInfo = getOrgInfo(organization);
const prevOrgInfo = getOrgInfo(prevProps.organization);
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.
Changes look great. Left a few questions and I'll take another look once we can get a green build. I ran tests locally and see there are plenty of failures from your changes so that's reassuring of our test coverage. Unfortunately I don't have any advice on testing the withOrg code, but breaking the part out that you mentioned seems like a good start!
Side note: i found an issue that was present on the page with and without this change - so I opened an issue https://projects.theforeman.org/issues/25969 |
I also found an issue (that exists in master) with the org switcher, which I wasn't able to solve in this PR https://projects.theforeman.org/issues/25967 |
@jturel updated the method name and the tests |
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.
Super nice changes. ACK
@@ -25,7 +24,8 @@ import SubscriptionsPage from './SubscriptionsPage'; | |||
// map state to props | |||
const mapStateToProps = (state) => { | |||
const subscriptions = selectSubscriptionsState(state); | |||
const subscriptionTableSettings = state.katello.settings.tables[SUBSCRIPTION_TABLE_NAME] || {}; | |||
const subscriptionTableSettings = |
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.
Could you use a selector here to make it a bit more readable?
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 mean something like:
const subscriptionTableSettings = selectTableSettings(SUBSCRIPTION_TABLE_NAME);
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 and a question.
@@ -268,6 +268,7 @@ class ManageManifestModal extends Component { | |||
rows={manifestHistory.results} | |||
columns={columns} | |||
emptyState={emptyStateData()} | |||
rowKey="created" |
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.
Is this guaranteed to be unique?
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.
good question, I can double check how granular the timestamp is
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.
The timestamp looks like its down to the second, here is the an example of the actual key react uses 2019-01-29T16:28:59+0000-row
The object we are getting looks like this:
{
"statusMessage":"test_manifest_roles file imported successfully.","
status":"SUCCESS",
"created":"2019-01-29T16:28:59+0000"
}
I added id
to the manifest history API, it looks like we can return a uuid too
{
"id":"4028f92a689a347f01689a7140c002b7",
"statusMessage":"test_manifest_roles file imported successfully.",
"status":"SUCCESS",
"created":"2019-01-29T16:28:59+0000"}
I can just use the id from the API after adding it there, I don't see a reason to not add it in the API. I'll revert the table changes too since I think we want to continue to use id
until there is a reason not too
}); | ||
|
||
const actions = { ...organizationActions }; | ||
const mapDispatchToProps = dispatch => bindActionCreators(actions, dispatch); |
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.
Is there any real need for this instead of just using bindActionCreators({ ...organizationActions }, dispatch);
?
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.
either way works for me, I can update to one line 👍
@sharvit @waldenraines updated (in separate commits) according to your suggestions |
[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.
LGTM, thanks @johnpmitsch
[test katello] |
@johnpmitsch just making sure ... you waiting for anything from me on this one? |
<CheckOrg> | ||
<Header | ||
title="Select Organization" | ||
<Connect(CheckOrg) |
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.
Those snapshots became too big to maintain and understand and the reason is that this component is now connected.
I would like to suggest a solution to it:
- Separate the
CheckOrg
class from thewithOrganization.js
to a new file (CheckOrg.js
) so it will be a standalone component.
TheCheckOrg
component will recive a children instead using theWrappedComponent
.
ThewithOrganization
hoc will renderCheckOrg
with theWrappedComponent
as it's children and will connect it toredux
. - Do the current snapshoot testings only for the
CheckOrg
component so we will have lean snapshoots. - Need to have lean snapshoot testing for actions/reducers/selectors/helpers.
- Need to have a lean integration-testing for the HOC that run all the react-redux lifecycle using the IntegrationTestHelper.
Notice theIntegrationTestHelper
is in a process to be a standalone npm package, see Fixes #25910 - Move js test-helpers to npm theforeman/foreman#6432 and Fixes #25912 - Move js test-helpers to npm #7940
You can use those docs: https://sharvit.github.io/react-redux-test-utils/manual/integration-testing.html
And some examples:
https://github.com/theforeman/foreman/blob/edc0a1c73eb59b28b266e63a1a028c788837a942/webpack/assets/javascripts/react_app/components/Layout/__tests__/integration.test.js
https://github.com/theforeman/foreman/blob/c18d67464d81943b77feeb0e24ec649574860ab7/webpack/assets/javascripts/react_app/components/BreadcrumbBar/__tests__/integration.test.js
https://github.com/theforeman/foreman/blob/26345fcd991a3d3ca63f917ae1eed161167dd5aa/webpack/assets/javascripts/react_app/components/SearchBar/__tests__/integration.test.js
https://github.com/theforeman/foreman/blob/c18d67464d81943b77feeb0e24ec649574860ab7/webpack/assets/javascripts/react_app/components/PasswordStrength/__tests__/integration.test.js
What do you think?
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 get what you are thinking, but I'm having a really hard time putting this into practice.
Here is where I am at johnpmitsch@5b74686 I've had to work past some issues including things like HOCs not playing nice with react-router
The current error that i'm blocked by is:
react-dom.development.js:506 Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.
in Unknown (created by Route)
in Route
in div
in Unknown (created by Application)
in Router (created by BrowserRouter)
in BrowserRouter (created by Application)
in Application (created by Connect(Application))
in Connect(Application) (created by I18nProviderWrapper(Connect(Application)))
in IntlProvider (created by I18nProviderWrapper(Connect(Application)))
in I18nProviderWrapper(Connect(Application)) (created by StoreProvider(I18nProviderWrapper(Connect(Application))))
in Provider (created by StoreProvider(I18nProviderWrapper(Connect(Application))))
in StoreProvider(I18nProviderWrapper(Connect(Application))) (created by DataProvider(StoreProvider(I18nProviderWrapper(Connect(Application)))))
in DataProvider(StoreProvider(I18nProviderWrapper(Connect(Application))))
Let me know if you can see where things are going wrong, I'll keep looking, but i'm pretty stumped to be honest :)
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.
Too bad, code-wise it makes so much sense 😞
Opened up a follow up issue for the HOC discussion https://projects.theforeman.org/issues/26071 |
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 @johnpmitsch LGTM 👍
Parts of the subscription page are not loading during certain
workflows and it was making duplicate API requests on load
There are multiple semi-related changes here, I'll detail them in PR
comments