fix: hidden settings menu affects settings layout (#7769)

This PR fixes #6746

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
ZiaCodes
2024-10-22 00:28:01 +05:00
committed by GitHub
parent 4407b1aaa2
commit 5e2df81211
7 changed files with 56 additions and 37 deletions

View File

@ -1,6 +1,6 @@
import { ApolloProvider } from '@/apollo/components/ApolloProvider'; import { ApolloProvider } from '@/apollo/components/ApolloProvider';
import { CommandMenuEffect } from '@/app/effect-components/CommandMenuEffect'; import { CommandMenuEffect } from '@/app/effect-components/CommandMenuEffect';
import { GotoHotkeys } from '@/app/effect-components/GotoHotkeysEffect'; import { GotoHotkeysEffectsProvider } from '@/app/effect-components/GotoHotkeysEffectsProvider';
import { PageChangeEffect } from '@/app/effect-components/PageChangeEffect'; import { PageChangeEffect } from '@/app/effect-components/PageChangeEffect';
import { AuthProvider } from '@/auth/components/AuthProvider'; import { AuthProvider } from '@/auth/components/AuthProvider';
import { ChromeExtensionSidecarEffect } from '@/chrome-extension-sidecar/components/ChromeExtensionSidecarEffect'; import { ChromeExtensionSidecarEffect } from '@/chrome-extension-sidecar/components/ChromeExtensionSidecarEffect';
@ -45,7 +45,7 @@ export const AppRouterProviders = () => {
<StrictMode> <StrictMode>
<PromiseRejectionEffect /> <PromiseRejectionEffect />
<CommandMenuEffect /> <CommandMenuEffect />
<GotoHotkeys /> <GotoHotkeysEffectsProvider />
<PageTitle title={pageTitle} /> <PageTitle title={pageTitle} />
<Outlet /> <Outlet />
</StrictMode> </StrictMode>

View File

@ -6,7 +6,7 @@ export const GoToHotkeyItemEffect = (props: {
}) => { }) => {
const { hotkey, pathToNavigateTo } = props; const { hotkey, pathToNavigateTo } = props;
useGoToHotkeys(hotkey, pathToNavigateTo); useGoToHotkeys({ key: hotkey, location: pathToNavigateTo });
return <></>; return <></>;
}; };

View File

@ -1,19 +0,0 @@
import { GoToHotkeyItemEffect } from '@/app/effect-components/GoToHotkeyItemEffect';
import { useNonSystemActiveObjectMetadataItems } from '@/object-metadata/hooks/useNonSystemActiveObjectMetadataItems';
import { useGoToHotkeys } from '@/ui/utilities/hotkey/hooks/useGoToHotkeys';
export const GotoHotkeys = () => {
const { nonSystemActiveObjectMetadataItems } =
useNonSystemActiveObjectMetadataItems();
// Hardcoded since settings is static
useGoToHotkeys('s', '/settings/profile');
return nonSystemActiveObjectMetadataItems.map((objectMetadataItem) => (
<GoToHotkeyItemEffect
key={`go-to-hokey-item-${objectMetadataItem.id}`}
hotkey={objectMetadataItem.namePlural[0]}
pathToNavigateTo={`/objects/${objectMetadataItem.namePlural}`}
/>
));
};

View File

@ -0,0 +1,37 @@
import { GoToHotkeyItemEffect } from '@/app/effect-components/GoToHotkeyItemEffect';
import { useNonSystemActiveObjectMetadataItems } from '@/object-metadata/hooks/useNonSystemActiveObjectMetadataItems';
import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
import { navigationDrawerExpandedMemorizedState } from '@/ui/navigation/states/navigationDrawerExpandedMemorizedState';
import { navigationMemorizedUrlState } from '@/ui/navigation/states/navigationMemorizedUrlState';
import { useGoToHotkeys } from '@/ui/utilities/hotkey/hooks/useGoToHotkeys';
import { useLocation } from 'react-router-dom';
import { useRecoilCallback } from 'recoil';
export const GotoHotkeysEffectsProvider = () => {
const { nonSystemActiveObjectMetadataItems } =
useNonSystemActiveObjectMetadataItems();
const location = useLocation();
useGoToHotkeys({
key: 's',
location: '/settings/profile',
preNavigateFunction: useRecoilCallback(
({ set }) =>
() => {
set(isNavigationDrawerExpandedState, true);
set(navigationDrawerExpandedMemorizedState, true);
set(navigationMemorizedUrlState, location.pathname + location.search);
},
[location.pathname, location.search],
),
});
return nonSystemActiveObjectMetadataItems.map((objectMetadataItem) => (
<GoToHotkeyItemEffect
key={`go-to-hokey-item-${objectMetadataItem.id}`}
hotkey={objectMetadataItem.namePlural[0]}
pathToNavigateTo={`/objects/${objectMetadataItem.namePlural}`}
/>
));
};

