feat(databases): Import Data modal — samples, CSV/JSON files, and URL loads#1412
Conversation
… loads Replaces the bare-bones Import CSV modal with an Import Data flow (#1292): - Sample Datasets: three bundled starter datasets (dogs, books, animals) loaded via csv_data_load, so they work on air-gapped instances too - Import from File: CSV via csv_data_load, JSON via insert - Load from URL: csv_url_load fetched by the instance - Missing tables are created automatically (primary key id) before loading - CSV loads now poll get_job until the job finishes instead of telling the user to wait and refresh - Second entry point in the Databases sidebar so import is available before any table exists Connect-to-database / live sync from the issue mockup needs backend support and is intentionally out of scope. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request replaces the CSV-only import modal with a comprehensive ImportDataModal that supports importing data from local CSV/JSON files, remote URLs, and pre-loaded sample datasets. It also introduces utility functions for parsing JSON records, a job polling mechanism to track asynchronous imports, and corresponding unit tests. Feedback on these changes includes improving the resilience of the job polling loop against transient network errors, handling potential FileReader failures when uploading files, and adding an error handler to the import mutation to provide user feedback on failures.
When the import target already exists and has columns beyond the primary key and system timestamps, the Sample Datasets picker gains a 'Random Data' option (under a 'This table' group) with a row-count input (1-1000, default 25). Values come from the column's declared type when the table has one, falling back to column-name heuristics (email, name, age, price, boolean-ish, dates, ...) for schemaless tables. The primary key is omitted so Harper assigns it. Verified end-to-end against a stage test cluster: Dogs sample import created data.dog and loaded 15 rows (csv_data_load + get_job polling), then Random Data inserted 7 heuristic rows into it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Review feedback: waitForJob now tolerates transient get_job failures (up to 5 consecutive) instead of failing an import whose job is still running, and the file dropzone reports FileReader errors via a toast. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
kriszyp
left a comment
There was a problem hiding this comment.
Nice modal — samples/file/URL import is a genuinely useful add. A couple of things worth addressing, plus one note:
Significant (client-side):
- Unbounded file read. The file path does a whole-file
FileReaderread with no size cap or streaming, so a large CSV/JSON will spike memory and freeze the tab. Consider a size limit with a clear error, and/or streaming for the large case. - Import-status poll retry gap. The status poll doesn't retry robustly on a transient failure, so a blip can leave the modal stuck / misreport the import. A bounded retry (or clear terminal-error surfacing) would firm it up.
Note (not a regression): the URL-load path is a server-side csv_url_load — the SSRF surface is server-side and pre-existing; this UI exposes it but doesn't broaden it. Flagging so it's on the radar (a server-side allowlist/guardrail is the real fix), not something to solve in this PR.
Two minor suggestions are in the review file. Thanks @dawsontoth!
— 🤖 KrAIs (Kris's review assistant)
The file import reads the whole file into memory and ships it in a single operation body, so an oversized pick now gets an inline error (with the actual size) pointing at Load from URL instead of freezing the tab. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Thanks @kriszyp! Point-by-point:
🤖 Addressed by Claude Code |
kriszyp
left a comment
There was a problem hiding this comment.
Reviewed via Claude review-queue. Solid rewrite of the CSV-only import modal into a three-method Import Data flow (samples/file/URL) with a sensible file-size cap and decent test coverage on the pure helpers. Two things worth addressing before merge:
Blocker: waitForJob can report success before the import job has started. getJob.ts (~line 48) resolves as soon as job.status !== 'IN_PROGRESS', treating anything else as terminal (only ERROR is special-cased). Harper's actual job lifecycle is CREATED → IN_PROGRESS → COMPLETE/ERROR — if the first poll lands while the job is still CREATED (plausible right after submission, before a worker picks it up), the function returns immediately as if the import succeeded. Fix: check terminal states explicitly (status === 'COMPLETE' || status === 'ERROR') instead of the inverse of the non-terminal state. No test currently exercises a CREATED-first sequence, so this isn't caught.
Significant: the importData mutation has no onError handler (ImportDataModal.tsx ~line 676). useMutation swallows the rejection into isError/error state with nothing reading it — a failed create_table, malformed CSV, or waitForJob timeout/rejection all fail silently. The button re-enables but there's no toast or inline message; the modal just looks idle.
Everything else looks good — the 10MB file-size cap with a streamed-read note is the right call, and the job-tracking replacement for the old "refresh manually" UX is a real improvement once #1 above is fixed.
Harper jobs go CREATED -> IN_PROGRESS -> COMPLETE|ERROR. waitForJob resolved on anything that wasn't IN_PROGRESS, so a poll landing before a worker picked the job up (still CREATED) reported success while the import was still queued. Terminal states are now explicit and a CREATED-first sequence is unit-tested. Also pins the global MutationCache -> errorHandler wiring with a test: import mutations intentionally have no per-mutation onError because every mutation error already surfaces as a toast through that handler. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Thanks @kriszyp — the blocker was a real bug. Both points addressed in beb4bab:
🤖 Addressed by Claude Code |
kriszyp
left a comment
There was a problem hiding this comment.
Reviewed via Claude review-queue — both prior findings (premature CREATED-status resolution in waitForJob, missing onError handler) are fixed and now test-pinned. LGTM.
Closes #1292.
What
Replaces the bare-bones Import CSV modal with an Import Data flow modeled on the issue's mockups, with three methods:
csv_data_load/insertcsv_data_load/insertcsv_url_loadUX details
id) when the target doesn't exist, with an inline heads-up alert. Picking a sample dataset auto-fills its suggested table name.job_idthat the old modal ignored ("Please wait a few moments then refresh the table"). The new flow pollsget_jobuntil the job completes, then refreshes the table tree and navigates to the imported table — data is just there when the modal closes. Job errors (e.g. malformed CSV) surface as real error toasts.?rawimports (~6 KB total), so they work on self-hosted/air-gapped instances that can't fetch external URLs.Scope notes
The mockup's Connect to Database (mongodump,
.zip, live sync) has no supporting operations in Harper today, so it's intentionally left out rather than shipped as a dead-end UI; the method picker makes it easy to add once the backend exists.import_from_s3is also a candidate for a follow-up method.Testing
get_jobpolling (waitForJob), JSON upload parsing, random-record generation (types, heuristics, skipped columns), and sample-dataset CSV validity (format, unique ids, consistent columns). Full suite green; tsc, oxlint, dprint clean.data.dogand loaded 15 records (create_table→csv_data_load→get_jobpolling → auto-navigate), and Random Data then inserted 7 generated rows into that table with sensible per-column values. Also exercised both entry points, method switching, dataset auto-fill, and the new-table alert.🤖 Generated with Claude Code