chore: full stack stability and migration fixes, plus react UI progress
This commit is contained in:
21
control-plane-ui/src/hooks/useDatabase.ts
Normal file
21
control-plane-ui/src/hooks/useDatabase.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { apiService, DbTable } from '../services/api'
|
||||
|
||||
export function useDatabase() {
|
||||
const tablesQuery = useQuery({
|
||||
queryKey: ['tables'],
|
||||
queryFn: () => apiService.getTables().then(res => res.data),
|
||||
})
|
||||
|
||||
const useTableData = (schema: string | null, name: string | null) => useQuery({
|
||||
queryKey: ['tableData', schema, name],
|
||||
queryFn: () => (schema && name) ? apiService.getTableData(schema, name).then(res => res.data) : Promise.resolve([]),
|
||||
enabled: !!(schema && name),
|
||||
})
|
||||
|
||||
return {
|
||||
tables: tablesQuery.data || [],
|
||||
isLoadingTables: tablesQuery.isLoading,
|
||||
useTableData,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user