Move video to folder
Summary
Implements comprehensive video folder management functionality with proper validation and space-aware operations.
Changes
- ✅ Added
moveVideosToFolderfunction with proper validation - ✅ Implemented proper ownership and permission checks
- ✅ Added validation for space context and folder access
Features
- Move videos between folders within organization context
- Validation of video ownership and folder permissions
https://github.com/user-attachments/assets/fe7c8b65-874f-4ecf-aac9-ec6f25bad7d4
Summary by CodeRabbit
-
New Features
- Folder selection dialog with hierarchical picker, loading state, and “Move to root folder”.
- New move action in selection bar to move videos/caps to a chosen folder; shows success toast and returns moved/original counts.
- Folder listing retrieval for user/space/org contexts to populate dialogs and UIs.
-
Bug Fixes
- Improved server-side validation, error handling, and cache revalidation for reliable move operations and updated folder counts.
Walkthrough
Adds server actions to list and move folders with root-aware (user/space/org) validation, a FolderSelectionDialog UI and SelectedCapsBar integration for moving items, and new Effect-based folder library functions implementing hierarchical queries and move logic.
Changes
| Cohort / File(s) | Summary of changes |
|---|---|
Server actions: folder APIsapps/web/actions/folders/getAllFolders.ts, apps/web/actions/folders/move-videos-to-folder.ts |
Added getAllFoldersAction and moveVideosToFolderAction. Both validate CurrentUser and active org, build root contexts (user/space/org), invoke Effect-based folder library functions, return structured success/error payloads, log failures, and the move action triggers route revalidation. |
Frontend: folder selection UI & integrationapps/web/app/(org)/dashboard/_components/folder-selection-dialog.tsx, apps/web/app/(org)/dashboard/caps/components/SelectedCapsBar.tsx |
New client component FolderSelectionDialog (hierarchical, expandable tree, select root or folder) and integration in SelectedCapsBar via an optional moveSelectedCaps prop. Moves invoke the server action, show toasts, perform optimistic cache updates, and handle loading/errors. |
Domain library: folder logicapps/web/lib/folder.ts |
Added getAllFolders(root) and moveVideosToFolder(videoIds, targetFolderId, root). Introduced root-aware queries, space/org scoping and validations, shared-spaces mapping per video, per-folder count deltas, and refactored folder/video helper functions to Effect-based implementations using new DB utils (inArray, isNull). |
Sequence Diagram(s)
sequenceDiagram
autonumber
actor U as User
participant SB as SelectedCapsBar
participant FD as FolderSelectionDialog
participant SA as moveVideosToFolderAction
participant LIB as folder.lib (moveVideosToFolder)
participant POL as CurrentUser/Policy
participant DB as Database
participant RV as Revalidation
U->>SB: Click "Move to folder"
SB->>FD: Open dialog
FD->>SA: Submit { videoIds, targetFolderId, spaceId? }
SA->>POL: Authenticate & validate active org (and space membership if needed)
SA->>LIB: moveVideosToFolder(videoIds, targetFolderId, root)
LIB->>DB: Validate target scope, update video.folderId rows, compute per-folder deltas
DB-->>LIB: Updated rows / deltas
LIB-->>SA: Return movedCounts, deltas
SA->>RV: Revalidate org/space/folder routes (affected)
SA-->>FD: Respond success/error
FD-->>SB: Notify, optimistic cache updated, close
sequenceDiagram
autonumber
actor U as User
participant FD as FolderSelectionDialog
participant GA as getAllFoldersAction
participant LIB as folder.lib (getAllFolders)
participant POL as CurrentUser/Policy
participant DB as Database
U->>FD: Open dialog
FD->>GA: Request folders for root
GA->>POL: Validate user + active org
GA->>LIB: getAllFolders(root)
LIB->>DB: Query folders, child relationships, and video counts
DB-->>LIB: Rows
LIB-->>GA: Hierarchical folder tree
GA-->>FD: { success, folders }
FD-->>U: Render folder tree
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~60 minutes
Possibly related PRs
- CapSoftware/Cap#1065 — Related Effect-based refactor of folder helpers and root-aware folder operations in
apps/web/lib/folder.ts. - CapSoftware/Cap#926 — Overlaps on shared-spaces mapping and
getVideosByFolderIdshaping inapps/web/lib/folder.ts. - CapSoftware/Cap#943 — Changes to
SelectedCapsBarprops/UI and bulk-action flows; related to the new move integration.
Poem
I hop through trees of folders bright,
I nudge each video toward its light.
With tiny paws I count and move,
Revalidate paths and smooth the groove.
A rabbit's job: tidy, swift, and right. 🐇✨
Pre-merge checks and finishing touches
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title Check | ✅ Passed | The title “Move video to folder” clearly refers to a real and significant part of the pull request’s changes (the moveVideosToFolder functionality) and is concise and specific enough that a teammate scanning the history understands the primary feature being introduced. |
| Docstring Coverage | ✅ Passed | No functions found in the changes. Docstring coverage check skipped. |
✨ Finishing touches
- [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
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.
Comment @coderabbitai help to get the list of available commands and usage tips.