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

Fixes #30412 - fix shifted react-container #7821

Merged
merged 1 commit into from
Jul 21, 2020

Conversation

Ron-Lavi
Copy link
Member

This is something that I think css @media query would do the work for.
patternfly hides the vertical-nav when the page gets smaller

I think our JS implementation is overkill to what the layout needs to do - to shift to the left when the vertical nav is hidden.
I don't think we need to use the session for it, and I didn't notice anyone using the ON_COLLAPSE/ON_EXPAND actions.

current react pages are shifted:
shifted_audits

this is how it looks with this PR:
Audits

@theforeman-bot
Copy link
Member

Issues: #30412

@Ron-Lavi
Copy link
Member Author

@sharvit @xprazak2 @MariaAga can you take a look? thanks

Copy link
Contributor

@sharvit sharvit 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 👍

We are getting the same features, it fixes a bug and it removes 140 lines of code. Sound like a good deal for me.

patternfly-sass hides the vertical-nav on smaller screens, see: https://github.com/patternfly/patternfly-sass/blob/5e7cce3445d5b1af1e16500695b9f33edc6a4f6c/assets/javascripts/patternfly-functions.js#L260
the react-container needs to be shifted when it happens.
*/
@media only screen and (max-width: 768px) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we put it in webpack and import the pf3 variable for the max-width?

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, added those in my last commit

Copy link
Member

Choose a reason for hiding this comment

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

Resolved

@sharvit
Copy link
Contributor

sharvit commented Jul 15, 2020

Look like it we still have it in the session storage, does patternfly manage that internally?

@MariaAga
Copy link
Member

@LaViro Do you think it will work with the Nav in PF4? #7809

app/assets/stylesheets/base.scss Outdated Show resolved Hide resolved
app/assets/stylesheets/base.scss Outdated Show resolved Hide resolved
app/assets/stylesheets/base.scss Outdated Show resolved Hide resolved
app/assets/stylesheets/base.scss Outdated Show resolved Hide resolved
app/assets/stylesheets/base.scss Outdated Show resolved Hide resolved
@Ron-Lavi
Copy link
Member Author

Look like it we still have it in the session storage, does patternfly manage that internally?

@sharvit after doing a hard reset to the browser I don't see it in the session anymore:
Selection_342

Do you think it will work with the Nav in PF4? #7809

@MariaAga If they use the same scss classnames, it even make the implementation easier because
you won't need to take care of it in the JS part, but still check the full-react pages to see if it works.

@sharvit
Copy link
Contributor

sharvit commented Jul 15, 2020

Look like it we still have it in the session storage, does patternfly manage that internally?

@sharvit after doing a hard reset to the browser I don't see it in the session anymore:
Selection_342

Do you think it will work with the Nav in PF4? #7809

@MariaAga If they use the same scss classnames, it even make the implementation easier because
you won't need to take care of it in the JS part, but still check the full-react pages to see if it works.

From the other side, I don't think pf4 has the implementation for collapsing the menu so we might want to keep the logic?

@Ron-Lavi
Copy link
Member Author

From the other side, I don't think pf4 has the implementation for collapsing the menu so we might want to keep the logic?

@MariaAga is it correct?
in that case I would just add a css rule to hide the vertical nav too, when they both use the same variable for md grid breakpoint.

@MariaAga
Copy link
Member

MariaAga commented Jul 15, 2020

There is an option to open/close the menu in PF4,I use oncollapse to move the page content (forexample host table) to the right of the menu and not under it when it's open

@sharvit
Copy link
Contributor

sharvit commented Jul 15, 2020

@LaViro the reason for the sessionStorage is to keep the state of the menu when you are refreshing the page or moving to a different page (if it's not using client-routing).
Looks like it is still working and I still see the sessionStorage after removing it and refreshing the page. Maybe we have something on the server?

@Ron-Lavi
Copy link
Member Author

There is an option to open/close the menu in PF4,I use oncollapse to move the page content (forexample host table) to the right of the menu and not under it when it's open

I still think in this case we should use only css, based of the width of the screen, look how much code does it reduce.
you can do it simply with JS too, but preferably css.

@LaViro the reason for the sessionStorage is to keep the state of the menu when you are refreshing the page or moving to a different page (if it's not using client-routing).
Looks like it is still working and I still see the sessionStorage after removing it and refreshing the page. Maybe we have something on the server?

interesting, I didn't see any usecase of "navCollapsed" or "pinnedPath" which are the values that was set in the session,
I think that the menu gets the "active" menu data from the server, based on the route

do you have any other concerns? I didn't find any regression

@MariaAga
Copy link
Member

Generally I'm not sure it's a good idea to add PRs right now to the old PF3 layout with PF3 rules when we have a PR to replace it with PF4

@Ron-Lavi
Copy link
Member Author

Well currently there is a bug in all of this pages,
Looks like the react implementation doesn't work atm
In your new PR you can add a simpler solution than was before, but lets fix the issue first and remove unused code.

Copy link
Contributor

@sharvit sharvit left a comment

Choose a reason for hiding this comment

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

$pf-global--breakpoint--md: 768px !default;
$pf-global--breakpoint--lg: 992px !default;
$pf-global--breakpoint--xl: 1200px !default;
$pf-global--breakpoint--2xl: 1450px !default;
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

nice thanks! I will change it.
while we are at it, is it possible to make those variables available all over the app without the import?
can we do the same for colors variables?

@Ron-Lavi
Copy link
Member Author

Looks like the pf3 component manages the session-storage for us, see:
https://github.com/patternfly/patternfly-react/blob/patternfly-3/packages/patternfly-react/src/components/VerticalNav/VerticalNav.js#L120

interesting, is that a good practice?

Copy link
Contributor

@sharvit sharvit left a comment

Choose a reason for hiding this comment

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

I am getting this layout issue in the hw-models page:
Screen Shot 2020-07-16 at 14 00 40

@sharvit
Copy link
Contributor

sharvit commented Jul 16, 2020

interesting, is that a good practice?

I think so, that way we can keep it in the same state when moving between pages

@MariaAga
Copy link
Member

MariaAga commented Jul 16, 2020

To solve this I think it be easier to just change:


to

return !!getValue(`["navCollapsed","pinnedPath"]`).navCollapsed;

And then we don't have to add more PF3 to our code...
Also with this I don't see Avi's issue

@Ron-Lavi
Copy link
Member Author

I am getting this layout issue in the hw-models page

Thanks! I forgot we can do that :) :)
so not much of code removal this time..

