Skip to content

fix(editor): convert create-table tab in place on commit and wire Cmd+S#1664

Merged
datlechin merged 1 commit into
mainfrom
fix/create-table-flow
Jun 12, 2026
Merged

fix(editor): convert create-table tab in place on commit and wire Cmd+S#1664
datlechin merged 1 commit into
mainfrom
fix/create-table-flow

Conversation

@datlechin

@datlechin datlechin commented Jun 12, 2026

Copy link
Copy Markdown
Member

Problem

Two defects in the create-table flow:

  1. Clicking Create Table opened a second window tab for the new table, left the creation tab open, and the sidebar did not show the new table until a manual Cmd+R.
  2. Cmd+S did nothing in the creation tab; only the Create Table button worked.

Root causes

  1. isActiveTabReusable had no case for .createTable, so openTableTab() skipped the in-place replaceTabContent path and spawned a new NSWindow tab. The refresh also fired before the tab transform, so the refresh subscriber bailed on the still-.createTable tab.
  2. Two gaps: the Save Changes menu item was always disabled for creation tabs (updateToolbarPendingState knew nothing about them), and saveChanges() had no .createTable branch.

Fix

  • .createTable tabs are now reusable: on success the creation tab converts in place into the new table's data tab (one tab, same window), matching TablePlus behavior and HIG Save semantics (commit in place, never spawn a second surface).
  • createTable() now transforms the tab before sending the refresh, so the sidebar and grid pick up the new table immediately.
  • Cmd+S routes through the existing Save Changes path: CreateTableView registers a createTableAction on the coordinator (same pattern as StructureViewActionHandler), and a hasCreateTablePending flag enables the menu item only when the form has a name, at least one valid column, and no create in flight. The flag observes the readiness condition itself, so edits made in any order (name first or columns first) update the menu state.
  • Cmd+Return on the button keeps working; Cmd+S is the standard additional path.
  • A creation tab with a committable design (name plus a valid column) is protected: opening another table from the sidebar opens a new tab instead of replacing the in-progress design. Only an empty or in-flight creation tab is reused.
  • The Cmd+S action lives on a CreateTableActionHandler held weakly by the coordinator (same lifetime semantics as StructureViewActionHandler), and createTable() guards against reentry while a create is in flight.

Error handling

A failed CREATE TABLE (SQL error, duplicate name) keeps the creation tab untouched; the error path never reaches the tab conversion.

Tests

  • OpenTableTabTests: createTable tab is reusable; openTableTab converts it in place.
  • CommandActionsDispatchTests: saveChanges() dispatches createTableAction for createTable tabs (and is a no-op without one).
  • PendingChangeTriggerTests: equality covers the new field (suite rewritten with a factory helper to stay within line limits).

Note: insertQueryFromAI_appendsToExisting fails at origin/main too (stale test expecting append behavior the app no longer has); verified pre-existing with a clean stash run, not touched here.

UI automation: the full flow needs a live database connection, so no deterministic UI test was added.

Docs

CHANGELOG under Unreleased (Fixed), docs/features/keyboard-shortcuts.mdx, docs/features/table-structure.mdx.

Out of scope

Cmd+W on a creation tab with unsaved work still closes silently (pre-existing: the unsaved-changes check never flags creation tabs). Doing it properly needs an async create-then-close flow; can follow up separately.

@datlechin datlechin force-pushed the fix/create-table-flow branch from 401b220 to 38a4e11 Compare June 12, 2026 07:36
@mintlify

mintlify Bot commented Jun 12, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
TablePro 🟢 Ready View Preview Jun 12, 2026, 7:37 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 401b2204fd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

|| tab.hasUserActiveSort {
return false
}
if tab.tabType == .createTable { return true }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Protect populated Create Table drafts from sidebar navigation

When the active tab is a Create Table tab with a filled-in draft, this unconditional true makes any sidebar table open reuse the tab and replace it with the clicked table. That loses the user's in-progress table definition without a prompt; before this change, the same sidebar navigation would open/select a table tab without treating the create-table draft as disposable. Consider only forcing reuse for the post-create flow, or gating this on !toolbarState.hasCreateTablePending/an explicit discard confirmation.

Useful? React with 👍 / 👎.

@datlechin datlechin force-pushed the fix/create-table-flow branch from 38a4e11 to 5685bdb Compare June 12, 2026 07:46
@datlechin datlechin merged commit 33a82e8 into main Jun 12, 2026
5 checks passed
@datlechin datlechin deleted the fix/create-table-flow branch June 12, 2026 07:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5685bdb1c4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

|| tab.hasUserActiveSort {
return false
}
if tab.tabType == .createTable { return !toolbarState.hasCreateTablePending }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Protect incomplete create-table drafts before reuse

When the selected Create Table tab is not yet ready to create, this returns true, so sidebar navigation replaces the tab in place. A user who has typed a table name or started a column but has not filled a valid name+type yet has hasCreateTablePending == false, and that draft is silently discarded when they click a table in the sidebar. Consider tracking draft dirtiness separately from create readiness, or only reusing truly empty create-table tabs.

Useful? React with 👍 / 👎.

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