Skip to content

fix(ui): resource tab fixes, add search to workspace modal#4166

Merged
TheodoreSpeaks merged 5 commits intostagingfrom
fix/resource-switch
Apr 14, 2026
Merged

fix(ui): resource tab fixes, add search to workspace modal#4166
TheodoreSpeaks merged 5 commits intostagingfrom
fix/resource-switch

Conversation

@TheodoreSpeaks
Copy link
Copy Markdown
Collaborator

@TheodoreSpeaks TheodoreSpeaks commented Apr 14, 2026

Summary

Added search to workspace modal. Allows users with tons of workspaces to easily query by name.

  • Auto-focused on search input when opened
  • Added keyboard controls for switching workspaces using arrow keys
    Also added resource tab improvements:
  • Multi select delete deletes in one atomic operation with optimistic delete client-side
  • Resource doesn't auto-switch to end resource on sending or aborting message
  • Auto-scroll to tab when context is switched to it, tab should be in view.
  • Cmd+click on workspace opens in new tab

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

  • Tested locally. Validated search, validated resource switch behavior.

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)

Screenshots/Videos

image

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 14, 2026 10:48pm

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 14, 2026

PR Summary

Medium Risk
Touches chat resource persistence and React Query optimistic mutation behavior, plus several UI interaction paths (multi-delete, active selection, keyboard navigation), which could cause subtle state/ordering regressions if edge cases are missed.

Overview
Improves chat resource tab UX and consistency: the active tab now auto-scrolls into view when changed, multi-select removal fires concurrent remove mutations, and chat hydration no longer forces the active resource to the last tab if the current selection still exists.

Makes resource removal more atomic and robust: the DELETE /api/mothership/chat/resources path now removes an entry via an in-DB JSONB filter and returns the updated resources, and useRemoveChatResource switches to a granular optimistic update that tracks removed items and restores only those on error.

Enhances the workspace switcher dropdown for large accounts with search + keyboard navigation (autofocus, arrow-key highlight, enter-to-switch), and adds cmd/ctrl-click or middle-click to open a workspace in a new tab.

Reviewed by Cursor Bugbot for commit 7e8833a. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 14, 2026

Greptile Summary

This PR adds a workspace search bar with keyboard navigation to the workspace switcher dropdown, fixes resource tab auto-switching behavior on send/abort, implements multi-select delete for resource tabs with optimistic client-side removal, and adds auto-scroll to bring the active resource tab into view. The changes are well-structured and follow the existing patterns. All findings are minor P2 suggestions.

Confidence Score: 5/5

Safe to merge — all findings are P2 style/UX suggestions with no correctness or data-integrity issues.

The core logic for multi-select delete, workspace search, keyboard navigation, and tab auto-scroll is sound. PostgreSQL row locking makes concurrent resource deletions safe server-side, and TanStack Query's onSettled invalidation ensures cache consistency even on partial errors. All remaining comments are minor style improvements.

workspace-header.tsx has two minor UX polish items (magic number threshold, highlight state leaking).

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/workspace-header.tsx Adds workspace search bar (visible only when >3 workspaces), keyboard arrow navigation, and auto-focus on open. Minor: hardcoded threshold and highlightedIndex highlight leaks to non-keyboard case.
apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-tabs/resource-tabs.tsx Adds auto-scroll-into-view effect on tab switch, fixes multi-select delete to remove all selected tabs in one optimistic client update (N server calls via loop). Clean implementation.
apps/sim/hooks/queries/tasks.ts Adds useDeleteTasks for batch task deletion via Promise.all, consistent with existing useDeleteTask pattern (no optimistic update, invalidates on settled).
apps/sim/app/api/copilot/chat/resources/route.ts DELETE handler uses a single atomic SQL UPDATE with JSON array aggregation to remove one resource per request; concurrent N deletes are safe due to PostgreSQL row-level locking.
apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Exports setActiveResourceId to allow external control; resource auto-switch on send/abort was removed as per the fix. No new issues introduced.

Sequence Diagram

sequenceDiagram
    participant U as User
    participant RT as ResourceTabs
    participant UC as useChat
    participant RQ as React Query Cache
    participant API as /api/mothership/chat/resources

    Note over U,API: Multi-select tab delete
    U->>RT: Click × on selected tab (N tabs selected)
    RT->>UC: onRemoveResource(type, id) × N (loop)
    UC->>UC: setResources batched → single render
    RT->>RT: setSelectedIds(remove deleted)
    loop for each non-ephemeral target
        RT->>RQ: removeResource.mutate({chatId, type, id})
        RQ->>RQ: onMutate → optimistic remove from cache
        RQ->>API: DELETE /resources {chatId, type, id}
        API->>API: SQL UPDATE JSONB (row-locked, atomic)
        API-->>RQ: {success, resources}
        RQ->>RQ: onSettled → invalidateQueries(detail)
    end

    Note over U,API: Workspace search + keyboard nav
    U->>RT: Opens workspace dropdown
    RT->>RT: setHighlightedIndex(0) + rAF focus
    U->>RT: Types search query
    RT->>RT: filter workspaces by name
    U->>RT: ArrowDown / ArrowUp
    RT->>RT: setHighlightedIndex(±1 mod len)
    U->>RT: Enter key
    RT->>RT: onWorkspaceSwitch(filteredWorkspaces[highlightedIndex])
Loading

Reviews (1): Last reviewed commit: "Add search bar to workspace modal" | Re-trigger Greptile

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b95c255. Configure here.

@TheodoreSpeaks TheodoreSpeaks merged commit 751eeac into staging Apr 14, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/resource-switch branch April 15, 2026 06:40
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