Skip to content

Remember the last used folder per purpose in Desktop file dialogs. #10381 - #10835

Merged
dpage merged 1 commit into
pgadmin-org:masterfrom
shuseng8:issue-10381-per-purpose-dialog-folders
Nov 27, 2026
Merged

dpage merged 1 commit into
pgadmin-org:masterfrom
shuseng8:issue-10381-per-purpose-dialog-folders

Conversation

@shuseng8

@shuseng8 shuseng8 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Remember the last used folder per purpose in Desktop file dialogs. #10381

Follow-up to #10327 (7c974c0). The desktop runtime currently remembers one lastVisitedDirectory for every native file dialog, so saving an ERD changes where the next Backup dialog opens. This change lets each kind of dialog remember its own folder.

How it works

  • FileManagerModule.showNative() passes params.purpose as a second argument to window.electronUI.showSaveDialog / showOpenDialog. The preload shims forward it to the showSaveDialog / showOpenDialog IPC handlers, so the Electron dialog options stay unchanged.
  • In the runtime, withLastVisitedDirectory() tries the folder saved for that purpose first (in the lastVisitedDirectories map in the config store), then the existing global lastVisitedDirectory. A caller's explicit defaultPath still wins, and folders that no longer exist are skipped as before.
  • rememberVisitedDirectory() still updates the global lastVisitedDirectory, so dialogs without a purpose, and purposes used for the first time, behave exactly as they do today. It also records the folder under the purpose when one is given. Purpose keys must match ^[a-z][a-z0-9_]*$, and the whole map is written at once, so a key is never read as a nested store path.
  • InputFileSelect passes a new controlProps.dialogPurpose through as params.purpose.

Purpose keys

Purpose Callers
backup Backup, Backup Globals/Server, Restore (Restore opens where backups were saved)
erd ERD open and save
query_tool Query Tool open and save
import_export_data Import/Export Data
import_export_servers Import/Export Servers
binary_path Preferences > Binary paths
ssh_identity Server dialog SSH tunnel identity file
certificates Subscription SSL files and file-type connection parameters
cloud_credentials Google Cloud client secret file

The Query Tool result download dialog (runtime/src/js/downloader.js) is unchanged, because it calls Electron directly and defaults to Downloads.

Testing

  • yarn run linter passes in web/ and runtime/.
  • New regression/javascript/file_manager/FileManagerModule.spec.js checks that showNative() passes the purpose (or undefined) to the save, open and folder dialogs. FormComponents.spec.js checks that dialogPurpose reaches showFileManager.
  • The full Jest suite passes.
  • I checked the runtime helpers against a stub config store and temporary directories: each purpose remembers its own folder, an unused purpose falls back to the global folder, an explicit defaultPath is kept, invalid keys are ignored, and a deleted folder falls back to the global one. I haven't tested this by hand in the packaged Desktop app.

There are no release notes in this PR, since recent commits leave them to the release notes chore commits.

Summary by CodeRabbit

  • New Features
    • Native file dialogs now remember the last-used folder separately for common tasks, such as opening certificates, backups, and query files. When no starting folder is specified, dialogs use the relevant saved folder when available, otherwise the general last-visited folder.
    • Canceled dialogs do not change saved folders.

…admin-org#10381

Native file dialogs in the desktop runtime shared a single remembered
directory, so saving an ERD changed where the next Backup dialog opened.
Callers now pass a purpose (e.g. 'backup', 'erd', 'query_tool') through
FileManagerModule.showNative() and the preload shims, and the runtime keeps
the last directory per purpose in its config store, falling back to the
global last visited directory when a purpose has nothing saved yet.

Signed-off-by: Shubham <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Native file dialogs now accept an optional purpose and remember directories separately for valid purposes. Frontend dialog calls pass purpose values for several file-selection workflows. Dialogs use the purpose-specific directory before the general last-visited directory when no default path is supplied.

Changes

Purpose-specific dialog folders

