Skip to content

feat(databases): Import Data modal — samples, CSV/JSON files, and URL loads#1412

Merged
dawsontoth merged 5 commits into
stagefrom
feat/easy-data-import-1292
Jul 6, 2026
Merged

feat(databases): Import Data modal — samples, CSV/JSON files, and URL loads#1412
dawsontoth merged 5 commits into
stagefrom
feat/easy-data-import-1292

Conversation

@dawsontoth

@dawsontoth dawsontoth commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Closes #1292.

What

Replaces the bare-bones Import CSV modal with an Import Data flow modeled on the issue's mockups, with three methods:

Method Backend operation
Sample Datasets — three bundled starter datasets (Dogs, Books, Animals), plus Random Data generation for the selected table csv_data_load / insert
Import from File — CSV or JSON upload (was CSV-only) csv_data_load / insert
Load from URL — CSV fetched by the instance csv_url_load

UX details

  • Front and center: a second entry point in the Databases sidebar (next to "Create a Table"), so import is available even on an empty database — the key onboarding moment the issue is about. The table-toolbar button ("Import CSV" → "Import Data") opens the same modal prefilled with the current table and defaults to the file method; the sidebar defaults to samples.
  • Random Data: when the target table already exists and has columns beyond the primary key/system timestamps, the dataset picker offers a "Random Data" option (with a 1–1000 row-count input). Values are driven by each column's declared type, with column-name heuristics (email, name, age, price, boolean-ish, dates, …) for schemaless tables; the primary key is omitted so Harper assigns it.
  • Tables are created automatically (primary key id) when the target doesn't exist, with an inline heads-up alert. Picking a sample dataset auto-fills its suggested table name.
  • Job tracking: CSV loads return a job_id that the old modal ignored ("Please wait a few moments then refresh the table"). The new flow polls get_job until 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.
  • Sample datasets are bundled into the app via ?raw imports (~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_s3 is also a candidate for a follow-up method.

Testing

  • New unit tests: get_job polling (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.
  • Verified end-to-end against a stage test cluster: the Dogs sample import created data.dog and loaded 15 records (create_tablecsv_data_loadget_job polling → 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

… 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>
@dawsontoth
dawsontoth requested a review from a team as a code owner July 2, 2026 20:56

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/integrations/api/instance/database/getJob.ts
Comment thread src/features/instance/databases/modals/ImportDataModal.tsx
Comment thread src/features/instance/databases/modals/ImportDataModal.tsx
dawsontoth and others added 2 commits July 2, 2026 17:05
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 kriszyp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice modal — samples/file/URL import is a genuinely useful add. A couple of things worth addressing, plus one note:

Significant (client-side):

  1. Unbounded file read. The file path does a whole-file FileReader read 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.
  2. 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>
@dawsontoth

Copy link
Copy Markdown
Contributor Author

Thanks @kriszyp! Point-by-point:

  1. Unbounded file read — fixed in 828e5d2: uploads are now capped at 10 MB with an inline error showing the actual file size and pointing at Load from URL for anything bigger (the whole file goes into one operation body anyway, so the server wouldn't enjoy a 200 MB POST either). Verified in-browser with a synthetic 11 MB file (rejected, input cleared) and a small file (accepted). Streaming is a fair follow-up, but for >10 MB csv_url_load/import_from_s3 are the better transport.
  2. Poll retry gap — already addressed in 0772a77 (from the earlier bot review): waitForJob tolerates transient get_job failures, bounded at 5 consecutive so persistent failures surface quickly with a real error rather than a stuck modal. Unit-tested for both the recovery and give-up paths.
  3. SSRF note — agreed on all counts: server-side and pre-existing surface, and the right fix is a server-side guardrail. The UI hint already tells users the URL is fetched by the instance; noting it in the tracking sense here. 👍

🤖 Addressed by Claude Code

@kriszyp kriszyp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@dawsontoth

Copy link
Copy Markdown
Contributor Author

Thanks @kriszyp — the blocker was a real bug. Both points addressed in beb4bab:

  1. waitForJob CREATED gap — confirmed and fixed. Terminal states are now explicit (COMPLETE returns, ERROR throws, everything else — including CREATED and any unknown status — keeps polling until the deadline). Added a unit test for the CREATED → IN_PROGRESS → COMPLETE sequence that fails against the old inverse check.
  2. Missing onError — intentional, and now pinned by a test. This repo routes every mutation error through a global MutationCache → errorHandler (src/react-query/queryClient.ts), which toasts the extracted message — a per-mutation onError here would double-toast, and no other modal in the repo adds one. Since this is the second review to flag it, beb4bab adds a regression test (queryClient.test.ts) asserting a failing mutation on the app's real queryClient produces the error toast, so the "silent failure" scenario is guarded against the wiring ever being removed.

🤖 Addressed by Claude Code

@dawsontoth
dawsontoth enabled auto-merge July 6, 2026 13:58
@dawsontoth
dawsontoth requested a review from kriszyp July 6, 2026 13:58

@kriszyp kriszyp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed via Claude review-queue — both prior findings (premature CREATED-status resolution in waitForJob, missing onError handler) are fixed and now test-pinned. LGTM.

@dawsontoth
dawsontoth added this pull request to the merge queue Jul 6, 2026
Merged via the queue into stage with commit b4e3b74 Jul 6, 2026
2 checks passed
@dawsontoth
dawsontoth deleted the feat/easy-data-import-1292 branch July 6, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make data ingestion super easy in the UI

2 participants