Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(resource): open the drive batch actions menu on click (#22237)

Rdmclin2ef2326c1e0d1
diff --git a/src/features/ResourceManager/components/Explorer/ToolBar/BatchActionsDropdown.test.tsx b/src/features/ResourceManager/components/Explorer/ToolBar/BatchActionsDropdown.test.tsx
new file mode 100644
index 00000000000..c9b545971a4
--- /dev/null
+++ b/src/features/ResourceManager/components/Explorer/ToolBar/BatchActionsDropdown.test.tsx
@@ -0,0 +1,60 @@
+import { fireEvent, render, screen } from '@testing-library/react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import BatchActionsDropdown from './BatchActionsDropdown';
+
+const permission = vi.hoisted(() => ({ allowed: true, reason: 'No permission' }));
+
+vi.mock('@/hooks/usePermission', () => ({
+ usePermission: () => permission,
+}));
+
+vi.mock('@/business/client/hooks/useActiveWorkspaceId', () => ({
+ useActiveWorkspaceId: () => undefined,
+}));
+
+vi.mock('@/features/ResourceManager/components/KnowledgeBaseListProvider', () => ({
+ useKnowledgeBaseListContext: () => [],
+}));
+
+vi.mock('@/features/ResourceManager/store', () => ({
+ useResourceManagerStore: (selector: (s: Record<string, unknown>) => unknown) =>
+ selector({
+ libraryId: undefined,
+ listVisibility: undefined,
+ resolveSelectedResourceIds: vi.fn(),
+ selectAllState: 'none',
+ }),
+}));
+
+vi.mock('@/store/library', () => ({
+ useKnowledgeBaseStore: (selector: (s: Record<string, unknown>) => unknown) =>
+ selector({ addFilesToKnowledgeBase: vi.fn() }),
+}));
+
+const getTrigger = () => screen.getByTitle('Batch actions');
+
+describe('BatchActionsDropdown', () => {
+ beforeEach(() => {
+ permission.allowed = true;
+ });
+
+ it('opens the batch actions menu when the trigger is clicked', async () => {
+ render(<BatchActionsDropdown selectCount={0} onActionClick={vi.fn()} />);
+
+ fireEvent.click(getTrigger());
+
+ expect(await screen.findByText('FileManager.actions.batchChunking')).toBeInTheDocument();
+ });
+
+ it('renders a disabled trigger without a menu when editing is not allowed', () => {
+ permission.allowed = false;
+ render(<BatchActionsDropdown selectCount={0} onActionClick={vi.fn()} />);
+
+ const trigger = getTrigger();
+ expect(trigger).toBeDisabled();
+
+ fireEvent.click(trigger);
+ expect(screen.queryByText('FileManager.actions.batchChunking')).not.toBeInTheDocument();
+ });
+});
diff --git a/src/features/ResourceManager/components/Explorer/ToolBar/BatchActionsDropdown.tsx b/src/features/ResourceManager/components/Explorer/ToolBar/BatchActionsDropdown.tsx
index 35e8e2f9217..bbf539c7544 100644
--- a/src/features/ResourceManager/components/Explorer/ToolBar/BatchActionsDropdown.tsx
+++ b/src/features/ResourceManager/components/Explorer/ToolBar/BatchActionsDropdown.tsx
@@ -231,15 +231,21 @@ const BatchActionsDropdown = memo<BatchActionsDropdownProps>(({ selectCount, onA
isWorkspaceDeleteAll,
]);
+ const title = t('FileManager.actions.batchActions', 'Batch actions');
+
+ // Without edit permission the menu has no items, so show the reason instead of a menu.
+ // Keep the button as DropdownMenu's direct child: a Tooltip without a title returns its
+ // children as-is and drops the trigger's onClick/ref, so the menu would never open.
+ if (!canEditResources)
+ return (
+ <Tooltip title={reason}>
+ <ActionIconWithChevron disabled icon={CircleEllipsisIcon} title={title} />
+ </Tooltip>
+ );
+
return (
<DropdownMenu items={menuItems} placement="bottomLeft">
- <Tooltip title={canEditResources ? undefined : reason}>
- <ActionIconWithChevron
- disabled={!canEditResources}
- icon={CircleEllipsisIcon}
- title={t('FileManager.actions.batchActions', 'Batch actions')}
- />
- </Tooltip>
+ <ActionIconWithChevron icon={CircleEllipsisIcon} title={title} />
</DropdownMenu>
);
});