Skip to content

refactor: decompose QueryEditor (#115)#128

Merged
nkcoder merged 3 commits into
mainfrom
refactor/115-queryeditor-decompose
Jul 4, 2026
Merged

refactor: decompose QueryEditor (#115)#128
nkcoder merged 3 commits into
mainfrom
refactor/115-queryeditor-decompose

Conversation

@nkcoder

@nkcoder nkcoder commented Jul 4, 2026

Copy link
Copy Markdown
Owner

What

First slice of #115 (M2 — oversized components). Decomposes QueryEditor.tsx (1040 → 352 lines) by lifting cohesive units into focused, independently-testable modules. No behavior change.

New modules

  • lib/sqlCompletion.ts (421) — pure SQL autocomplete helpers: extractFromTables, extractAliasMap, detectSqlContext, statement/string/subquery scanning, applyFuzzyMatch, buildCompletionOptions, keyword constants, makeKeyTypeBadge, and the CompletionEntry/SqlContext/FuzzyCompletion types.
  • lib/editorTheme.ts (115) — the CodeMirror snowySqlHighlight + editorTheme definitions.
  • components/FindBar.tsx (172) — the FindBar component plus findMatchInfo and its MatchInfo/FindBarProps types.

QueryEditor.tsx now only owns the editor instance wiring (completion source, keymaps, find state) and imports the above.

Tests split to match the modules

  • lib/sqlCompletion.test.ts — the pure-helper tests
  • components/FindBar.test.tsxFindBar + findMatchInfo tests
  • QueryEditor.test.tsx — keeps only the component-level tests (and CodeMirror mocks)

useDatasourceSession now imports CompletionEntry from its new home instead of via QueryEditor (no re-export left behind).

Acceptance criteria

  • File meaningfully reduced by extracting sub-components/helpers (1040 → 352)
  • Pure helpers live in separately unit-tested modules
  • No behavior change — design tokens (T.*) and patterns preserved
  • Suites pass: 449 unit + 91 e2e, tsc build, biome check

Scope note

This is the QueryEditor slice of the three-file issue. ConnectionManager and Sidebar will follow as separate PRs.

nkcoder added 3 commits July 4, 2026 13:48
…r modules (#115)

Extract the pure SQL autocomplete helpers (parsing, context detection,
fuzzy matching, keyword constants) into lib/sqlCompletion.ts, the
CodeMirror theme/highlight into lib/editorTheme.ts, and the FindBar
component + findMatchInfo into components/FindBar.tsx. QueryEditor.tsx
drops from 1040 to 352 lines and now only owns the editor wiring.

Tests split to match: pure-helper tests move to lib/sqlCompletion.test.ts,
FindBar/findMatchInfo tests to components/FindBar.test.tsx. No behavior
change; unit (449) + e2e (91) suites pass.

Part of M2 code-review finding.
The callback's return is only inspected via the `=== false` sentinel.
The prior `boolean | undefined` type rejected the void-returning callback
in innerSubqueryContext under strict TypeScript (ts 2345), while `void`
in the union trips biome's noConfusingVoidType. `unknown` satisfies both.

Pre-existing looseness carried over from QueryEditor.tsx; no behavior change.
Revert to the honest `boolean | undefined` contract (return false to stop
early). The only offender was innerSubqueryContext's first callback, which
had no return statement and so inferred `void`; give it an explicit
`return undefined` to match the documented protocol. No any/unknown, no
behavior change.
@nkcoder nkcoder merged commit 4d8eb5c into main Jul 4, 2026
2 checks passed
@nkcoder nkcoder deleted the refactor/115-queryeditor-decompose branch July 4, 2026 06:44
nkcoder added a commit that referenced this pull request Jul 4, 2026
…131)

* test: cover Find, ConnectionGeneralTab, and session-hook error paths

Fills gaps surfaced while regression-testing the #127#130 refactor:

- e2e/query-editor-find.spec.ts: in-editor Find (Cmd+F) had no e2e
  coverage after the #128 QueryEditor/FindBar split — open/focus/close,
  match count, next/prev navigation, clear-resets.
- ConnectionGeneralTab.test.tsx: the #129-extracted tab had no test
  (40% func) — field edits, port numeric coercion, password
  mask/reveal, isEdit placeholder, derived URL.
- useDatasourceSession: GetCompletions failure during connect/refresh;
  disconnect no-op when nothing is connected.
- useQueryHistory: null history result coerces to [].

* test: raise hooks branch coverage + set two-tier coverage thresholds

Adds the missing hooks-branch tests and turns the flat #51 threshold into
a two-tier gate:

- useSidebarTree.test.ts (new): the hook had no direct test — covers the
  live-load error branches (columns/sub-folder load failures), the
  toggleColumnsFolder guard + toggle, and each sub-folder loader.
- useQueryExecution: non-result-set (DDL) rows-affected path; error leaves
  a pinned tab intact; double-pin preserves the first; close a non-active tab.
- useDatasourceSession: successful refresh clears a same-ds warning; a
  refresh for one ds leaves another ds's warning intact.

hooks branch coverage 78.6% -> 82.7%; overall 89.8% -> 90.6% stmt.

vitest.config.ts: global ratchet floor (90/82/90/91) as a regression gate,
plus higher per-dir floors for pure logic (lib/ 97/90/100/99, hooks/
95/82/95/97). Verified the glob thresholds are enforced.
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.

1 participant