View File

@ -1,5 +1,4 @@
import { useEffect } from 'react'; import { useRecoilValue } from 'recoil';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState'; import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { SettingsNavigationDrawerItems } from '@/settings/components/SettingsNavigationDrawerItems'; import { SettingsNavigationDrawerItems } from '@/settings/components/SettingsNavigationDrawerItems';
@ -9,13 +8,11 @@ import {
NavigationDrawerProps, NavigationDrawerProps,
} from '@/ui/navigation/navigation-drawer/components/NavigationDrawer'; } from '@/ui/navigation/navigation-drawer/components/NavigationDrawer';
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
import { getImageAbsoluteURI } from '~/utils/image/getImageAbsoluteURI'; import { getImageAbsoluteURI } from '~/utils/image/getImageAbsoluteURI';
import { useIsSettingsDrawer } from '@/navigation/hooks/useIsSettingsDrawer'; import { useIsSettingsDrawer } from '@/navigation/hooks/useIsSettingsDrawer';
import { AdvancedSettingsToggle } from '@/ui/navigation/link/components/AdvancedSettingsToggle'; import { AdvancedSettingsToggle } from '@/ui/navigation/link/components/AdvancedSettingsToggle';
import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
import { MainNavigationDrawerItems } from './MainNavigationDrawerItems'; import { MainNavigationDrawerItems } from './MainNavigationDrawerItems';
export type AppNavigationDrawerProps = { export type AppNavigationDrawerProps = {
@ -25,11 +22,8 @@ export type AppNavigationDrawerProps = {
export const AppNavigationDrawer = ({ export const AppNavigationDrawer = ({
className, className,
}: AppNavigationDrawerProps) => { }: AppNavigationDrawerProps) => {
const isMobile = useIsMobile();
const isSettingsDrawer = useIsSettingsDrawer(); const isSettingsDrawer = useIsSettingsDrawer();
const setIsNavigationDrawerExpanded = useSetRecoilState(
isNavigationDrawerExpandedState,
);
const currentWorkspace = useRecoilValue(currentWorkspaceState); const currentWorkspace = useRecoilValue(currentWorkspaceState);
const drawerProps: NavigationDrawerProps = isSettingsDrawer const drawerProps: NavigationDrawerProps = isSettingsDrawer
@ -48,10 +42,6 @@ export const AppNavigationDrawer = ({
footer: <SupportDropdown />, footer: <SupportDropdown />,
}; };
useEffect(() => {
setIsNavigationDrawerExpanded(!isMobile);
}, [isMobile, setIsNavigationDrawerExpanded]);
return ( return (
<NavigationDrawer <NavigationDrawer
className={className} className={className}

View File

@ -1,6 +1,6 @@
import { fireEvent, renderHook } from '@testing-library/react';
import { act } from 'react-dom/test-utils'; import { act } from 'react-dom/test-utils';
import { MemoryRouter, useLocation } from 'react-router-dom'; import { MemoryRouter, useLocation } from 'react-router-dom';
import { fireEvent, renderHook } from '@testing-library/react';
import { RecoilRoot } from 'recoil'; import { RecoilRoot } from 'recoil';
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope'; import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
@ -23,7 +23,7 @@ const renderHookConfig = {
describe('useGoToHotkeys', () => { describe('useGoToHotkeys', () => {
it('should navigate on hotkey trigger', () => { it('should navigate on hotkey trigger', () => {
const { result } = renderHook(() => { const { result } = renderHook(() => {
useGoToHotkeys('a', '/three'); useGoToHotkeys({ key: 'a', location: '/three' });
const setHotkeyScope = useSetHotkeyScope(); const setHotkeyScope = useSetHotkeyScope();

View File

@ -5,13 +5,24 @@ import { AppHotkeyScope } from '../types/AppHotkeyScope';
import { useSequenceHotkeys } from './useSequenceScopedHotkeys'; import { useSequenceHotkeys } from './useSequenceScopedHotkeys';
export const useGoToHotkeys = (key: Keys, location: string) => { type GoToHotkeysProps = {
key: Keys;
location: string;
preNavigateFunction?: () => void;
};
export const useGoToHotkeys = ({
key,
location,
preNavigateFunction,
}: GoToHotkeysProps) => {
const navigate = useNavigate(); const navigate = useNavigate();
useSequenceHotkeys( useSequenceHotkeys(
'g', 'g',
key, key,
() => { () => {
preNavigateFunction?.();
navigate(location); navigate(location);
}, },
AppHotkeyScope.Goto, AppHotkeyScope.Goto,