Skip to content

refactor(resources): converge Files onto the shared drag hook and batch bulk authorization - #6748

Merged
waleedlatif1 merged 2 commits into
stagingfrom
refactor/foldered-drag-convergence
Aug 15, 2026
Merged

refactor(resources): converge Files onto the shared drag hook and batch bulk authorization#6748
waleedlatif1 merged 2 commits into
stagingfrom
refactor/foldered-drag-convergence

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Files kept a 280-line copy of the foldered-list drag logic because it also accepts OS file drops, and the copies had drifted. The external drop is now an externalDrop option on the shared hook and the copy is gone — folder rows highlight and spring open for an OS file drag exactly as for a move, while the body and breadcrumb decline so the page-level upload overlay owns those regions
  • Collapsed the three drop-active booleans into one ActiveDropTarget union, so exactly one affordance is armed by construction instead of by hand-clearing the other two
  • Kept drop-target state writes identity-stable, so dragover no longer re-renders the list on every event
  • Restored per-list drag MIMEs, so the cross-surface isolation drag-payload.ts documents is true again
  • A folder can now spring open more than once per drag: descend, walk back out through the breadcrumb, descend again. The guard against re-entering the folder already on screen moved to useSpringNavigation, the only layer that can express it
  • Bulk move/delete now resolve each item against the workspace context the batch already holds, and memoize the effective-permission lookup for the batch — two invariant queries per item removed
  • Drop target fills at --surface-active; --surface-4 is the button-base token and is lighter than hover in light mode, so the strongest row state painted the faintest fill

Type of Change

  • Refactor / improvement

Testing

bun run type-check, bun run check:audits (27/27), and 4013 tests pass.

New coverage for the drag lifecycle: re-entering a folder through the breadcrumb, refusing to re-open the folder already on screen, cancelling a pending open when the drag moves onto the current folder, one-hop return to origin after a multi-level round trip, staying put when the round trip ends in a drop, and the next drag taking a fresh origin. Plus unit tests for the permission memo, including key separation and re-query after a rejection.

Not browser-tested — the convergence changes which code path Files runs, so the drag interactions are worth a manual pass.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

…ch bulk authorization

Files kept a 280-line copy of the foldered-list drag logic because it also
accepts OS file drops. The copies had already drifted, so the external drop
becomes an option on the shared hook and the copy goes away.

- Add `externalDrop` to `useFolderRowDragDrop`: folder rows highlight and spring
  open for an OS file drag exactly as for a move, while the body and breadcrumb
  decline so the page-level upload overlay owns those regions
- Collapse the three drop-active booleans into one `ActiveDropTarget` union, so
  exactly one affordance is armed by construction rather than by hand-clearing
- Keep drop-target writes identity-stable so `dragover` does not re-render the
  list on every event
- Give each list its own drag MIME again, restoring the cross-surface isolation
  `drag-payload.ts` documents
- Let a folder spring open more than once per drag, so a drag can walk back out
  through the breadcrumb and descend again; the guard against re-entering the
  folder already on screen moves to `useSpringNavigation`, the only layer that
  can state it
- Resolve each bulk item against the workspace context the batch already holds,
  and memoize the effective-permission lookup for the batch, replacing two
  invariant queries per item
- Fill the drop target at `--surface-active`: `--surface-4` is the button-base
  token and is lighter than hover in light mode, so the strongest row state read
  the faintest
@vercel

vercel Bot commented Aug 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 15, 2026 11:27pm

Request Review

@cursor

cursor Bot commented Aug 15, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches drag-and-drop navigation across Files/Knowledge/Tables and bulk authorization paths; behavior is well-tested but manual drag/upload passes are worthwhile given Files switched code paths.

Overview
Foldered lists share one drag implementation again. Files drops its large duplicate handler and wires useFolderRowDragDrop with per-list dragMime, an externalDrop path for OS files onto folder rows (body/breadcrumb stay with the page upload overlay), and externalDropHandled() so spring navigation does not bounce away after upload.

Drop affordance state is a single ActiveDropTarget union (row / body / crumb) with armDropTarget identity reuse so continuous dragover does not re-render the whole list. Spring-loaded folders can open the same folder again in one drag after backing out via the breadcrumb; useSpringNavigation refuses arming the folder already on screen and cancels pending opens when hovering the current folder crumb.

