Skip to content

Add a Collapse option to the Object Explorer that closes a node and everything beneath it. #7208 - #10844

Merged
dpage merged 1 commit into
pgadmin-org:masterfrom
dpage:fix/issue-7208-tree-collapse-all
Nov 27, 2026
Merged

dpage merged 1 commit into
pgadmin-org:masterfrom
dpage:fix/issue-7208-tree-collapse-all

Conversation

@dpage

@dpage dpage commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Every node and collection in the Object Explorer gets a Collapse context-menu item, and the focused tree gets Shift + Left Arrow for the same action (no existing shortcut uses it, and it only fires when the tree itself has focus).
  • On an expanded node it closes that node and every expanded node beneath it, so expanding it again shows just the next level rather than restoring the whole old subtree.
  • On a node that is not expanded (the reporter's case: a table deep in a long Tables list) it closes the parent and selects it, scrolling it into view, so there is no need to scroll back up. This is the two-step Left Arrow workaround from the issue comments, in one action.
  • Each node is closed through FileTreeX.closeDir, so the closed tree event, and with it the saved tree state, fires for each one. The logic lives in PgTree/services/collapse.ts and is shared by the menu callback (Tree#collapse) and the keyboard handler.
  • docs/en_US/tree_control.rst documents the menu item and the shortcut.

Test plan

  • New regression/javascript/tree/tree_collapse_spec.js (real TreeModelX): target selection, deepest-first closing including expanded nodes hidden under a closed one, Tree#collapse, and Shift + Left Arrow, with plain Left Arrow and other Shift keys unchanged.
  • Existing tree, browser and PgTree Jest specs pass; eslint clean on changed files.
  • Manual check in a running pgAdmin: right-click a table in an expanded Tables list and choose Collapse.

Closes #7208

Summary by CodeRabbit

  • New Features
    • Added a Collapse option to the Object Explorer context menu to close a node and its expanded descendants.
    • Added Shift + Left Arrow as a keyboard shortcut to collapse the selected node. If it is already closed, the shortcut selects and collapses its parent.
    • Updated the tree-control documentation with collapse instructions.
  • Tests
    • Added coverage for collapsing nested nodes, selecting the collapse target, and keyboard shortcut behavior.

…verything beneath it. pgadmin-org#7208

The context menu of every node and collection gains a 'Collapse' item,
and the tree gains Shift + Left Arrow for the same thing. On an expanded
node it closes that node and every expanded node beneath it, so that
expanding it again shows only the next level. On a node that is not
expanded, such as a table in a long Tables list, it closes the parent
instead and selects it, so the user does not have to scroll back up.

Each node is closed through FileTreeX.closeDir, so the 'closed' tree
event, and with it the saved tree state, is updated for all of them.

Closes pgadmin-org#7208
@dpage dpage self-assigned this Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The tree now supports collapsing a directory and its expanded descendants. Shift+ArrowLeft and the context-menu Collapse action use this behavior. When the selected node is not expanded, the action targets its parent.

Changes

Tree Collapse

Layer / File(s) Summary
Collapse behavior and tree integration
web/pgadmin/static/js/components/PgTree/types.ts, web/pgadmin/static/js/components/PgTree/services/collapse.ts, web/pgadmin/static/js/components/PgTree/FileTreeX/index.tsx, web/pgadmin/static/js/tree/tree.js, web/regression/javascript/tree/tree_collapse_spec.js
The tree handle exposes recursive directory collapse. The tree model selects a collapse target, and tests cover target selection, recursive closure, and tree collapse behavior.
Keyboard and context-menu actions
web/pgadmin/static/js/components/PgTree/services/keyboardHotkeys.ts, web/pgadmin/browser/static/js/collection.js, web/pgadmin/browser/static/js/node.js, docs/en_US/tree_control.rst, web/regression/javascript/tree/tree_collapse_spec.js
Shift+ArrowLeft and the context-menu Collapse item invoke the collapse behavior. Documentation describes the actions, and tests check the keyboard behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant KeyboardHotkeys
  participant collapseTarget
  participant FileTreeX
  participant collapseBranch
  User->>KeyboardHotkeys: Press Shift+ArrowLeft
  KeyboardHotkeys->>collapseTarget: Resolve target from active file
  collapseTarget-->>KeyboardHotkeys: Return target or null
  KeyboardHotkeys->>FileTreeX: Call collapseAll(target)
  FileTreeX->>collapseBranch: Close expanded descendants
  collapseBranch-->>FileTreeX: Complete recursive closure
  FileTreeX-->>KeyboardHotkeys: Complete collapse
  KeyboardHotkeys->>KeyboardHotkeys: Activate target when it differs
Loading
Merge Risk: Minimal · up to 8cb80

This change adds a Collapse context-menu item and Shift+Left Arrow shortcut to the Object Explorer tree. No concrete defect was found, so the merge risk is minimal. Manual verification in a running pgAdmin is still outstanding.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title states the main change: a Collapse option in the Object Explorer that closes a node and its descendants. The changeset adds a Collapse context-menu item, a Shift+Left Arrow shortcut, collaps…
Linked Issues check Passed Issue #7208 asks for a one-action way to collapse a large parent branch (for example, the Tables node) from a deep child, without scrolling. The issue offers either a "Go to root node" action or a col…
Out of Scope Changes check Passed All changed areas connect to the collapse feature: collapse.ts (new logic), node.js and collection.js (context-menu registration and callback), tree.js (Tree#collapse), FileTreeX/index.tsx and types.t…
Full details: Title check

Explanation

The title states the main change: a Collapse option in the Object Explorer that closes a node and its descendants. The changeset adds a Collapse context-menu item, a Shift+Left Arrow shortcut, collapseBranch/collapseTarget helpers, and Tree#collapse. The title does not mention the Shift+Left Arrow shortcut or the select-parent behavior, which is acceptable because the title need not cover every detail. The issue number reference is a minor addition.

Full details: Linked Issues check

Explanation

Issue #7208 asks for a one-action way to collapse a large parent branch (for example, the Tables node) from a deep child, without scrolling. The issue offers either a "Go to root node" action or a collapse function that unexpands the branch. The PR adds a Collapse context-menu item and Shift + Left Arrow. On a node that is not expanded, collapseTarget selects the parent, closes it, and scrolls it into view. This matches the issue workflow (select table T, act, parent is selected and collapsed) in one step. On an expanded node, collapseBranch closes the node and its expanded descendants, deepest first, through closeDir. The shared logic is in PgTree/services/collapse.ts and is wired to Node/Collection callbacks, Tree#collapse, and KeyboardHotkeys. Automated coverage is in regression/javascript/tree/tree_collapse_spec.js (target selection, recursive closing, Tree#collapse, Shift + Left Arrow). The issue's suggested "Go to the database node" shortcut is optional ("would be also useful") and is not implemented as a separate action. The unchecked manual check is non-coding and does not affect this result.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to the collapse feature: collapse.ts (new logic), node.js and collection.js (context-menu registration and callback), tree.js (Tree#collapse), FileTreeX/index.tsx and types.ts (collapseAll handle), keyboardHotkeys.ts (Shift + ArrowLeft binding), tree_collapse_spec.js (tests), and tree_control.rst (documentation of the menu item and shortcut). The keyboardHotkeys.ts change to handleKeyDown alters how Shift-modified keys resolve. Shift is prefixed only when a shifted binding exists; otherwise the unshifted binding applies. This is needed for the new shortcut and is covered by tests that check plain Left Arrow and other Shift keys keep their behavior. No unrelated change was found in the summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 3b6b9b2 and 8cb80b6.

Files selected for processing: 9

  • docs/en_US/tree_control.rst
  • web/pgadmin/browser/static/js/collection.js
  • web/pgadmin/browser/static/js/node.js
  • web/pgadmin/static/js/components/PgTree/FileTreeX/index.tsx
  • web/pgadmin/static/js/components/PgTree/services/collapse.ts
  • web/pgadmin/static/js/components/PgTree/services/keyboardHotkeys.ts
  • web/pgadmin/static/js/components/PgTree/types.ts
  • web/pgadmin/static/js/tree/tree.js
  • web/regression/javascript/tree/tree_collapse_spec.js

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@dpage
dpage merged commit 5343b43 into pgadmin-org:master Nov 27, 2026
18 checks passed
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.

Go to the root node in the Tree to close (collapse) all nodes of the root node

1 participant