ruvector/studio/components/ui/DataTable/LiveButton.tsx
rUv 814f595995 feat(studio): Add complete RuVector Studio application
Major additions:
- Complete Next.js studio application with 1600+ components
- Docker support (Dockerfile.combined, docker-compose.yml)
- GCP deployment documentation and benchmarks
- SQL benchmark scripts for performance testing
- Sentry integration for monitoring
- Comprehensive test suite and mocks

Studio features:
- Dashboard and admin interfaces
- Data visualization components
- Authentication and user management
- API integration with RuVector backend
- Static data and public assets

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-06 23:04:48 +00:00

71 lines
1.8 KiB
TypeScript

import type { FetchPreviousPageOptions } from '@tanstack/react-query'
import { CirclePause, CirclePlay } from 'lucide-react'
import { useQueryStates } from 'nuqs'
import { useEffect } from 'react'
import { useHotKey } from 'hooks/ui/useHotKey'
import { Button, cn } from 'ui'
import { useDataTable } from './providers/DataTableProvider'
const REFRESH_INTERVAL = 10_000
interface LiveButtonProps {
searchParamsParser: any
fetchPreviousPage?: (options?: FetchPreviousPageOptions | undefined) => Promise<unknown>
}
export function LiveButton({ fetchPreviousPage, searchParamsParser }: LiveButtonProps) {
const [{ live, date, sort }, setSearch] = useQueryStates(searchParamsParser)
const { table } = useDataTable()
useHotKey(handleClick, 'j')
useEffect(() => {
let timeoutId: NodeJS.Timeout
async function fetchData() {
if (live) {
await fetchPreviousPage?.()
timeoutId = setTimeout(fetchData, REFRESH_INTERVAL)
} else {
clearTimeout(timeoutId)
}
}
fetchData()
return () => {
clearTimeout(timeoutId)
}
}, [live, fetchPreviousPage])
// REMINDER: make sure to reset live when date is set
// TODO: test properly
useEffect(() => {
if ((date || sort) && live) {
setSearch((prev) => ({ ...prev, live: null }))
}
}, [date, sort])
function handleClick() {
setSearch((prev) => ({
...prev,
live: !prev.live,
date: null,
sort: null,
}))
table.getColumn('date')?.setFilterValue(undefined)
table.resetSorting()
}
return (
<Button
className={cn(live && 'border-info text-info hover:text-info')}
onClick={handleClick}
type={live ? 'primary' : 'default'}
size="tiny"
icon={live ? <CirclePause className="h-4 w-4" /> : <CirclePlay className="h-4 w-4" />}
>
Live
</Button>
)
}