Skip to content

refactor: useMultipleAllFields returns each table connection's fields, columns, and error - #3344

Merged
kodiakhq[bot] merged 2 commits into
mainfrom
drew/refactor-all-fields-per-connection
Oct 13, 2026
Merged

kodiakhq[bot] merged 2 commits into
mainfrom
drew/refactor-all-fields-per-connection

Conversation

@pulpdrew

@pulpdrew pulpdrew commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR makes a few changes to the useMultipleAllFields hook (used to fetch columns and map keys for search filters).

Limitations before:

  1. Callers could not determine which source(s) a returned field came from, when multiple tableConnections were provided as arguments
  2. Callers could not determine when all lookups failed - there was no error state returned since all errors were swallowed inside of Promise.allSettled
  3. Callers could not use a source's columns list when the team disables metadata queries, despite that toggle being intended to block the more expensive map key fetch.

Changes to eliminate these limitations:

  1. The hook now returns fieldsByTableConnection so that the caller can find which table connection each field came from
  2. The hook returns each table connection's error state in errorsByTableConnection and (when all connections error) an error and isError result.
  3. The hook returns columnsByTableConnection and isFieldMetadataDisabled allowing callers to use the list of columns even when the team's isFieldMetadataDisabled is true.

Screenshots or video

This is a refactor, no changes are expected EXCEPT the search page will now show an error toast when filters fail to fetch (since the hook now returns an error state in that case).

How to test on Vercel preview

Play around with search filters and autocomplete to ensure that nothing has regressed

References

  • Linear Issue: Closes HDX-5679
  • Related PRs:

@changeset-bot

changeset-bot Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dd3ae90

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/app Patch
@hyperdx/api Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Oct 13, 2026 11:08am UTC
hyperdx-storybook Ready Ready Preview Oct 13, 2026 11:08am UTC

Request Review

@github-actions github-actions Bot added the review/tier-2 Low risk — AI review + quick human skim label Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🔵 Tier 2 — Low Risk

Small, isolated change with no API route or data model modifications.

Why this tier:

  • Standard feature/fix — introduces new logic or modifies core functionality

Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns.
SLA: Resolve within 4 business hours.

Stats
  • Production files changed: 1
  • Production lines changed: 194 (+ 163 in test files, excluded from tier calculation)
  • Branch: drew/refactor-all-fields-per-connection
  • Author: pulpdrew

To override this classification, remove the review/tier-2 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 125 in total (1.75%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

Comment thread packages/app/src/hooks/useMetadata.tsx Resolved
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 critical or 🟠 major in code this PR adds or changes: fix before asking for review.
  • 🔵 minor in code this PR changes: your call. Fix if small, otherwise reply.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    severity. Reply with one sentence; if it is critical, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

2 finding(s): 🔴 0 critical · 🟠 0 major · 🔵 2 minor

None could be anchored to changed lines; they are listed below.

Findings outside the changed lines

2 minor
  • 🔵 packages/app/src/hooks/useMetadata.tsx:447 — New per-connection outputs have no production consumer, yet DESCRIBE now runs for field-metadata-disabled teams → Nothing outside tests reads fieldsByTableConnection, columnsByTableConnection, errorsByTableConnection or isFieldMetadataDisabled. The only callers are SQLEditor.tsx:69, SQLInlineEditor.tsx:112 and DBSearchPageFilters/hooks.ts:105, and they read just data, error and isLoading. The queryFn still runs getColumns for every connection, so teams with field metadata disabled now send ClickHouse queries they didn't send before, and nothing uses the result. Either ship these outputs together with the caller that needs them, or skip getColumns while isFieldMetadataDisabled is set until that caller exists. Note also that useFetchFacets already loads the same columns through useColumns (hooks.ts:95), so the two copies need to stay in sync.
  • 🔵 packages/app/src/hooks/useMetadata.tsx:429 — as ReadonlyMap casts break the 'avoid as casts' convention → Give the useMemo callback an explicit return type, or type the result object with satisfies, using ReadonlyMap<number, Field[]> and the matching types for columns and errors. A Map can be assigned to a ReadonlyMap without a cast, so all three as casts can go.

Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides.

@greptile-apps

greptile-apps Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues remain.

Summary

useMultipleAllFields now returns each table connection's fields, columns, and errors.

  • The fields hook returns columns, fields, and errors for each table connection.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Table connections] --> B[Fetch columns for each table]
  B --> C{Field metadata disabled?}
  C -->|Yes| D[Keep columns and empty fields]
  C -->|No| E[Fetch fields]
  E --> F[Keep fields or lookup error]
  D --> G[Build maps by input index]
  F --> G
  G --> H[Merge or intersect fields]
  G --> I[Report shared error if every table failed]