Bulk move/delete for tables and knowledge bases resolves each item with resolveActiveTableInWorkspace / resolveActiveKnowledgeBaseInWorkspace using the workspace context already loaded for the batch (shared requireTable / requireKnowledgeBase helpers). Table tests assert workspace context loads once per batch and permissions are still checked per item.

UI: chipDropTargetSurfaceClass uses --surface-active plus inset outline instead of --surface-4 so drop targets read stronger in light mode.

Reviewed by Cursor Bugbot for commit 6ab3c6f. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR consolidates Files drag-and-drop behavior into the shared folder-list hook, improves spring navigation and drop-target state, restores per-surface drag payload isolation, and optimizes bulk resource context resolution while retaining per-item authorization checks.

  • Adds external OS-file drop support to the shared folder-row drag hook.
  • Reworks spring navigation to support repeated folder entry during one drag while preserving origin restoration.
  • Replaces multiple drop-state booleans with one mutually exclusive active-target union.
  • Reuses canonical workspace context during table and knowledge bulk operations without caching permission decisions.
  • Updates drag lifecycle, authorization, and context-resolution tests.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/components/folders/use-folder-row-drag-drop.ts Extends the shared drag hook for surface-specific MIME payloads, external file drops, and mutually exclusive drop-target state.
apps/sim/app/workspace/[workspaceId]/components/folders/use-spring-loaded-folder.ts Allows repeated spring-opening during one drag while retaining first-navigation history semantics.
apps/sim/app/workspace/[workspaceId]/components/folders/use-spring-navigation.ts Prevents navigation to the folder already displayed and preserves drag-origin restoration behavior.
apps/sim/app/workspace/[workspaceId]/files/files.tsx Replaces the Files-specific drag implementation with the shared hook and integrates OS-file upload handling.
apps/sim/lib/knowledge/application/bulk.ts Reuses canonical workspace context across the batch while retaining a fresh authorization check for each knowledge item.
apps/sim/lib/table/application/bulk.ts Reuses canonical workspace context across the batch while retaining a fresh authorization check for each table item.
apps/sim/lib/knowledge/application/contexts.ts Adds resource resolution against an already-established workspace context without carrying an authorization verdict.
apps/sim/lib/table/application/context.ts Adds table resolution against an already-established workspace context without carrying an authorization verdict.
packages/emcn/src/components/chip/chip-chrome.ts Updates the drop-target surface styling to use the stronger active-surface token.

Sequence Diagram

sequenceDiagram
  participant Request as Bulk request
  participant Bulk as Bulk operation
  participant Context as Canonical workspace context
  participant Auth as Workspace authorization
  participant DB as Database
  Request->>Bulk: Move or delete multiple items
  Bulk->>Context: Resolve workspace context once
  loop Each item
    Bulk->>DB: Resolve active resource in workspace
    Bulk->>Auth: Authorize current item
    Auth->>DB: Read current effective permission
    Auth-->>Bulk: Allow or reject
    Bulk->>DB: Commit authorized item
  end
Loading

Reviews (2): Last reviewed commit: "fix(resources): dismiss the upload overl..." | Re-trigger Greptile

Comment thread apps/sim/lib/core/application/workspace-authorization.ts Outdated
Comment thread apps/sim/app/workspace/[workspaceId]/files/files.tsx
…eck permission per item

The drag hook stops propagation on a drop it handles, so the page-level handler
that cleared the upload overlay never ran and the chrome stayed up over the
finished upload. Both consuming paths now share one dismissal.

Drop the batch permission memo: each item in a bulk move or delete commits
independently, so reusing one allow verdict let a revocation part-way through a
batch go unseen by the remaining items. The workspace context is still resolved
once per batch, which was the larger saving.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6ab3c6f. Configure here.

@waleedlatif1
waleedlatif1 merged commit 4fc0fb4 into staging Aug 15, 2026
30 checks passed
@waleedlatif1
waleedlatif1 deleted the refactor/foldered-drag-convergence branch August 15, 2026 23:44
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.

1 participant