thanks @MariaAga, added your session suggestion though the container was shifted 200px to the right on small screens when the vertical nav is hidden.
so I kept the css changes and the move of them to webpack,

ready for another review 👍

@Ron-Lavi Ron-Lavi changed the title Fixes #30412 - use css rule instead of JS implementation for vertical nav collapse Fixes #30412 - fix shifted react-container Jul 16, 2020
Comment on lines 49 to 53
@media only screen and (max-width: $pf-global--breakpoint--md) {
.react-container {
margin-left: 0;
}
}
Copy link
Member

@MariaAga MariaAga Jul 16, 2020

Choose a reason for hiding this comment

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

This is getting overridden by the previous rule:
&.collapsed-nav { margin-left: 75px; }
as #react-app-root is an ID so the rule is more specific

Copy link
Member Author

Choose a reason for hiding this comment

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

done, fixed the situation where screen was small and nav collapsed 👍

@Ron-Lavi
Copy link
Member Author

How I love css 🤣

added another fix, ready for another review
this is how the page reacts now ( sorry for the low quality )

Hardware Models

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.

Thanks @LaViro, tested on some foreman pages and also Katello Angular and React pages. works great!

Just one nit below

@@ -1,4 +1,4 @@
import { getValue } from '../../common/SessionStorage';

export const getIsNavbarCollapsed = () =>
!!getValue(`["navCollapsed","pinnedPath"]`);
!!getValue(`["navCollapsed","pinnedPath"]`)?.navCollapsed;
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional chaining party! 🎉

Prefer adding parenthesis to avoid ambiguity (does the !! apply to everything?)

Suggested change
!!getValue(`["navCollapsed","pinnedPath"]`)?.navCollapsed;
!!(getValue(`["navCollapsed","pinnedPath"]`)?.navCollapsed);

Copy link
Member

@amirfefer amirfefer Jul 17, 2020

Choose a reason for hiding this comment

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

no need to add !! operator
the navCollapsed is already a boolean
btw, this line caused the regression with the vertical navigation
Thanks for the @media extra feature :)

Copy link
Member Author

Choose a reason for hiding this comment

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

no need to add !! operator
the navCollapsed is already a boolean

before the user clicks to collapse the menu, the values are initially set to null by us
I guess that's why !! was used,to make sure it's a boolean.

Copy link
Member

@amirfefer amirfefer Jul 19, 2020

Choose a reason for hiding this comment

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

works for me without the !!
null is still a false value in conditions

Copy link
Member Author

Choose a reason for hiding this comment

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

ok lets do this.. since it's only being used to set a className it's indeed not important if it's null or false

Copy link
Member Author

Choose a reason for hiding this comment

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

oh no.. removing it just failed 4 snapshots in travis
showing undefined instead of false.. I am reverting it so the snapshot will stay the same

@jeremylenz I tried to add those brackets you ask for, but the prettier linter is annoyed by that and ask to remove it :(

Copy link
Contributor

Choose a reason for hiding this comment

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

If we can't ignore the lint rule I'd go for updating the snapshots. But either way this isn't a big enough deal to be a blocker, if it has to remain without parenthesis then I guess I'll live with it 🤷‍♂️

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 prefer a snapshot with the prop as false instead of undefined
because it is not clear whether the prop wasn't passed at all, or was it pass as undefined?
(in our case it was passed as undefined)

MariaAga
MariaAga previously approved these changes Jul 19, 2020
Copy link
Member

@MariaAga MariaAga left a comment

Choose a reason for hiding this comment

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

React and not React margin works correctly now 🎉

@Ron-Lavi
Copy link
Member Author

rebased as Refactor the Layout component got merged,
everything seem to work fine, any other suggestions before merging?

@coveralls
Copy link

Coverage Status

Coverage remained the same at 74.617% when pulling ec7832b on laviro:fix/react_container_margin into e4c39a7 on theforeman:develop.

@ezr-ondrej ezr-ondrej dismissed sharvit’s stale review July 21, 2020 06:28

Requested changes addressed.

Copy link
Member

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

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

Works for me, test failure unrelated.
Thanks @LaViro and @sharvit, @jeremylenz, @MariaAga and @amirfefer for reviews! 👍

@ezr-ondrej ezr-ondrej merged commit d2b79df into theforeman:develop Jul 21, 2020
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