-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
fix: hidden settings menu affects settings layout #7769
fix: hidden settings menu affects settings layout #7769
Conversation
Welcome!
Hello there, congrats on your first PR! We're excited to have you contributing to this project. |
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.
PR Summary
This pull request addresses an issue where hiding the left navigation menu affects the layout of the Settings page, causing it to shift to the left.
- Added
useIsRoute
hook inpackages/twenty-front/src/utils/currentPage.ts
to check if the current route matches a given path - Modified
PageHeader
component inpackages/twenty-front/src/modules/ui/layout/page/PageHeader.tsx
to conditionally render theNavigationDrawerCollapseButton
based on the current route - Prevents
NavigationDrawerCollapseButton
from rendering on the Settings page, fixing the layout issue when the left menu is hidden - Utilizes the new
useIsRoute
hook to determine if the current page is the Settings page
2 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile
|
||
return ( | ||
<StyledTopBarContainer width={width}> | ||
<StyledLeftContainer> | ||
{!isMobile && !isNavigationDrawerOpen && ( | ||
{!isMobile && !isNavigationDrawerOpen && !isSettingsPage && ( |
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.
style: This condition now has multiple checks. Consider extracting it into a separate function for better readability
export const useIsRoute = (path: string): boolean => { | ||
const location = useLocation(); | ||
return location.pathname === path; | ||
}; |
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.
style: Consider using startsWith(path)
instead of strict equality for more flexible route matching
* @param path The route to match. | ||
* @returns True if the current route matches the given path, false otherwise. | ||
*/ | ||
export const useIsRoute = (path: string): boolean => { |
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.
a few feedbacks about this file:
- we don't add JS doc in the project as we try to avoid comments and we are already using typescript to provide a nice dev xp. Function names should be clear enough to avoid doing it
- useIsRoute is a hook so it should not be in a utils folder
- I don't thin this s actually useful, we can just do useLocation().pathname === path whenever we need
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.
So I would remove this hook actually
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.
Right. I'll remove it.
I was also thinking the same
@@ -109,11 +110,12 @@ export const PageHeader = ({ | |||
const isMobile = useIsMobile(); | |||
const theme = useTheme(); | |||
const isNavigationDrawerOpen = useRecoilValue(isNavigationDrawerOpenState); | |||
const isSettingsPage = useIsRoute('/settings/profile'); |
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.
we should not only check for settings/profile but for all settings route
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.
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 for the link, I'll have a look
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 @Khaan25, I have left comments :)
@@ -109,11 +110,12 @@ export const PageHeader = ({ | |||
const isMobile = useIsMobile(); | |||
const theme = useTheme(); | |||
const isNavigationDrawerOpen = useRecoilValue(isNavigationDrawerOpenState); | |||
const isSettingsPage = useIsRoute('/settings/profile'); |
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.
There you go! @charlesBochet |
const isNavigationDrawerExpanded = useRecoilValue( | ||
isNavigationDrawerExpandedState, | ||
); | ||
const isNavigationDrawerOpen = useRecoilValue(isNavigationDrawerOpenState); |
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.
not sure why you changed the state name 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.
this is actually breaking the app
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.
@Khaan25 Thanks for pushing changes/
-
I have taken a new look and found that we actually already have a
useIsSettingsPage
hook -
fixing the state name (mentioned in comment), we are still having a blank Settings menu
That's strange. I've tested it multiple times. Let me double check and get back to you. Regarding the change, there was new code on the repo and I pulled in the latest changes. |
Here you go! @charlesBochet It's fixed :) Let me know if there's any other issue with more points 😄You can assign me 2024-10-18.23-15-08.mp4 |
Hey, could you review it? I can work on other issues? |
Hey @charlesBochet, could you please review :) |
On it :) |
// Check if the user is on the settings page and the navigation drawer is not expanded | ||
// Then open it automatically | ||
useEffect(() => { | ||
if (!isNavigationDrawerExpanded && isSettingsPage) { |
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.
we don't put side effects in components as we don't want to encourage developers to implement behaviors during rendering (this is pushing them to take dependencies on variables and trigger re-renders). Instead, we either:
- implement sync behaviors (in callbacks, event handlers, ...)
- move useEffects to ComponentEffects that have no children so it's not a big deal from a performance perspective
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.
Right. I should be creating a custom hook to achieve it, right?
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.
Current behavior is functional but I'm not a fan of this useEffect
I believe that we need to have this useEffect because it's gonna only trigger it when we've settings page :) I really thought about solving without useEffect but I ran into bugs as we've had before. |
@@ -48,10 +42,6 @@ export const AppNavigationDrawer = ({ | |||
footer: <SupportDropdown />, | |||
}; | |||
|
|||
useEffect(() => { |
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 useEffect spotted :p
Really amazing job here. It opened my eyes that we could really remove it 🙌 |
@@ -5,13 +5,24 @@ import { AppHotkeyScope } from '../types/AppHotkeyScope'; | |||
|
|||
import { useSequenceHotkeys } from './useSequenceScopedHotkeys'; | |||
|
|||
export const useGoToHotkeys = (key: Keys, location: string) => { | |||
type GoToHotkeysProps = { |
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.
changing the API to take an object which is better from a dev XP as parameters are named when using the hook
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.
Yes, I fully agree, Object is way more easier to debug and use.
I always to that :)
import { useLocation } from 'react-router-dom'; | ||
import { useRecoilCallback } from 'recoil'; | ||
|
||
export const GotoHotkeysEffectsProvider = () => { |
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'm actually only renaming this file from GoToHokeysEffect
export const useGoToHotkeys = ({ | ||
key, | ||
location, | ||
preNavigateFunction, |
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.
passing a a preNavigationFunction to update the problematic state
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 please explain me how this part is working?
I mean we did avoid useEffect but how's it solving the problem?
@Khaan25 I have made some changes to avoid useEffects. Could you pull the changes and see if the functional behavior looks good? |
Sure, let me try |
@Khaan25 I can't reproduce, what are you doing to get this error? |
I think we are good, I'll merge it :) |
Awarding Khaan25: 150 points 🕹️ Well done! Check out your new contribution on oss.gg/Khaan25 |
I just ran the twenty-front, maybe it's cache or something. Will try again and let you know it gives error again |
This PR fixes #6746