* Merge workspaces across all hosts in the sidebar Replace per-host sidebar sections with a single merged project list. Projects that exist on multiple hosts (matched by projectKey) are collapsed into one row. Host identity is surfaced via: - A status-only footer pill showing online/offline host counts - Hover cards with a mandatory host row on every workspace entry - Subtitles showing the host name when a project spans >1 host - A host filter in the grouping dropdown (not a sidebar switcher) Order and group-mode stores migrated from per-server to global keys with zustand persist migrations. New-workspace screen now shows a merged project list with a host selector combobox. Key files: - workspace-structure.ts: merge algorithm by projectKey - sidebar-view-store.ts / sidebar-order-store.ts: global state - sidebar-workspace-list.tsx: context-based subtitle injection - new-workspace-screen.tsx: host selector in footer row * Add host filtering to the merged sidebar The sidebar now merges workspaces from every connected host, so a single global "active host" no longer fits. Host selection becomes explicit per action via a host chooser, and agent history pages across all hosts at once. Removes the active-host / active-server-id model and the all-agents-list hook that fed it. * Fix rebase fallout: translate archive host error, update stale workspace-key test archiveWorkspacesOptimistically used a raw "Host is not connected" string that the i18n completeness test forbids; route it through i18n.t with the existing hostDisconnected key. The selectors memoization test asserted un-prefixed workspace keys, but merged-sidebar keys are serverId-prefixed. * Fix sidebar review fallout * Address sidebar review followups * Fix sidebar workspace identity migration * Address sidebar review followups * Handle partial host history failures * Fix merged sidebar project removal and E2E drift * Restore history routes and project removal shape * Remove sidebar host context plumbing * Tighten sidebar status and host filter state * Keep new workspace project selection host-compatible * Migrate sidebar view storage * Streamline host selection flows * Update all-host history on archive * Fix empty project sidebar action Code regression: the main merge dropped the empty-project New workspace child row while keeping the empty project persistence contract. Restore the row using the project host target so the sidebar stays aligned with the no-host-selection model. * Fix Japanese shortcut translation key Stale-base integration: main added the Japanese locale after this branch added cycleAgentMode to the English shortcut help map. Merging main exposed the missing ja key in CI typecheck and resources.test. * Fix Playwright speech teardown race
218 lines
6.4 KiB
TypeScript
218 lines
6.4 KiB
TypeScript
import { useCallback } from "react";
|
|
import { Text, View, type PressableStateCallbackType } from "react-native";
|
|
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
|
import { Settings2 } from "lucide-react-native";
|
|
import type { Theme } from "@/styles/theme";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
} from "@/components/ui/dropdown-menu";
|
|
import { isWeb as platformIsWeb } from "@/constants/platform";
|
|
import { useAppSettings, type WorkspaceTitleSource } from "@/hooks/use-settings";
|
|
import { useHosts, useHostRuntimeSnapshot } from "@/runtime/host-runtime";
|
|
import { useSidebarViewStore, type SidebarGroupMode } from "@/stores/sidebar-view-store";
|
|
import { formatConnectionStatus } from "@/utils/daemons";
|
|
|
|
const ThemedSettings2 = withUnistyles(Settings2);
|
|
const filterColorMapping = (theme: Theme) => ({ color: theme.colors.foregroundMuted });
|
|
|
|
const GROUP_MODE_ITEMS: Array<{ value: SidebarGroupMode; label: string }> = [
|
|
{ value: "project", label: "Project" },
|
|
{ value: "status", label: "Status" },
|
|
];
|
|
|
|
const WORKSPACE_TITLE_SOURCE_ITEMS: Array<{ value: WorkspaceTitleSource; label: string }> = [
|
|
{ value: "title", label: "Title" },
|
|
{ value: "branch", label: "Branch name" },
|
|
];
|
|
|
|
interface DisplayPreferenceOption<Value extends string> {
|
|
value: Value;
|
|
label: string;
|
|
}
|
|
|
|
export function SidebarDisplayPreferencesMenu() {
|
|
const groupMode = useSidebarViewStore((state) => state.groupMode);
|
|
const hostFilter = useSidebarViewStore((state) => state.hostFilter);
|
|
const setGroupMode = useSidebarViewStore((state) => state.setGroupMode);
|
|
const setHostFilter = useSidebarViewStore((state) => state.setHostFilter);
|
|
const hosts = useHosts();
|
|
const {
|
|
settings: { workspaceTitleSource },
|
|
updateSettings,
|
|
} = useAppSettings();
|
|
|
|
const handleSelectMode = useCallback(
|
|
(mode: SidebarGroupMode) => {
|
|
setGroupMode(mode);
|
|
},
|
|
[setGroupMode],
|
|
);
|
|
|
|
const handleSelectHost = useCallback(
|
|
(serverId: string | null) => {
|
|
setHostFilter(serverId);
|
|
},
|
|
[setHostFilter],
|
|
);
|
|
|
|
const handleWorkspaceTitleSourceSelect = useCallback(
|
|
(source: WorkspaceTitleSource) => {
|
|
void updateSettings({ workspaceTitleSource: source });
|
|
},
|
|
[updateSettings],
|
|
);
|
|
|
|
const triggerStyle = useCallback(
|
|
({ hovered = false }: PressableStateCallbackType & { hovered?: boolean }) => [
|
|
styles.trigger,
|
|
hovered && styles.triggerHovered,
|
|
],
|
|
[],
|
|
);
|
|
|
|
const showHostFilter = hosts.length > 1;
|
|
|
|
return (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger
|
|
style={triggerStyle}
|
|
accessibilityRole={platformIsWeb ? undefined : "button"}
|
|
accessibilityLabel="Display preferences"
|
|
testID="sidebar-display-preferences-menu"
|
|
>
|
|
<ThemedSettings2 size={14} uniProps={filterColorMapping} />
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end" width={220} testID="sidebar-display-preferences-content">
|
|
<View style={styles.menuHeader}>
|
|
<Text style={styles.menuHeaderLabel}>Group by</Text>
|
|
</View>
|
|
{GROUP_MODE_ITEMS.map((item) => (
|
|
<DisplayPreferenceMenuItem
|
|
key={item.value}
|
|
item={item}
|
|
isSelected={groupMode === item.value}
|
|
testIDPrefix="sidebar-grouping"
|
|
onSelect={handleSelectMode}
|
|
/>
|
|
))}
|
|
{showHostFilter ? (
|
|
<>
|
|
<DropdownMenuSeparator />
|
|
<View style={styles.menuHeader}>
|
|
<Text style={styles.menuHeaderLabel}>Filter</Text>
|
|
</View>
|
|
<HostFilterItem
|
|
label="All hosts"
|
|
value={null}
|
|
hostFilter={hostFilter}
|
|
onSelect={handleSelectHost}
|
|
/>
|
|
{hosts.map((host) => (
|
|
<HostFilterItem
|
|
key={host.serverId}
|
|
label={host.label?.trim() || host.serverId}
|
|
serverId={host.serverId}
|
|
value={host.serverId}
|
|
hostFilter={hostFilter}
|
|
onSelect={handleSelectHost}
|
|
/>
|
|
))}
|
|
</>
|
|
) : null}
|
|
<DropdownMenuSeparator />
|
|
<View style={styles.menuHeader}>
|
|
<Text style={styles.menuHeaderLabel}>Workspace title</Text>
|
|
</View>
|
|
{WORKSPACE_TITLE_SOURCE_ITEMS.map((item) => (
|
|
<DisplayPreferenceMenuItem
|
|
key={item.value}
|
|
item={item}
|
|
isSelected={workspaceTitleSource === item.value}
|
|
testIDPrefix="sidebar-workspace-title-source"
|
|
onSelect={handleWorkspaceTitleSourceSelect}
|
|
/>
|
|
))}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
);
|
|
}
|
|
|
|
function DisplayPreferenceMenuItem<Value extends string>({
|
|
item,
|
|
isSelected,
|
|
testIDPrefix,
|
|
onSelect,
|
|
}: {
|
|
item: DisplayPreferenceOption<Value>;
|
|
isSelected: boolean;
|
|
testIDPrefix: string;
|
|
onSelect: (value: Value) => void;
|
|
}) {
|
|
const handleSelect = useCallback(() => onSelect(item.value), [item.value, onSelect]);
|
|
return (
|
|
<DropdownMenuItem
|
|
testID={`${testIDPrefix}-${item.value}`}
|
|
selected={isSelected}
|
|
onSelect={handleSelect}
|
|
>
|
|
<Text style={styles.optionLabel}>{item.label}</Text>
|
|
</DropdownMenuItem>
|
|
);
|
|
}
|
|
|
|
function HostFilterItem({
|
|
label,
|
|
serverId,
|
|
value,
|
|
hostFilter,
|
|
onSelect,
|
|
}: {
|
|
label: string;
|
|
serverId?: string;
|
|
value: string | null;
|
|
hostFilter: string | null;
|
|
onSelect: (serverId: string | null) => void;
|
|
}) {
|
|
const isSelected = hostFilter === value;
|
|
const handleSelect = useCallback(() => onSelect(value), [value, onSelect]);
|
|
const status = useHostRuntimeSnapshot(serverId ?? "");
|
|
const subtitle = serverId
|
|
? formatConnectionStatus(status?.connectionStatus ?? "idle")
|
|
: undefined;
|
|
|
|
return (
|
|
<DropdownMenuItem selected={isSelected} description={subtitle} onSelect={handleSelect}>
|
|
{label}
|
|
</DropdownMenuItem>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create((theme) => ({
|
|
trigger: {
|
|
width: 28,
|
|
height: 28,
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
borderRadius: theme.borderRadius.md,
|
|
},
|
|
triggerHovered: {
|
|
backgroundColor: theme.colors.surfaceSidebarHover,
|
|
},
|
|
menuHeader: {
|
|
paddingHorizontal: theme.spacing[3],
|
|
paddingVertical: theme.spacing[2],
|
|
},
|
|
menuHeaderLabel: {
|
|
fontSize: theme.fontSize.xs,
|
|
fontWeight: theme.fontWeight.medium,
|
|
color: theme.colors.foregroundMuted,
|
|
},
|
|
optionLabel: {
|
|
fontSize: theme.fontSize.sm,
|
|
},
|
|
}));
|