mirror of
https://github.com/supabase/supabase.git
synced 2026-10-19 16:19:10 +03:00
* Fix tests in tests/unit, tests/components and files under tests, looking into tests/pages * Fix tests under pages/projects root * Fix * Comment out broken tests that im stuck with * Fix api-report.test * Fix storage-report-test * chore: fix some tests * chore: remove logging * Fix LogsPreviewer.test.js * Fix most of logs-query-test * Skip broken tests instead of false positiving them --------- Co-authored-by: TzeYiing <ty@tzeyiing.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 { LogsEndpointParams } from 'components/interfaces/Settings/Logs'
|
|
|
|
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,
|
|
}
|
|
}
|