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(terminal): size the target picker to its content and show the local label (#20929)

Inneib1ce64100876
diff --git a/src/features/ChatTerminal/Content.tsx b/src/features/ChatTerminal/Content.tsx
index 70a704bb5a8..f39ea90f85f 100644
--- a/src/features/ChatTerminal/Content.tsx
+++ b/src/features/ChatTerminal/Content.tsx
@@ -36,12 +36,10 @@ import { useGlobalStore } from '@/store/global';
import SplitView from './SplitView';
import type { TerminalTab } from './store';
import { useChatTerminalStore } from './store';
+import { buildTargetOptions, LOCAL_TARGET } from './targetOptions';
const EMPTY_TABS: TerminalTab[] = [];
-/** Sentinel for "run on this machine"; device ids are never empty strings. */
-const LOCAL_TARGET = '';
-
const styles = createStaticStyles(({ css, cssVar }) => ({
container: css`
overflow: hidden;
@@ -188,13 +186,10 @@ const Content = memo(() => {
void createTab(topicKey, cwd);
};
- const targetOptions = [
- ...(isDesktop ? [{ label: t('terminalPanel.targetLocal'), value: LOCAL_TARGET }] : []),
- ...targets.map((device) => ({
- label: device.friendlyName || device.hostname || device.deviceId,
- value: device.deviceId,
- })),
- ];
+ const targetOptions = buildTargetOptions(
+ targets,
+ isDesktop ? t('terminalPanel.targetLocal') : undefined,
+ );
return (
<Flexbox className={styles.container}>
@@ -235,14 +230,15 @@ const Content = memo(() => {
title={t('terminalPanel.newTab')}
onClick={() => createTab(topicKey, cwd)}
/>
+ <Flexbox flex={1} />
<Select
options={targetOptions}
size={'small'}
- style={{ minWidth: 120 }}
+ // The trigger defaults to `width: 100%`, which fills the whole tab bar.
+ style={{ flex: 'none', maxWidth: 240, minWidth: 120, width: 'auto' }}
value={targetDeviceId ?? LOCAL_TARGET}
onChange={(value) => selectTarget(String(value))}
/>
- <Flexbox flex={1} />
<ActionIcon
disabled={!activeTab || creating}
icon={SquareSplitHorizontalIcon}
diff --git a/src/features/ChatTerminal/targetOptions.test.ts b/src/features/ChatTerminal/targetOptions.test.ts
new file mode 100644
index 00000000000..434b4005a79
--- /dev/null
+++ b/src/features/ChatTerminal/targetOptions.test.ts
@@ -0,0 +1,30 @@
+import type { DeviceListItem } from '@lobechat/types';
+import { describe, expect, it } from 'vitest';
+
+import { buildTargetOptions, LOCAL_TARGET } from './targetOptions';
+
+const device = (patch: Partial<DeviceListItem>) =>
+ ({ deviceId: 'dev_1', ...patch }) as DeviceListItem;
+
+describe('buildTargetOptions', () => {
+ it('gives the local option a non-empty value so Select can render its label', () => {
+ const [local] = buildTargetOptions([], 'This computer');
+
+ expect(local).toEqual({ label: 'This computer', value: LOCAL_TARGET });
+ expect(local.value).not.toBe('');
+ });
+
+ it('omits the local option without a label', () => {
+ expect(buildTargetOptions([device({})])).toEqual([{ label: 'dev_1', value: 'dev_1' }]);
+ });
+
+ it('labels devices by friendly name, then hostname, then id', () => {
+ const options = buildTargetOptions([
+ device({ deviceId: 'a', friendlyName: 'Laptop', hostname: 'host-a' }),
+ device({ deviceId: 'b', hostname: 'host-b' }),
+ device({ deviceId: 'c' }),
+ ]);
+
+ expect(options.map((option) => option.label)).toEqual(['Laptop', 'host-b', 'c']);
+ });
+});
diff --git a/src/features/ChatTerminal/targetOptions.ts b/src/features/ChatTerminal/targetOptions.ts
new file mode 100644
index 00000000000..9018e9da13b
--- /dev/null
+++ b/src/features/ChatTerminal/targetOptions.ts
@@ -0,0 +1,24 @@
+import type { DeviceListItem } from '@lobechat/types';
+
+/**
+ * Sentinel for "run on this machine". Not an empty string: Select treats `''`
+ * as no value and renders a blank trigger instead of the option's label.
+ */
+export const LOCAL_TARGET = '__local__';
+
+interface TargetOption {
+ label: string;
+ value: string;
+}
+
+/** Options for the terminal target picker; `localLabel` adds "this machine" first. */
+export const buildTargetOptions = (
+ devices: DeviceListItem[],
+ localLabel?: string,
+): TargetOption[] => [
+ ...(localLabel ? [{ label: localLabel, value: LOCAL_TARGET }] : []),
+ ...devices.map((device) => ({
+ label: device.friendlyName || device.hostname || device.deviceId,
+ value: device.deviceId,
+ })),
+];