Skip to content

feat(overview): let the user choose the folder for new files - #211

Open
seecker-ionos wants to merge 1 commit into
nextcloud:mainfrom
seecker-ionos:feat/create-target-folder
Open

seecker-ionos wants to merge 1 commit into
nextcloud:mainfrom
seecker-ionos:feat/create-target-folder

Conversation

@seecker-ionos

Copy link
Copy Markdown

Closes #205

Problem

New files from the Office overview are always created in the user's root folder. Anyone who keeps documents in folders, project folders or team folders has to move every file afterwards.

Change

  • The create dialog shows the target folder ("Save in Documents · Change"). Change opens the Nextcloud file picker (@nextcloud/dialogs), folders only; only folders with create permission can be picked (setCanPick, also applied to the folder being browsed), so team folders and shares follow their own permissions, including groupfolder ACLs.
  • The last used folder is remembered per user with @nextcloud/browser-storage (persist().clearOnLogout(), key includes the user id). When the dialog opens it is re-checked (depth-0 PROPFIND with the default properties, oc:permissions parsed with parsePermissions()); if it was deleted, unshared or lost create permission, the dialog shows a note and falls back to the root folder. Stored values that are not a plain absolute path (.., empty segments) are ignored.
  • The dialog still opens immediately. A late folder check never overrides a folder the user picked or a create that was already sent; Change is disabled while the remembered folder is being checked.
  • Folder names go into the labels as plain text: translate(…, { escape: false, sanitize: false }), since they are only rendered as text (aria-label, the picker's button label) — otherwise R&D reads R&amp;D and <Drafts> disappears. The current folder is announced via aria-live="polite". If the picker cannot be opened (e.g. its chunk fails to load), a note appears below the folder.

Relation to #210

Independent of #210 (free filename suggestion); both touch OfficeOverview.vue, so whichever lands second needs a small rebase. Once both are in, the free name should be looked up in the chosen folder instead of the root — a few lines, since #210's nameExists(folder, name) already takes the folder. Happy to do that in the rebase.

Reuse

Rung 2 throughout: the standard file picker from @nextcloud/dialogs (getFilePickerBuilder) — the same picker Files, Talk and Text use — @nextcloud/browser-storage for the remembered folder, and parsePermissions() from @nextcloud/files/dav.

New dependencies and bundle size — contestable call

  • @nextcloud/dialogs 7.6.0 (AGPL-3.0-or-later). 7.5.0 is deprecated on npm; 8.0.0 does not satisfy @nextcloud/vue 9's peerOptional @nextcloud/dialogs ^7.4.0, so I stayed on 7.x. 7.6.0 brings its own @vueuse/core 15 (nested; the app uses 14.4) and requires vue ^3.5.44, so the lockfile also bumps vue 3.5.43 → 3.5.44 (and @babel/parser|types).
  • @nextcloud/browser-storage 0.5.0 (GPL-3.0-or-later), already in the tree via @nextcloud/auth; now a direct dependency.
  • The picker and its stylesheet (@nextcloud/dialogs/style.css) are imported on demand, so they are only downloaded when Change is clicked: ~98 KB gzip in 6 JS chunks plus ~9 KB gzip in 3 new CSS chunks. The entry chunk office-main.mjs grows from 623 KB to 649 KB raw, 206.5 KB → 215.1 KB gzip (+8.6 KB) — code shared with the lazy chunks that Rollup keeps in the entry. /compile will therefore add those chunk files (with their .license files) to js/ and css/; Vite also emits a style-*.chunk.mjs.license without a matching chunk.
  • Alternative with zero bundle cost: the server's global OC.dialogs.filepicker, but it is deprecated, so I did not use it. Happy to switch if you prefer.

Tests

  • TargetFolderPicker.spec.ts: label for root/nested folders, folder names with &/< shown as-is (label, aria-label, picker button), aria-live, folder-only picker started at the current folder, canPick (team folder with create permission ✓, read-only ✗), disabled button when nothing can be picked, root called "All files" instead of the user id, disabled prop, emit on pick, error on picker failure, no change on close.
  • folders.spec.ts: canCreateIn() against realistic stat results — writable folder (RGDNVCK), team folder mount (MGCK), read-only (RG), file, missing permissions, failed stat.
  • config.spec.ts: default, round-trip, rejected values (.., //, relative, trailing slash, .), separate per user, stored in the logout-cleared scope.
  • OfficeOverview.spec.ts: root without check, remembered folder used when still usable, fallback with note for read-only and deleted folders, no note when usable, Change disabled during the check and not re-enabled by an older check, folder picked during the check wins, create during the check keeps the folder, picker error shown below the folder (not on the filename) and cleared on pick, create path in picked folder and root (no double slash), folder remembered only on success. The race tests fail when their guards are removed.
  • vitest.setup.ts: @nextcloud/l10n is no longer mocked — the stand-in skipped escaping/sanitizing, so a label test could pass here and still render mangled in a browser. All existing tests pass against the real translate().
  • npm run test:unit, npm run lint, npm run stylelint, npm run build pass locally; vue-tsc --noEmit reports the same 4 errors as on main.
  • Manually verified on a Nextcloud 35.0.2 instance (built on top of v35.0.2 together with fix(overview): suggest a filename that is not taken yet #210) with a team folder: picked Team Folders/<team folder>, the file was created there, the folder was preselected on the next create; a remembered folder that no longer exists shows the note and falls back to "All files"; a folder R&D <Test> is shown unescaped in the label, aria-label and picker button; the picker loads its own stylesheet chunks and renders correctly. A read-only team folder was not available on that instance; that case is covered by the unit tests.

js/ and css/ are not committed — please /compile.

New files were always created in the user's root folder, so anyone who
keeps documents in folders, project folders or team folders had to move
every file afterwards.

The create dialog now shows the target folder with a "Change" button
that opens the Nextcloud file picker. Only folders the user may create
files in can be picked, so team folders and shares work through their
own permissions. The last used folder is remembered per user in
Nextcloud's scoped browser storage, which the server clears on logout,
and is re-checked when the dialog opens; if it is gone or no longer
writable, the dialog says so and falls back to the root folder. The
dialog still opens at once, and a late check never overrides a folder
the user picked or a create already sent.

@nextcloud/dialogs is imported on demand together with its stylesheet,
so the file picker is only downloaded when the folder is changed. Folder
names go into labels as plain text, without escaping or sanitizing. The
tests now run against the real translate() instead of a stand-in that
skipped its escaping and sanitizing.

Closes nextcloud#205

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Sebastian Ecker <sebastian.ecker@world4you.com>
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.

Create dialog: allow choosing a target folder (or configurable default folder) instead of always creating in Files root

1 participant