mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
chore: remove maybeShowUpgradePrompt for entitlement-based gate (#43457)
### Changes - Remove maybeShowUpgradePrompt (plan-based) in favor of maybeShowUpgradePromptIfNotEntitled (entitlement-based) - Replaced the `maybeShowUpgradePrompt` with a `hasAccessToHelper` callback to default the date selection to a safe default so pages don't load with an out-of-range date. ### Testing - With an Org on the Free Plan, head to `/project/_/observability/api-overview?its=2026-03-04T15:06:50.704Z&ite=2026-03-20T15:06:50.704Z`. Notice that the end date in the URL is 16 days after the start date. - Assert that the actual range defaults to the entitled range of 1 day. <img width="467" height="483" alt="image" src="https://github.com/user-attachments/assets/e17c6957-3ece-4956-87aa-30cf62c84acd" />
This commit is contained in:
1 parent
8f71a43b86
commit
9f8536584c
2 files changed
+25
-27
No files matched your search
@@ -6,7 +6,6 @@ import { useEffect } from 'react'
|
||||
|
||||
import { IS_PLATFORM } from 'common'
|
||||
import BackwardIterator from 'components/ui/CodeEditor/Providers/BackwardIterator'
|
||||
import type { PlanId } from 'data/subscriptions/types'
|
||||
import logConstants from 'shared-data/logConstants'
|
||||
import { LogsTableName, SQL_FILTER_TEMPLATES } from './Logs.constants'
|
||||
import type { Filters, LogData, LogsEndpointParams } from './Logs.types'
|
||||
@@ -281,21 +280,6 @@ export const genSingleLogQuery = (table: LogsTableName, id: string) =>
|
||||
/**
|
||||
* Determine if we should show the user an upgrade prompt while browsing logs
|
||||
*/
|
||||
export const maybeShowUpgradePrompt = (from: string | null | undefined, planId?: PlanId) => {
|
||||
const day = Math.abs(dayjs().diff(dayjs(from), 'day'))
|
||||
|
||||
return (
|
||||
(day > 1 && planId === 'free') ||
|
||||
(day > 7 && planId === 'pro') ||
|
||||
(day > 28 && planId === 'team') ||
|
||||
(day > 90 && planId === 'enterprise')
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if we should show the user an upgrade prompt while browsing logs
|
||||
* This method should replace maybeShowUpgradePrompt once we have migrated all usage to the Entitlements API.
|
||||
*/
|
||||
export const maybeShowUpgradePromptIfNotEntitled = (
|
||||
from: string | null | undefined,
|
||||
entitledToDays: number | undefined
|
||||
|
||||
@@ -4,9 +4,10 @@ import {
|
||||
ReportsDatetimeHelper,
|
||||
} from 'components/interfaces/Reports/Reports.constants'
|
||||
import { DatePickerValue } 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 { AnalyticsInterval } from 'data/analytics/constants'
|
||||
import dayjs from 'dayjs'
|
||||
import { useCheckEntitlements } from 'hooks/misc/useCheckEntitlements'
|
||||
import { useCurrentOrgPlan } from 'hooks/misc/useCurrentOrgPlan'
|
||||
import { createParser, useQueryState } from 'nuqs'
|
||||
import { useCallback, useMemo, useState } from 'react'
|
||||
@@ -49,6 +50,8 @@ export const useReportDateRange = (
|
||||
| ReportsDatetimeHelper = REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES
|
||||
) => {
|
||||
const { plan: orgPlan, isLoading: isOrgPlanLoading } = useCurrentOrgPlan()
|
||||
const { getEntitlementNumericValue } = useCheckEntitlements('log.retention_days')
|
||||
const entitledToAuditLogDays = getEntitlementNumericValue()
|
||||
const [showUpgradePrompt, setShowUpgradePrompt] = useState(false)
|
||||
|
||||
// Get filtered date picker helpers based on organization plan
|
||||
@@ -67,6 +70,15 @@ export const useReportDateRange = (
|
||||
const [isHelperValue, setIsHelper] = useQueryState('isHelper', booleanWithDefault(false))
|
||||
const [helperTextValue, setHelperText] = useQueryState('helperText', stringWithDefault(''))
|
||||
|
||||
const hasAccessToHelper = useCallback(
|
||||
(helper: ReportsDatetimeHelper) => {
|
||||
if (!entitledToAuditLogDays) return true
|
||||
const days = Math.abs(dayjs().diff(dayjs(helper.calcFrom()), 'day'))
|
||||
return days <= entitledToAuditLogDays
|
||||
},
|
||||
[entitledToAuditLogDays]
|
||||
)
|
||||
|
||||
const getDefaultHelper = useCallback(() => {
|
||||
let targetHelper: ReportsDatetimeHelper | undefined
|
||||
|
||||
@@ -78,8 +90,8 @@ export const useReportDateRange = (
|
||||
targetHelper = defaultHelper
|
||||
}
|
||||
|
||||
// Check if the target helper is available for the current plan
|
||||
if (targetHelper && targetHelper.availableIn?.includes(orgPlan?.id || 'free')) {
|
||||
// Check if the target helper is available for the current entitlement
|
||||
if (targetHelper && hasAccessToHelper(targetHelper)) {
|
||||
return {
|
||||
start: targetHelper.calcFrom(),
|
||||
end: targetHelper.calcTo(),
|
||||
@@ -89,7 +101,7 @@ export const useReportDateRange = (
|
||||
|
||||
// Fallback: look for default helper marked in REPORTS_DATEPICKER_HELPERS
|
||||
const fallbackHelper = REPORTS_DATEPICKER_HELPERS.find(
|
||||
(helper) => helper.default && helper.availableIn?.includes(orgPlan?.id || 'free')
|
||||
(helper) => helper.default && hasAccessToHelper(helper)
|
||||
)
|
||||
|
||||
if (fallbackHelper) {
|
||||
@@ -101,9 +113,7 @@ export const useReportDateRange = (
|
||||
}
|
||||
|
||||
// Final fallback: use first available helper
|
||||
const firstAvailable = REPORTS_DATEPICKER_HELPERS.find((helper) =>
|
||||
helper.availableIn?.includes(orgPlan?.id || 'free')
|
||||
)
|
||||
const firstAvailable = REPORTS_DATEPICKER_HELPERS.find((helper) => hasAccessToHelper(helper))
|
||||
|
||||
if (firstAvailable) {
|
||||
return {
|
||||
@@ -121,7 +131,7 @@ export const useReportDateRange = (
|
||||
end: defaultEnd,
|
||||
helper: { isHelper: false },
|
||||
}
|
||||
}, [defaultHelper, orgPlan?.id])
|
||||
}, [defaultHelper, hasAccessToHelper])
|
||||
|
||||
// Get current effective values (from URL or defaults, but don't set URL)
|
||||
const timestampStart = useMemo(() => {
|
||||
@@ -132,14 +142,15 @@ export const useReportDateRange = (
|
||||
if (
|
||||
storedFrom.isValid() &&
|
||||
storedFrom.isAfter(now.subtract(90, 'day')) &&
|
||||
storedFrom.isBefore(now.add(1, 'day'))
|
||||
storedFrom.isBefore(now.add(1, 'day')) &&
|
||||
!maybeShowUpgradePromptIfNotEntitled(timestampStartValue, entitledToAuditLogDays)
|
||||
) {
|
||||
return timestampStartValue
|
||||
}
|
||||
}
|
||||
// Return default without setting URL
|
||||
return getDefaultHelper().start
|
||||
}, [timestampStartValue, getDefaultHelper])
|
||||
}, [timestampStartValue, getDefaultHelper, entitledToAuditLogDays])
|
||||
|
||||
const timestampEnd = useMemo(() => {
|
||||
if (timestampEndValue) {
|
||||
@@ -230,7 +241,10 @@ export const useReportDateRange = (
|
||||
)
|
||||
|
||||
const handleDatePickerChange = (values: DatePickerValue) => {
|
||||
const shouldShowUpgradePrompt = maybeShowUpgradePrompt(values.from, orgPlan?.id)
|
||||
const shouldShowUpgradePrompt = maybeShowUpgradePromptIfNotEntitled(
|
||||
values.from,
|
||||
entitledToAuditLogDays
|
||||
)
|
||||
if (shouldShowUpgradePrompt) {
|
||||
setShowUpgradePrompt(true)
|
||||
return true
|
||||
|
||||
Reference in new issue
Block a user