import { useState, useEffect } from 'react' import { api } from '../api' export default function Records({ source }) { const [rows, setRows] = useState([]) const [exists, setExists] = useState(null) const [offset, setOffset] = useState(0) const [loading, setLoading] = useState(false) const LIMIT = 100 useEffect(() => { if (!source) return setOffset(0) load(0) }, [source]) async function load(off) { setLoading(true) try { const res = await api.getViewData(source, LIMIT, off) setExists(res.exists) setRows(res.rows) } catch (err) { console.error(err) } finally { setLoading(false) } } function prev() { const o = Math.max(0, offset - LIMIT); setOffset(o); load(o) } function next() { const o = offset + LIMIT; setOffset(o); load(o) } if (!source) return
Loading…
} {!loading && exists === false && (No view generated yet. Go to Sources, check fields as In view, then click Generate view.
)} {!loading && exists && rows.length === 0 && (View exists but no transformed records yet. Import data and run a transform first.
)} {!loading && exists && rows.length > 0 && ( <>| {col} | ))}
|---|
| {val === null ? — : String(val)} | ))}