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.

✨ feat(chat-input): link the Cloud drive menu to Sandbox Storage (#22816)

Rdmclin2b7887894881b
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index f0364b03c46..129775f8a6e 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -2128,6 +2128,7 @@
"sandboxDrive.fallbackChip.instanceUnavailable": "Environment unavailable",
"sandboxDrive.fallbackChip.rootNotAllowed": "Pick a folder",
"sandboxDrive.manageEnvironments": "Settings",
+ "sandboxDrive.openStorage": "Sandbox Storage",
"sandboxDrive.pickerInfoTooltip": "A temporary directory is cleaned up with the sandbox. A folder on your cloud drive is kept across conversations. A repository is cloned before the first command.",
"sandboxDrive.pickerTitle": "Work location",
"sandboxDrive.root": "Root",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index e21a1ce2c82..07bd24397fc 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -2128,6 +2128,7 @@
"sandboxDrive.fallbackChip.instanceUnavailable": "环境目录不可用",
"sandboxDrive.fallbackChip.rootNotAllowed": "请选择文件夹",
"sandboxDrive.manageEnvironments": "设置",
+ "sandboxDrive.openStorage": "沙箱存储",
"sandboxDrive.pickerInfoTooltip": "临时工作目录随沙箱清理;云盘文件夹跨会话保留;代码仓库在第一条命令前克隆好。",
"sandboxDrive.pickerTitle": "工作位置",
"sandboxDrive.root": "根目录",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index ccb46160d56..2345c8b0883 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -4368,6 +4368,7 @@ export default {
'userFeedbackCard.title': 'User feedback',
'you': 'You',
'sandboxDrive.manageEnvironments': 'Settings',
+ 'sandboxDrive.openStorage': 'Sandbox Storage',
'sandboxEnvironment.missing': 'Environment unavailable',
'sandboxEnvironment.loading': 'Loading environment…',
'sandboxDrive.pickerTitle': 'Work location',
diff --git a/src/features/ChatInput/ControlBar/SandboxDriveMenu.tsx b/src/features/ChatInput/ControlBar/SandboxDriveMenu.tsx
index 499616dc850..e64a6c976ed 100644
--- a/src/features/ChatInput/ControlBar/SandboxDriveMenu.tsx
+++ b/src/features/ChatInput/ControlBar/SandboxDriveMenu.tsx
@@ -5,7 +5,7 @@ import { SANDBOX_DRIVE_ROOT } from '@lobechat/builtin-tool-cloud-sandbox';
import { Button, Flexbox, Icon, Text } from '@lobehub/ui';
import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';
import * as stylex from '@stylexjs/stylex';
-import { FolderIcon, FolderOpenIcon, HomeIcon } from 'lucide-react';
+import { FolderIcon, FolderOpenIcon, HomeIcon, ServerIcon } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import useSWR from 'swr';
@@ -14,15 +14,9 @@ import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspace
import { sandboxStorageService } from '@/services/sandboxStorage';
import OptionRow from './OptionRow';
+import SubmenuHeader from './SubmenuHeader';
const styles = stylex.create({
- header: {
- paddingBlock: '4px',
- paddingInline: '8px',
- fontSize: '12px',
- fontWeight: 500,
- color: cssVar.colorTextSecondary,
- },
hint: {
paddingInline: '8px',
fontSize: '12px',
@@ -42,6 +36,8 @@ export interface SandboxDriveFolderPick {
interface SandboxDriveMenuProps {
/** Opens the full directory browser, for folders this short list does not reach. */
onBrowse: () => void;
+ /** Leaves the menu for Sandbox Storage, where the drives are browsed and managed. */
+ onOpenStorage: () => void;
onPick: (pick: SandboxDriveFolderPick) => void;
/** The label of a pick the list cannot show: a nested folder, or another drive. */
selectedLabel?: string;
@@ -55,7 +51,7 @@ interface SandboxDriveMenuProps {
* fetched once the row is opened.
*/
const SandboxDriveMenu = memo<SandboxDriveMenuProps>(
- ({ onBrowse, onPick, selectedLabel, selectedPath }) => {
+ ({ onBrowse, onOpenStorage, onPick, selectedLabel, selectedPath }) => {
const { t } = useTranslation(['chat', 'device']);
const workspaceId = useActiveWorkspaceId();
// The public drive's root is not a place to work, so a workspace starts on
@@ -76,7 +72,14 @@ const SandboxDriveMenu = memo<SandboxDriveMenuProps>(
return (
<Flexbox gap={2} style={{ maxWidth: 360, minWidth: 280 }}>
- <div {...stylex.props(styles.header)}>{t('sandboxDrive.title')}</div>
+ <SubmenuHeader
+ title={t('sandboxDrive.title')}
+ action={{
+ icon: ServerIcon,
+ label: t('sandboxDrive.openStorage'),
+ onClick: onOpenStorage,
+ }}
+ />
<div {...stylex.props(styles.list)}>
{selectedLabel && !listed && (
diff --git a/src/features/ChatInput/ControlBar/SandboxDrivePicker.tsx b/src/features/ChatInput/ControlBar/SandboxDrivePicker.tsx
index 5ba05b03e0e..90639f685e6 100644
--- a/src/features/ChatInput/ControlBar/SandboxDrivePicker.tsx
+++ b/src/features/ChatInput/ControlBar/SandboxDrivePicker.tsx
@@ -21,6 +21,7 @@ import useSWR from 'swr';
import { openSandboxStorageUpsell } from '@/business/client/features/SandboxStorageUpsell';
import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';
import { openCreateEnvironmentModal } from '@/features/EnvironmentManager/CreateEnvironmentModal';
+import { SANDBOX_STORAGE_PATH } from '@/features/ResourceHome/paths';
import { openSandboxDirectoryModal } from '@/features/WorkingDirectory';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
import { environmentService } from '@/services/environment';
@@ -312,6 +313,10 @@ const SandboxDrivePicker = memo<SandboxDrivePickerProps>(
selectedPath={showFolder ? value.workingDirectory : undefined}
onBrowse={openBrowser}
onPick={(folder) => void select(folder)}
+ onOpenStorage={() => {
+ setOpen(false);
+ navigate(SANDBOX_STORAGE_PATH);
+ }}
/>
}
>
diff --git a/src/features/ChatInput/ControlBar/SandboxRepositoryMenu.tsx b/src/features/ChatInput/ControlBar/SandboxRepositoryMenu.tsx
index b438de3f649..65f954eb8f1 100644
--- a/src/features/ChatInput/ControlBar/SandboxRepositoryMenu.tsx
+++ b/src/features/ChatInput/ControlBar/SandboxRepositoryMenu.tsx
@@ -11,20 +11,9 @@ import { useTranslation } from 'react-i18next';
import OptionRow from './OptionRow';
import { repositorySlug } from './sandboxEnvironmentOptions';
+import SubmenuHeader from './SubmenuHeader';
const styles = stylex.create({
- header: {
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'space-between',
- paddingBlock: '4px',
- paddingInline: '8px',
- },
- headerTitle: {
- fontSize: '12px',
- fontWeight: 500,
- color: cssVar.colorTextSecondary,
- },
hint: {
paddingInline: '8px',
fontSize: '12px',
@@ -34,19 +23,6 @@ const styles = stylex.create({
maxHeight: '280px',
overflowY: 'auto',
},
- manageButton: {
- cursor: 'pointer',
- display: 'flex',
- gap: '4px',
- alignItems: 'center',
- padding: '0',
- borderStyle: 'none',
- fontSize: '11px',
- color: { 'default': cssVar.colorTextQuaternary, ':hover': cssVar.colorPrimary },
- backgroundColor: 'transparent',
- backgroundImage: 'none',
- transition: 'color 0.2s',
- },
});
export interface SandboxRepositoryOption {
@@ -78,13 +54,14 @@ const SandboxRepositoryMenu = memo<SandboxRepositoryMenuProps>(
const { t } = useTranslation('chat');
return (
<Flexbox gap={2} style={{ maxWidth: 360, minWidth: 280 }}>
- <div {...stylex.props(styles.header)}>
- <span {...stylex.props(styles.headerTitle)}>{t('sandboxEnvironment.title')}</span>
- <button {...stylex.props(styles.manageButton)} type={'button'} onClick={onManage}>
- <Icon icon={SettingsIcon} size={11} />
- <span>{t('sandboxDrive.manageEnvironments')}</span>
- </button>
- </div>
+ <SubmenuHeader
+ title={t('sandboxEnvironment.title')}
+ action={{
+ icon: SettingsIcon,
+ label: t('sandboxDrive.manageEnvironments'),
+ onClick: onManage,
+ }}
+ />
<Text className={stylex.props(styles.hint).className}>{t('sandboxEnvironment.hint')}</Text>
<div {...stylex.props(styles.list)}>
diff --git a/src/features/ChatInput/ControlBar/SubmenuHeader.tsx b/src/features/ChatInput/ControlBar/SubmenuHeader.tsx
new file mode 100644
index 00000000000..3b5feca5d9d
--- /dev/null
+++ b/src/features/ChatInput/ControlBar/SubmenuHeader.tsx
@@ -0,0 +1,58 @@
+'use client';
+
+import { Icon } from '@lobehub/ui';
+import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';
+import * as stylex from '@stylexjs/stylex';
+import type { LucideIcon } from 'lucide-react';
+import { memo } from 'react';
+
+const styles = stylex.create({
+ action: {
+ cursor: 'pointer',
+ display: 'flex',
+ gap: '4px',
+ alignItems: 'center',
+ padding: '0',
+ borderStyle: 'none',
+ fontSize: '11px',
+ color: { 'default': cssVar.colorTextQuaternary, ':hover': cssVar.colorPrimary },
+ backgroundColor: 'transparent',
+ backgroundImage: 'none',
+ transition: 'color 0.2s',
+ },
+ header: {
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'space-between',
+ paddingBlock: '4px',
+ paddingInline: '8px',
+ },
+ title: {
+ fontSize: '12px',
+ fontWeight: 500,
+ color: cssVar.colorTextSecondary,
+ },
+});
+
+interface SubmenuHeaderProps {
+ /** A quiet link on the right that leaves the menu for the place this list is managed. */
+ action?: { icon: LucideIcon; label: string; onClick: () => void };
+ title: string;
+}
+
+/** The title row of a work-location submenu. */
+const SubmenuHeader = memo<SubmenuHeaderProps>(({ action, title }) => (
+ <div {...stylex.props(styles.header)}>
+ <span {...stylex.props(styles.title)}>{title}</span>
+ {action && (
+ <button {...stylex.props(styles.action)} type={'button'} onClick={action.onClick}>
+ <Icon icon={action.icon} size={11} />
+ <span>{action.label}</span>
+ </button>
+ )}
+ </div>
+));
+
+SubmenuHeader.displayName = 'SubmenuHeader';
+
+export default SubmenuHeader;
diff --git a/src/features/ChatInput/ControlBar/__tests__/SandboxDriveMenu.test.tsx b/src/features/ChatInput/ControlBar/__tests__/SandboxDriveMenu.test.tsx
new file mode 100644
index 00000000000..fbc433b3cd0
--- /dev/null
+++ b/src/features/ChatInput/ControlBar/__tests__/SandboxDriveMenu.test.tsx
@@ -0,0 +1,36 @@
+import { fireEvent, render, screen } from '@testing-library/react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import SandboxDriveMenu from '../SandboxDriveMenu';
+
+vi.mock('react-i18next', () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+}));
+
+vi.mock('@/business/client/hooks/useActiveWorkspaceId', () => ({
+ useActiveWorkspaceId: () => undefined,
+}));
+
+vi.mock('@/services/sandboxStorage', () => ({
+ sandboxStorageService: { listFiles: vi.fn(async () => ({ entries: [] })) },
+}));
+
+describe('SandboxDriveMenu', () => {
+ const onOpenStorage = vi.fn();
+ const onPick = vi.fn();
+
+ beforeEach(() => {
+ onOpenStorage.mockClear();
+ onPick.mockClear();
+ });
+
+ it('links to Sandbox Storage from the header without picking a folder', () => {
+ render(<SandboxDriveMenu onBrowse={vi.fn()} onOpenStorage={onOpenStorage} onPick={onPick} />);
+
+ expect(screen.getByText('sandboxDrive.title')).toBeInTheDocument();
+ fireEvent.click(screen.getByRole('button', { name: 'sandboxDrive.openStorage' }));
+
+ expect(onOpenStorage).toHaveBeenCalledTimes(1);
+ expect(onPick).not.toHaveBeenCalled();
+ });
+});