📈 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
Code refactoring
Blue Mouseb380dc4c1478
diff --git a/web/app/pages/Project/Settings/Alerts/ProjectAlertsView.tsx b/web/app/pages/Project/Settings/Alerts/ProjectAlertsView.tsxindex dfdde881e..d96d82f28 100644--- a/web/app/pages/Project/Settings/Alerts/ProjectAlertsView.tsx+++ b/web/app/pages/Project/Settings/Alerts/ProjectAlertsView.tsx@@ -445,15 +445,17 @@ const ProjectAlertsInner = ({>{t('dashboard.alertsDesc')}</Text>- <div className='mt-6'>- <Link- to={routes.signup}- aria-label={t('titles.signup')}- className='inline-flex items-center justify-center rounded-md border border-transparent bg-slate-900 px-4 py-2 text-sm font-medium text-white shadow-xs transition-colors hover:bg-slate-700 dark:bg-slate-100 dark:text-slate-900 dark:hover:bg-white'- >- {t('header.startForFree')}- </Link>- </div>+ {!isAuthenticated ? (+ <div className='mt-6'>+ <Link+ to={routes.signup}+ aria-label={t('titles.signup')}+ className='inline-flex items-center justify-center rounded-md border border-transparent bg-slate-900 px-4 py-2 text-sm font-medium text-white shadow-xs transition-colors hover:bg-slate-700 dark:bg-slate-100 dark:text-slate-900 dark:hover:bg-white'+ >+ {t('header.startForFree')}+ </Link>+ </div>+ ) : null}</div>)}diff --git a/web/app/pages/Project/View/components/RefreshStatsButton.tsx b/web/app/pages/Project/View/components/RefreshStatsButton.tsxindex 87073a937..e89386818 100644--- a/web/app/pages/Project/View/components/RefreshStatsButton.tsx+++ b/web/app/pages/Project/View/components/RefreshStatsButton.tsx@@ -101,7 +101,7 @@ export const RefreshStatsButton = ({ onRefresh }: RefreshStatsButtonProps) => {variant='icon'onClick={handleManualRefresh}aria-label={t('project.refreshStats')}- disabled={authLoading}+ disabled={authLoading || dataLoading || isRefreshing}><span className='relative size-5'><ArrowClockwiseIcondiff --git a/web/app/pages/UserSettings/components/Organisations.tsx b/web/app/pages/UserSettings/components/Organisations.tsxindex 96d61d134..9ddc9637e 100644--- a/web/app/pages/UserSettings/components/Organisations.tsx+++ b/web/app/pages/UserSettings/components/Organisations.tsx@@ -103,6 +103,7 @@ const Organisations = ({ membership }: OrganisationsProps) => {) : (<><Button+ variant='secondary'size='xs'className='mr-2'onClick={() => setShowDeleteModal(true)}diff --git a/web/app/pages/UserSettings/components/ProjectList.tsx b/web/app/pages/UserSettings/components/ProjectList.tsxindex 062708861..4db312b4d 100644--- a/web/app/pages/UserSettings/components/ProjectList.tsx+++ b/web/app/pages/UserSettings/components/ProjectList.tsx@@ -101,6 +101,7 @@ const ProjectList = ({ item }: ProjectListProps) => {) : (<><Button+ variant='secondary'size='xs'className='mr-2'onClick={() => setShowDeleteModal(true)}diff --git a/web/app/ui/Combobox.tsx b/web/app/ui/Combobox.tsxindex ee26d4943..b3ce2309d 100644--- a/web/app/ui/Combobox.tsx+++ b/web/app/ui/Combobox.tsx@@ -68,7 +68,7 @@ const Combobox = ({/><ComboboxButtonclassName='absolute inset-y-0 right-0 flex items-center pr-2 text-gray-400 dark:text-gray-500'- aria-label='Toggle options'+ aria-label={t('common.toggleOptions')}><CaretUpDownIcon className='size-4' aria-hidden='true' /></ComboboxButton>diff --git a/web/app/ui/FileUpload.tsx b/web/app/ui/FileUpload.tsxindex e6be1a1e0..80a4e54a6 100644--- a/web/app/ui/FileUpload.tsx+++ b/web/app/ui/FileUpload.tsx@@ -118,7 +118,9 @@ export default function FileUpload({<div className='space-y-2'><divclassName={cn(- 'mx-auto flex size-10 items-center justify-center rounded-lg bg-gray-100 text-gray-500 transition-colors duration-200 ease-out group-hover:bg-gray-200 group-hover:text-gray-700 dark:bg-slate-800/80 dark:text-gray-400 dark:group-hover:bg-slate-800 dark:group-hover:text-gray-200',+ 'mx-auto flex size-10 items-center justify-center rounded-lg bg-gray-100 text-gray-500 transition-colors duration-200 ease-out dark:bg-slate-800/80 dark:text-gray-400',+ !isDisabled &&+ 'group-hover:bg-gray-200 group-hover:text-gray-700 dark:group-hover:bg-slate-800 dark:group-hover:text-gray-200',dragOver &&'bg-slate-200 text-slate-900 dark:bg-slate-700 dark:text-white',)}diff --git a/web/app/ui/Input.tsx b/web/app/ui/Input.tsxindex 4c3c8f57d..5ce029f89 100644--- a/web/app/ui/Input.tsx+++ b/web/app/ui/Input.tsx@@ -94,11 +94,16 @@ const Input = ({{inputElement}<buttontype='button'- onClick={() => setShowPassword(!showPassword)}+ onClick={() => {+ if (disabled || readOnly) return+ setShowPassword(!showPassword)+ }}aria-label={showPassword ? 'Hide password' : 'Show password'}aria-pressed={showPassword}- tabIndex={disabled ? -1 : 0}- className='absolute inset-y-0 right-0 my-1 mr-1 flex items-center rounded-md px-2 text-gray-400 transition-colors hover:text-gray-700 focus-visible:ring-2 focus-visible:ring-slate-900 focus-visible:outline-hidden dark:text-gray-500 dark:hover:text-gray-200 dark:focus-visible:ring-slate-300'+ disabled={disabled || readOnly}+ aria-disabled={disabled || readOnly || undefined}+ tabIndex={disabled || readOnly ? -1 : 0}+ className='absolute inset-y-0 right-0 my-1 mr-1 flex items-center rounded-md px-2 text-gray-400 transition-colors hover:text-gray-700 focus-visible:ring-2 focus-visible:ring-slate-900 focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-60 disabled:hover:text-gray-400 dark:text-gray-500 dark:hover:text-gray-200 dark:focus-visible:ring-slate-300 dark:disabled:hover:text-gray-500'>{showPassword ? (<EyeSlashIcon className='size-4.5' />diff --git a/web/app/ui/MultiProgress.tsx b/web/app/ui/MultiProgress.tsxindex a8866d954..7b78a45ae 100644--- a/web/app/ui/MultiProgress.tsx+++ b/web/app/ui/MultiProgress.tsx@@ -13,11 +13,48 @@ interface Progress {interface MultiProgressProps {progress: Progress[]className?: string+ /**+ * Accessible label. When provided (along with valuenow / labelledby), the bar is+ * exposed as `role="progressbar"`. When omitted, the bar is purely decorative+ * and hidden from assistive technology.+ */+ 'aria-label'?: string+ 'aria-labelledby'?: string+ /**+ * Current value (defaults to the sum of `progress[].value`). Used only when the+ * bar is announced (i.e. when an accessible name is provided).+ */+ 'aria-valuenow'?: number+ 'aria-valuemin'?: number+ 'aria-valuemax'?: number}-const MultiProgress = ({ progress, className }: MultiProgressProps) => {+const MultiProgress = ({+ progress,+ className,+ 'aria-label': ariaLabel,+ 'aria-labelledby': ariaLabelledby,+ 'aria-valuenow': ariaValuenow,+ 'aria-valuemin': ariaValuemin = 0,+ 'aria-valuemax': ariaValuemax = 100,+}: MultiProgressProps) => {const { theme } = useTheme()+ const hasAccessibleName = Boolean(ariaLabel || ariaLabelledby)+ const valuenow =+ ariaValuenow ?? progress.reduce((sum, item) => sum + item.value, 0)++ const a11yProps = hasAccessibleName+ ? {+ role: 'progressbar' as const,+ 'aria-label': ariaLabel,+ 'aria-labelledby': ariaLabelledby,+ 'aria-valuenow': valuenow,+ 'aria-valuemin': ariaValuemin,+ 'aria-valuemax': ariaValuemax,+ }+ : { 'aria-hidden': true as const }+return (<div className='relative'><div@@ -25,7 +62,7 @@ const MultiProgress = ({ progress, className }: MultiProgressProps) => {'flex h-2.5 overflow-hidden rounded-full bg-gray-200 ring-1 ring-gray-200/40 ring-inset dark:bg-slate-800 dark:ring-slate-700/30',className,)}- role='progressbar'+ {...a11yProps}>{_map(progress, ({ value, lightColour, darkColour }) => (<divdiff --git a/web/app/ui/MultiSelect.tsx b/web/app/ui/MultiSelect.tsxindex e5b9e9f95..814e9cf93 100644--- a/web/app/ui/MultiSelect.tsx+++ b/web/app/ui/MultiSelect.tsx@@ -1,3 +1,4 @@+import { Transition } from '@headlessui/react'import { CheckIcon, CaretUpDownIcon, XIcon } from '@phosphor-icons/react'import cx from 'clsx'import _includes from 'lodash/includes'@@ -165,69 +166,74 @@ const MultiSelect = ({<CaretUpDownIcon className='size-4' aria-hidden='true' /></span>- <div- id={listboxId}- role='listbox'- aria-multiselectable='true'- className={cx(- 'absolute top-full z-30 mt-1.5 max-h-60 w-full overflow-auto rounded-lg bg-white py-1 text-sm shadow-lg ring-1 ring-gray-200/80 focus:outline-hidden dark:bg-slate-950 dark:ring-slate-700/60',- 'transition-[opacity,transform] duration-150 ease-out',- isOpen- ? 'translate-y-0 opacity-100'- : 'pointer-events-none -translate-y-0.5 opacity-0',- )}+ <Transition+ show={isOpen}+ enter='transition-[opacity,transform] duration-150 ease-out'+ enterFrom='-translate-y-0.5 opacity-0'+ enterTo='translate-y-0 opacity-100'+ leave='transition-[opacity,transform] duration-150 ease-out'+ leaveFrom='translate-y-0 opacity-100'+ leaveTo='-translate-y-0.5 opacity-0'>- {_isEmpty(items) ? (- <div className='mx-1 px-3 py-2 text-gray-500 dark:text-gray-400'>- No options available- </div>- ) : (- _map(items, (item, index) => {- const isSelected = _includes(label, item)- const isActive = index === activeIndex- const optionId = `${optionIdPrefix}-${itemKey(item)}`- return (- <button- type='button'- id={optionId}- role='option'- aria-selected={isSelected}- key={`${itemKey(item)}-select`}- onClick={() => handleSelectItem(item)}- onMouseEnter={() => setActiveIndex(index)}- className={cx(- 'relative mx-1 flex w-[calc(100%-0.5rem)] cursor-pointer items-center rounded-md py-2 pr-8 pl-3 text-left text-sm transition-colors duration-100 ease-out select-none',- {- 'bg-gray-100 text-gray-900 dark:bg-slate-800/80 dark:text-white':- isActive,- 'text-gray-700 dark:text-gray-50':- !isActive && !isSelected,- 'text-gray-900 dark:text-white': isSelected && !isActive,- },- )}- >- <span- className={cx('block truncate', {- 'font-semibold': isSelected,- 'font-normal': !isSelected,- })}+ <div+ id={listboxId}+ role='listbox'+ aria-multiselectable='true'+ className='absolute top-full z-30 mt-1.5 max-h-60 w-full overflow-auto rounded-lg bg-white py-1 text-sm shadow-lg ring-1 ring-gray-200/80 focus:outline-hidden dark:bg-slate-950 dark:ring-slate-700/60'+ >+ {_isEmpty(items) ? (+ <div className='mx-1 px-3 py-2 text-gray-500 dark:text-gray-400'>+ No options available+ </div>+ ) : (+ _map(items, (item, index) => {+ const isSelected = _includes(label, item)+ const isActive = index === activeIndex+ const optionId = `${optionIdPrefix}-${itemKey(item)}`+ return (+ <button+ type='button'+ id={optionId}+ role='option'+ aria-selected={isSelected}+ key={`${itemKey(item)}-select`}+ onClick={() => handleSelectItem(item)}+ onMouseEnter={() => setActiveIndex(index)}+ className={cx(+ 'relative mx-1 flex w-[calc(100%-0.5rem)] cursor-pointer items-center rounded-md py-2 pr-8 pl-3 text-left text-sm transition-colors duration-100 ease-out select-none',+ {+ 'bg-gray-100 text-gray-900 dark:bg-slate-800/80 dark:text-white':+ isActive,+ 'text-gray-700 dark:text-gray-50':+ !isActive && !isSelected,+ 'text-gray-900 dark:text-white':+ isSelected && !isActive,+ },+ )}>- {itemExtractor ? itemExtractor(item) : item}- </span>- {isSelected ? (- <span className='absolute inset-y-0 right-2 flex items-center text-slate-900 dark:text-slate-100'>- <CheckIcon- weight='bold'- className='size-4'- aria-hidden='true'- />+ <span+ className={cx('block truncate', {+ 'font-semibold': isSelected,+ 'font-normal': !isSelected,+ })}+ >+ {itemExtractor ? itemExtractor(item) : item}</span>- ) : null}- </button>- )- })- )}- </div>+ {isSelected ? (+ <span className='absolute inset-y-0 right-2 flex items-center text-slate-900 dark:text-slate-100'>+ <CheckIcon+ weight='bold'+ className='size-4'+ aria-hidden='true'+ />+ </span>+ ) : null}+ </button>+ )+ })+ )}+ </div>+ </Transition></div>{!_isEmpty(label) ? (diff --git a/web/app/ui/Pagination.tsx b/web/app/ui/Pagination.tsxindex f23008492..997da6cd2 100644--- a/web/app/ui/Pagination.tsx+++ b/web/app/ui/Pagination.tsx@@ -108,7 +108,7 @@ const Pagination = ({) : null}<navclassName='inline-flex items-center gap-0.5'- aria-label='Pagination'+ aria-label={t('common.paginationNavLabel')}><buttontype='button'@@ -125,21 +125,19 @@ const Pagination = ({</button>{_map(paginationRange, (item, index) => {if (item === DOTS) {+ const lastShownPage = paginationRange[index - 1] as number+ const nextShownPage = paginationRange[index + 1] as number+ const middlePage = Math.floor(+ (lastShownPage + nextShownPage) / 2,+ )+return (<buttontype='button'key={`dots-${index}`}- onClick={() => {- const lastShownPage = paginationRange[index - 1] as number- const nextShownPage = paginationRange[index + 1] as number- const middlePage = Math.floor(- (lastShownPage + nextShownPage) / 2,- )-- setPage(middlePage)- }}+ onClick={() => setPage(middlePage)}className={cx(navButtonClasses, 'tabular-nums')}- aria-label={`Jump to page ${Math.floor(((paginationRange[index - 1] as number) + (paginationRange[index + 1] as number)) / 2)}`}+ aria-label={t('common.jumpToPage', { page: middlePage })}>{DOTS}</button>@@ -154,7 +152,7 @@ const Pagination = ({key={item}onClick={() => setPage(item)}aria-current={isActive ? 'page' : undefined}- aria-label={`Page ${item}`}+ aria-label={t('common.pageNumber', { page: item })}className={cx('inline-flex size-8 items-center justify-center rounded-md text-sm font-medium tabular-nums transition-[background-color,color,box-shadow] duration-150 ease-out focus-visible:ring-2 focus-visible:ring-slate-900 focus-visible:outline-hidden dark:focus-visible:ring-slate-300',isActivediff --git a/web/app/ui/PasswordStrength.tsx b/web/app/ui/PasswordStrength.tsxindex 7d3b89dc7..b21deaf79 100644--- a/web/app/ui/PasswordStrength.tsx+++ b/web/app/ui/PasswordStrength.tsx@@ -88,6 +88,7 @@ const PasswordStrength = ({ password, className }: PasswordStrengthProps) => {aria-valuemin={0}aria-valuemax={totalSegments}aria-valuenow={currentConfig.segments}+ aria-valuetext={currentConfig.label || undefined}aria-label={t('auth.passwordStrength.label', {defaultValue: 'Password strength',})}diff --git a/web/app/ui/ProgressRing.tsx b/web/app/ui/ProgressRing.tsxindex 4481d76c3..f7077fb5a 100644--- a/web/app/ui/ProgressRing.tsx+++ b/web/app/ui/ProgressRing.tsx@@ -83,7 +83,7 @@ const ProgressRing = ({)const center = size / 2- const rounded = Math.round(normalizedValue)+ const displayValue = Math.floor(normalizedValue)return (<div@@ -94,8 +94,8 @@ const ProgressRing = ({role='progressbar'aria-valuemin={0}aria-valuemax={100}- aria-valuenow={rounded}- aria-label={ariaLabel}+ aria-valuenow={displayValue}+ aria-label={ariaLabel ?? `Progress: ${displayValue}%`}><svg width={size} height={size} className='-rotate-90' aria-hidden='true'><circle@@ -129,7 +129,7 @@ const ProgressRing = ({)}style={{ fontSize: size * 0.22 }}>- {rounded}%+ {displayValue}%</span>) : null}</div>diff --git a/web/app/ui/StatusPage.tsx b/web/app/ui/StatusPage.tsxindex ba68725d5..b67b8b985 100644--- a/web/app/ui/StatusPage.tsx+++ b/web/app/ui/StatusPage.tsx@@ -5,6 +5,7 @@ import { Link } from '~/ui/Link'import { cn } from '~/utils/generic'+import { buttonClasses } from './Button'import Spin from './icons/Spin'import { Text } from './Text'@@ -65,15 +66,6 @@ const iconBgMap: Record<StatusType, string> = {info: 'bg-amber-100/70 dark:bg-amber-500/10',}-const baseActionClasses =- 'inline-flex items-center justify-center rounded-md px-4 py-2 text-sm font-medium transition-[background-color,color,transform] duration-150 ease-out active:scale-[0.985] focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden'--const primaryActionClasses =- 'bg-slate-900 text-white shadow-xs hover:bg-slate-700 focus-visible:ring-slate-900 dark:bg-slate-100 dark:text-slate-900 dark:hover:bg-white dark:focus-visible:ring-slate-300 dark:focus-visible:ring-offset-slate-950'--const secondaryActionClasses =- 'bg-white text-gray-700 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus-visible:ring-slate-900 dark:bg-slate-900 dark:text-gray-200 dark:ring-slate-700/80 dark:hover:bg-slate-800 dark:focus-visible:ring-slate-300 dark:focus-visible:ring-offset-slate-950'-const StatusPage = ({loading,type = 'success',@@ -137,18 +129,14 @@ const StatusPage = ({{actions && actions.length > 0 ? (<div className='mt-6 flex flex-wrap items-center justify-center gap-2.5'>- {actions.map((action, index) =>- isActionLink(action) ? (- <Link- key={action.to}- to={action.to}- className={cn(- baseActionClasses,- action.primary- ? primaryActionClasses- : secondaryActionClasses,- )}- >+ {actions.map((action, index) => {+ const className = buttonClasses({+ variant: action.primary ? 'primary' : 'secondary',+ size: 'lg',+ })++ return isActionLink(action) ? (+ <Link key={action.to} to={action.to} className={className}>{action.label}</Link>) : (@@ -156,17 +144,12 @@ const StatusPage = ({key={index}type='button'onClick={action.onClick}- className={cn(- baseActionClasses,- action.primary- ? primaryActionClasses- : secondaryActionClasses,- )}+ className={className}>{action.label}</button>- ),- )}+ )+ })}</div>) : null}</div>diff --git a/web/app/ui/Switch.tsx b/web/app/ui/Switch.tsxindex 30e8a2a14..1357b0095 100644--- a/web/app/ui/Switch.tsx+++ b/web/app/ui/Switch.tsx@@ -50,9 +50,9 @@ const SwitchTrack = ({<spanaria-hidden='true'className={cx(- 'pointer-events-none inline-block size-3 transform rounded-full bg-white shadow-sm ring-0 transition-transform duration-200 ease-out',+ 'pointer-events-none inline-block size-3 transform rounded-full bg-white shadow-sm ring-0 transition-[transform,background-color] duration-200 ease-out',{- 'translate-x-3': checked,+ 'translate-x-3 dark:bg-slate-900': checked,'translate-x-0': !checked,},)}diff --git a/web/public/locales/de.json b/web/public/locales/de.jsonindex 3b8e27a9d..bcdf2f190 100644--- a/web/public/locales/de.json+++ b/web/public/locales/de.json@@ -153,7 +153,11 @@"create": "Erstellen","unknown": "Unbekannt","showMore": "{{count}} weitere anzeigen",- "showLess": "Weniger anzeigen"+ "showLess": "Weniger anzeigen",+ "toggleOptions": "Optionen umschalten",+ "paginationNavLabel": "Seitennavigation",+ "jumpToPage": "Zu Seite {{page}} springen",+ "pageNumber": "Seite {{page}}"},"performance": {"slogan": "Endbenutzer <span>Leistungsüberwachung</span> um schnelle Webseiten zu liefern.",diff --git a/web/public/locales/en.json b/web/public/locales/en.jsonindex 48fcfb6ba..5d0a5a3cb 100644--- a/web/public/locales/en.json+++ b/web/public/locales/en.json@@ -153,7 +153,11 @@"create": "Create","unknown": "Unknown","showMore": "Show {{count}} more",- "showLess": "Show less"+ "showLess": "Show less",+ "toggleOptions": "Toggle options",+ "paginationNavLabel": "Pagination",+ "jumpToPage": "Jump to page {{page}}",+ "pageNumber": "Page {{page}}"},"performance": {"slogan": "End user <span>performance monitoring</span> to deliver fast websites.",diff --git a/web/public/locales/fr.json b/web/public/locales/fr.jsonindex 2a5d02e78..bb062bfe9 100644--- a/web/public/locales/fr.json+++ b/web/public/locales/fr.json@@ -153,7 +153,11 @@"create": "Créer","unknown": "Inconnu","showMore": "Afficher {{count}} de plus",- "showLess": "Afficher moins"+ "showLess": "Afficher moins",+ "toggleOptions": "Basculer les options",+ "paginationNavLabel": "Pagination",+ "jumpToPage": "Aller à la page {{page}}",+ "pageNumber": "Page {{page}}"},"performance": {"slogan": "<span>Contrôle des performances</span> de l'utilisateur final afin de fournir des sites web rapides.",diff --git a/web/public/locales/pl.json b/web/public/locales/pl.jsonindex 442485a3e..bd6050f7b 100644--- a/web/public/locales/pl.json+++ b/web/public/locales/pl.json@@ -153,7 +153,11 @@"create": "Utwórz","unknown": "Nieznane","showMore": "Pokaż {{count}} więcej",- "showLess": "Pokaż mniej"+ "showLess": "Pokaż mniej",+ "toggleOptions": "Przełącz opcje",+ "paginationNavLabel": "Paginacja",+ "jumpToPage": "Przejdź do strony {{page}}",+ "pageNumber": "Strona {{page}}"},"performance": {"slogan": "Monitorowanie <span>wydajności</span> końcowego użytkownika, aby dostarczać szybkie strony internetowe.",diff --git a/web/public/locales/uk.json b/web/public/locales/uk.jsonindex ac355de3d..07bcd1d16 100644--- a/web/public/locales/uk.json+++ b/web/public/locales/uk.json@@ -153,7 +153,11 @@"create": "Створити","unknown": "Невідомо","showMore": "Показати ще {{count}}",- "showLess": "Показати менше"+ "showLess": "Показати менше",+ "toggleOptions": "Перемкнути опції",+ "paginationNavLabel": "Пагінація",+ "jumpToPage": "Перейти на сторінку {{page}}",+ "pageNumber": "Сторінка {{page}}"},"performance": {"slogan": "<span>Моніторинг ефективності</span> для створення швидких вебсайтів.",