Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: entitlement log retention in new interface (#40040)

Ignacio Dobronich89d556c57e24
diff --git a/apps/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx b/apps/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx
index 4d5083d4c8e..702e01e77e6 100644
--- a/apps/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx
@@ -21,6 +21,7 @@ import {
} from 'ui'
import { LOGS_LARGE_DATE_RANGE_DAYS_THRESHOLD } from './Logs.constants'
import type { DatetimeHelper } from './Logs.types'
+import { useCheckEntitlements } from 'hooks/misc/useCheckEntitlements'
export type DatePickerValue = {
to: string
@@ -237,13 +238,16 @@ export const LogsDatePicker = ({
Math.abs(dayjs(startDate).diff(dayjs(endDate), 'days')) >
LOGS_LARGE_DATE_RANGE_DAYS_THRESHOLD - 1
- const { plan: orgPlan, isLoading: isOrgPlanLoading } = useCurrentOrgPlan()
+ const { getEntitlementNumericValue } = useCheckEntitlements('log.retention_days')
+ const entitledToAuditLogDays = getEntitlementNumericValue()
+
const showHelperBadge = (helper?: DatetimeHelper) => {
if (!helper) return false
if (!helper.availableIn?.length) return false
+ if (!entitledToAuditLogDays) return false
- if (helper.availableIn.includes('free')) return false
- if (helper.availableIn.includes(orgPlan?.id || 'free') && !isOrgPlanLoading) return false
+ const day = Math.abs(dayjs().diff(dayjs(helper.calcFrom()), 'day'))
+ if (day <= entitledToAuditLogDays) return false
return true
}
diff --git a/apps/studio/components/ui/DataTable/DataTableFilters/DataTableFilterTimerange.tsx b/apps/studio/components/ui/DataTable/DataTableFilters/DataTableFilterTimerange.tsx
index 7656a5a1c9b..5bd4bf95c22 100644
--- a/apps/studio/components/ui/DataTable/DataTableFilters/DataTableFilterTimerange.tsx
+++ b/apps/studio/components/ui/DataTable/DataTableFilters/DataTableFilterTimerange.tsx
@@ -6,12 +6,12 @@ import {
DatePickerValue,
LogsDatePicker,
} from 'components/interfaces/Settings/Logs/Logs.DatePickers'
-import { maybeShowUpgradePrompt } from 'components/interfaces/Settings/Logs/Logs.utils'
+import { maybeShowUpgradePromptIfNotEntitled } from 'components/interfaces/Settings/Logs/Logs.utils'
import UpgradePrompt from 'components/interfaces/Settings/Logs/UpgradePrompt'
-import { useCurrentOrgPlan } from 'hooks/misc/useCurrentOrgPlan'
import type { DataTableTimerangeFilterField } from '../DataTable.types'
import { isArrayOfDates } from '../DataTable.utils'
import { useDataTable } from '../providers/DataTableProvider'
+import { useCheckEntitlements } from 'hooks/misc/useCheckEntitlements'
export function DataTableFilterTimerange<TData>({
value: _value,
@@ -21,9 +21,11 @@ export function DataTableFilterTimerange<TData>({
const column = table.getColumn(value)
const filterValue = columnFilters.find((i) => i.id === value)?.value
- const { plan: orgPlan } = useCurrentOrgPlan()
const [showUpgradePrompt, setShowUpgradePrompt] = useState(false)
+ const { getEntitlementNumericValue } = useCheckEntitlements('log.retention_days')
+ const entitledToAuditLogDays = getEntitlementNumericValue()
+
const date: DateRange | undefined = useMemo(
() =>
filterValue instanceof Date
@@ -36,7 +38,10 @@ export function DataTableFilterTimerange<TData>({
const handleDatePickerChange = (vals: DatePickerValue) => {
// Check if the selected date range exceeds the plan limits
- const shouldShowUpgradePrompt = maybeShowUpgradePrompt(vals.from, orgPlan?.id)
+ const shouldShowUpgradePrompt = maybeShowUpgradePromptIfNotEntitled(
+ vals.from,
+ entitledToAuditLogDays
+ )
if (shouldShowUpgradePrompt) {
setShowUpgradePrompt(true)