f44f42e9a0
This PR address advanced toggle alignment, especially the left yellow dot placement. In other advanced settings navigation drawer, the dot appears -20px to left, while this was not the case for advanced toggle's dot. Matched the height and paddings to that of NavigationDrawerItem. @Bonapara FYI before: <img width="399" alt="Screenshot 2025-03-13 at 15 49 21" src="https://github.com/user-attachments/assets/6dd60b3a-1b2e-43a0-ad28-dc44437460ab" /> after: <img width="401" alt="Screenshot 2025-03-13 at 15 47 43" src="https://github.com/user-attachments/assets/86e51b07-e84a-413a-8a49-1820c165dc68" /> --------- Co-authored-by: Charles Bochet <charles@twenty.com>
115 lines
4.4 KiB
TypeScript
115 lines
4.4 KiB
TypeScript
import { AdvancedSettingsWrapper } from '@/settings/components/AdvancedSettingsWrapper';
|
|
import { SettingsNavigationDrawerItem } from '@/settings/components/SettingsNavigationDrawerItem';
|
|
import {
|
|
SettingsNavigationItem,
|
|
SettingsNavigationSection,
|
|
useSettingsNavigationItems,
|
|
} from '@/settings/hooks/useSettingsNavigationItems';
|
|
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 { getNavigationSubItemLeftAdornment } from '@/ui/navigation/navigation-drawer/utils/getNavigationSubItemLeftAdornment';
|
|
import { matchPath, resolvePath, useLocation } from 'react-router-dom';
|
|
import { getSettingsPath } from '~/utils/navigation/getSettingsPath';
|
|
|
|
export const SettingsNavigationDrawerItems = () => {
|
|
const settingsNavigationItems: SettingsNavigationSection[] =
|
|
useSettingsNavigationItems();
|
|
|
|
const currentPathName = useLocation().pathname;
|
|
|
|
const getSelectedIndexForSubItems = (subItems: SettingsNavigationItem[]) => {
|
|
return subItems.findIndex((subItem) => {
|
|
const href = subItem.path ? getSettingsPath(subItem.path) : '';
|
|
const pathName = resolvePath(href).pathname;
|
|
|
|
return matchPath(
|
|
{
|
|
path: pathName,
|
|
end: subItem.matchSubPages === false,
|
|
},
|
|
currentPathName,
|
|
);
|
|
});
|
|
};
|
|
|
|
return (
|
|
<>
|
|
{settingsNavigationItems.map((section) => {
|
|
const allItemsHidden = section.items.every((item) => item.isHidden);
|
|
if (allItemsHidden) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<NavigationDrawerSection key={section.label}>
|
|
{section.isAdvanced ? (
|
|
<AdvancedSettingsWrapper hideDot>
|
|
<NavigationDrawerSectionTitle label={section.label} />
|
|
</AdvancedSettingsWrapper>
|
|
) : (
|
|
<NavigationDrawerSectionTitle label={section.label} />
|
|
)}
|
|
{section.items.map((item, index) => {
|
|
const subItems = item.subItems;
|
|
if (Array.isArray(subItems) && subItems.length > 0) {
|
|
const selectedSubItemIndex =
|
|
getSelectedIndexForSubItems(subItems);
|
|
|
|
return (
|
|
<NavigationDrawerItemGroup
|
|
key={item.path || `group-${index}`}
|
|
>
|
|
<SettingsNavigationDrawerItem
|
|
item={item}
|
|
subItemState={
|
|
item.indentationLevel
|
|
? getNavigationSubItemLeftAdornment({
|
|
arrayLength: section.items.length,
|
|
index,
|
|
selectedIndex: selectedSubItemIndex,
|
|
})
|
|
: undefined
|
|
}
|
|
/>
|
|
{subItems.map((subItem, subIndex) => (
|
|
<SettingsNavigationDrawerItem
|
|
key={subItem.path || `subitem-${subIndex}`}
|
|
item={subItem}
|
|
subItemState={
|
|
subItem.indentationLevel
|
|
? getNavigationSubItemLeftAdornment({
|
|
arrayLength: subItems.length,
|
|
index: subIndex,
|
|
selectedIndex: selectedSubItemIndex,
|
|
})
|
|
: undefined
|
|
}
|
|
/>
|
|
))}
|
|
</NavigationDrawerItemGroup>
|
|
);
|
|
}
|
|
return (
|
|
<SettingsNavigationDrawerItem
|
|
key={item.path || `item-${index}`}
|
|
item={item}
|
|
subItemState={
|
|
item.indentationLevel
|
|
? getNavigationSubItemLeftAdornment({
|
|
arrayLength: section.items.length,
|
|
index,
|
|
selectedIndex: index,
|
|
})
|
|
: undefined
|
|
}
|
|
/>
|
|
);
|
|
})}
|
|
</NavigationDrawerSection>
|
|
);
|
|
})}
|
|
</>
|
|
);
|
|
};
|