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!

Use selector for retention policy

Blue Mouse6c1eb523211d
diff --git a/web/app/pages/Project/Settings/tabs/SessionReplays.tsx b/web/app/pages/Project/Settings/tabs/SessionReplays.tsx
index 36966fa21..65dd403d3 100644
--- a/web/app/pages/Project/Settings/tabs/SessionReplays.tsx
+++ b/web/app/pages/Project/Settings/tabs/SessionReplays.tsx
@@ -3,12 +3,12 @@ import { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import Button from '~/ui/Button'
+import Select from '~/ui/Select'
import { Text } from '~/ui/Text'
-import Tooltip from '~/ui/Tooltip'
-import { cn } from '~/utils/generic'
import routes from '~/utils/routes'
const RETENTION_OPTIONS = [30, 90, 365, 1825] as const
+type RetentionOption = (typeof RETENTION_OPTIONS)[number]
interface SessionReplaysProps {
retentionDays: number
@@ -25,6 +25,16 @@ const SessionReplays = ({
const selectedRetention = RETENTION_OPTIONS.includes(retentionDays as any)
? retentionDays
: 30
+ const retentionItems = useMemo(
+ () => RETENTION_OPTIONS.map((days) => ({ days })),
+ [],
+ )
+ const selectedRetentionItem = useMemo(
+ () =>
+ retentionItems.find((item) => item.days === selectedRetention) ||
+ retentionItems[0],
+ [retentionItems, selectedRetention],
+ )
const hasLockedOptions = useMemo(
() => RETENTION_OPTIONS.some((days) => days > maxRetentionDays),
[maxRetentionDays],
@@ -41,55 +51,42 @@ const SessionReplays = ({
</Text>
</div>
- <div
- role='radiogroup'
- aria-label={t('project.settings.sessionReplays.retentionLabel')}
- className='mt-5 grid w-full max-w-2xl grid-cols-2 gap-1 rounded-lg border border-gray-200 bg-white p-1 sm:grid-cols-4 dark:border-slate-800 dark:bg-slate-950'
- >
- {RETENTION_OPTIONS.map((days) => {
- const allowed = days <= maxRetentionDays
- const active = selectedRetention === days
- const label = t(`project.settings.sessionReplays.retention.${days}`)
- const className = cn(
- 'flex min-h-14 items-center justify-center rounded-md px-3 py-2 text-center text-sm font-medium transition-colors',
- {
- 'bg-slate-900 text-white dark:bg-slate-100 dark:text-slate-950':
- active && allowed,
- 'text-gray-700 hover:bg-gray-100 dark:text-gray-200 dark:hover:bg-slate-900':
- !active && allowed,
- 'cursor-not-allowed text-gray-400 dark:text-slate-600': !allowed,
- },
- )
-
- if (!allowed) {
- return (
- <Tooltip
- key={days}
- text={t('project.settings.sessionReplays.upgradeRequired')}
- tooltipNode={
- <span className={className}>
- <span>{label}</span>
- <LockIcon className='ml-1.5 size-3.5' />
- </span>
- }
- />
- )
+ <div className='mt-5 max-w-xs'>
+ <Select<{ days: RetentionOption }>
+ label={t('project.settings.sessionReplays.retentionLabel')}
+ title={t(
+ `project.settings.sessionReplays.retention.${selectedRetentionItem.days}`,
+ )}
+ items={retentionItems}
+ keyExtractor={(item) => String(item.days)}
+ labelExtractor={(item) =>
+ t(`project.settings.sessionReplays.retention.${item.days}`)
+ }
+ iconExtractor={(item) =>
+ item.days > maxRetentionDays ? (
+ <LockIcon className='size-4 text-gray-400 dark:text-slate-600' />
+ ) : null
+ }
+ descriptionExtractor={(item) =>
+ item.days > maxRetentionDays
+ ? t('project.settings.sessionReplays.upgradeRequired')
+ : null
+ }
+ disabledItemExtractor={(item) =>
+ item.days > maxRetentionDays && item.days !== selectedRetention
}
+ selectedItem={selectedRetentionItem}
+ onSelect={(item) => {
+ if (
+ item.days > maxRetentionDays ||
+ item.days === selectedRetention
+ ) {
+ return
+ }
- return (
- <label key={days} className={className}>
- <input
- type='radio'
- name='retention'
- className='sr-only'
- aria-label={label}
- checked={active}
- onChange={() => onRetentionChange(days)}
- />
- {label}
- </label>
- )
- })}
+ onRetentionChange(item.days)
+ }}
+ />
</div>
<Text as='p' size='xs' colour='secondary' className='mt-3 max-w-2xl'>
@@ -104,7 +101,7 @@ const SessionReplays = ({
<Text as='p' size='sm' colour='secondary' className='mt-1'>
{t('project.settings.sessionReplays.upgradeDescription')}
</Text>
- <Button to={routes.billing_choose_plan} className='mt-4'>
+ <Button to={`${routes.user_settings}?tab=billing`} className='mt-4'>
{t('project.settings.sessionReplays.upgradeCta')}
</Button>
</div>
diff --git a/web/app/ui/Select.tsx b/web/app/ui/Select.tsx
index 2db4ad435..69f5f5ad9 100644
--- a/web/app/ui/Select.tsx
+++ b/web/app/ui/Select.tsx
@@ -29,6 +29,7 @@ interface SelectProps<T> {
keyExtractor?: (item: T, index: number) => string
iconExtractor?: (item: T, index: number) => React.ReactNode | null
descriptionExtractor?: (item: T, index: number) => React.ReactNode | null
+ disabledItemExtractor?: (item: T, index: number) => boolean
onSelect: (item: T) => void
selectedItem?: T
wrap?: boolean
@@ -46,6 +47,7 @@ function Select<T>({
keyExtractor,
iconExtractor,
descriptionExtractor,
+ disabledItemExtractor,
onSelect,
id,
buttonClassName,
@@ -170,6 +172,7 @@ function Select<T>({
>
{_map(items, (item, index) => {
const selected = isItemSelected(item)
+ const disabled = disabledItemExtractor?.(item, index) || false
const itemDescription = descriptionExtractor
? descriptionExtractor(item, index)
: null
@@ -183,13 +186,16 @@ function Select<T>({
'relative mx-1 cursor-pointer rounded-md pr-8 pl-3 transition-colors duration-100 ease-out select-none',
hasDescriptions ? 'py-2.5' : 'py-2',
{
+ 'cursor-not-allowed text-gray-400 dark:text-slate-600':
+ disabled && !selected,
'bg-gray-100 dark:bg-slate-900': focus || selected,
'text-gray-700 dark:text-gray-50':
- !focus && !selected,
+ !focus && !selected && !disabled,
'text-gray-900 dark:text-white': focus || selected,
},
)
}
+ disabled={disabled}
value={item}
>
<>
diff --git a/web/public/locales/en.json b/web/public/locales/en.json
index 01c7692b9..33a9f017c 100644
--- a/web/public/locales/en.json
+++ b/web/public/locales/en.json
@@ -2401,7 +2401,7 @@
"upgradeRequired": "Upgrade to unlock longer replay retention.",
"upgradeTitle": "Need more replay capacity?",
"upgradeDescription": "Longer retention and higher replay capacity are available through upgraded replay entitlements.",
- "upgradeCta": "View plans"
+ "upgradeCta": "Go to billing"
},
"dataImport": {
"importFrom": "Import from",