Skip to content

feat: add Copy as JSON for selected rows#331

Merged
datlechin merged 2 commits intomainfrom
worktree-feature/copy-as-json
Mar 15, 2026
Merged

feat: add Copy as JSON for selected rows#331
datlechin merged 2 commits intomainfrom
worktree-feature/copy-as-json

Conversation

@datlechin
Copy link
Copy Markdown
Collaborator

@datlechin datlechin commented Mar 15, 2026

Summary

  • Add "Copy as JSON" option to the data grid context menu ("Copy as > JSON") and Edit menu
  • Type-aware formatting: integers/decimals as unquoted numbers, booleans as true/false, nulls as null, valid JSON columns embedded verbatim, blobs as base64
  • Works for all database types and any query result (no table name or database type restriction)

Closes #325

Test plan

  • Right-click selected rows → Copy as > JSON → paste in editor → verify valid JSON array of objects
  • Edit menu → Copy as JSON → same result
  • Test with NULL values → should appear as null in JSON
  • Test with numeric columns → should appear as unquoted numbers
  • Test with boolean columns → should appear as true/false
  • Test with JSON columns → should embed valid JSON verbatim
  • Test with MongoDB/Redis results → JSON option should still be available
  • Run JsonRowConverterTests → all 20 tests pass

Summary by CodeRabbit

Release Notes

  • New Features

    • Added "Copy as JSON" feature allowing users to export selected table rows in JSON format. Accessible from both the context menu and Edit menu, this enhancement streamlines data export workflows and enables seamless integration with external applications and systems.
  • Tests

    • Added extensive test coverage for JSON export functionality, including comprehensive validation of data type handling, value formatting rules, and edge cases.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 15, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This pull request introduces a new feature enabling users to copy selected database rows as JSON format. It adds a JSON conversion utility, integrates it into both the application menu and row context menu, and includes comprehensive test coverage for the conversion logic.

Changes

Cohort / File(s) Summary
Core JSON Conversion Utility
TablePro/Core/Utilities/SQL/JsonRowConverter.swift
New struct providing JSON serialization for SQL query results with type-aware formatting for integers, decimals, booleans, JSON, blobs, and text fields. Includes robust escaping and validation logic, with a 50,000-row cap per conversion.
Menu Integration
TablePro/TableProApp.swift, TablePro/Views/Results/TableRowViewWithMenu.swift
Added "Copy as JSON" menu item in Pasteboard menu and context menu with corresponding action handlers and row selection guards.
Coordination & Action Handling
TablePro/Views/Main/MainContentCommandActions.swift, TablePro/Views/Main/Extensions/MainContentCoordinator+RowOperations.swift, TablePro/Views/Results/DataGridView+RowActions.swift
Added action methods to retrieve selected row indices and delegate JSON conversion to the coordinator, building row data structures and managing clipboard writes.
Testing
TableProTests/Core/Utilities/JsonRowConverterTests.swift
Comprehensive test suite covering empty rows, type-specific formatting (integers, decimals, booleans, JSON, blobs), string escaping, column name escaping, row cap enforcement, and edge case handling.
Documentation
CHANGELOG.md
Added entry documenting the new feature under Unreleased > Added.

Sequence Diagram

sequenceDiagram
    actor User
    participant Menu as Menu/Context Menu
    participant Actions as MainContentCommandActions
    participant Coordinator as MainContentCoordinator
    participant GridCoord as TableViewCoordinator
    participant Converter as JsonRowConverter
    participant Clipboard as Clipboard

    User->>Menu: Click "Copy as JSON"
    Menu->>Actions: copySelectedRowsAsJson()
    Actions->>Coordinator: copySelectedRowsAsJson(indices)
    alt Main Content View
        Coordinator->>Coordinator: Validate tab & indices
        Coordinator->>Coordinator: Build row dictionaries
        Coordinator->>Converter: init(columns, columnTypes)
        Coordinator->>Converter: generateJson(rows)
        Converter->>Converter: Format values by type
        Converter->>Converter: Escape strings & validate JSON
        Converter-->>Coordinator: JSON string
        Coordinator->>Clipboard: Write JSON
    else Results Grid View
        User->>Menu: Click context menu
        Menu->>GridCoord: copyRowsAsJson(indices)
        GridCoord->>Converter: init(columns, columnTypes)
        GridCoord->>Converter: generateJson(rows)
        Converter-->>GridCoord: JSON string
        GridCoord->>Clipboard: Write JSON
    end
    Clipboard-->>User: JSON copied
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 With whiskers twitching, rows take flight,
To JSON form, so clean and bright!
A copy here, a paste right there,
The data flows through clipboard's care!
From menu's click to format true,
The feature hops, all shiny new! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.09% 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 PR title clearly summarizes the main change: adding a 'Copy as JSON' feature for selected rows, which is the primary objective across all file changes.
Linked Issues check ✅ Passed The PR fully implements issue #325 requirements: provides 'Copy as JSON' feature accessible via context menu and Edit menu, supports type-aware JSON output (integers, decimals, booleans, nulls, JSON columns, blobs), and applies broadly to all database types without restrictions.
Out of Scope Changes check ✅ Passed All code changes are directly scoped to implementing the 'Copy as JSON' feature: JSON converter utility, UI integration (menu items), coordinator methods, and comprehensive test coverage. No unrelated changes detected.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch worktree-feature/copy-as-json
📝 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 00da11e into main Mar 15, 2026
2 of 3 checks passed
@datlechin datlechin deleted the worktree-feature/copy-as-json branch March 15, 2026 07:17
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.

Copy as Json

1 participant