mirror of
https://github.com/supabase/supabase.git
synced 2026-05-31 18:03:33 +08:00
* chore: cleanup packages - Avoid circular imports - Export API-types as types - pg-format without depending on Node internal Buffer (not browser-compatible) - Avoid importing from barrel files in ui dir * chore: avoid barrel file imports in studio (#27771) * chore: avoid barrel file imports - Removes some unused imports - Avoids barrel file import for faster builds + less memory * add eslint rule * type fixes * delete layouts barrel * delete components/grid barrel file * delete components/grid/utils barrel file * delete components/grid/components/common barrel file * delete components/grid/components/editor barrel file * delete components/grid/components/formatter barrel file * delete components/grid/components/grid barrel file * delete components/grid/components/header/filter barrel file * remote components/grid/store barrel file * remove components/interfaces/Auth/Policies barrel file * delete components/interfaces/Settings/Logs barrel file * delete components/ui/CodeEditor barrel file * delete components/ui/Forms barrel file * delete components/ui/Shimmers barrel file * delete data/analytics barrel file * delete hooks barrel file * cleanup lib/common/fetch barrel file * final * barral files cleanup * global react-data-grid styles * remove console.log --------- Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com> * fix build --------- Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { useEffect } from 'react'
|
|
|
|
import { useParams } from 'common'
|
|
import { PRESET_CONFIG } from 'components/interfaces/Reports/Reports.constants'
|
|
import { queriesFactory } from 'components/interfaces/Reports/Reports.utils'
|
|
import type { LogsEndpointParams } from 'components/interfaces/Settings/Logs/Logs.types'
|
|
|
|
export const useStorageReport = () => {
|
|
const { ref: projectRef } = useParams()
|
|
|
|
const queryHooks = queriesFactory<keyof typeof PRESET_CONFIG.storage.queries>(
|
|
PRESET_CONFIG.storage.queries,
|
|
projectRef ?? 'default'
|
|
)
|
|
const cacheHitRate = queryHooks.cacheHitRate()
|
|
const topCacheMisses = queryHooks.topCacheMisses()
|
|
const activeHooks = [cacheHitRate, topCacheMisses]
|
|
|
|
const handleRefresh = async () => {
|
|
activeHooks.forEach((hook) => hook.runQuery())
|
|
}
|
|
const handleSetParams = (params: Partial<LogsEndpointParams>) => {
|
|
activeHooks.forEach((hook) => {
|
|
hook.setParams?.((prev: LogsEndpointParams) => ({ ...prev, ...params }))
|
|
})
|
|
}
|
|
|
|
useEffect(() => {
|
|
if (cacheHitRate.changeQuery) {
|
|
cacheHitRate.changeQuery(PRESET_CONFIG.storage.queries.cacheHitRate.sql([]))
|
|
}
|
|
|
|
if (topCacheMisses.changeQuery) {
|
|
topCacheMisses.changeQuery(PRESET_CONFIG.storage.queries.topCacheMisses.sql([]))
|
|
}
|
|
}, [])
|
|
|
|
const isLoading = activeHooks.some((hook) => hook.isLoading)
|
|
|
|
return {
|
|
data: {
|
|
cacheHitRate: cacheHitRate.logData,
|
|
topCacheMisses: topCacheMisses.logData,
|
|
},
|
|
params: {
|
|
cacheHitRate: cacheHitRate.params,
|
|
topCacheMisses: topCacheMisses.params,
|
|
},
|
|
mergeParams: handleSetParams,
|
|
isLoading,
|
|
refresh: handleRefresh,
|
|
}
|
|
}
|