Loading

Reviews (4) · Last reviewed commit: "Merge branch 'main' into drew/refactor-a..." · Reviewed by Greptile

Comment thread packages/app/src/hooks/useMetadata.tsx Resolved
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

Refactor of useMultipleAllFields / useAllFields (packages/app/src/hooks/useMetadata.tsx) to return per-table-connection fields/columns/errors maps, a correct aggregate isError/error (set only when every table connection fails), and isFieldMetadataDisabled so callers can use columns even when map-key metadata is disabled. All three production call sites (SQLEditor.tsx, SQLInlineEditor.tsx, DBSearchPageFilters/hooks.ts) were verified against the new return shape and remain compatible. New behavior is well covered by unit tests (partial failure, all-fail, intersect fail-closed, metadata-disabled, reference stability) and a new useFetchFacets error test.

✅ No critical issues found.

The prior greptile inline comment ("Individual table errors are hidden", P2) is resolved: the hook now returns errorsByTableConnection and a partial-failure case is asserted in useMetadata.test.tsx.

🔵 P3 nitpicks (3)
  • packages/app/src/hooks/useMetadata.tsx:243 — useMultipleAllFields/useAllFields dropped the Partial<UseQueryOptions<Field[]>> passthrough in favor of the narrow MultipleAllFieldsOptions, so callers can no longer tune react-query behavior (retry, staleTime, select, placeholderData); no current caller passes such options so nothing breaks today, but the contract narrowing is undocumented.
    • Fix: Note the removed react-query option passthrough in the hook's doc comment so future callers know it is intentional.
  • packages/app/src/hooks/useMetadata.tsx:356 — when every table connection fails, the aggregate error surfaces only tableConnectionFields[0].error, discarding the other connections' errors (though they remain in errorsByTableConnection).
    • Fix: Document that error is a representative first error and direct callers to errorsByTableConnection for per-connection detail.
  • packages/app/src/hooks/useMetadata.tsx:287 — getColumns is now fetched for every table connection even when isFieldMetadataDisabled is true, issuing a DESCRIBE-style query that the metadata-disabled path previously skipped entirely; this is intentional to populate columnsByTableConnection, but adds a query for teams that disabled metadata to reduce load.
    • Fix: Confirm the added columns fetch under the metadata-disabled toggle is acceptable, or gate it behind a caller opt-in.

Reviewers (9): correctness, adversarial, kieran-typescript, reliability, api-contract, testing, maintainability, previous-comments, project-standards.

Testing gaps: none substantive — new per-connection error, all-fail, intersect-fail-closed, metadata-disabled, reference-stability, and caller-facing error paths are all covered.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 408 passed • 1 skipped • 1295s

Status Count
✅ Passed 408
❌ Failed 0
⚠️ Flaky 0
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@kodiakhq
kodiakhq Bot merged commit 07de613 into main Oct 13, 2026
29 checks passed
@kodiakhq
kodiakhq Bot deleted the drew/refactor-all-fields-per-connection branch October 13, 2026 11:14

This branch was successfully deployed

2 active deployments
Preview – hyperdx-storybook — dd3ae90c Deployed Oct 13, 2026 by vercel[bot]
Preview – hyperdx-oss — dd3ae90c Deployed Oct 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge review/tier-2 Low risk — AI review + quick human skim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants