Skip to content

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

feat: add storage renderers

TzeYiingb7342f4fa8ed
diff --git a/studio/components/interfaces/Reports/renderers/StorageRenderers.tsx b/studio/components/interfaces/Reports/renderers/StorageRenderers.tsx
index 6e1fadd7933..eba43e7e5d2 100644
--- a/studio/components/interfaces/Reports/renderers/StorageRenderers.tsx
+++ b/studio/components/interfaces/Reports/renderers/StorageRenderers.tsx
@@ -1,18 +1,9 @@
-import { Button, IconChevronRight } from 'ui'
-import { jsonSyntaxHighlight } from 'components/interfaces/Settings/Logs/LogsFormatters'
-import { BarChart } from 'components/to-be-cleaned/Charts/ChartRenderer'
import Table from 'components/to-be-cleaned/Table'
-import { USAGE_COLORS } from 'components/ui/Charts/Charts.constants'
-import StackedAreaChart from 'components/ui/Charts/StackedAreaChart'
-import { useState } from 'react'
-import { DATETIME_FORMAT } from '../Reports.constants'
-import { PathsDatum, StatusCodesDatum } from '../Reports.types'
-import { queryParamsToObject } from '../Reports.utils'
import { ReportWidgetProps } from '../ReportWidget'
export const renderLargestObjectsPerBucket = (
props: ReportWidgetProps<{
- path_tokens: string
+ name: string
mimetype: string
bucket_id: string
size: number
@@ -25,7 +16,7 @@ export const renderLargestObjectsPerBucket = (
className="relative rounded border border-scale-600"
head={
<>
- <Table.th className="sticky top-0 z-10">Path</Table.th>
+ <Table.th className="sticky top-0 z-10">Name</Table.th>
<Table.th className="sticky top-0 z-10">Mimetype</Table.th>
<Table.th className="sticky top-0 z-10">Size</Table.th>
</>
@@ -34,7 +25,7 @@ export const renderLargestObjectsPerBucket = (
<>
{props.data.map((row, index) => (
<Table.tr key={index}>
- <Table.td>{row.path_tokens}</Table.td>
+ <Table.td>{row.name}</Table.td>
<Table.td>{row.bucket_id}</Table.td>
<Table.td>{row.size}</Table.td>
<Table.td>{row.row}</Table.td>
@@ -45,3 +36,163 @@ export const renderLargestObjectsPerBucket = (
/>
)
}
+
+export const renderTopDownloaded = (
+ props: ReportWidgetProps<{
+ count: number
+ path: string
+ }>
+) => {
+ return (
+ <Table
+ containerClassName="max-h-72 w-full overflow-y-auto"
+ className="relative rounded border border-scale-600"
+ head={
+ <>
+ <Table.th className="sticky top-0 z-10">Path</Table.th>
+ <Table.th className="sticky top-0 z-10">Download Count</Table.th>
+ </>
+ }
+ body={
+ <>
+ {props.data.map((row, index) => (
+ <Table.tr key={index}>
+ <Table.td>{row.path}</Table.td>
+ <Table.td>{row.count}</Table.td>
+ </Table.tr>
+ ))}
+ </>
+ }
+ />
+ )
+}
+
+export const renderMostFiles = (
+ props: ReportWidgetProps<{
+ owner: string
+ file_count: number
+ total_size: number
+ }>
+) => {
+ return (
+ <Table
+ containerClassName="max-h-72 w-full overflow-y-auto"
+ className="relative rounded border border-scale-600"
+ head={
+ <>
+ <Table.th className="sticky top-0 z-10">User</Table.th>
+ <Table.th className="sticky top-0 z-10">Count</Table.th>
+ <Table.th className="sticky top-0 z-10">Total Size</Table.th>
+ </>
+ }
+ body={
+ <>
+ {props.data.map((row, index) => (
+ <Table.tr key={index}>
+ <Table.td>{row.owner}</Table.td>
+ <Table.td>{row.file_count}</Table.td>
+ <Table.td>{row.total_size}</Table.td>
+ </Table.tr>
+ ))}
+ </>
+ }
+ />
+ )
+}
+export const renderStaleFiles = (
+ props: ReportWidgetProps<{
+ one_month: number
+ three_month: number
+ six_month: number
+ one_year: number
+ }>
+) => {
+ return (
+ <Table
+ containerClassName="max-h-72 w-full overflow-y-auto"
+ className="relative rounded border border-scale-600"
+ head={
+ <>
+ <Table.th className="sticky top-0 z-10">1 Month</Table.th>
+ <Table.th className="sticky top-0 z-10">3 Months</Table.th>
+ <Table.th className="sticky top-0 z-10">6 Months</Table.th>
+ <Table.th className="sticky top-0 z-10">12 Months</Table.th>
+ </>
+ }
+ body={
+ <>
+ {props.data.map((row, index) => (
+ <Table.tr key={index}>
+ <Table.td>{row.one_month}</Table.td>
+ <Table.td>{row.three_month}</Table.td>
+ <Table.td>{row.six_month}</Table.td>
+ <Table.td>{row.one_year}</Table.td>
+ </Table.tr>
+ ))}
+ </>
+ }
+ />
+ )
+}
+
+export const renderTopSizes = (
+ props: ReportWidgetProps<{
+ count: number
+ search: string
+ }>
+) => {
+ return (
+ <Table
+ containerClassName="max-h-72 w-full overflow-y-auto"
+ className="relative rounded border border-scale-600"
+ head={
+ <>
+ <Table.th className="sticky top-0 z-10">Search</Table.th>
+ <Table.th className="sticky top-0 z-10">Count</Table.th>
+ </>
+ }
+ body={
+ <>
+ {props.data.map((row, index) => (
+ <Table.tr key={index}>
+ <Table.td>{row.count}</Table.td>
+ <Table.td>{row.search}</Table.td>
+ </Table.tr>
+ ))}
+ </>
+ }
+ />
+ )
+}
+export const renderCacheHitRate = (
+ props: ReportWidgetProps<{
+ timestamp: string
+ hit_count: number
+ miss_count: number
+ }>
+) => {
+ return (
+ <Table
+ containerClassName="max-h-72 w-full overflow-y-auto"
+ className="relative rounded border border-scale-600"
+ head={
+ <>
+ <Table.th className="sticky top-0 z-10">timestamp</Table.th>
+ <Table.th className="sticky top-0 z-10">hit</Table.th>
+ <Table.th className="sticky top-0 z-10">miss</Table.th>
+ </>
+ }
+ body={
+ <>
+ {props.data.map((row, index) => (
+ <Table.tr key={index}>
+ <Table.td>{row.timestamp}</Table.td>
+ <Table.td>{row.hit_count}</Table.td>
+ <Table.td>{row.miss_count}</Table.td>
+ </Table.tr>
+ ))}
+ </>
+ }
+ />
+ )
+}
diff --git a/studio/pages/project/[ref]/reports/storage.tsx b/studio/pages/project/[ref]/reports/storage.tsx
index 6dce6bc3bf4..150975754ac 100644
--- a/studio/pages/project/[ref]/reports/storage.tsx
+++ b/studio/pages/project/[ref]/reports/storage.tsx
@@ -8,8 +8,14 @@ import { hooksFactory, usePresetReport } from 'components/interfaces/Reports/Rep
import { PRESET_CONFIG } from 'components/interfaces/Reports/Reports.constants'
import ReportWidget from 'components/interfaces/Reports/ReportWidget'
import {
+ renderCacheHitRate,
renderLargestObjectsPerBucket,
+ renderMostFiles,
+ renderStaleFiles,
+ renderTopDownloaded,
+ renderTopSizes,
} from 'components/interfaces/Reports/renderers/StorageRenderers'
+import Divider from 'components/ui/Divider'
export const StorageReport: NextPageWithLayout = () => {
const router = useRouter()
@@ -22,13 +28,6 @@ export const StorageReport: NextPageWithLayout = () => {
const staleFiles = hooks.staleFiles()
const topSizes = hooks.topSizes()
const cacheHitRate = hooks.cacheHitRate()
- // const dailyActiveUsers = hooks.dailyActiveUsers()
- // const newUsers = hooks.newUsers()
- // const cumulativeUsers = hooks.cumulativeUsers()
- // const failedMigrations = hooks.failedMigrations()
- // const signUpProviders = hooks.signUpProviders()
- // const unverifiedUsers = hooks.unverifiedUsers()
- // const bannedUsers = hooks.bannedUsers()
const { isLoading, Layout } = usePresetReport([
largestObjectsPerBucket,
@@ -36,90 +35,72 @@ export const StorageReport: NextPageWithLayout = () => {
mostFiles,
staleFiles,
topSizes,
- cacheHitRate,
-
+ cacheHitRate,
])
return (
<Layout title={config.title}>
<div className="flex flex-col grid lg:grid-cols-6 gap-4">
- <ReportWidget
+ <ReportWidget
+ isLoading={isLoading}
+ params={cacheHitRate[0].params}
+ className="col-span-3 col-start-1"
+ title="Cache Hit Rate"
+ description="Edge Network Cache Hit Rate"
+ data={cacheHitRate[0]?.logData || []}
+ renderer={renderCacheHitRate}
+ />
+
+ <ReportWidget
isLoading={isLoading}
params={largestObjectsPerBucket[0].params}
className="col-span-3 col-start-1"
title="Largest Objects"
description="Large objects in each bucket"
- data={largestObjectsPerBucket[0].data}
+ data={largestObjectsPerBucket[0]?.data || []}
renderer={renderLargestObjectsPerBucket}
/>
- {/* <ReportWidget
- isLoading={isLoading}
- params={cumulativeUsers[0].params}
- className="col-span-3 col-start-1"
- title="Users Over Time"
- description="Cumulative count of confirmed users"
- data={cumulativeUsers[0].data!}
- renderer={renderCumulativeUsers}
- />
- <ReportWidget
- isLoading={isLoading}
- params={newUsers[0].params}
- className="col-span-3 col-start-4"
- title="Daily New Users"
- description="The daily count of new user signups"
- data={newUsers[0].data!}
- renderer={renderNewUsers}
- />
<ReportWidget
isLoading={isLoading}
- params={dailyActiveUsers[0].params}
- className="col-span-6 col-start-1"
- title="Daily Active Users"
- description="The daily count of active authenticated users"
- data={dailyActiveUsers[0].logData!}
- renderer={renderDailyActiveUsers}
+ params={topDownloaded[0].params}
+ className="col-span-3 col-start-1"
+ title="Top Downloaded Objects"
+ description="Top download objectss"
+ data={topDownloaded[0]?.data || []}
+ renderer={renderTopDownloaded}
/>
+ <Divider light />
+
<ReportWidget
isLoading={isLoading}
- params={signUpProviders[0].params}
- className="row-span-4 col-span-4 col-start-3"
- title="Sign Up Providers"
- description="The breakdown of providers used for user creation"
- data={signUpProviders[0].data!}
- renderer={renderSignUpProviders}
- />
- <ReportWidget
- isLoading={isLoading}
- params={unverifiedUsers[0].params}
- className="row-span-1 col-span-2 col-start-1"
- title="Unverified Users"
- tooltip="High number of unverified users may indicate spamming and malicious behavior."
- data={unverifiedUsers[0].data! || []}
- renderer={renderUnverifiedUsers}
+ params={mostFiles[0].params}
+ className="col-span-3 col-start-1"
+ title="Users with Most Files"
+ description="Users with the most associated storage files"
+ data={mostFiles[0]?.data || []}
+ renderer={renderMostFiles}
/>
<ReportWidget
isLoading={isLoading}
- params={bannedUsers[0].params}
- className="row-span-1 col-span-2 col-start-1"
- title="Banned Users"
- tooltip="High number of banned users may indicate malicious behavior."
- data={bannedUsers[0].data! || []}
- renderer={renderBannedUsers}
+ params={staleFiles[0].params}
+ className="col-span-3 col-start-1"
+ title="Stale Objects"
+ description="Objects by months from last access"
+ data={staleFiles[0]?.data || []}
+ renderer={renderStaleFiles}
/>
- <h2 className="col-span-full">Sever Health</h2>
<ReportWidget
isLoading={isLoading}
- params={failedMigrations[0].params}
- className="col-span-2 col-start-1"
- title="Failed Migrations"
- tooltip="Failed GoTrue migrations may cause issues with user authentication."
- data={failedMigrations[0].logData!}
- renderer={renderFailedMigrations}
+ params={topSizes[0].params}
+ className="col-span-3 col-start-1"
+ title="Top Object Sizes"
+ description="Most frequently used object sizes"
+ data={topSizes[0]?.logData || []}
+ renderer={renderTopSizes}
/>
- */}
- </div>
+ </div>
</Layout>
)
}