Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Project settings sidebar groups

Blue Moused52fc26c7a61
diff --git a/web/app/pages/Project/Settings/ProjectSettings.tsx b/web/app/pages/Project/Settings/ProjectSettings.tsx
index e51cbf45d..2a5f766ec 100644
--- a/web/app/pages/Project/Settings/ProjectSettings.tsx
+++ b/web/app/pages/Project/Settings/ProjectSettings.tsx
@@ -71,6 +71,7 @@ import ProjectAlerts from './Alerts/ProjectAlertsView'
import NotificationChannels from '~/components/NotificationChannels/NotificationChannels'
import DataImportTab from './components/DataImportTab'
import ProxyDomainsTab from './components/ProxyDomainsTab'
+import SettingsSidebar, { SettingsTabConfig } from './SettingsSidebar'
const MAX_NAME_LENGTH = 50
const MAX_ORIGINS_LENGTH = 300
@@ -372,122 +373,124 @@ const ProjectSettings = () => {
| 'proxy'
| 'danger'
- const tabs = useMemo(
+ const tabs = useMemo<SettingsTabConfig<SettingsTab>[]>(
() =>
- [
- {
- id: 'general',
- label: t('project.settings.tabs.general'),
- description: t('project.settings.tabs.generalDesc'),
- icon: SlidersHorizontalIcon,
- iconColor: 'text-blue-500',
- visible: true,
- },
- {
- id: 'access',
- label: t('project.settings.tabs.access'),
- description: t('project.settings.tabs.accessDesc'),
- icon: LockIcon,
- iconColor: 'text-amber-500',
- visible: true,
- },
- {
- id: 'shields',
- label: t('project.settings.tabs.shields'),
- description: t('project.settings.tabs.shieldsDesc'),
- icon: ShieldIcon,
- iconColor: 'text-emerald-500',
- visible: true,
- },
- {
- id: 'captcha',
- label: t('project.settings.tabs.captcha'),
- description: t('project.settings.tabs.captchaDesc'),
- icon: ShieldCheckIcon,
- iconColor: 'text-teal-500',
- visible: true,
- },
- {
- id: 'integrations',
- label: t('project.settings.tabs.integrations'),
- description: t('project.settings.tabs.integrationsDesc'),
- icon: PuzzlePieceIcon,
- iconColor: 'text-purple-500',
- visible: !isSelfhosted,
- },
- {
- id: 'alerts',
- label: t('project.settings.tabs.alerts'),
- description: t('project.settings.tabs.alertsDesc'),
- icon: BellRingingIcon,
- iconColor: 'text-cyan-500',
- visible: !isSelfhosted && project?.role === 'owner',
- },
- {
- id: 'channels',
- label: t('project.settings.tabs.channels'),
- description: t('project.settings.tabs.channelsDesc'),
- icon: BellRingingIcon,
- iconColor: 'text-pink-500',
- visible: !isSelfhosted && project?.role === 'owner',
- },
- {
- id: 'revenue',
- label: t('project.settings.tabs.revenue'),
- description: t('project.settings.tabs.revenueDesc'),
- icon: CurrencyDollarIcon,
- iconColor: 'text-green-500',
- visible: !isSelfhosted,
- },
- {
- id: 'emails',
- label: t('project.settings.tabs.emails'),
- description: t('project.settings.tabs.emailsDesc'),
- icon: EnvelopeIcon,
- iconColor: 'text-sky-500',
- visible: !isSelfhosted,
- },
- {
- id: 'people',
- label: t('project.settings.tabs.people'),
- description: t('project.settings.tabs.peopleDesc'),
- icon: UserCircleIcon,
- iconColor: 'text-indigo-500',
- visible: true,
- },
- {
- id: 'import',
- label: t('project.settings.tabs.import'),
- description: t('project.settings.tabs.importDesc'),
- icon: DownloadIcon,
- iconColor: 'text-cyan-500',
- visible: true,
- },
- {
- id: 'proxy',
- label: t('project.settings.tabs.proxy'),
- description: t('project.settings.tabs.proxyDesc'),
- icon: GlobeIcon,
- iconColor: 'text-fuchsia-500',
- visible: !isSelfhosted,
- },
- {
- id: 'annotations',
- label: t('project.settings.tabs.annotations'),
- description: t('project.settings.tabs.annotationsDesc'),
- icon: NoteIcon,
- iconColor: 'text-orange-500',
- visible: true,
- },
- {
- id: 'danger',
- label: t('project.settings.tabs.danger'),
- description: t('project.settings.tabs.dangerDesc'),
- icon: WarningOctagonIcon,
- iconColor: 'text-red-500',
- visible: project?.role === 'owner',
- },
- ].filter((tab) => tab.visible),
+ (
+ [
+ {
+ id: 'general',
+ label: t('project.settings.tabs.general'),
+ description: t('project.settings.tabs.generalDesc'),
+ icon: SlidersHorizontalIcon,
+ iconColor: 'text-blue-500',
+ visible: true,
+ },
+ {
+ id: 'access',
+ label: t('project.settings.tabs.access'),
+ description: t('project.settings.tabs.accessDesc'),
+ icon: LockIcon,
+ iconColor: 'text-amber-500',
+ visible: true,
+ },
+ {
+ id: 'shields',
+ label: t('project.settings.tabs.shields'),
+ description: t('project.settings.tabs.shieldsDesc'),
+ icon: ShieldIcon,
+ iconColor: 'text-emerald-500',
+ visible: true,
+ },
+ {
+ id: 'captcha',
+ label: t('project.settings.tabs.captcha'),
+ description: t('project.settings.tabs.captchaDesc'),
+ icon: ShieldCheckIcon,
+ iconColor: 'text-teal-500',
+ visible: true,
+ },
+ {
+ id: 'integrations',
+ label: t('project.settings.tabs.integrations'),
+ description: t('project.settings.tabs.integrationsDesc'),
+ icon: PuzzlePieceIcon,
+ iconColor: 'text-purple-500',
+ visible: !isSelfhosted,
+ },
+ {
+ id: 'alerts',
+ label: t('project.settings.tabs.alerts'),
+ description: t('project.settings.tabs.alertsDesc'),
+ icon: BellRingingIcon,
+ iconColor: 'text-cyan-500',
+ visible: !isSelfhosted && project?.role === 'owner',
+ },
+ {
+ id: 'channels',
+ label: t('project.settings.tabs.channels'),
+ description: t('project.settings.tabs.channelsDesc'),
+ icon: BellRingingIcon,
+ iconColor: 'text-pink-500',
+ visible: !isSelfhosted && project?.role === 'owner',
+ },
+ {
+ id: 'revenue',
+ label: t('project.settings.tabs.revenue'),
+ description: t('project.settings.tabs.revenueDesc'),
+ icon: CurrencyDollarIcon,
+ iconColor: 'text-green-500',
+ visible: !isSelfhosted,
+ },
+ {
+ id: 'emails',
+ label: t('project.settings.tabs.emails'),
+ description: t('project.settings.tabs.emailsDesc'),
+ icon: EnvelopeIcon,
+ iconColor: 'text-sky-500',
+ visible: !isSelfhosted,
+ },
+ {
+ id: 'people',
+ label: t('project.settings.tabs.people'),
+ description: t('project.settings.tabs.peopleDesc'),
+ icon: UserCircleIcon,
+ iconColor: 'text-indigo-500',
+ visible: true,
+ },
+ {
+ id: 'import',
+ label: t('project.settings.tabs.import'),
+ description: t('project.settings.tabs.importDesc'),
+ icon: DownloadIcon,
+ iconColor: 'text-cyan-500',
+ visible: true,
+ },
+ {
+ id: 'proxy',
+ label: t('project.settings.tabs.proxy'),
+ description: t('project.settings.tabs.proxyDesc'),
+ icon: GlobeIcon,
+ iconColor: 'text-fuchsia-500',
+ visible: !isSelfhosted,
+ },
+ {
+ id: 'annotations',
+ label: t('project.settings.tabs.annotations'),
+ description: t('project.settings.tabs.annotationsDesc'),
+ icon: NoteIcon,
+ iconColor: 'text-orange-500',
+ visible: true,
+ },
+ {
+ id: 'danger',
+ label: t('project.settings.tabs.danger'),
+ description: t('project.settings.tabs.dangerDesc'),
+ icon: WarningOctagonIcon,
+ iconColor: 'text-red-500',
+ visible: project?.role === 'owner',
+ },
+ ] as const satisfies readonly SettingsTabConfig<SettingsTab>[]
+ ).filter((tab) => tab.visible) as SettingsTabConfig<SettingsTab>[],
[t, project?.role],
)
@@ -960,38 +963,11 @@ const ProjectSettings = () => {
</div>
<aside className='hidden w-56 shrink-0 md:block'>
- <nav className='flex flex-col space-y-0.5' aria-label='Sidebar'>
- {_map(tabs, (tab) => {
- const isCurrent = tab.id === activeTab
- const Icon = tab.icon
-
- return (
- <button
- key={tab.id}
- type='button'
- onClick={() => setActiveTab(tab.id as typeof activeTab)}
- className={cx(
- 'group flex items-center rounded-md px-3 py-2 text-left text-sm text-gray-900 transition-colors',
- {
- 'bg-gray-200 font-semibold dark:bg-slate-900 dark:text-gray-50':
- isCurrent,
- 'hover:bg-gray-200 dark:text-gray-200 dark:hover:bg-slate-900 dark:hover:text-gray-50':
- !isCurrent,
- },
- )}
- aria-current={isCurrent ? 'page' : undefined}
- >
- <Icon
- className={cx('mr-2 size-4 shrink-0 transition-colors', {
- 'text-gray-900 dark:text-gray-50': isCurrent,
- 'text-gray-600 dark:text-gray-300': !isCurrent,
- })}
- />
- <span className='truncate'>{tab.label}</span>
- </button>
- )
- })}
- </nav>
+ <SettingsSidebar
+ tabs={tabs}
+ activeTab={activeTab}
+ onTabChange={(tabId) => setActiveTab(tabId)}
+ />
</aside>
<section className='flex-1'>
diff --git a/web/app/pages/Project/Settings/SettingsSidebar.tsx b/web/app/pages/Project/Settings/SettingsSidebar.tsx
new file mode 100644
index 000000000..efdb73930
--- /dev/null
+++ b/web/app/pages/Project/Settings/SettingsSidebar.tsx
@@ -0,0 +1,277 @@
+import _map from 'lodash/map'
+import { CaretDownIcon, CaretRightIcon, Icon } from '@phosphor-icons/react'
+import { memo, useEffect, useMemo, useRef, useState } from 'react'
+import { useTranslation } from 'react-i18next'
+
+import { Text } from '~/ui/Text'
+import { cn } from '~/utils/generic'
+
+const SIDEBAR_GROUPS_KEY = 'project-settings-sidebar-groups'
+
+const getGroupExpandedState = (groupId: string): boolean => {
+ if (typeof window === 'undefined') return true
+ try {
+ const stored = localStorage.getItem(SIDEBAR_GROUPS_KEY)
+ if (stored) {
+ const states = JSON.parse(stored)
+ return states[groupId] !== false
+ }
+ } catch {
+ // Ignore parse errors
+ }
+ return true
+}
+
+const setGroupExpandedState = (groupId: string, isExpanded: boolean) => {
+ if (typeof window === 'undefined') return
+ try {
+ const stored = localStorage.getItem(SIDEBAR_GROUPS_KEY)
+ const states = stored ? JSON.parse(stored) : {}
+ states[groupId] = isExpanded
+ localStorage.setItem(SIDEBAR_GROUPS_KEY, JSON.stringify(states))
+ } catch {
+ // Ignore errors
+ }
+}
+
+export interface SettingsTabConfig<TabId extends string = string> {
+ id: TabId
+ label: string
+ description: string
+ icon: Icon
+ iconColor: string
+ visible: boolean
+}
+
+interface SettingsTabGroup<TabId extends string = string> {
+ id: string
+ label: string
+ tabIds: TabId[]
+}
+
+interface SettingsSidebarProps<TabId extends string> {
+ tabs: SettingsTabConfig<TabId>[]
+ activeTab: TabId
+ onTabChange: (tabId: TabId) => void
+}
+
+const TabButton = <TabId extends string>({
+ tab,
+ isCurrent,
+ onClick,
+}: {
+ tab: SettingsTabConfig<TabId>
+ isCurrent: boolean
+ onClick: () => void
+}) => {
+ const TabIcon = tab.icon
+
+ return (
+ <button
+ type='button'
+ onClick={onClick}
+ className={cn(
+ 'group flex items-center gap-1.5 rounded-md px-2.5 py-2 text-left transition-colors',
+ {
+ 'bg-gray-100 dark:bg-slate-900': isCurrent,
+ 'hover:bg-gray-100 dark:hover:bg-slate-900/60': !isCurrent,
+ },
+ )}
+ aria-current={isCurrent ? 'page' : undefined}
+ >
+ <TabIcon
+ className={cn('size-4 shrink-0', tab.iconColor)}
+ weight='duotone'
+ aria-hidden='true'
+ />
+ <Text as='span' size='sm' weight='medium' truncate className='max-w-full'>
+ {tab.label}
+ </Text>
+ </button>
+ )
+}
+
+const CollapsibleGroup = <TabId extends string>({
+ group,
+ tabs,
+ activeTab,
+ onTabChange,
+}: {
+ group: SettingsTabGroup<TabId>
+ tabs: SettingsTabConfig<TabId>[]
+ activeTab: TabId
+ onTabChange: (tabId: TabId) => void
+}) => {
+ const [isExpanded, setIsExpanded] = useState(() =>
+ getGroupExpandedState(group.id),
+ )
+
+ const hasActiveTab = useMemo(
+ () => tabs.some((tab) => tab.id === activeTab),
+ [tabs, activeTab],
+ )
+
+ const prevHasActiveTab = useRef(hasActiveTab)
+
+ useEffect(() => {
+ if (hasActiveTab && !prevHasActiveTab.current && !isExpanded) {
+ setIsExpanded(true)
+ setGroupExpandedState(group.id, true)
+ }
+ prevHasActiveTab.current = hasActiveTab
+ }, [hasActiveTab, group.id]) // eslint-disable-line react-hooks/exhaustive-deps
+
+ return (
+ <div className='mb-1'>
+ <button
+ type='button'
+ onClick={() => {
+ const newValue = !isExpanded
+ setIsExpanded(newValue)
+ setGroupExpandedState(group.id, newValue)
+ }}
+ className='group flex w-full items-center justify-between rounded-md px-2 py-1.5 text-left transition-colors hover:bg-gray-100 dark:hover:bg-slate-900/60'
+ >
+ <Text
+ as='span'
+ size='xs'
+ colour='secondary'
+ weight='semibold'
+ truncate
+ className='max-w-full'
+ >
+ {group.label}
+ </Text>
+ {isExpanded ? (
+ <CaretDownIcon className='size-3.5 text-gray-400' />
+ ) : (
+ <CaretRightIcon className='size-3.5 text-gray-400' />
+ )}
+ </button>
+
+ <div
+ className={cn(
+ 'overflow-hidden transition-all duration-200 ease-in-out',
+ {
+ 'max-h-96 opacity-100': isExpanded,
+ 'max-h-0 opacity-0': !isExpanded,
+ },
+ )}
+ >
+ <nav
+ className='mt-1 flex flex-col gap-0.5 pl-2'
+ aria-label={group.label}
+ >
+ {_map(tabs, (tab) => (
+ <TabButton
+ key={tab.id}
+ tab={tab}
+ isCurrent={tab.id === activeTab}
+ onClick={() => onTabChange(tab.id)}
+ />
+ ))}
+ </nav>
+ </div>
+ </div>
+ )
+}
+
+const SettingsSidebar = <TabId extends string>({
+ tabs,
+ activeTab,
+ onTabChange,
+}: SettingsSidebarProps<TabId>) => {
+ const { t } = useTranslation('common')
+
+ const groupsConfig = useMemo<SettingsTabGroup<TabId>[]>(
+ () => [
+ {
+ id: 'general',
+ label: t('project.settings.sidebarGroups.general'),
+ tabIds: ['general', 'access', 'people'] as TabId[],
+ },
+ {
+ id: 'protection',
+ label: t('project.settings.sidebarGroups.protection'),
+ tabIds: ['shields', 'captcha'] as TabId[],
+ },
+ {
+ id: 'data',
+ label: t('project.settings.sidebarGroups.data'),
+ tabIds: ['annotations', 'revenue', 'import'] as TabId[],
+ },
+ {
+ id: 'integrations',
+ label: t('project.settings.sidebarGroups.integrations'),
+ tabIds: ['integrations', 'proxy'] as TabId[],
+ },
+ {
+ id: 'notifications',
+ label: t('project.settings.sidebarGroups.notifications'),
+ tabIds: ['alerts', 'channels', 'emails'] as TabId[],
+ },
+ ],
+ [t],
+ )
+
+ const visibleTabsById = useMemo(() => {
+ const map = new Map<TabId, SettingsTabConfig<TabId>>()
+ tabs.forEach((tab) => map.set(tab.id, tab))
+ return map
+ }, [tabs])
+
+ const groups = useMemo(
+ () =>
+ groupsConfig
+ .map((group) => ({
+ ...group,
+ tabs: group.tabIds
+ .map((id) => visibleTabsById.get(id))
+ .filter((tab): tab is SettingsTabConfig<TabId> => Boolean(tab)),
+ }))
+ .filter((group) => group.tabs.length > 0),
+ [groupsConfig, visibleTabsById],
+ )
+
+ const groupedTabIds = useMemo(() => {
+ const set = new Set<TabId>()
+ groupsConfig.forEach((group) => {
+ group.tabIds.forEach((id) => set.add(id))
+ })
+ return set
+ }, [groupsConfig])
+
+ const ungroupedTabs = useMemo(
+ () => tabs.filter((tab) => !groupedTabIds.has(tab.id)),
+ [tabs, groupedTabIds],
+ )
+
+ return (
+ <nav className='flex flex-col' aria-label='Sidebar'>
+ {_map(groups, (group) => (
+ <CollapsibleGroup
+ key={group.id}
+ group={group}
+ tabs={group.tabs}
+ activeTab={activeTab}
+ onTabChange={onTabChange}
+ />
+ ))}
+
+ {ungroupedTabs.length > 0 ? (
+ <div className='mt-2 flex flex-col gap-0.5 border-t border-gray-200 pt-2 dark:border-slate-800/60'>
+ {_map(ungroupedTabs, (tab) => (
+ <TabButton
+ key={tab.id}
+ tab={tab}
+ isCurrent={tab.id === activeTab}
+ onClick={() => onTabChange(tab.id)}
+ />
+ ))}
+ </div>
+ ) : null}
+ </nav>
+ )
+}
+
+export default memo(SettingsSidebar) as typeof SettingsSidebar
diff --git a/web/public/locales/en.json b/web/public/locales/en.json
index c824fa5d4..021d4f344 100644
--- a/web/public/locales/en.json
+++ b/web/public/locales/en.json
@@ -1895,6 +1895,13 @@
"proxy": "Managed proxy",
"proxyDesc": "Route the tracker script and analytics events through your own domain to bypass ad blockers."
},
+ "sidebarGroups": {
+ "general": "General",
+ "protection": "Protection",
+ "notifications": "Notifications",
+ "data": "Data",
+ "integrations": "Integrations"
+ },
"revenue": {
"title": "Revenue Tracking",
"description": "Connect your payment provider to track revenue and attribute sales to marketing channels.",