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(devices): add recent-directory button to device detail panel (#16040)

Arvin Xudeb4bd6a3c0f
diff --git a/src/features/ChatInput/ControlBar/WorkingDirectoryPicker.tsx b/src/features/ChatInput/ControlBar/WorkingDirectoryPicker.tsx
index 139fb2e0c62..2f169d7a6a3 100644
--- a/src/features/ChatInput/ControlBar/WorkingDirectoryPicker.tsx
+++ b/src/features/ChatInput/ControlBar/WorkingDirectoryPicker.tsx
@@ -14,6 +14,7 @@ import {
import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { openAddWorkingDirModal } from '@/features/WorkingDirectory';
import {
resolveAgentWorkingDirectory,
resolveTargetDeviceId,
@@ -29,7 +30,6 @@ import { useElectronStore } from '@/store/electron';
import { useUserStore } from '@/store/user';
import { authSelectors } from '@/store/user/selectors';
-import { openAddWorkingDirModal } from './AddWorkingDirModal';
import DirIcon from './DirIcon';
import { useCommitWorkingDirectory } from './useCommitWorkingDirectory';
import { useMigrateDeviceRecents } from './useMigrateDeviceRecents';
diff --git a/src/features/ChatInput/ControlBar/AddWorkingDirModal.tsx b/src/features/WorkingDirectory/AddWorkingDirModal.tsx
similarity index 100%
rename from src/features/ChatInput/ControlBar/AddWorkingDirModal.tsx
rename to src/features/WorkingDirectory/AddWorkingDirModal.tsx
diff --git a/src/features/WorkingDirectory/index.ts b/src/features/WorkingDirectory/index.ts
new file mode 100644
index 00000000000..a39ebf2dd3b
--- /dev/null
+++ b/src/features/WorkingDirectory/index.ts
@@ -0,0 +1 @@
+export { openAddWorkingDirModal } from './AddWorkingDirModal';
diff --git a/src/routes/(main)/settings/devices/features/DeviceDetailPanel.tsx b/src/routes/(main)/settings/devices/features/DeviceDetailPanel.tsx
index 5618c287bc4..919055bbb58 100644
--- a/src/routes/(main)/settings/devices/features/DeviceDetailPanel.tsx
+++ b/src/routes/(main)/settings/devices/features/DeviceDetailPanel.tsx
@@ -10,7 +10,9 @@ import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import DirIcon from '@/features/ChatInput/ControlBar/DirIcon';
+import { openAddWorkingDirModal } from '@/features/WorkingDirectory';
import { lambdaQuery } from '@/libs/trpc/client';
+import { deviceService } from '@/services/device';
import { electronSystemService } from '@/services/electron/system';
import { nextWorkingDirs } from '@/store/device';
@@ -59,7 +61,7 @@ interface DeviceDetailPanelProps {
}
const DeviceDetailPanel = memo<DeviceDetailPanelProps>(({ device, isCurrent, onClose }) => {
- const { t } = useTranslation('setting');
+ const { t } = useTranslation(['setting', 'device']);
const utils = lambdaQuery.useUtils();
const [name, setName] = useState(device.friendlyName ?? '');
@@ -113,19 +115,37 @@ const DeviceDetailPanel = memo<DeviceDetailPanelProps>(({ device, isCurrent, onC
}
};
- const handleAddRecent = async () => {
- const result = await electronSystemService.selectFolder({
- title: t('devices.detail.addDir'),
+ const addRecent = (entry: { path: string; repoType?: 'git' | 'github' }) => {
+ update.mutate({
+ deviceId: device.deviceId,
+ workingDirs: nextWorkingDirs(entry, device.workingDirs),
});
- if (result?.path) {
- update.mutate({
- deviceId: device.deviceId,
- workingDirs: nextWorkingDirs(
- { path: result.path, repoType: result.repoType },
- device.workingDirs,
- ),
+ };
+
+ const handleAddRecent = async () => {
+ // This machine: browse natively. A remote / non-current device isn't
+ // browsable from here, so fall back to manual absolute-path entry (the same
+ // modal the chat control bar uses), statting the path on the target device.
+ if (canBrowse) {
+ const result = await electronSystemService.selectFolder({
+ title: t('devices.detail.addDir'),
});
+ if (result?.path) addRecent({ path: result.path, repoType: result.repoType });
+ return;
}
+
+ openAddWorkingDirModal({
+ onSubmit: async (path) => {
+ const result = await deviceService.statPath(device.deviceId, path);
+ if (result) {
+ if (!result.exists) return t('device:workingDirectory.pathNotExist');
+ if (!result.isDirectory) return t('device:workingDirectory.pathNotDirectory');
+ }
+ addRecent({ path, repoType: result?.repoType });
+ return undefined;
+ },
+ placeholder: device.defaultCwd || undefined,
+ });
};
const handleRemoveRecent = (path: string) => {
@@ -220,7 +240,15 @@ const DeviceDetailPanel = memo<DeviceDetailPanelProps>(({ device, isCurrent, onC
{/* ─── Recent directories ─── */}
<Flexbox gap={6}>
- <span className={styles.label}>{t('devices.detail.recentDirs')}</span>
+ <Flexbox horizontal align={'center'} distribution={'space-between'}>
+ <span className={styles.label}>{t('devices.detail.recentDirs')}</span>
+ <ActionIcon
+ icon={FolderPlusIcon}
+ size={'small'}
+ title={t('devices.detail.addDir')}
+ onClick={handleAddRecent}
+ />
+ </Flexbox>
{device.workingDirs.length === 0 ? (
<Text style={{ fontSize: 12 }} type={'secondary'}>
{t('devices.detail.noRecent')}
@@ -245,16 +273,6 @@ const DeviceDetailPanel = memo<DeviceDetailPanelProps>(({ device, isCurrent, onC
onChange={handleReorderRecent}
/>
)}
- {canBrowse && (
- <Button
- block
- icon={<Icon icon={FolderPlusIcon} />}
- variant={'filled'}
- onClick={handleAddRecent}
- >
- {t('devices.detail.addDir')}
- </Button>
- )}
</Flexbox>
</Flexbox>
);