Skip to content

Commit

Permalink
Merge branch 'main' into TWNTY-6808
Browse files Browse the repository at this point in the history
  • Loading branch information
bosiraphael committed Oct 2, 2024
2 parents 159b471 + 23001ac commit ce1f4d0
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useRecoilValue, useSetRecoilState } from 'recoil';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { SettingsNavigationDrawerItems } from '@/settings/components/SettingsNavigationDrawerItems';
import { SupportDropdown } from '@/support/components/SupportDropdown';
import { GithubVersionLink } from '@/ui/navigation/link/components/GithubVersionLink';
import {
NavigationDrawer,
NavigationDrawerProps,
Expand All @@ -16,6 +15,7 @@ import { getImageAbsoluteURI } from '~/utils/image/getImageAbsoluteURI';
import { useIsSettingsPage } from '../hooks/useIsSettingsPage';
import { currentMobileNavigationDrawerState } from '../states/currentMobileNavigationDrawerState';

import { AdvancedSettingsToggle } from '@/ui/navigation/link/components/AdvancedSettingsToggle';
import { MainNavigationDrawerItems } from './MainNavigationDrawerItems';

export type AppNavigationDrawerProps = {
Expand Down Expand Up @@ -44,7 +44,7 @@ export const AppNavigationDrawer = ({
isSubMenu: true,
title: 'Exit Settings',
children: <SettingsNavigationDrawerItems />,
footer: <GithubVersionLink />,
footer: <AdvancedSettingsToggle />,
}
: {
logo:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ import {
IconMail,
IconRocket,
IconSettings,
IconTool,
IconUserCircle,
IconUsers,
MAIN_COLORS,
} from 'twenty-ui';

import { useAuth } from '@/auth/hooks/useAuth';
import { billingState } from '@/client-config/states/billingState';
import { SettingsNavigationDrawerItem } from '@/settings/components/SettingsNavigationDrawerItem';
import { useExpandedHeightAnimation } from '@/settings/hooks/useExpandedHeightAnimation';
import { getSettingsPagePath } from '@/settings/utils/getSettingsPagePath';
import { SettingsPath } from '@/types/SettingsPath';
import {
Expand All @@ -29,10 +32,38 @@ import {
import { NavigationDrawerItemGroup } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerItemGroup';
import { NavigationDrawerSection } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSection';
import { NavigationDrawerSectionTitle } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSectionTitle';
import { isAdvancedModeEnabledState } from '@/ui/navigation/navigation-drawer/states/isAdvancedModeEnabledState';
import { getNavigationSubItemState } from '@/ui/navigation/navigation-drawer/utils/getNavigationSubItemState';
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import styled from '@emotion/styled';
import { AnimatePresence, motion } from 'framer-motion';
import { matchPath, resolvePath, useLocation } from 'react-router-dom';

const StyledNavigationDrawerSection = styled(NavigationDrawerSection)<{
withLeftMargin?: boolean;
}>`
margin-left: ${({ withLeftMargin, theme }) =>
withLeftMargin && theme.spacing(5)};
margin-top: ${({ theme }) => theme.spacing(3)};
`;

const StyledIconContainer = styled.div`
border-right: 1px solid ${MAIN_COLORS.yellow};
display: flex;
margin-top: ${({ theme }) => theme.spacing(5)};
width: 16px;
`;

const StyledDeveloperSection = styled.div`
display: flex;
width: 100%;
gap: ${({ theme }) => theme.spacing(1)};
`;

const StyledIconTool = styled(IconTool)`
margin-right: ${({ theme }) => theme.spacing(0.5)};
`;

type SettingsNavigationItem = {
label: string;
path: SettingsPath;
Expand All @@ -42,6 +73,10 @@ type SettingsNavigationItem = {
};

export const SettingsNavigationDrawerItems = () => {
const isAdvancedModeEnabled = useRecoilValue(isAdvancedModeEnabledState);
const { contentRef, motionAnimationVariants } = useExpandedHeightAnimation(
isAdvancedModeEnabled,
);
const { signOut } = useAuth();

const billing = useRecoilValue(billingState);
Expand Down Expand Up @@ -88,7 +123,7 @@ export const SettingsNavigationDrawerItems = () => {

return (
<>
<NavigationDrawerSection>
<StyledNavigationDrawerSection withLeftMargin>
<NavigationDrawerSectionTitle label="User" />
<SettingsNavigationDrawerItem
label="Profile"
Expand Down Expand Up @@ -121,8 +156,8 @@ export const SettingsNavigationDrawerItems = () => {
/>
))}
</NavigationDrawerItemGroup>
</NavigationDrawerSection>
<NavigationDrawerSection>
</StyledNavigationDrawerSection>
<StyledNavigationDrawerSection withLeftMargin>
<NavigationDrawerSectionTitle label="Workspace" />
<SettingsNavigationDrawerItem
label="General"
Expand All @@ -147,18 +182,6 @@ export const SettingsNavigationDrawerItems = () => {
Icon={IconHierarchy2}
matchSubPages
/>
<SettingsNavigationDrawerItem
label="Developers"
path={SettingsPath.Developers}
Icon={IconCode}
/>
{isFunctionSettingsEnabled && (
<SettingsNavigationDrawerItem
label="Functions"
path={SettingsPath.ServerlessFunctions}
Icon={IconFunction}
/>
)}
<SettingsNavigationDrawerItem
label="Integrations"
path={SettingsPath.Integrations}
Expand All @@ -171,8 +194,40 @@ export const SettingsNavigationDrawerItems = () => {
Icon={IconCode}
/>
)}
</NavigationDrawerSection>
<NavigationDrawerSection>
</StyledNavigationDrawerSection>
<AnimatePresence>
{isAdvancedModeEnabled && (
<motion.div
ref={contentRef}
initial="initial"
animate="animate"
exit="exit"
variants={motionAnimationVariants}
>
<StyledDeveloperSection>
<StyledIconContainer>
<StyledIconTool size={12} color={MAIN_COLORS.yellow} />
</StyledIconContainer>
<StyledNavigationDrawerSection>
<NavigationDrawerSectionTitle label="Developers" />
<SettingsNavigationDrawerItem
label="API & Webhooks"
path={SettingsPath.Developers}
Icon={IconCode}
/>
{isFunctionSettingsEnabled && (
<SettingsNavigationDrawerItem
label="Functions"
path={SettingsPath.ServerlessFunctions}
Icon={IconFunction}
/>
)}
</StyledNavigationDrawerSection>
</StyledDeveloperSection>
</motion.div>
)}
</AnimatePresence>
<StyledNavigationDrawerSection withLeftMargin>
<NavigationDrawerSectionTitle label="Other" />
<SettingsNavigationDrawerItem
label="Releases"
Expand All @@ -184,7 +239,7 @@ export const SettingsNavigationDrawerItems = () => {
onClick={signOut}
Icon={IconDoorEnter}
/>
</NavigationDrawerSection>
</StyledNavigationDrawerSection>
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useEffect, useRef, useState } from 'react';
import { isDefined } from 'twenty-ui';

const transitionValues = {
transition: {
opactity: { duration: 0.2 },
height: { duration: 0.4 },
},
transitionEnd: {
overflow: 'visible',
},
};

const commonStyles = {
opacity: 0,
height: 0,
overflow: 'hidden',
...transitionValues,
};

const advancedSectionAnimationConfig = (
isExpanded: boolean,
measuredHeight: number,
) => ({
initial: {
...commonStyles,
},
animate: {
opacity: 1,
height: isExpanded ? measuredHeight : 0,
...transitionValues,
overflow: 'hidden',
},
exit: {
...commonStyles,
},
});

export const useExpandedHeightAnimation = (isExpanded: boolean) => {
const contentRef = useRef<HTMLDivElement>(null);
const [measuredHeight, setMeasuredHeight] = useState(0);

useEffect(() => {
if (isDefined(contentRef.current)) {
setMeasuredHeight(contentRef.current.scrollHeight);
}
}, [isExpanded]);

return {
contentRef,
measuredHeight,
motionAnimationVariants: advancedSectionAnimationConfig(
isExpanded,
measuredHeight,
),
};
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { css, Global, useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { AnimatePresence, LayoutGroup, motion } from 'framer-motion';
import { Outlet } from 'react-router-dom';
import { AuthModal } from '@/auth/components/AuthModal';
import { CommandMenu } from '@/command-menu/components/CommandMenu';
import { AppErrorBoundary } from '@/error-handler/components/AppErrorBoundary';
import { KeyboardShortcutMenu } from '@/keyboard-shortcut-menu/components/KeyboardShortcutMenu';
Expand All @@ -14,7 +11,10 @@ import { useShowAuthModal } from '@/ui/layout/hooks/useShowAuthModal';
import { DESKTOP_NAV_DRAWER_WIDTHS } from '@/ui/navigation/navigation-drawer/constants/DesktopNavDrawerWidths';
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
import { useScreenSize } from '@/ui/utilities/screen-size/hooks/useScreenSize';
import { AuthModal } from '@/auth/components/AuthModal';
import { css, Global, useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { AnimatePresence, LayoutGroup, motion } from 'framer-motion';
import { Outlet } from 'react-router-dom';

const StyledLayout = styled.div`
background: ${({ theme }) => theme.background.noisy};
Expand Down Expand Up @@ -85,7 +85,7 @@ export const DefaultLayout = () => {
? (windowsWidth -
(OBJECT_SETTINGS_WIDTH +
DESKTOP_NAV_DRAWER_WIDTHS.menu +
64)) /
88)) /
2
: 0,
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Toggle } from '@/ui/input/components/Toggle';
import { isAdvancedModeEnabledState } from '@/ui/navigation/navigation-drawer/states/isAdvancedModeEnabledState';
import styled from '@emotion/styled';
import { useRecoilState } from 'recoil';
import { IconTool, MAIN_COLORS } from 'twenty-ui';

const StyledContainer = styled.div`
align-items: center;
display: flex;
width: 100%;
gap: ${({ theme }) => theme.spacing(2)};
`;

const StyledText = styled.span`
color: ${({ theme }) => theme.font.color.secondary};
font-size: ${({ theme }) => theme.font.size.sm};
font-weight: ${({ theme }) => theme.font.weight.medium};
padding: ${({ theme }) => theme.spacing(1)};
`;

const StyledIconContainer = styled.div`
border-right: 1px solid ${MAIN_COLORS.yellow};
display: flex;
height: 16px;
`;

const StyledToggleContainer = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
`;

const StyledIconTool = styled(IconTool)`
margin-right: ${({ theme }) => theme.spacing(0.5)};
`;

export const AdvancedSettingsToggle = () => {
const [isAdvancedModeEnabled, setIsAdvancedModeEnabled] = useRecoilState(
isAdvancedModeEnabledState,
);

const onChange = (newValue: boolean) => {
setIsAdvancedModeEnabled(newValue);
};

return (
<StyledContainer>
<StyledIconContainer>
<StyledIconTool size={12} color={MAIN_COLORS.yellow} />
</StyledIconContainer>
<StyledToggleContainer>
<StyledText>Advanced</StyledText>
<Toggle
onChange={onChange}
color={MAIN_COLORS.yellow}
value={isAdvancedModeEnabled}
/>
</StyledToggleContainer>
</StyledContainer>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const StyledContainer = styled.div<{ isSubMenu?: boolean }>`
${({ isSubMenu, theme }) =>
isSubMenu
? css`
padding-left: ${theme.spacing(0)};
padding-right: ${theme.spacing(8)};
`
: ''}
Expand All @@ -48,13 +49,12 @@ const StyledContainer = styled.div<{ isSubMenu?: boolean }>`
width: 100%;
}
`;

const StyledItemsContainer = styled.div`
const StyledItemsContainer = styled.div<{ isSubMenu?: boolean }>`
display: flex;
flex-direction: column;
gap: ${({ theme }) => theme.spacing(3)};
margin-bottom: auto;
overflow-y: auto;
${({ isSubMenu, theme }) => !isSubMenu && `gap: ${theme.spacing(3)}`}
`;

export const NavigationDrawer = ({
Expand Down Expand Up @@ -111,7 +111,9 @@ export const NavigationDrawer = ({
showCollapseButton={isHovered}
/>
)}
<StyledItemsContainer>{children}</StyledItemsContainer>
<StyledItemsContainer isSubMenu={isSubMenu}>
{children}
</StyledItemsContainer>
{footer}
</StyledContainer>
</StyledAnimatedContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const StyledContainer = styled.div`
flex-direction: row;
height: ${({ theme }) => theme.spacing(8)};
justify-content: space-between;
margin-left: ${({ theme }) => theme.spacing(5)};
`;

export const NavigationDrawerBackButton = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const StyledSection = styled.div`
display: flex;
flex-direction: column;
gap: ${({ theme }) => theme.betweenSiblingsGap};
width: 100%;
`;

export { StyledSection as NavigationDrawerSection };
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { atom } from 'recoil';
import { localStorageEffect } from '~/utils/recoil-effects';

export const isAdvancedModeEnabledState = atom<boolean>({
key: 'isAdvancedModeEnabledAtom',
default: false,
effects: [localStorageEffect()],
});
Loading

0 comments on commit ce1f4d0

Please sign in to comment.