Skip to content

fix: read safe mode level from live toolbar state#362

Merged
datlechin merged 1 commit intomainfrom
fix/safe-mode-live-sync
Mar 18, 2026
Merged

fix: read safe mode level from live toolbar state#362
datlechin merged 1 commit intomainfrom
fix/safe-mode-live-sync

Conversation

@datlechin
Copy link
Copy Markdown
Collaborator

@datlechin datlechin commented Mar 18, 2026

Summary

Fixes #357

All 13 safe mode enforcement points read connection.safeModeLevel — but connection is let (immutable) on MainContentCoordinator, frozen at connection time. The toolbar UI binds to toolbarState.safeModeLevel which IS updated when the user changes the picker, but the enforcement points never see the change.

This PR makes toolbarState.safeModeLevel the single source of truth for the live session:

  • Add safeModeLevel computed property on MainContentCoordinator that delegates to toolbarState.safeModeLevel
  • Replace all 13 connection.safeModeLevel reads in coordinator extensions with the new property
  • Fix view-level reads in MainEditorContentView and MainContentView+Bindings
  • Sync AppState.shared.safeModeLevel via .onChange so sidebar context menus also reflect live changes

Test plan

  • Open connection with safe mode Full → run destructive query → password dialog appears
  • Change safe mode to Silent in toolbar → run destructive query → no dialog (fix verified)
  • Change safe mode to Read-Only → verify cells become non-editable, add/delete/paste rows blocked
  • Change safe mode back to Silent → verify editing works again
  • Sidebar context menu respects live safe mode changes (import disabled in read-only)
  • Regression: safe mode set at connection creation time still works on first connect

Summary by CodeRabbit

  • Refactor
    • Safe mode restrictions now dynamically reflect the current toolbar state, ensuring write protections remain consistent throughout your editing session.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fbf5b541-f403-4340-a9e7-194067ac787f

📥 Commits

Reviewing files that changed from the base of the PR and between eee2ce8 and f7d3b5c.

📒 Files selected for processing (8)
  • TablePro/ContentView.swift
  • TablePro/Views/Main/Child/MainEditorContentView.swift
  • TablePro/Views/Main/Extensions/MainContentCoordinator+Discard.swift
  • TablePro/Views/Main/Extensions/MainContentCoordinator+RowOperations.swift
  • TablePro/Views/Main/Extensions/MainContentCoordinator+SaveChanges.swift
  • TablePro/Views/Main/Extensions/MainContentCoordinator+SidebarActions.swift
  • TablePro/Views/Main/Extensions/MainContentView+Bindings.swift
  • TablePro/Views/Main/MainContentCoordinator.swift

📝 Walkthrough

Walkthrough

This change refactors safe mode level checks throughout the codebase to read from the coordinator's toolbar state instead of the immutable connection object, enabling real-time safe mode changes made in the UI to take effect immediately during query execution.

Changes

Cohort / File(s) Summary
Safe Mode State Syncing
ContentView.swift
Adds onChange handler to sync toolbar's safe mode level changes into AppState.shared.safeModeLevel.
Coordinator Safe Mode Accessor
TablePro/Views/Main/MainContentCoordinator.swift
Introduces safeModeLevel computed property that reads from toolbarState.safeModeLevel, providing live access to UI-controlled safe mode state.
Safe Mode Checks in Extensions
TablePro/Views/Main/Extensions/MainContentCoordinator+Discard.swift, MainContentCoordinator+RowOperations.swift, MainContentCoordinator+SaveChanges.swift, MainContentCoordinator+SidebarActions.swift
Replace references from connection.safeModeLevel to local safeModeLevel property in permission checks and write-operation guards.
Safe Mode Checks in Views
TablePro/Views/Main/MainEditorContentView.swift, MainContentView+Bindings.swift
Update isEditable computations to reference coordinator.safeModeLevel instead of coordinator.connection.safeModeLevel.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A toolbar's touch now steers the way,
No longer chained to yesterday,
Safe mode swiftly finds its flow,
Real-time whispers, UI's glow!
The connection learns: let toolbar lead,
And queries honor what users need. 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: replacing immutable connection-based safe mode reads with live toolbar state reads throughout the codebase.
Linked Issues check ✅ Passed All coding requirements from issue #357 are met: the new safeModeLevel computed property on MainContentCoordinator now reads from live toolbarState, all 13 enforcement points have been updated, view-level reads fixed, and AppState syncing added.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing issue #357: introducing the safeModeLevel property and systematically replacing connection.safeModeLevel references with the new live toolbar-backed property across all enforcement points.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/safe-mode-live-sync
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@datlechin datlechin merged commit 10cd406 into main Mar 18, 2026
2 checks passed
@datlechin datlechin deleted the fix/safe-mode-live-sync branch March 18, 2026 01:51
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.

bug: safe mode edits don't apply when connection already opened

1 participant