Skip to content

feat: Add open/close all Godley tables menu items. For feature #173.#657

Open
highperformancecoder wants to merge 1 commit into
masterfrom
feature-173-open-all-godley-tables
Open

feat: Add open/close all Godley tables menu items. For feature #173.#657
highperformancecoder wants to merge 1 commit into
masterfrom
feature-173-open-all-godley-tables

Conversation

@highperformancecoder
Copy link
Copy Markdown
Owner

@highperformancecoder highperformancecoder commented May 26, 2026

This change is Reviewable

Summary by CodeRabbit

  • New Features
    • Added "Open All Godley Tables" and "Close All Godley Tables" options to the Edit menu for batch management of all Godley tables in your model.

Review Change Stack

Copilot AI review requested due to automatic review settings May 26, 2026 06:19
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

📝 Walkthrough

Walkthrough

This PR adds the ability to open and close all Godley tables in bulk through menu commands. The changes include new backend C++ methods to enumerate Godley tables and resolve named items, a TypeScript bridge to access them, refactored command dispatching, and menu items wired to the bulk operations.

Changes

Godley Table Bulk Operations

Layer / File(s) Summary
Backend: allGodleyTables and itemFromNamedItem support
model/minsky.h, model/minsky.cc
New C++ methods: allGodleyTables() iterates canvas items and collects Godley table IDs; itemFromNamedItem(name) resolves named items and lazily populates the namedItems map on first lookup failure.
Frontend-backend bridge: async allGodleyTables wrapper
gui-js/libs/shared/src/lib/backend/minsky.ts
New async method allGodleyTables() in the TypeScript Minsky class delegates to the C++ backend via RPC.
Command handlers: double-click dispatch and bulk Godley operations
gui-js/apps/minsky-electron/src/app/managers/CommandsManager.ts
handleDoubleClick refactored to extract Godley item ID from minsky.canvas.item and name it; openAllGodleyTables() and closeAllGodleyTables() iterate all enumerated tables; openGodleyTable() updated to use the id parameter for window tracking.
Menu UI integration: Edit menu and context menu updates
gui-js/apps/minsky-electron/src/app/managers/ApplicationMenuManager.ts, gui-js/apps/minsky-electron/src/app/managers/ContextMenuManager.ts
ApplicationMenuManager adds "Open All Godley Tables" and "Close All Godley Tables" to the Edit menu. ContextMenuManager updates the Godley icon context menu handler to asynchronously fetch the item ID before invoking the open command.

🎯 3 (Moderate) | ⏱️ ~25 minutes

A rabbit hops through Godley's garden,
Opening tables, shutting them tight—
Bulk commands dancing, a menu's sweet pardon,
All spreadsheets managed with logical might! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% 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 describes the main change: adding menu items for opening and closing all Godley tables, which is the primary focus across multiple manager files and backend implementations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 feature-173-open-all-godley-tables

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@gui-js/apps/minsky-electron/src/app/managers/CommandsManager.ts`:
- Around line 894-897: openAllGodleyTables currently calls openGodleyTable(id)
without awaiting it, causing fire-and-forget async calls and possible unhandled
rejections; update openAllGodleyTables to await the async opens (either
sequentially with "for ... of" + await openGodleyTable(id) or concurrently with
Promise.all over minsky.allGodleyTables().map(id => openGodleyTable(id))) and
ensure errors are propagated/handled so unhandled rejections are avoided.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fb3e2587-e75f-416f-9509-e7474ca49f6d

📥 Commits

Reviewing files that changed from the base of the PR and between 255ad12 and 149a5d1.

📒 Files selected for processing (6)
  • gui-js/apps/minsky-electron/src/app/managers/ApplicationMenuManager.ts
  • gui-js/apps/minsky-electron/src/app/managers/CommandsManager.ts
  • gui-js/apps/minsky-electron/src/app/managers/ContextMenuManager.ts
  • gui-js/libs/shared/src/lib/backend/minsky.ts
  • model/minsky.cc
  • model/minsky.h

Comment on lines +894 to +897
static async openAllGodleyTables() {
for (const id of await minsky.allGodleyTables())
this.openGodleyTable(id);
}
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot May 26, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Await bulk Godley opens to avoid unhandled async failures.

At Line 895, openGodleyTable(id) is async but not awaited, so bulk-open runs as fire-and-forget. That can produce unhandled rejections and nondeterministic behavior when many tables are opened.

Proposed fix
 static async openAllGodleyTables() {
-  for (const id of await minsky.allGodleyTables()) 
-    this.openGodleyTable(id);
+  for (const id of await minsky.allGodleyTables()) {
+    await this.openGodleyTable(id);
+  }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static async openAllGodleyTables() {
for (const id of await minsky.allGodleyTables())
this.openGodleyTable(id);
}
static async openAllGodleyTables() {
for (const id of await minsky.allGodleyTables()) {
await this.openGodleyTable(id);
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@gui-js/apps/minsky-electron/src/app/managers/CommandsManager.ts` around lines
894 - 897, openAllGodleyTables currently calls openGodleyTable(id) without
awaiting it, causing fire-and-forget async calls and possible unhandled
rejections; update openAllGodleyTables to await the async opens (either
sequentially with "for ... of" + await openGodleyTable(id) or concurrently with
Promise.all over minsky.allGodleyTables().map(id => openGodleyTable(id))) and
ensure errors are propagated/handled so unhandled rejections are avoided.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