Layer / File(s) Summary
Runtime directory selection and storage
runtime/src/js/pgadmin.js, runtime/src/js/pgadmin_preload.js
Open and save dialog handlers accept an optional purpose. When no default path is supplied, the runtime checks the purpose-specific directory, then the general last-visited directory. Successful selections update the general directory and, for valid purposes, the purpose-specific directory.
Frontend purpose handoff
web/pgadmin/misc/file_manager/static/js/FileManagerModule.jsx, web/pgadmin/static/js/components/FormComponents.jsx, web/regression/javascript/components/FormComponents.spec.js, web/regression/javascript/file_manager/FileManagerModule.spec.js
FileManagerModule forwards the purpose to Electron dialogs. FormComponents passes the configured purpose to the file manager. Tests cover purpose forwarding, selected paths, and cancellation.
Purpose values for dialog callers
web/pgadmin/browser/server_groups/servers/..., web/pgadmin/misc/cloud/static/js/google_schema.ui.js, web/pgadmin/preferences/static/js/components/binary_path.ui.jsx, web/pgadmin/tools/backup/static/js/*, web/pgadmin/tools/erd/static/js/erd_tool/components/ERDTool.jsx, web/pgadmin/tools/import_export/static/js/import_export.ui.js, web/pgadmin/tools/import_export_servers/static/js/import_export_selection.ui.js, web/pgadmin/tools/restore/static/js/restore.ui.js, web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx
Dialog configurations specify purpose values for certificate, SSH identity, cloud credential, binary path, backup, ERD, import/export, and Query Tool dialogs.

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant FormComponents
  participant FileManagerModule.showNative
  participant electronUI
  participant pgadmin.js IPC handlers
  FormComponents->>FileManagerModule.showNative: Pass configured purpose
  FileManagerModule.showNative->>electronUI: Pass purpose with open or save options
  electronUI->>pgadmin.js IPC handlers: Forward purpose through IPC
  pgadmin.js IPC handlers->>pgadmin.js IPC handlers: Select and remember directories by purpose
Loading

Possibly related issues

  • Issue 10381 requests remembering the last-used folder per file-dialog purpose. This change adds purpose-specific directory storage with a general-directory fallback.

Suggested reviewers: dpage, adityatoshniwal

Merge Risk: Minimal · up to 4daa8

Desktop file dialogs now remember a separate folder for each purpose and fall back to the previous shared folder when none is saved. No concrete merge-blocking risk was found, though the change has not been tested by hand in the packaged Desktop app.

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 says the runtime remembers the last used folder per purpose in Desktop file dialogs. The changeset does this: runtime/src/js/pgadmin.js stores a directory per purpose and falls back to the g…
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.
Full details: Title check

Explanation

The title says the runtime remembers the last used folder per purpose in Desktop file dialogs. The changeset does this: runtime/src/js/pgadmin.js stores a directory per purpose and falls back to the global last-visited directory, and pgadmin_preload.js, FileManagerModule.jsx, and the many UI schema files pass a purpose through. The title is specific, matches the main change, and is concise. The issue reference #10381 differs from the #10835 referenced in the objectives, but that does not make the title unrelated to the changeset.

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 cac95b6 and 4daa841.

Files selected for processing: 18

  • runtime/src/js/pgadmin.js
  • runtime/src/js/pgadmin_preload.js
  • web/pgadmin/browser/server_groups/servers/databases/subscriptions/static/js/subscription.ui.js
  • web/pgadmin/browser/server_groups/servers/static/js/server.ui.js
  • web/pgadmin/browser/server_groups/servers/static/js/variable.ui.js
  • web/pgadmin/misc/cloud/static/js/google_schema.ui.js
  • web/pgadmin/misc/file_manager/static/js/FileManagerModule.jsx
  • web/pgadmin/preferences/static/js/components/binary_path.ui.jsx
  • web/pgadmin/static/js/components/FormComponents.jsx
  • web/pgadmin/tools/backup/static/js/backup.ui.js
  • web/pgadmin/tools/backup/static/js/backupGlobal.ui.js
  • web/pgadmin/tools/erd/static/js/erd_tool/components/ERDTool.jsx
  • web/pgadmin/tools/import_export/static/js/import_export.ui.js
  • web/pgadmin/tools/import_export_servers/static/js/import_export_selection.ui.js
  • web/pgadmin/tools/restore/static/js/restore.ui.js
  • web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx
  • web/regression/javascript/components/FormComponents.spec.js
  • web/regression/javascript/file_manager/FileManagerModule.spec.js

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

@dpage dpage left a comment

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.

Summary

This passes a purpose key from each native file dialog caller through FileManagerModule.showNative() and the preload shims, so that the desktop runtime remembers a folder per kind of dialog and falls back to the existing global lastVisitedDirectory when a purpose has nothing saved yet. It follows the design sketched in #10381 closely, covers every type: 'file' control and direct FileManager.show() caller in the tree, and I have nothing that needs changing before merge.

Issues Found

No Must Fix, Should Fix or Suggestion findings.

ℹ️ Note: the runtime half (withLastVisitedDirectory() and rememberVisitedDirectory() in runtime/src/js/pgadmin.js) has no automated coverage, since runtime/ has no test harness, and as the description says it has not been tried in a packaged Desktop build. The logic reads correctly to me: the purpose is validated against ^[a-z][a-z0-9_]*$ before it is used as a key (which also rules out __proto__), the whole map is written at once rather than through a dotted store path, an unset or deleted per-purpose folder falls through to the global one, and cancelled dialogs still write nothing. A quick manual pass in the Desktop app before release would be worthwhile, but it is not something I would hold the PR for.

A couple of things I checked and am happy with: the extra purpose key also reaches the in-browser file manager through showInternal(), where it is posted to file_manager.init, but that endpoint only reads the keys it knows about, so server mode is unaffected; and having Restore share the backup key, so that it opens where backups were saved, is a sensible choice.

The targeted Jest specs (FileManagerModule.spec.js, FormComponents.spec.js) pass locally, as does eslint on the changed web/ files.

Checklist

  • Correctness: logic is sound
  • Security: no vulnerabilities introduced
  • Error handling: failures are handled gracefully
  • Tests: changes are adequately tested (runtime half by inspection only, as noted)
  • Documentation: docs updated if needed (no user-facing docs affected)

@dpage
dpage merged commit b4b0f4e into pgadmin-org:master Nov 27, 2026
17 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.

2 participants