Skip to content

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

reports pricing (#36992)

Jordi Enric804f270c3a0e
diff --git a/apps/studio/components/interfaces/Reports/ReportChart.tsx b/apps/studio/components/interfaces/Reports/ReportChart.tsx
index 378e11abb32..831c3ff7b8c 100644
--- a/apps/studio/components/interfaces/Reports/ReportChart.tsx
+++ b/apps/studio/components/interfaces/Reports/ReportChart.tsx
@@ -11,6 +11,11 @@ import LogChartHandler from 'components/ui/Charts/LogChartHandler'
import { useChartData } from 'hooks/useChartData'
import type { UpdateDateRange } from 'pages/project/[ref]/reports/database'
import type { MultiAttribute } from 'components/ui/Charts/ComposedChart.utils'
+import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
+import Link from 'next/link'
+import { Button } from 'ui'
+import Panel from 'components/ui/Panel'
+import { useRef, useState } from 'react'
const ReportChart = ({
chart,
@@ -19,6 +24,8 @@ const ReportChart = ({
interval,
updateDateRange,
functionIds,
+ orgPlanId,
+ isLoading,
}: {
chart: any
startDate: string
@@ -26,10 +33,17 @@ const ReportChart = ({
interval: string
updateDateRange: UpdateDateRange
functionIds?: string[]
+ orgPlanId?: string
+ isLoading?: boolean
}) => {
+ const org = useSelectedOrganization()
+ const [isHoveringUpgrade, setIsHoveringUpgrade] = useState(false)
+ const isAvailable =
+ chart.availableIn === undefined || (orgPlanId && chart.availableIn.includes(orgPlanId))
+ const canFetch = orgPlanId !== undefined
const {
data,
- isLoading: isLoading,
+ isLoading: isLoadingChart,
chartAttributes,
highlightedValue,
} = useChartData({
@@ -39,12 +53,76 @@ const ReportChart = ({
interval,
functionIds,
data: undefined,
+ enabled: canFetch,
highlightedValue:
chart.id === 'client-connections' || chart.id === 'pgbouncer-connections'
? true
: chart.showMaxValue,
})
+ const getExpDemoChartData = () =>
+ new Array(20).fill(0).map((_, index) => ({
+ period_start: new Date(startDate).getTime() + index * 1000,
+ demo: Math.floor(Math.pow(1.25, index) * 10),
+ max_demo: 1000,
+ }))
+
+ const getDemoChartData = () =>
+ new Array(20).fill(0).map((_, index) => ({
+ period_start: new Date(startDate).getTime() + index * 1000,
+ demo: Math.floor(Math.random() * 10) + 1,
+ max_demo: 1000,
+ }))
+
+ // [Jordi] useRef to prevent re-rendering making the chart change.
+ const demoChartData = useRef(getDemoChartData())
+ const exponentialChartData = useRef(getExpDemoChartData())
+
+ const chartData = isHoveringUpgrade ? exponentialChartData.current : demoChartData.current
+
+ if (!isAvailable && !isLoading) {
+ return (
+ <Panel title={<h2 className="text-sm">{chart.label}</h2>} className="h-[260px] relative">
+ <div className="z-10 flex flex-col items-center justify-center space-y-2 h-full absolute top-0 left-0 w-full bg-surface-100/70 backdrop-blur-md">
+ <h2 className="">{chart.label}</h2>
+ <p className="text-sm text-foreground-light">
+ This chart is available from Pro plan and above
+ </p>
+ <Button
+ asChild
+ type="primary"
+ onMouseEnter={() => setIsHoveringUpgrade(true)}
+ onMouseLeave={() => setIsHoveringUpgrade(false)}
+ >
+ <Link href={`/org/${org?.slug}/billing?panel=subscriptionPlan&source=reports`}>
+ Upgrade to Pro
+ </Link>
+ </Button>
+ </div>
+ <div className="absolute top-0 left-0 w-full h-full z-0">
+ <LogChartHandler
+ attributes={[
+ {
+ attribute: 'demo',
+ enabled: true,
+ label: 'Demo',
+ provider: 'logs',
+ },
+ ]}
+ label={chart.label}
+ startDate={startDate}
+ endDate={endDate}
+ interval={interval}
+ data={chartData as any}
+ isLoading={false}
+ highlightedValue={0}
+ updateDateRange={updateDateRange}
+ />
+ </div>
+ </Panel>
+ )
+ }
+
return (
<LogChartHandler
{...chart}
@@ -52,7 +130,7 @@ const ReportChart = ({
(chartAttributes.length > 0 ? chartAttributes : chart.attributes) as MultiAttribute[]
}
data={data}
- isLoading={isLoading}
+ isLoading={isLoadingChart || isLoading}
highlightedValue={highlightedValue as any}
updateDateRange={updateDateRange}
/>
diff --git a/apps/studio/components/interfaces/Reports/Reports.constants.ts b/apps/studio/components/interfaces/Reports/Reports.constants.ts
index a46746ec604..ff12e3fdfee 100644
--- a/apps/studio/components/interfaces/Reports/Reports.constants.ts
+++ b/apps/studio/components/interfaces/Reports/Reports.constants.ts
@@ -56,30 +56,23 @@ export const REPORTS_DATEPICKER_HELPERS: ReportsDatetimeHelper[] = [
{
text: REPORT_DATERANGE_HELPER_LABELS.LAST_7_DAYS,
calcFrom: () => dayjs().subtract(7, 'day').startOf('day').toISOString(),
- calcTo: () => '',
+ calcTo: () => dayjs().toISOString(),
availableIn: ['pro', 'team', 'enterprise'],
},
{
text: REPORT_DATERANGE_HELPER_LABELS.LAST_14_DAYS,
calcFrom: () => dayjs().subtract(14, 'day').startOf('day').toISOString(),
- calcTo: () => '',
+ calcTo: () => dayjs().toISOString(),
availableIn: ['team', 'enterprise'],
},
{
text: REPORT_DATERANGE_HELPER_LABELS.LAST_28_DAYS,
calcFrom: () => dayjs().subtract(28, 'day').startOf('day').toISOString(),
- calcTo: () => '',
+ calcTo: () => dayjs().toISOString(),
availableIn: ['team', 'enterprise'],
},
]
-export const createFilteredDatePickerHelpers = (planId: PlanId) => {
- return REPORTS_DATEPICKER_HELPERS.map((helper) => ({
- ...helper,
- disabled: !helper.availableIn?.includes(planId),
- }))
-}
-
export const DEFAULT_QUERY_PARAMS = {
iso_timestamp_start: REPORTS_DATEPICKER_HELPERS[0].calcFrom(),
iso_timestamp_end: REPORTS_DATEPICKER_HELPERS[0].calcTo(),
diff --git a/apps/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx b/apps/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx
index f3576372338..e7b88a9a552 100644
--- a/apps/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsx
@@ -5,8 +5,10 @@ import { PropsWithChildren, useEffect, useState } from 'react'
import DatePicker from 'react-datepicker'
import { Label } from '@ui/components/shadcn/ui/label'
+import { Badge } from '@ui/components/shadcn/ui/badge'
import { RadioGroup, RadioGroupItem } from '@ui/components/shadcn/ui/radio-group'
import TimeSplitInput from 'components/ui/DatePicker/TimeSplitInput'
+import { useCurrentOrgPlan } from 'hooks/misc/useCurrentOrgPlan'
import {
Button,
PopoverContent_Shadcn_,
@@ -27,8 +29,8 @@ export type DatePickerValue = {
interface Props {
value: DatePickerValue
- onSubmit: (args: DatePickerValue) => void
helpers: DatetimeHelper[]
+ onSubmit: (value: DatePickerValue) => void
}
export const LogsDatePicker = ({ onSubmit, helpers, value }: PropsWithChildren<Props>) => {
@@ -215,6 +217,16 @@ export const LogsDatePicker = ({ onSubmit, helpers, value }: PropsWithChildren<P
Math.abs(dayjs(startDate).diff(dayjs(endDate), 'days')) >
LOGS_LARGE_DATE_RANGE_DAYS_THRESHOLD - 1
+ const { plan: orgPlan, isLoading: isOrgPlanLoading } = useCurrentOrgPlan()
+ const showHelperBadge = (helper?: DatetimeHelper) => {
+ if (!helper) return false
+ if (!helper.availableIn?.length) return false
+
+ if (helper.availableIn.includes('free')) return false
+ if (helper.availableIn.includes(orgPlan?.id || 'free') && !isOrgPlanLoading) return false
+ return true
+ }
+
return (
<Popover_Shadcn_ open={open} onOpenChange={setOpen}>
<PopoverTrigger_Shadcn_ asChild>
@@ -239,7 +251,7 @@ export const LogsDatePicker = ({ onSubmit, helpers, value }: PropsWithChildren<P
<Label
key={helper.text}
className={cn(
- '[&:has([data-state=checked])]:bg-background-overlay-hover [&:has([data-state=checked])]:text-foreground px-4 py-1.5 text-foreground-light flex items-center gap-2 hover:bg-background-overlay-hover hover:text-foreground transition-all rounded-sm text-xs',
+ '[&:has([data-state=checked])]:bg-background-overlay-hover [&:has([data-state=checked])]:text-foreground px-4 py-1.5 text-foreground-light flex items-center gap-2 hover:bg-background-overlay-hover hover:text-foreground transition-all rounded-sm text-xs w-full',
{
'cursor-not-allowed pointer-events-none opacity-50': helper.disabled,
}
@@ -253,6 +265,15 @@ export const LogsDatePicker = ({ onSubmit, helpers, value }: PropsWithChildren<P
aria-disabled={helper.disabled}
></RadioGroupItem>
{helper.text}
+ {showHelperBadge(helper) ? (
+ <Badge
+ size="small"
+ variant="outline"
+ className="h-5 text-[10px] text-foreground-light capitalize"
+ >
+ {helper.availableIn?.[0] || ''}
+ </Badge>
+ ) : null}
</Label>
))}
</RadioGroup>
diff --git a/apps/studio/components/interfaces/Settings/Logs/Logs.types.ts b/apps/studio/components/interfaces/Settings/Logs/Logs.types.ts
index ef3597a06fb..d1f606a72ff 100644
--- a/apps/studio/components/interfaces/Settings/Logs/Logs.types.ts
+++ b/apps/studio/components/interfaces/Settings/Logs/Logs.types.ts
@@ -1,5 +1,6 @@
import type { Datum } from 'components/ui/Charts/Charts.types'
import React from 'react'
+import type { PlanId } from 'data/subscriptions/types'
interface Metadata {
[key: string]: string | number | Object | Object[] | any
@@ -142,6 +143,7 @@ export interface DatetimeHelper {
calcFrom: () => string
default?: boolean
disabled?: boolean
+ availableIn?: PlanId[]
}
export interface WarehouseCollection {
diff --git a/apps/studio/components/interfaces/Settings/Logs/UpgradePrompt.tsx b/apps/studio/components/interfaces/Settings/Logs/UpgradePrompt.tsx
index be49b0132bb..5869c5b5f8b 100644
--- a/apps/studio/components/interfaces/Settings/Logs/UpgradePrompt.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/UpgradePrompt.tsx
@@ -7,9 +7,25 @@ import { TIER_QUERY_LIMITS } from './Logs.constants'
interface Props {
show: boolean
setShowUpgradePrompt: (value: boolean) => void
+ title?: string
+ description?: string
+ source?: string
}
-
-const UpgradePrompt: React.FC<Props> = ({ show, setShowUpgradePrompt }) => {
+/**
+ * @param show - whether to show the modal
+ * @param setShowUpgradePrompt - function to set the show state
+ * @param title - title of the modal
+ * @param description - description of the modal
+ * @param source - source of the upgrade prompt used to track the source of the upgrade prompt in the billing page
+ * @returns
+ */
+const UpgradePrompt: React.FC<Props> = ({
+ show,
+ setShowUpgradePrompt,
+ title = 'Log retention',
+ description = 'Logs can be retained up to a duration of 3 months depending on the plan that your project is on.',
+ source = 'logsRetentionUpgradePrompt',
+}) => {
const organization = useSelectedOrganization()
return (
@@ -17,15 +33,12 @@ const UpgradePrompt: React.FC<Props> = ({ show, setShowUpgradePrompt }) => {
hideFooter
visible={show}
size="medium"
- header="Log retention"
+ header={title}
onCancel={() => setShowUpgradePrompt(false)}
>
<Modal.Content>
<div className="space-y-4">
- <p className="text-sm">
- Logs can be retained up to a duration of 3 months depending on the plan that your
- project is on.
- </p>
+ <p className="text-sm">{description}</p>
<div className="border-control bg-surface-300 rounded border">
<div className="flex items-center px-4 pt-2 pb-1">
<p className="text-foreground-light w-[40%] text-sm">Plan</p>
@@ -58,9 +71,7 @@ const UpgradePrompt: React.FC<Props> = ({ show, setShowUpgradePrompt }) => {
Close
</Button>
<Button asChild size="tiny">
- <Link
- href={`/org/${organization?.slug}/billing?panel=subscriptionPlan&source=logsRetentionUpgradePrompt`}
- >
+ <Link href={`/org/${organization?.slug}/billing?panel=subscriptionPlan&source=${source}`}>
Upgrade
</Link>
</Button>
diff --git a/apps/studio/components/ui/Charts/ComposedChart.utils.tsx b/apps/studio/components/ui/Charts/ComposedChart.utils.tsx
index ab9726edb72..6fa1dbbe8b5 100644
--- a/apps/studio/components/ui/Charts/ComposedChart.utils.tsx
+++ b/apps/studio/components/ui/Charts/ComposedChart.utils.tsx
@@ -14,6 +14,7 @@ export interface ReportAttributes {
attributes?: (MultiAttribute | false)[]
defaultChartStyle?: 'bar' | 'line' | 'stackedAreaLine'
hide?: boolean
+ availableIn?: string[]
hideChartType?: boolean
format?: string
className?: string
diff --git a/apps/studio/components/ui/Charts/ComposedChartHandler.tsx b/apps/studio/components/ui/Charts/ComposedChartHandler.tsx
index 833730cf659..bcaa3911cec 100644
--- a/apps/studio/components/ui/Charts/ComposedChartHandler.tsx
+++ b/apps/studio/components/ui/Charts/ComposedChartHandler.tsx
@@ -41,6 +41,7 @@ export interface ComposedChartHandlerProps {
valuePrecision?: number
isVisible?: boolean
docsUrl?: string
+ hide?: boolean
}
/**
@@ -355,6 +356,8 @@ const useAttributeQueries = (
}
export default function LazyComposedChartHandler(props: ComposedChartHandlerProps) {
+ if (props.hide) return null
+
return (
<LazyChartWrapper>
<ComposedChartHandler {...props} />
diff --git a/apps/studio/components/ui/Charts/LogChartHandler.tsx b/apps/studio/components/ui/Charts/LogChartHandler.tsx
index ee21b67be55..4e96f28ad89 100644
--- a/apps/studio/components/ui/Charts/LogChartHandler.tsx
+++ b/apps/studio/components/ui/Charts/LogChartHandler.tsx
@@ -116,7 +116,7 @@ const LogChartHandler = ({
return (
<Panel
className={cn(
- 'flex min-h-[320px] w-full flex-col items-center justify-center gap-y-2',
+ 'flex min-h-[280px] w-full flex-col items-center justify-center gap-y-2',
className
)}
wrapWithLoading={false}
diff --git a/apps/studio/data/reports/database-charts.ts b/apps/studio/data/reports/database-charts.ts
index 1fd8ac468b2..e8e91cdc375 100644
--- a/apps/studio/data/reports/database-charts.ts
+++ b/apps/studio/data/reports/database-charts.ts
@@ -40,6 +40,7 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Rep
{
id: 'ram-usage',
label: 'Memory usage',
+ availableIn: ['free', 'pro', 'team'],
hide: false,
showTooltip: true,
showLegend: true,
@@ -83,6 +84,7 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Rep
syncId: 'database-reports',
format: '%',
valuePrecision: 2,
+ availableIn: ['free', 'pro', 'team'],
hide: false,
showTooltip: true,
showLegend: true,
@@ -148,6 +150,7 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Rep
id: 'disk-iops',
label: 'Disk Input/Output operations per second (IOPS)',
syncId: 'database-reports',
+ availableIn: ['free', 'pro', 'team'],
hide: false,
showTooltip: true,
valuePrecision: 2,
@@ -191,6 +194,7 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Rep
id: 'disk-io-usage',
label: 'Disk IO Usage',
syncId: 'database-reports',
+ availableIn: ['pro', 'team'],
hide: false,
showTooltip: true,
format: '%',
@@ -218,7 +222,38 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Rep
id: 'client-connections',
label: 'Database connections',
valuePrecision: 0,
- hide: false,
+ availableIn: ['free', 'pro', 'team'],
+ hide: !isFreePlan, // [Jordi] Paid plans can see grouped client connections instead, so this chart is not needed for them. See below.
+ showTooltip: true,
+ showLegend: false,
+ showMaxValue: true,
+ hideChartType: false,
+ showGrid: true,
+ YAxisProps: { width: 30 },
+ defaultChartStyle: 'line',
+ attributes: [
+ {
+ attribute: 'pg_stat_database_num_backends',
+ provider: 'infra-monitoring',
+ label: 'Total connections',
+ tooltip: 'Total number of client connections to the database',
+ },
+ {
+ attribute: 'max_db_connections',
+ provider: 'reference-line',
+ label: 'Max connections',
+ value: getConnectionLimits(computeSize).direct,
+ tooltip: 'Max available connections for your current compute size',
+ isMaxValue: true,
+ },
+ ],
+ },
+ {
+ id: 'client-connections',
+ label: 'Direct Database Client Connections Grouped',
+ valuePrecision: 0,
+ availableIn: ['pro', 'team'],
+ hide: isFreePlan, // [Jordi] Paid plans can see grouped client connections instead, so this chart is not needed for them. See above.
showTooltip: true,
showLegend: true,
showMaxValue: true,
@@ -277,10 +312,11 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Rep
},
{
id: 'pgbouncer-connections',
- label: 'Dedicated Pooler client connections',
+ label: 'Dedicated Pooler Client Connections',
syncId: 'database-reports',
valuePrecision: 0,
- hide: false,
+ availableIn: ['pro', 'team'],
+ hide: isFreePlan,
showTooltip: true,
showLegend: true,
showMaxValue: true,
@@ -311,6 +347,7 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Rep
label: 'Shared Pooler (Supavisor) client connections',
syncId: 'database-reports',
valuePrecision: 0,
+ availableIn: ['pro', 'team'],
hide: isFreePlan,
showTooltip: false,
showLegend: false,
@@ -333,6 +370,7 @@ export const getReportAttributesV2: (org: Organization, project: Project) => Rep
label: 'Disk Usage',
syncId: 'database-reports',
valuePrecision: 2,
+ availableIn: ['free', 'pro', 'team'],
hide: false,
showTooltip: true,
showLegend: true,
diff --git a/apps/studio/data/reports/edgefn-charts.ts b/apps/studio/data/reports/edgefn-charts.ts
index 315c10c0d02..aa2dd98de82 100644
--- a/apps/studio/data/reports/edgefn-charts.ts
+++ b/apps/studio/data/reports/edgefn-charts.ts
@@ -2,8 +2,8 @@ import { ReportAttributes } from 'components/ui/Charts/ComposedChart.utils'
export const getEdgeFunctionReportAttributes = (): ReportAttributes[] => [
{
- id: 'invocations',
- label: 'Edge Function Invocations',
+ id: 'execution-status-codes',
+ label: 'Edge Function Status Codes',
valuePrecision: 0,
hide: false,
showTooltip: true,
@@ -11,32 +11,39 @@ export const getEdgeFunctionReportAttributes = (): ReportAttributes[] => [
showMaxValue: false,
hideChartType: false,
defaultChartStyle: 'bar',
- titleTooltip: 'The total number of edge function invocations.',
+ titleTooltip: 'The total number of edge function executions by status code.',
+ availableIn: ['free', 'pro', 'team'],
attributes: [
{
- attribute: 'TotalInvocations',
+ attribute: 'ExecutionStatusCodes',
provider: 'logs',
- label: 'Invocations',
- enabled: true,
+ label: 'Execution Status Codes',
},
],
},
{
- id: 'execution-status-codes',
- label: 'Edge Function Execution Status Codes',
+ id: 'execution-time',
+ label: 'Edge Function Execution Time',
valuePrecision: 0,
hide: false,
showTooltip: true,
showLegend: true,
showMaxValue: false,
hideChartType: false,
- defaultChartStyle: 'bar',
- titleTooltip: 'The total number of edge function executions by status code.',
+ defaultChartStyle: 'line',
+ titleTooltip: 'Average execution time for edge functions.',
+ availableIn: ['free', 'pro', 'team'],
+ format: 'ms',
+ YAxisProps: {
+ width: 50,
+ tickFormatter: (value: number) => `${value}ms`,
+ },
attributes: [
{
- attribute: 'ExecutionStatusCodes',
+ attribute: 'ExecutionTime',
+ label: 'Avg. Execution Time (ms)',
provider: 'logs',
- label: 'Execution Status Codes',
+ enabled: true,
},
],
},
@@ -51,6 +58,7 @@ export const getEdgeFunctionReportAttributes = (): ReportAttributes[] => [
hideChartType: false,
defaultChartStyle: 'bar',
titleTooltip: 'The total number of edge function invocations by region.',
+ availableIn: ['pro', 'team'],
attributes: [
{
attribute: 'InvocationsByRegion',
@@ -59,29 +67,4 @@ export const getEdgeFunctionReportAttributes = (): ReportAttributes[] => [
},
],
},
- {
- id: 'execution-time',
- label: 'Edge Function Execution Time',
- valuePrecision: 0,
- hide: false,
- showTooltip: true,
- showLegend: true,
- showMaxValue: false,
- hideChartType: false,
- defaultChartStyle: 'line',
- titleTooltip: 'Average execution time for edge functions.',
- format: 'ms',
- YAxisProps: {
- width: 50,
- tickFormatter: (value: number) => `${value}ms`,
- },
- attributes: [
- {
- attribute: 'ExecutionTime',
- label: 'Avg. Execution Time (ms)',
- provider: 'logs',
- enabled: true,
- },
- ],
- },
]
diff --git a/apps/studio/hooks/misc/useReportDateRange.ts b/apps/studio/hooks/misc/useReportDateRange.ts
index 216448751bc..de0cd99df35 100644
--- a/apps/studio/hooks/misc/useReportDateRange.ts
+++ b/apps/studio/hooks/misc/useReportDateRange.ts
@@ -1,14 +1,21 @@
-import { useCallback, useMemo } from 'react'
+import { useCallback, useMemo, useState } from 'react'
import dayjs from 'dayjs'
import { createParser, useQueryState } from 'nuqs'
import { DatePickerValue } from 'components/interfaces/Settings/Logs/Logs.DatePickers'
import {
- createFilteredDatePickerHelpers,
REPORTS_DATEPICKER_HELPERS,
ReportsDatetimeHelper,
REPORT_DATERANGE_HELPER_LABELS,
} from 'components/interfaces/Reports/Reports.constants'
import { useCurrentOrgPlan } from 'hooks/misc/useCurrentOrgPlan'
+import { maybeShowUpgradePrompt } from 'components/interfaces/Settings/Logs/Logs.utils'
+
+export const DATERANGE_LIMITS: { [key: string]: number } = {
+ free: 1,
+ pro: 7,
+ team: 28,
+ enterprise: 90,
+}
export interface ReportDateRange {
period_start: { date: string; time_period: string }
@@ -40,9 +47,17 @@ export const useReportDateRange = (
| ReportsDatetimeHelper = REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES
) => {
const { plan: orgPlan, isLoading: isOrgPlanLoading } = useCurrentOrgPlan()
+ const [showUpgradePrompt, setShowUpgradePrompt] = useState(false)
// Get filtered date picker helpers based on organization plan
- const datePickerHelpers = createFilteredDatePickerHelpers(orgPlan?.id || 'free')
+ const datePickerHelpers: ReportsDatetimeHelper[] = useMemo(
+ () =>
+ REPORTS_DATEPICKER_HELPERS.map((helper) => ({
+ ...helper,
+ disabled: false,
+ })),
+ []
+ )
// Use nuqs for URL state management with individual parameters (empty defaults)
const [timestampStartValue, setTimestampStart] = useQueryState('its', stringWithDefault(''))
@@ -159,12 +174,13 @@ export const useReportDateRange = (
}, [timestampStartValue, timestampEndValue, helperTextValue, getDefaultHelper])
const handleIntervalGranularity = useCallback((from: string, to: string) => {
+ const diffInDays = dayjs(to).diff(from, 'day', true)
const conditions = {
'1m': dayjs(to).diff(from, 'hour') < 3, // less than 3 hours
'10m': dayjs(to).diff(from, 'hour') < 6, // less than 6 hours
'30m': dayjs(to).diff(from, 'hour') < 18, // less than 18 hours
- '1h': dayjs(to).diff(from, 'day') < 10, // less than 10 days
- '1d': dayjs(to).diff(from, 'day') >= 10, // more than 10 days
+ '1h': diffInDays < 10, // less than 10 days
+ '1d': diffInDays >= 10, // more than 10 days
}
switch (true) {
@@ -199,18 +215,6 @@ export const useReportDateRange = (
[setTimestampStart, setTimestampEnd, setIsHelper, setHelperText]
)
- const handleDatePickerChange = useCallback(
- (values: DatePickerValue) => {
- if (values.from && values.to) {
- setTimestampStart(values.from)
- setTimestampEnd(values.to)
- setIsHelper(values.isHelper || false)
- setHelperText(values.text || '')
- }
- },
- [setTimestampStart, setTimestampEnd, setIsHelper, setHelperText]
- )
-
// For backward compatibility, provide a setter that updates the derived state
const setSelectedDateRange = useCallback(
(newRange: ReportDateRange) => {
@@ -234,14 +238,32 @@ export const useReportDateRange = (
[timestampStart, timestampEnd, isHelper, helperText]
)
+ const handleDatePickerChange = (values: DatePickerValue) => {
+ const shouldShowUpgradePrompt = maybeShowUpgradePrompt(values.from, orgPlan?.id)
+ if (shouldShowUpgradePrompt) {
+ setShowUpgradePrompt(true)
+ return true
+ } else {
+ if (values.from && values.to) {
+ setTimestampStart(values.from)
+ setTimestampEnd(values.to)
+ setIsHelper(values.isHelper || false)
+ setHelperText(values.text || '')
+ }
+ return false
+ }
+ }
+
return {
selectedDateRange,
setSelectedDateRange,
updateDateRange,
- handleDatePickerChange,
datePickerValue,
datePickerHelpers,
isOrgPlanLoading,
orgPlan,
+ showUpgradePrompt,
+ setShowUpgradePrompt,
+ handleDatePickerChange,
}
}
diff --git a/apps/studio/hooks/useChartData.ts b/apps/studio/hooks/useChartData.ts
index ce90139b960..b9abe0bc317 100644
--- a/apps/studio/hooks/useChartData.ts
+++ b/apps/studio/hooks/useChartData.ts
@@ -18,6 +18,8 @@ import type { ChartData } from 'components/ui/Charts/Charts.types'
import type { MultiAttribute } from 'components/ui/Charts/ComposedChart.utils'
import { useAttributeQueries } from 'components/ui/Charts/LogChartHandler'
import { useEdgeFunctionReport } from 'data/reports/edgefn-query'
+import { useInfraMonitoringQuery } from 'data/analytics/infra-monitoring-query'
+import type { InfraMonitoringAttribute } from 'data/analytics/infra-monitoring-query'
export const useChartData = ({
attributes,
@@ -27,6 +29,7 @@ export const useChartData = ({
data,
highlightedValue,
functionIds,
+ enabled = true,
}: {
attributes: MultiAttribute[]
startDate: string
@@ -35,6 +38,7 @@ export const useChartData = ({
data?: ChartData
highlightedValue?: string | number
functionIds?: string[]
+ enabled?: boolean
}) => {
const router = useRouter()
const { ref } = router.query
@@ -55,7 +59,7 @@ export const useChartData = ({
startDate,
endDate,
interval: interval as AnalyticsInterval,
- enabled: logsAttributes.length > 0 && !isEdgeFunctionRoute,
+ enabled: enabled && logsAttributes.length > 0 && !isEdgeFunctionRoute,
})
const {
@@ -68,10 +72,26 @@ export const useChartData = ({
startDate,
endDate,
interval: interval as AnalyticsInterval,
- enabled: logsAttributes.length > 0 && isEdgeFunctionRoute,
+ enabled: enabled && logsAttributes.length > 0 && isEdgeFunctionRoute,
functionIds,
})
+ const {
+ data: infraData,
+ error: infraError,
+ isLoading: isInfraLoading,
+ } = useInfraMonitoringQuery(
+ {
+ projectRef: ref as string,
+ attribute: nonLogsAttributes[0]?.attribute as InfraMonitoringAttribute,
+ interval: interval as AnalyticsInterval,
+ startDate,
+ endDate,
+ databaseIdentifier: state.selectedDatabaseId,
+ },
+ { enabled: enabled && nonLogsAttributes.length > 0 }
+ )
+
const logsData = isEdgeFunctionRoute ? edgeFunctionData : authData
const logsChartAttributes = isEdgeFunctionRoute
? edgeFunctionChartAttributes
diff --git a/apps/studio/pages/project/[ref]/reports/api-overview.tsx b/apps/studio/pages/project/[ref]/reports/api-overview.tsx
index ac4fbf258d2..6db01dc456b 100644
--- a/apps/studio/pages/project/[ref]/reports/api-overview.tsx
+++ b/apps/studio/pages/project/[ref]/reports/api-overview.tsx
@@ -14,10 +14,12 @@ import DefaultLayout from 'components/layouts/DefaultLayout'
import ReportsLayout from 'components/layouts/ReportsLayout/ReportsLayout'
import ReportStickyNav from 'components/interfaces/Reports/ReportStickyNav'
import { REPORT_DATERANGE_HELPER_LABELS } from 'components/interfaces/Reports/Reports.constants'
+import { useState } from 'react'
import { useApiReport } from 'data/reports/api-report-query'
import { useReportDateRange } from 'hooks/misc/useReportDateRange'
import { NextPageWithLayout } from 'types'
+import UpgradePrompt from 'components/interfaces/Settings/Logs/UpgradePrompt'
export const ApiReport: NextPageWithLayout = () => {
const report = useApiReport()
@@ -34,18 +36,22 @@ export const ApiReport: NextPageWithLayout = () => {
refresh,
} = report
- const { datePickerHelpers, datePickerValue, handleDatePickerChange } = useReportDateRange(
- REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES
- )
+ const {
+ datePickerHelpers,
+ datePickerValue,
+ handleDatePickerChange: handleDatePickerChangeFromHook,
+ showUpgradePrompt,
+ setShowUpgradePrompt,
+ } = useReportDateRange(REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES)
const handleDatepickerChange = (vals: DatePickerValue) => {
- // Update localStorage and hook state
- handleDatePickerChange(vals)
- // Update query params for the report
- mergeParams({
- iso_timestamp_start: vals.from || '',
- iso_timestamp_end: vals.to || '',
- })
+ const promptShown = handleDatePickerChangeFromHook(vals)
+ if (!promptShown) {
+ mergeParams({
+ iso_timestamp_start: vals.from || '',
+ iso_timestamp_end: vals.to || '',
+ })
+ }
}
return (
@@ -53,20 +59,29 @@ export const ApiReport: NextPageWithLayout = () => {
<ReportHeader title="API Gateway" showDatabaseSelector={false} />
<ReportStickyNav
content={
- <ReportFilterBar
- onRemoveFilters={removeFilters}
- onDatepickerChange={handleDatepickerChange}
- datepickerFrom={params.totalRequests.iso_timestamp_start}
- datepickerTo={params.totalRequests.iso_timestamp_end}
- onAddFilter={addFilter}
- onRefresh={refresh}
- isLoading={isLoading}
- filters={filters}
- datepickerHelpers={datePickerHelpers}
- initialDatePickerValue={datePickerValue}
- className="w-full"
- showDatabaseSelector={false}
- />
+ <div className="flex items-center gap-3">
+ <ReportFilterBar
+ onRemoveFilters={removeFilters}
+ onDatepickerChange={handleDatepickerChange}
+ datepickerFrom={params.totalRequests.iso_timestamp_start}
+ datepickerTo={params.totalRequests.iso_timestamp_end}
+ onAddFilter={addFilter}
+ onRefresh={refresh}
+ isLoading={isLoading}
+ filters={filters}
+ datepickerHelpers={datePickerHelpers}
+ initialDatePickerValue={datePickerValue}
+ className="w-full"
+ showDatabaseSelector={false}
+ />
+ <UpgradePrompt
+ show={showUpgradePrompt}
+ setShowUpgradePrompt={setShowUpgradePrompt}
+ title="Report date range"
+ description="Report data can be stored for a maximum of 3 months depending on the plan that your project is on."
+ source="apiReportDateRange"
+ />
+ </div>
}
>
<ReportWidget
diff --git a/apps/studio/pages/project/[ref]/reports/auth.tsx b/apps/studio/pages/project/[ref]/reports/auth.tsx
index edf622e70f1..30391fa409d 100644
--- a/apps/studio/pages/project/[ref]/reports/auth.tsx
+++ b/apps/studio/pages/project/[ref]/reports/auth.tsx
@@ -16,7 +16,8 @@ import ReportStickyNav from 'components/interfaces/Reports/ReportStickyNav'
import { getAuthReportAttributes } from 'data/reports/auth-charts'
import { useReportDateRange } from 'hooks/misc/useReportDateRange'
import { REPORT_DATERANGE_HELPER_LABELS } from 'components/interfaces/Reports/Reports.constants'
-
+import UpgradePrompt from 'components/interfaces/Settings/Logs/UpgradePrompt'
+import { DatePickerValue } from 'components/interfaces/Settings/Logs/Logs.DatePickers'
import type { NextPageWithLayout } from 'types'
const AuthReport: NextPageWithLayout = () => {
@@ -41,12 +42,14 @@ const AuthUsage = () => {
const {
selectedDateRange,
- updateDateRange: updateDateRangeFromHook,
- handleDatePickerChange,
+ updateDateRange,
datePickerValue,
datePickerHelpers,
isOrgPlanLoading,
orgPlan,
+ showUpgradePrompt,
+ setShowUpgradePrompt,
+ handleDatePickerChange,
} = useReportDateRange(REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES)
const queryClient = useQueryClient()
@@ -74,10 +77,6 @@ const AuthUsage = () => {
setTimeout(() => setIsRefreshing(false), 1000)
}
- const updateDateRange: UpdateDateRange = (from: string, to: string) => {
- updateDateRangeFromHook(from, to)
- }
-
return (
<>
<ReportHeader title="Auth" showDatabaseSelector={false} />
@@ -98,6 +97,13 @@ const AuthUsage = () => {
value={datePickerValue}
helpers={datePickerHelpers}
/>
+ <UpgradePrompt
+ show={showUpgradePrompt}
+ setShowUpgradePrompt={setShowUpgradePrompt}
+ title="Report date range"
+ description="Report data can be stored for a maximum of 3 months depending on the plan that your project is on."
+ source="authReportDateRange"
+ />
{selectedDateRange && (
<div className="flex items-center gap-x-2 text-xs">
<p className="text-foreground-light">
@@ -124,6 +130,7 @@ const AuthUsage = () => {
startDate={selectedDateRange?.period_start?.date}
endDate={selectedDateRange?.period_end?.date}
updateDateRange={updateDateRange}
+ orgPlanId={orgPlan?.id}
/>
))}
</ReportStickyNav>
diff --git a/apps/studio/pages/project/[ref]/reports/database.tsx b/apps/studio/pages/project/[ref]/reports/database.tsx
index 5aac7249277..e0a4c9faffd 100644
--- a/apps/studio/pages/project/[ref]/reports/database.tsx
+++ b/apps/studio/pages/project/[ref]/reports/database.tsx
@@ -21,7 +21,10 @@ import ChartHandler from 'components/ui/Charts/ChartHandler'
import Panel from 'components/ui/Panel'
import { useDatabaseSelectorStateSnapshot } from 'state/database-selector'
import ComposedChartHandler from 'components/ui/Charts/ComposedChartHandler'
-import { LogsDatePicker } from 'components/interfaces/Settings/Logs/Logs.DatePickers'
+import {
+ LogsDatePicker,
+ DatePickerValue,
+} from 'components/interfaces/Settings/Logs/Logs.DatePickers'
import ReportStickyNav from 'components/interfaces/Reports/ReportStickyNav'
import GrafanaPromoBanner from 'components/ui/GrafanaPromoBanner'
@@ -36,6 +39,7 @@ import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { useReportDateRange } from 'hooks/misc/useReportDateRange'
import { REPORT_DATERANGE_HELPER_LABELS } from 'components/interfaces/Reports/Reports.constants'
import { formatBytes } from 'lib/helpers'
+import UpgradePrompt from 'components/interfaces/Settings/Logs/UpgradePrompt'
import type { NextPageWithLayout } from 'types'
import type { MultiAttribute } from 'components/ui/Charts/ComposedChart.utils'
@@ -65,12 +69,14 @@ const DatabaseUsage = () => {
const {
selectedDateRange,
- updateDateRange: updateDateRangeFromHook,
- handleDatePickerChange,
+ updateDateRange,
datePickerValue,
datePickerHelpers,
isOrgPlanLoading,
orgPlan,
+ showUpgradePrompt,
+ setShowUpgradePrompt,
+ handleDatePickerChange,
} = useReportDateRange(REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES)
const isFreePlan = !isOrgPlanLoading && orgPlan?.id === 'free'
@@ -82,6 +88,7 @@ const DatabaseUsage = () => {
const queryClient = useQueryClient()
const [isRefreshing, setIsRefreshing] = useState(false)
+ const [showIncreaseDiskSizeModal, setshowIncreaseDiskSizeModal] = useState(false)
const isReplicaSelected = state.selectedDatabaseId !== project?.ref
@@ -95,7 +102,6 @@ const DatabaseUsage = () => {
const databaseSizeBytes = databaseSizeData ?? 0
const currentDiskSize = project?.volumeSizeGb ?? 0
- const [showIncreaseDiskSizeModal, setshowIncreaseDiskSizeModal] = useState(false)
const canUpdateDiskSizeConfig = useCheckPermissions(PermissionAction.UPDATE, 'projects', {
resource: {
project_id: project?.id,
@@ -178,10 +184,6 @@ const DatabaseUsage = () => {
}
}, [db, chart])
- const updateDateRange: UpdateDateRange = (from: string, to: string) => {
- updateDateRangeFromHook(from, to)
- }
-
return (
<>
<ReportHeader showDatabaseSelector title="Database" />
@@ -203,6 +205,13 @@ const DatabaseUsage = () => {
value={datePickerValue}
helpers={datePickerHelpers}
/>
+ <UpgradePrompt
+ show={showUpgradePrompt}
+ setShowUpgradePrompt={setShowUpgradePrompt}
+ title="Report date range"
+ description="Report data can be stored for a maximum of 3 months depending on the plan that your project is on."
+ source="databaseReportDateRange"
+ />
{selectedDateRange && (
<div className="flex items-center gap-x-2 text-xs">
<p className="text-foreground-light">
diff --git a/apps/studio/pages/project/[ref]/reports/edge-functions.tsx b/apps/studio/pages/project/[ref]/reports/edge-functions.tsx
index fe5a1329bb3..aca909da528 100644
--- a/apps/studio/pages/project/[ref]/reports/edge-functions.tsx
+++ b/apps/studio/pages/project/[ref]/reports/edge-functions.tsx
@@ -11,7 +11,10 @@ import ReportsLayout from 'components/layouts/ReportsLayout/ReportsLayout'
import ReportChart from 'components/interfaces/Reports/ReportChart'
import ReportStickyNav from 'components/interfaces/Reports/ReportStickyNav'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
-import { LogsDatePicker } from 'components/interfaces/Settings/Logs/Logs.DatePickers'
+import {
+ LogsDatePicker,
+ DatePickerValue,
+} from 'components/interfaces/Settings/Logs/Logs.DatePickers'
import { Button, Checkbox, DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from 'ui'
import { Label } from '@ui/components/shadcn/ui/label'
@@ -19,6 +22,7 @@ import { getEdgeFunctionReportAttributes } from 'data/reports/edgefn-charts'
import { useEdgeFunctionsQuery } from 'data/edge-functions/edge-functions-query'
import { useReportDateRange } from 'hooks/misc/useReportDateRange'
import { REPORT_DATERANGE_HELPER_LABELS } from 'components/interfaces/Reports/Reports.constants'
+import UpgradePrompt from 'components/interfaces/Settings/Logs/UpgradePrompt'
import type { NextPageWithLayout } from 'types'
@@ -56,10 +60,14 @@ const EdgeFunctionsUsage = () => {
const {
selectedDateRange,
- updateDateRange: updateDateRangeFromHook,
- handleDatePickerChange,
+ updateDateRange,
datePickerValue,
datePickerHelpers,
+ isOrgPlanLoading,
+ orgPlan,
+ showUpgradePrompt,
+ setShowUpgradePrompt,
+ handleDatePickerChange,
} = useReportDateRange(REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES)
const queryClient = useQueryClient()
@@ -75,10 +83,6 @@ const EdgeFunctionsUsage = () => {
setTimeout(() => setIsRefreshing(false), 1000)
}
- const updateDateRange: UpdateDateRange = (from: string, to: string) => {
- updateDateRangeFromHook(from, to)
- }
-
if (!ref) {
// Prevent rendering charts until the ref is available
return <></>
@@ -104,6 +108,13 @@ const EdgeFunctionsUsage = () => {
value={datePickerValue}
helpers={datePickerHelpers}
/>
+ <UpgradePrompt
+ show={showUpgradePrompt}
+ setShowUpgradePrompt={setShowUpgradePrompt}
+ title="Report date range"
+ description="Report data can be stored for a maximum of 3 months depending on the plan that your project is on."
+ source="edgeFunctionsReportDateRange"
+ />
<DropdownMenu open={isOpen} onOpenChange={setIsOpen}>
<DropdownMenuTrigger asChild>
<Button type="default" iconRight={<ChevronDown />}>
@@ -213,6 +224,7 @@ const EdgeFunctionsUsage = () => {
endDate={selectedDateRange?.period_end?.date}
updateDateRange={updateDateRange}
functionIds={functionIds}
+ orgPlanId={orgPlan?.id}
/>
))}
</ReportStickyNav>
diff --git a/apps/studio/pages/project/[ref]/reports/realtime.tsx b/apps/studio/pages/project/[ref]/reports/realtime.tsx
index 17de0d3a1b4..8e3608d854f 100644
--- a/apps/studio/pages/project/[ref]/reports/realtime.tsx
+++ b/apps/studio/pages/project/[ref]/reports/realtime.tsx
@@ -10,7 +10,10 @@ import ReportPadding from 'components/interfaces/Reports/ReportPadding'
import ReportsLayout from 'components/layouts/ReportsLayout/ReportsLayout'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { useDatabaseSelectorStateSnapshot } from 'state/database-selector'
-import { LogsDatePicker } from 'components/interfaces/Settings/Logs/Logs.DatePickers'
+import {
+ LogsDatePicker,
+ DatePickerValue,
+} from 'components/interfaces/Settings/Logs/Logs.DatePickers'
import {
ResponseSpeedChartRenderer,
TopApiRoutesRenderer,
@@ -26,6 +29,7 @@ import { useApiReport } from 'data/reports/api-report-query'
import { useReportDateRange } from 'hooks/misc/useReportDateRange'
import { REPORT_DATERANGE_HELPER_LABELS } from 'components/interfaces/Reports/Reports.constants'
import ReportStickyNav from 'components/interfaces/Reports/ReportStickyNav'
+import UpgradePrompt from 'components/interfaces/Settings/Logs/UpgradePrompt'
import type { NextPageWithLayout } from 'types'
import type { MultiAttribute } from 'components/ui/Charts/ComposedChart.utils'
@@ -68,9 +72,11 @@ const RealtimeUsage = () => {
const {
selectedDateRange,
updateDateRange: updateDateRangeFromHook,
- handleDatePickerChange,
datePickerValue,
datePickerHelpers,
+ showUpgradePrompt,
+ setShowUpgradePrompt,
+ handleDatePickerChange: handleDatePickerChangeFromHook,
isOrgPlanLoading,
orgPlan,
} = useReportDateRange(REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES)
@@ -123,6 +129,16 @@ const RealtimeUsage = () => {
}
}, [])
+ const handleDatePickerChange = (values: DatePickerValue) => {
+ const promptShown = handleDatePickerChangeFromHook(values)
+ if (!promptShown) {
+ report.mergeParams({
+ iso_timestamp_start: values.from,
+ iso_timestamp_end: values.to,
+ })
+ }
+ }
+
const updateDateRange: UpdateDateRange = (from: string, to: string) => {
updateDateRangeFromHook(from, to)
report.mergeParams({
@@ -151,6 +167,13 @@ const RealtimeUsage = () => {
value={datePickerValue}
helpers={datePickerHelpers}
/>
+ <UpgradePrompt
+ show={showUpgradePrompt}
+ setShowUpgradePrompt={setShowUpgradePrompt}
+ title="Report date range"
+ description="Report data can be stored for a maximum of 3 months depending on the plan that your project is on."
+ source="realtimeReportDateRange"
+ />
{selectedDateRange && (
<div className="flex items-center gap-x-2 text-xs">
<p className="text-foreground-light">
diff --git a/apps/studio/pages/project/[ref]/reports/storage.tsx b/apps/studio/pages/project/[ref]/reports/storage.tsx
index 2497f568645..8a9cfc0fa15 100644
--- a/apps/studio/pages/project/[ref]/reports/storage.tsx
+++ b/apps/studio/pages/project/[ref]/reports/storage.tsx
@@ -8,7 +8,10 @@ import {
CacheHitRateChartRenderer,
TopCacheMissesRenderer,
} from 'components/interfaces/Reports/renderers/StorageRenderers'
-import { DatePickerValue } from 'components/interfaces/Settings/Logs/Logs.DatePickers'
+import {
+ DatePickerValue,
+ LogsDatePicker,
+} from 'components/interfaces/Settings/Logs/Logs.DatePickers'
import DefaultLayout from 'components/layouts/DefaultLayout'
import {
NetworkTrafficRenderer,
@@ -19,10 +22,12 @@ import {
import ReportsLayout from 'components/layouts/ReportsLayout/ReportsLayout'
import { REPORT_DATERANGE_HELPER_LABELS } from 'components/interfaces/Reports/Reports.constants'
import ReportStickyNav from 'components/interfaces/Reports/ReportStickyNav'
+import { useState } from 'react'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { useReportDateRange } from 'hooks/misc/useReportDateRange'
import { useStorageReport } from 'data/reports/storage-report-query'
+import UpgradePrompt from 'components/interfaces/Settings/Logs/UpgradePrompt'
import type { NextPageWithLayout } from 'types'
@@ -42,18 +47,23 @@ export const StorageReport: NextPageWithLayout = () => {
refresh,
} = report
- const { datePickerHelpers, datePickerValue, handleDatePickerChange } = useReportDateRange(
- REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES
- )
+ const {
+ datePickerHelpers,
+ datePickerValue,
+ handleDatePickerChange: handleDatePickerChangeFromHook,
+ showUpgradePrompt,
+ setShowUpgradePrompt,
+ } = useReportDateRange(REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES)
const handleDatepickerChange = (vals: DatePickerValue) => {
- // Update localStorage and hook state
- handleDatePickerChange(vals)
- // Update query params for the report
- mergeParams({
- iso_timestamp_start: vals.from || '',
- iso_timestamp_end: vals.to || '',
- })
+ const promptShown = handleDatePickerChangeFromHook(vals)
+ if (!promptShown) {
+ // Update query params for the report
+ mergeParams({
+ iso_timestamp_start: vals.from || '',
+ iso_timestamp_end: vals.to || '',
+ })
+ }
}
return (
@@ -61,7 +71,7 @@ export const StorageReport: NextPageWithLayout = () => {
<ReportHeader title="Storage" showDatabaseSelector={false} />
<ReportStickyNav
content={
- <>
+ <div className="flex items-center gap-3">
<ReportFilterBar
onRemoveFilters={removeFilters}
onDatepickerChange={handleDatepickerChange}
@@ -77,7 +87,14 @@ export const StorageReport: NextPageWithLayout = () => {
className="w-full"
showDatabaseSelector={false}
/>
- </>
+ <UpgradePrompt
+ show={showUpgradePrompt}
+ setShowUpgradePrompt={setShowUpgradePrompt}
+ title="Report date range"
+ description="Report data can be stored for a maximum of 3 months depending on the plan that your project is on."
+ source="storageReportDateRange"
+ />
+ </div>
}
>
<ReportWidget
diff --git a/apps/studio/tests/features/reports/api-report.test.tsx b/apps/studio/tests/features/reports/api-report.test.tsx
index 40b671833c0..73692908236 100644
--- a/apps/studio/tests/features/reports/api-report.test.tsx
+++ b/apps/studio/tests/features/reports/api-report.test.tsx
@@ -1,26 +1,8 @@
import { screen } from '@testing-library/react'
-import { beforeAll, test, vi } from 'vitest'
+import { test } from 'vitest'
import { ApiReport } from 'pages/project/[ref]/reports/api-overview'
-import { render } from 'tests/helpers'
-
-// [Joshen] Mock data for ApiReport is in __mocks__/hooks/useApiReport
-// I don't think this is an ideal set up as the mock data is not clear in this file itself
-// But this is the method that worked for me after hours of wrangling with jest.spyOn and jest.mock
-// which for some reason none of them worked when I was trying to mock the data within the file itself
-// I'd be keen to see how we can do this better if anyone is more familiar to jest 🙏
-
-beforeAll(() => {
- vi.mock('nuqs', async () => {
- let queryValue = 'example'
- return {
- useQueryState: () => [queryValue, (v: string) => (queryValue = v)],
- parseAsBoolean: {
- withDefault: () => true,
- },
- }
- })
-})
+import { customRender as render } from 'tests/lib/custom-render'
test(`Render static elements`, async () => {
render(<ApiReport dehydratedState={{}} />)
@@ -28,7 +10,7 @@ test(`Render static elements`, async () => {
await screen.findByText('Response Errors')
await screen.findByText('Response Speed')
await screen.findByText('Network Traffic')
- await screen.findByText(/Last 10 minutes/)
+ await screen.findByText(/Last 60 minutes/)
await screen.findByText(/Add filter/)
await screen.findByText(/All Requests/)
})