mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
chore: refactor useSingleLog
This commit is contained in:
1 parent
a18bca75ef
commit
006f871f11
2 files changed
+9
-15
No files matched your search
@@ -35,7 +35,7 @@ const LogSelection: FC<LogSelectionProps> = ({
|
||||
queryType,
|
||||
params = {},
|
||||
}) => {
|
||||
const [{ logData: fullLog, isLoading }] = useSingleLog(
|
||||
const { logData: fullLog, isLoading } = useSingleLog(
|
||||
projectRef,
|
||||
queryType,
|
||||
params,
|
||||
|
||||
@@ -11,12 +11,10 @@ import { API_URL } from 'lib/constants'
|
||||
import { get } from 'lib/common/fetch'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
|
||||
interface Data {
|
||||
interface SingleLogHook {
|
||||
logData: LogData | undefined
|
||||
error: string | Object | null
|
||||
isLoading: boolean
|
||||
}
|
||||
interface Handlers {
|
||||
refresh: () => void
|
||||
}
|
||||
function useSingleLog(
|
||||
@@ -24,7 +22,7 @@ function useSingleLog(
|
||||
queryType?: QueryType,
|
||||
paramsToMerge?: Partial<LogsEndpointParams>,
|
||||
id?: string | null
|
||||
): [Data, Handlers] {
|
||||
): SingleLogHook {
|
||||
const table = queryType ? LOGS_TABLES[queryType] : undefined
|
||||
const sql = id && table ? genSingleLogQuery(table, id) : ''
|
||||
const params: LogsEndpointParams = { ...paramsToMerge, project: projectRef, sql }
|
||||
@@ -52,15 +50,11 @@ function useSingleLog(
|
||||
)
|
||||
|
||||
let error: null | string | object = rcError ? (rcError as any).message : null
|
||||
return [
|
||||
{
|
||||
logData: data?.result ? data.result[0] : undefined,
|
||||
isLoading: (enabled && isLoading) || isRefetching,
|
||||
error,
|
||||
},
|
||||
{
|
||||
refresh: () => refetch(),
|
||||
},
|
||||
]
|
||||
return {
|
||||
logData: data?.result ? data.result[0] : undefined,
|
||||
isLoading: (enabled && isLoading) || isRefetching,
|
||||
error,
|
||||
refresh: () => refetch(),
|
||||
}
|
||||
}
|
||||
export default useSingleLog
|
||||
Reference in new issue
Block a user