Repository navigation
Remember the last used folder per purpose in Desktop file dialogs. #10381 - #10835
Conversation
…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]>
|
No actionable comments were generated in the recent review. WalkthroughNative 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. ChangesPurpose-specific dialog folders
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
Possibly related issues
Suggested reviewers: Merge Risk:
|
dpage
left a comment
There was a problem hiding this comment.
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)
Remember the last used folder per purpose in Desktop file dialogs. #10381
Follow-up to #10327 (7c974c0). The desktop runtime currently remembers one
lastVisitedDirectoryfor 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()passesparams.purposeas a second argument towindow.electronUI.showSaveDialog/showOpenDialog. The preload shims forward it to theshowSaveDialog/showOpenDialogIPC handlers, so the Electron dialog options stay unchanged.withLastVisitedDirectory()tries the folder saved for that purpose first (in thelastVisitedDirectoriesmap in the config store), then the existing globallastVisitedDirectory. A caller's explicitdefaultPathstill wins, and folders that no longer exist are skipped as before.rememberVisitedDirectory()still updates the globallastVisitedDirectory, 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.InputFileSelectpasses a newcontrolProps.dialogPurposethrough asparams.purpose.Purpose keys
backuperdquery_toolimport_export_dataimport_export_serversbinary_pathssh_identitycertificatescloud_credentialsThe Query Tool result download dialog (
runtime/src/js/downloader.js) is unchanged, because it calls Electron directly and defaults to Downloads.Testing
yarn run linterpasses inweb/andruntime/.regression/javascript/file_manager/FileManagerModule.spec.jschecks thatshowNative()passes the purpose (orundefined) to the save, open and folder dialogs.FormComponents.spec.jschecks thatdialogPurposereachesshowFileManager.defaultPathis 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