📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
add: Metrics selector UI
Blue Mouseb07ce61f7ee4
diff --git a/web/app/api/index.ts b/web/app/api/index.tsindex d036855e9..230e82176 100644--- a/web/app/api/index.ts+++ b/web/app/api/index.ts@@ -266,9 +266,9 @@ export const verifyShare = ({ path, id }: { path: string; id: string }) =>throw _isEmpty(error.response.data?.message) ? error.response.data : error.response.data.message})-export const getProjects = (take: number = 0, skip: number = 0, search?: string) =>+export const getProjects = (take: number = 0, skip: number = 0, search?: string, mode?: string) =>api- .get(`/project?take=${take}&skip=${skip}&search=${search}`)+ .get(`/project?take=${take}&skip=${skip}&search=${search}&mode=${mode}`).then((response,diff --git a/web/app/pages/Dashboard/Dashboard.tsx b/web/app/pages/Dashboard/Dashboard.tsxindex 63b61d9f5..a0331748b 100644--- a/web/app/pages/Dashboard/Dashboard.tsx+++ b/web/app/pages/Dashboard/Dashboard.tsx@@ -24,6 +24,7 @@ import { NoProjects } from './NoProjects'import { AddProject } from './AddProject'import { Overall, Project } from '~/lib/models/Project'import { getProjects, getLiveVisitors, getOverallStats, getOverallStatsCaptcha } from '~/api'+import { DASHBOARD_TABS, Tabs } from './Tabs'const PAGE_SIZE_OPTIONS = [12, 24, 48, 96]@@ -43,6 +44,8 @@ const Dashboard = () => {const [liveStats, setLiveStats] = useState<Record<string, number>>({})const [overallStats, setOverallStats] = useState<Overall>({})+ const [activeTab, setActiveTab] = useState<(typeof DASHBOARD_TABS)[number]['id']>(DASHBOARD_TABS[0].id)+const pageAmount = Math.ceil(paginationTotal / pageSize)// This search represents what's inside the search input@@ -58,14 +61,14 @@ const Dashboard = () => {setShowActivateEmailModal(true)}- const loadProjects = async (take: number, skip: number, search?: string) => {+ const loadProjects = async (take: number, skip: number, search?: string, tab?: string) => {if (isLoading) {return}setIsLoading(true)try {- const result = await getProjects(take, skip, search)+ const result = await getProjects(take, skip, search, tab)setProjects(result.results)setPaginationTotal(result.total)} catch (reason: any) {@@ -76,10 +79,10 @@ const Dashboard = () => {}useEffect(() => {- loadProjects(pageSize, (page - 1) * pageSize, debouncedSearch)+ loadProjects(pageSize, (page - 1) * pageSize, debouncedSearch, activeTab)// eslint-disable-next-line react-hooks/exhaustive-deps- }, [page, pageSize, debouncedSearch])+ }, [page, pageSize, debouncedSearch, activeTab])// Set up interval for live visitorsuseEffect(() => {@@ -185,7 +188,7 @@ const Dashboard = () => {<DashboardLockedBanner /><div className='flex flex-col px-4 py-6 sm:px-6 lg:px-8'><div className='mx-auto w-full max-w-7xl'>- <div className='mb-6 flex justify-between'>+ <div className='flex justify-between'><div className='flex items-end justify-between'><h2 className='mt-2 flex items-baseline text-3xl font-bold text-gray-900 dark:text-gray-50'>{t('titles.dashboard')}@@ -255,6 +258,12 @@ const Dashboard = () => {</div></div>)}+ <Tabs+ activeTab={activeTab}+ setActiveTab={setActiveTab}+ isLoading={isLoading === null || isLoading}+ className='mb-4 mt-2'+ />{isLoading || isLoading === null ? (<div className='min-h-min-footer bg-gray-50 dark:bg-slate-900'><ProjectCardSkeleton />diff --git a/web/app/pages/Dashboard/Tabs.tsx b/web/app/pages/Dashboard/Tabs.tsxnew file mode 100644index 000000000..82c42da71--- /dev/null+++ b/web/app/pages/Dashboard/Tabs.tsx@@ -0,0 +1,77 @@+import React from 'react'+import _map from 'lodash/map'+import cx from 'clsx'+import { FlameIcon, LayoutListIcon, PowerOffIcon, TrendingDownIcon, TrendingUpIcon } from 'lucide-react'++export const DASHBOARD_TABS = [+ {+ id: 'default',+ label: 'Default view',+ icon: LayoutListIcon,+ },+ {+ id: 'high-traffic',+ label: 'High traffic',+ icon: TrendingUpIcon,+ },+ {+ id: 'low-traffic',+ label: 'Low traffic',+ icon: TrendingDownIcon,+ },+ {+ id: 'performance',+ label: 'Performance',+ icon: FlameIcon,+ },+ {+ id: 'lost-traffic',+ label: 'Abandoned / Lost Traffic',+ icon: PowerOffIcon,+ },+] as const++interface TabsProps {+ activeTab: (typeof DASHBOARD_TABS)[number]['id']+ setActiveTab: React.Dispatch<React.SetStateAction<(typeof DASHBOARD_TABS)[number]['id']>>+ isLoading: boolean+ className?: string+}++export const Tabs = ({ activeTab, setActiveTab, className, isLoading }: TabsProps) => (+ <nav className={cx('-mb-px flex space-x-4 overflow-x-auto', className)} aria-label='Tabs'>+ {_map(DASHBOARD_TABS, (tab) => {+ const isCurrent = tab.id === activeTab++ return (+ <button+ key={tab.id}+ onClick={() => setActiveTab(tab.id)}+ className={cx(+ 'text-md group inline-flex cursor-pointer items-center whitespace-nowrap border-b-2 px-1 py-2 font-bold',+ {+ 'border-slate-900 text-slate-900 dark:border-gray-50 dark:text-gray-50': isCurrent,+ 'border-transparent text-gray-500 dark:text-gray-400': !isCurrent,+ 'cursor-wait': isLoading,+ 'hover:border-gray-300 hover:text-gray-700 dark:hover:border-gray-300 dark:hover:text-gray-300':+ !isCurrent && !isLoading,+ },+ )}+ aria-current={isCurrent ? 'page' : undefined}+ >+ <tab.icon+ className={cx(+ isCurrent+ ? 'text-slate-900 dark:text-gray-50'+ : 'text-gray-500 group-hover:text-gray-500 dark:text-gray-400 dark:group-hover:text-gray-300',+ '-ml-0.5 mr-2 h-5 w-5',+ )}+ aria-hidden='true'+ strokeWidth={1.5}+ />+ <span>{tab.label}</span>+ </button>+ )+ })}+ </nav>+)