How do menu handlers handle asynchronous rejections?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find ApplicationMenuManager to see how menu handlers are structured
fd -e ts ApplicationMenuManager --exec cat {}

# Also search for how click handlers are generally structured in menus
rg -n "click.*async\|async.*click\|openAllGodleyTables\|closeAllGodleyTables" --type ts -C 3

# Check for global unhandledRejection handlers
rg -n "unhandledRejection\|uncaughtException" --type ts -C 3

Length of output: 22444



@highperformancecoder — They don't, at least not at the menu level. Here's what the actual wiring looks like in ApplicationMenuManager:

{
  label: 'Open All Godley Tables',
  click() { CommandsManager.openAllGodleyTables(); },  // synchronous click, Promise dropped
},

The click function is synchronous — it calls an async function but neither awaits nor .catch()-es the returned Promise. That means:

  1. Any rejection from openAllGodleyTables() (or from openGodleyTable inside it) immediately becomes an unhandled Promise rejection.
  2. There is no global unhandledRejection / uncaughtException handler found anywhere in the TypeScript code to catch it as a fallback.
  3. In Electron ≥14 / Node.js ≥15 the process-level default for unhandled rejections is to terminate the process (though Electron may demote it to a warning in practice).

So my original comment about awaiting openGodleyTable(id) inside the loop is still relevant (it prevents racing opens and surfaces errors to the caller), but the more complete fix is at the menu-handler level too:

// Option A: propagate errors sequentially
{
  label: 'Open All Godley Tables',
  async click() {
    try {
      await CommandsManager.openAllGodleyTables();
    } catch (err) {
      console.error('openAllGodleyTables failed', err);
    }
  },
},
// Option B: open concurrently and catch per-table
static async openAllGodleyTables() {
  const ids = await minsky.allGodleyTables();
  await Promise.allSettled(ids.map(id => this.openGodleyTable(id)));
}

Promise.allSettled is particularly handy here because it lets all opens run concurrently and collects both successes and failures without short-circuiting, matching the "best-effort bulk open" intent.

That said, looking at the broader codebase, several other menu items follow the same fire-and-forget pattern (e.g. upgrade(), randomLayout()), so this is a pre-existing pattern rather than something introduced by this PR. Whether to address it consistently across all handlers is a separate question, but for the new bulk-open items it would be worth being explicit since they involve network-style async window creation.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds UI commands and backend support to open/close Godley table windows in bulk, as well as refactors Godley-table opening to be ID-based.

Changes:

  • Added a backend API to enumerate Godley table IDs and exposed it to the JS/Electron client.
  • Added “Open All Godley Tables” / “Close All Godley Tables” actions to the application menu and Godley context menu.
  • Updated Godley table opening logic to operate on item IDs and to (re)populate namedItems when needed.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
model/minsky.h Declares allGodleyTables() and moves itemFromNamedItem() to an out-of-line definition.
model/minsky.cc Implements itemFromNamedItem() fallback population and adds allGodleyTables() implementation.
gui-js/libs/shared/src/lib/backend/minsky.ts Exposes allGodleyTables() to the TypeScript client wrapper.
gui-js/apps/minsky-electron/src/app/managers/ContextMenuManager.ts Adds context menu entries for opening/closing all Godley tables and adjusts single-table open behavior.
gui-js/apps/minsky-electron/src/app/managers/CommandsManager.ts Adds bulk open/close commands and refactors Godley opening to accept an ID.
gui-js/apps/minsky-electron/src/app/managers/ApplicationMenuManager.ts Adds application menu items for opening/closing all Godley tables.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +835 to +838
const id=await minsky.canvas.item.id();
if (id) {
await minsky.nameCurrentItem(id);
CommandsManager.openGodleyTable(id);
Comment on lines +895 to +896
for (const id of await minsky.allGodleyTables())
this.openGodleyTable(id);
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Backend commands are queued and run on a single backend thread, rather than run concurrently. There is no issue with running the commands out of order.

Comment on lines +650 to +652
const id=await minsky.canvas.item.id();
if (id)
CommandsManager.openGodleyTable(id);
Comment on lines +453 to +457
click() {CommandsManager.openAllGodleyTables();},
},
{
label: 'Close All Godley Tables',
click() {CommandsManager.closeAllGodleyTables();},
Comment thread model/minsky.h
Comment thread model/minsky.cc
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.

2 participants