The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
refactor(studio): remove legacy homepage usage section (V1) (#46994)
Jordi Enric0c9eb15cbab1
diff --git a/apps/studio/components/interfaces/Home/ProjectUsage.tsx b/apps/studio/components/interfaces/Home/ProjectUsage.tsxdeleted file mode 100644index abf36066ec2..00000000000--- a/apps/studio/components/interfaces/Home/ProjectUsage.tsx+++ /dev/null@@ -1,238 +0,0 @@-import { useParams } from 'common'-import dayjs from 'dayjs'-import { Auth, Database, Realtime, Storage } from 'icons'-import sumBy from 'lodash/sumBy'-import Link from 'next/link'-import { useRouter } from 'next/router'-import { useEffect, useState } from 'react'-import { Loading } from 'ui'--import BarChart from '@/components/ui/Charts/BarChart'-import { ChartIntervalDropdown } from '@/components/ui/Logs/ChartIntervalDropdown'-import { CHART_INTERVALS } from '@/components/ui/Logs/logs.utils'-import Panel from '@/components/ui/Panel'-import {- ProjectLogStatsVariables,- UsageApiCounts,- useProjectLogStatsQuery,-} from '@/data/analytics/project-log-stats-query'-import { useFillTimeseriesSorted } from '@/hooks/analytics/useFillTimeseriesSorted'-import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements'-import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'-import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'--type ChartIntervalKey = ProjectLogStatsVariables['interval']--const ProjectUsage = () => {- const router = useRouter()- const { ref: projectRef } = useParams()- const { data: organization } = useSelectedOrganizationQuery()-- const { projectAuthAll: authEnabled, projectStorageAll: storageEnabled } = useIsFeatureEnabled([- 'project_auth:all',- 'project_storage:all',- ])-- const { getEntitlementMax } = useCheckEntitlements('log.retention_days')- const retentionDays = getEntitlementMax()-- const DEFAULT_INTERVAL: ChartIntervalKey =- retentionDays !== undefined && retentionDays < 7 ? '1hr' : '1day'-- const [interval, setInterval] = useState<ChartIntervalKey>(DEFAULT_INTERVAL)-- useEffect(() => {- setInterval(retentionDays !== undefined && retentionDays < 7 ? '1hr' : '1day')- }, [retentionDays])-- const { data, isPending: isLoading } = useProjectLogStatsQuery({ projectRef, interval })-- const selectedInterval = CHART_INTERVALS.find((i) => i.key === interval) || CHART_INTERVALS[1]- const startDateLocal = dayjs().subtract(- selectedInterval.startValue,- selectedInterval.startUnit as dayjs.ManipulateType- )- const endDateLocal = dayjs()- const { data: charts } = useFillTimeseriesSorted({- data: data?.result ?? [],- timestampKey: 'timestamp',- valueKey: [- 'total_auth_requests',- 'total_rest_requests',- 'total_storage_requests',- 'total_realtime_requests',- ],- defaultValue: 0,- startDate: startDateLocal.toISOString(),- endDate: endDateLocal.toISOString(),- minPointsToFill: 5,- })- const datetimeFormat = selectedInterval.format || 'MMM D, ha'-- const handleBarClick = (- value: UsageApiCounts,- _type: 'rest' | 'realtime' | 'storage' | 'auth'- ) => {- const unit = selectedInterval.startUnit- const selectedStart = dayjs(value?.timestamp)- const selectedEnd = selectedStart.add(1, unit)-- if (_type === 'rest') {- router.push(- `/project/${projectRef}/logs/edge-logs?its=${selectedStart.toISOString()}&ite=${selectedEnd.toISOString()}`- )- return- }-- router.push(- `/project/${projectRef}/logs/edge-logs?its=${selectedStart.toISOString()}&ite=${selectedEnd.toISOString()}&f=${JSON.stringify(- {- product: {- [_type]: true,- },- }- )}`- )- }-- return (- <div className="space-y-6">- <div className="flex flex-row items-center gap-x-2">- <ChartIntervalDropdown- value={interval || '1day'}- onChange={(interval) => setInterval(interval as ProjectLogStatsVariables['interval'])}- organizationSlug={organization?.slug}- dropdownAlign="start"- tooltipSide="right"- />- <span className="text-xs text-foreground-light">- Statistics for {selectedInterval.label.toLowerCase()}- </span>- </div>- <div className="grid grid-cols-1 @md:grid-cols-2 gap-4 @2xl:grid-cols-4">- <Panel className="mb-0">- <Panel.Content className="space-y-4">- <PanelHeader- icon={- <div className="rounded-sm bg-surface-300 p-1.5 text-foreground-light shadow-xs">- <Database strokeWidth={1.5} size={16} />- </div>- }- title="Database"- href={`/project/${projectRef}/editor`}- />-- <Loading active={isLoading}>- <BarChart- title="REST Requests"- data={charts}- xAxisKey="timestamp"- yAxisKey="total_rest_requests"- onBarClick={(v: unknown) => handleBarClick(v as UsageApiCounts, 'rest')}- customDateFormat={datetimeFormat}- highlightedValue={sumBy(charts, 'total_rest_requests')}- />- </Loading>- </Panel.Content>- </Panel>- {authEnabled && (- <Panel className="mb-0 md:mb-0">- <Panel.Content className="space-y-4">- <PanelHeader- icon={- <div className="rounded-sm bg-surface-300 p-1.5 text-foreground-light shadow-xs">- <Auth strokeWidth={1.5} size={16} />- </div>- }- title="Auth"- href={`/project/${projectRef}/auth/users`}- />- <Loading active={isLoading}>- <BarChart- title="Auth Requests"- data={charts}- xAxisKey="timestamp"- yAxisKey="total_auth_requests"- onBarClick={(v: unknown) => handleBarClick(v as UsageApiCounts, 'auth')}- customDateFormat={datetimeFormat}- highlightedValue={sumBy(charts || [], 'total_auth_requests')}- />- </Loading>- </Panel.Content>- </Panel>- )}- {storageEnabled && (- <Panel className="mb-0 md:mb-0">- <Panel.Content className="space-y-4">- <PanelHeader- icon={- <div className="rounded-sm bg-surface-300 p-1.5 text-foreground-light shadow-xs">- <Storage strokeWidth={1.5} size={16} />- </div>- }- title="Storage"- href={`/project/${projectRef}/storage/buckets`}- />-- <Loading active={isLoading}>- <BarChart- title="Storage Requests"- data={charts}- xAxisKey="timestamp"- yAxisKey="total_storage_requests"- onBarClick={(v: unknown) => handleBarClick(v as UsageApiCounts, 'storage')}- customDateFormat={datetimeFormat}- highlightedValue={sumBy(charts, 'total_storage_requests')}- />- </Loading>- </Panel.Content>- </Panel>- )}- <Panel className="mb-0 md:mb-0">- <Panel.Content className="space-y-4">- <PanelHeader- icon={- <div className="rounded-sm bg-surface-300 p-1.5 text-foreground-light shadow-xs">- <Realtime strokeWidth={1.5} size={16} />- </div>- }- title="Realtime"- />-- <Loading active={isLoading}>- <BarChart- title="Realtime Requests"- data={charts}- xAxisKey="timestamp"- yAxisKey="total_realtime_requests"- onBarClick={(v: unknown) => handleBarClick(v as UsageApiCounts, 'realtime')}- customDateFormat={datetimeFormat}- highlightedValue={sumBy(charts, 'total_realtime_requests')}- />- </Loading>- </Panel.Content>- </Panel>- </div>- </div>- )-}-export default ProjectUsage--const PanelHeader = (props: any) => {- const Tag = props?.href ? Link : 'div'- return (- <Tag href={props.href}>- <div- className={- 'flex items-center space-x-3 opacity-80 transition ' +- (props.href ? 'cursor-pointer hover:text-gray-1200 hover:opacity-100' : '')- }- >- <div>{props.icon}</div>- <span className="flex items-center space-x-1">- <h4 className="mb-0 text-lg">{props.title}</h4>- </span>- </div>- </Tag>- )-}diff --git a/apps/studio/components/interfaces/Home/ProjectUsageSection.tsx b/apps/studio/components/interfaces/Home/ProjectUsageSection.tsxdeleted file mode 100644index a59bc01245d..00000000000--- a/apps/studio/components/interfaces/Home/ProjectUsageSection.tsx+++ /dev/null@@ -1,38 +0,0 @@-import { AlertCircle } from 'lucide-react'--import ProjectUsage from './ProjectUsage'-import { ProjectUsageLoadingState } from '@/components/layouts/ProjectLayout/LoadingState'-import InformationBox from '@/components/ui/InformationBox'-import { useProjectLogRequestsCountQuery } from '@/data/analytics/project-log-requests-count-query'-import { useProjectLogStatsQuery } from '@/data/analytics/project-log-stats-query'-import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'--export const ProjectUsageSection = () => {- const { data: project } = useSelectedProjectQuery()- const { error, isPending: isLoading } = useProjectLogRequestsCountQuery({- projectRef: project?.ref,- })-- // wait for the stats to load before showing the usage section to eliminate multiple spinners- const { isPending: isLogsStatsLoading } = useProjectLogStatsQuery({- projectRef: project?.ref,- interval: '1hr',- })-- if (isLoading || isLogsStatsLoading) {- return <ProjectUsageLoadingState />- }-- if (error) {- return (- <InformationBox- hideCollapse- defaultVisibility- icon={<AlertCircle size={18} strokeWidth={2} />}- title="There was an issue loading the usage details of your project"- />- )- }-- return <ProjectUsage />-}diff --git a/apps/studio/components/interfaces/ProjectHome/Home.tsx b/apps/studio/components/interfaces/ProjectHome/Home.tsxindex bf906404a4e..6186810f5ea 100644--- a/apps/studio/components/interfaces/ProjectHome/Home.tsx+++ b/apps/studio/components/interfaces/ProjectHome/Home.tsx@@ -1,6 +1,6 @@import { DndContext, DragEndEvent, PointerSensor, useSensor, useSensors } from '@dnd-kit/core'import { arrayMove, SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable'-import { useFlag, useParams } from 'common'+import { useParams } from 'common'import dayjs from 'dayjs'import { useEffect, useRef } from 'react'import { cn } from 'ui'@@ -9,8 +9,7 @@ import { AdvisorSection } from './AdvisorSection'import { ConnectSection } from './ConnectSection'import { CustomReportSection } from './CustomReportSection'import { DEFAULT_SECTION_ORDER, mergeSectionOrder } from './Home.utils'-import { ProjectUsageSection as ProjectUsageSectionV2 } from './ProjectUsageSection'-import { ProjectUsageSection as ProjectUsageSectionV1 } from '@/components/interfaces/Home/ProjectUsageSection'+import { ProjectUsageSection } from './ProjectUsageSection'import { SortableSection } from '@/components/interfaces/ProjectHome/SortableSection'import { TopSection } from '@/components/interfaces/ProjectHome/TopSection'import { ProjectNeedsSecuring } from '@/components/layouts/ProjectNeedsSecuring/ProjectNeedsSecuring'@@ -27,8 +26,6 @@ export const ProjectHome = () => {const { data: project } = useSelectedProjectQuery()const track = useTrack()- const showHomepageUsageV2 = useFlag('newHomepageUsageV2')-const isMatureProject = dayjs(project?.inserted_at).isBefore(dayjs().subtract(10, 'day'))const hasShownEnableBranchingModalRef = useRef(false)@@ -40,8 +37,6 @@ export const ProjectHome = () => {DEFAULT_SECTION_ORDER)- const UsageSection = showHomepageUsageV2 ? ProjectUsageSectionV2 : ProjectUsageSectionV1-const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 8 } }))const handleDragEnd = (event: DragEndEvent) => {@@ -109,7 +104,7 @@ export const ProjectHome = () => {className={cn(isComingUp && 'opacity-60 pointer-events-none')}><SortableSection id={id}>- <UsageSection />+ <ProjectUsageSection /></SortableSection></div>)diff --git a/apps/studio/data/analytics/keys.ts b/apps/studio/data/analytics/keys.tsindex 966d2f80419..d95f98d4da9 100644--- a/apps/studio/data/analytics/keys.ts+++ b/apps/studio/data/analytics/keys.ts@@ -153,9 +153,6 @@ export const analyticsKeys = {usageApiCounts: (projectRef: string | undefined, interval: string | undefined) =>['projects', projectRef, 'usage.api-counts', interval] as const,- usageApiRequestsCount: (projectRef: string | undefined) =>- ['projects', projectRef, 'usage.api-requests-count'] as const,-serviceHealth: (projectRef: string | undefined,{diff --git a/apps/studio/data/analytics/project-log-requests-count-query.ts b/apps/studio/data/analytics/project-log-requests-count-query.tsdeleted file mode 100644index 9c4697495df..00000000000--- a/apps/studio/data/analytics/project-log-requests-count-query.ts+++ /dev/null@@ -1,58 +0,0 @@-import { QueryClient, useQuery } from '@tanstack/react-query'--import { analyticsKeys } from './keys'-import { get, handleError } from '@/data/fetchers'-import type { ResponseError, UseCustomQueryOptions } from '@/types'--export type ProjectLogRequestsCountVariables = {- projectRef?: string-}--export async function getProjectLogRequestsCountStats(- { projectRef }: ProjectLogRequestsCountVariables,- signal?: AbortSignal-) {- if (!projectRef) {- throw new Error('projectRef is required')- }-- const { data, error } = await get(- '/platform/projects/{ref}/analytics/endpoints/usage.api-requests-count',- {- params: { path: { ref: projectRef } },- signal,- }- )-- if (error) handleError(error)- return data-}--export type ProjectLogRequestsCountData = Awaited<- ReturnType<typeof getProjectLogRequestsCountStats>->-export type ProjectLogRequestsCountError = ResponseError--export const useProjectLogRequestsCountQuery = <TData = ProjectLogRequestsCountData>(- { projectRef }: ProjectLogRequestsCountVariables,- {- enabled = true,- ...options- }: UseCustomQueryOptions<ProjectLogRequestsCountData, ProjectLogRequestsCountError, TData> = {}-) =>- useQuery<ProjectLogRequestsCountData, ProjectLogRequestsCountError, TData>({- queryKey: analyticsKeys.usageApiRequestsCount(projectRef),- queryFn: ({ signal }) => getProjectLogRequestsCountStats({ projectRef }, signal),- enabled: enabled && typeof projectRef !== 'undefined',- ...options,- })--export function prefetchProjectLogRequestsCount(- client: QueryClient,- { projectRef }: ProjectLogRequestsCountVariables-) {- return client.fetchQuery({- queryKey: analyticsKeys.usageApiRequestsCount(projectRef),- queryFn: ({ signal }) => getProjectLogRequestsCountStats({ projectRef }, signal),- })-}