You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(datagrid): drop DataGridIdentity + version-counter bridge (#938)
* refactor(datagrid): drop DataGridIdentity early-return + version-counter bridge (Phase D-b)
Completes Phase D. The remaining metadataChanged (FK column reload) and paginationChanged (scroll-to-top) branches in updateNSView were the last consumers of DataGridIdentity. Both convert to explicit dispatch on TableViewCoordinating:
- refreshForeignKeyColumns(): reloads visible FK column cells (lifted verbatim from the metadataChanged branch). Called from MainContentCoordinator+QueryHelpers after the columnEnumValues mutation that bumps metadataVersion. The other metadataVersion bump (in setupResultsForExecutedQuery) is followed immediately by setActiveTableRows, which already dispatches applyFullReplace and renders FK columns fresh — no extra dispatch needed there.
- scrollToTop(): scrolls to row 0 if any rows exist. Trickier than refreshFK because pagination bumps the version BEFORE runQuery is fired; the scroll has to wait until the new data lands. Added pendingScrollToTopAfterReplace flag on MainContentCoordinator. paginateAfterConfirmation sets it; notifyFullReplaceIfActive checks and clears it after applyFullReplace fires.
With both branches gone, DataGridIdentity has no consumers. Drops:
- struct DataGridIdentity (entire type, 25 LOC)
- var lastIdentity on TableViewCoordinator
- The early-return short-circuit in updateNSView
- previousIdentity capture and the metadataChanged / paginationChanged variables
- metadataVersion / paginationVersion / schemaVersion props on DataGridView (no remaining readers)
- The matching call-site args in MainEditorContentView.dataGridView and TableStructureView
- DataGridIdentityTests entirely (-105 LOC test file)
The 'initial pre-warm display cache' check (was `previousIdentity == nil || previousIdentity?.rowCount == 0`) becomes `oldRowCount == 0, rowDisplayCount > 0` — same intent, derived from the existing cachedRowCount instead of the dropped identity.
Without the early-return, every SwiftUI body re-eval runs updateNSView's full body. After previous Phase D + the cachedTableRows / sort-cache / FK-routing PRs, that body is mostly cheap idempotent assignments and Equatable guards. Smoke-tested cell edit + undo, add row + undo, table switch, FK column display, pagination scroll, sort. Net -165 LOC including the deleted test file.
* fix(datagrid): scope pendingScrollToTopAfterReplace per-tabId, add dispatch tests
The original Bool flag could strand if pagination's runQuery failed before setActiveTableRows fired — the flag would stay set, and the next setActiveTableRows from any other code path (undo, FK navigation, multi-statement query) would unexpectedly scroll to top.
Changing to Set<UUID> scopes the intent per-tab. Pagination inserts the tabId; notifyFullReplaceIfActive checks via remove() and only dispatches scrollToTop on a matching hit. A stranded entry stays scoped to that one tab and only fires when that tab next receives a full replace — narrow blast radius.
Adds three regression tests:
- scrollToTopFiresOnPendingFlag: setActiveTableRows on the active tab WITH the flag set dispatches scrollToTop and clears the flag
- scrollToTopFlagIsScopedPerTab: a flag set for tab A doesn't fire when tab B is replaced; tab A's entry stays
- scrollToTopSkippedWhenFlagAbsent: setActiveTableRows without the flag doesn't scroll
0 commit comments