Initial commit: group-by-host Paseo sidebar plugin
This commit is contained in:
commit
dcfe97a2e6
13 files changed
+6789
No files matched your search
@@ -0,0 +1,342 @@
|
||||
import type { PluginTheme } from "@getpaseo/plugin";
|
||||
import type {
|
||||
AgentRef,
|
||||
PluginHostSummary,
|
||||
ProjectRef,
|
||||
WorkspaceRef,
|
||||
} from "@getpaseo/plugin/client";
|
||||
import { useProject } from "@getpaseo/plugin/client";
|
||||
import { Icon } from "@getpaseo/plugin/client/ui";
|
||||
import { useState } from "react";
|
||||
import { Pressable, Text, View } from "react-native";
|
||||
import type { ContextMenuRequest } from "./context-menu";
|
||||
import { getHostStatusColor, getHostStatusLabel } from "./grouping";
|
||||
import { WorkspaceRow } from "./workspace-row";
|
||||
|
||||
interface ProjectItemProps {
|
||||
projectRef: ProjectRef;
|
||||
theme: PluginTheme;
|
||||
onOpenProject(ref: ProjectRef): void;
|
||||
}
|
||||
|
||||
function ProjectItem({ projectRef, theme, onOpenProject }: ProjectItemProps) {
|
||||
const project = useProject(projectRef);
|
||||
if (!project) return null;
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={`New workspace in ${project.displayName}`}
|
||||
onPress={() => onOpenProject(project.ref)}
|
||||
style={({ pressed }) => ({
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: 7,
|
||||
paddingVertical: 5,
|
||||
paddingHorizontal: 8,
|
||||
borderRadius: 6,
|
||||
backgroundColor: pressed ? theme.colors.surface2 : "transparent",
|
||||
})}
|
||||
>
|
||||
<Icon
|
||||
name={project.kind === "git" ? "FolderGit2" : "Folder"}
|
||||
size={13}
|
||||
color={theme.colors.accent}
|
||||
/>
|
||||
<Text
|
||||
style={{
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
fontSize: 12,
|
||||
color: theme.colors.foreground,
|
||||
}}
|
||||
>
|
||||
{project.displayName}
|
||||
</Text>
|
||||
<Icon name="Plus" size={12} color={theme.colors.foregroundMuted} />
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
|
||||
export interface HostGroupProps {
|
||||
hostId: string;
|
||||
hostLabel: string;
|
||||
hostStatus: PluginHostSummary["status"];
|
||||
workspaceRefs: readonly WorkspaceRef[];
|
||||
projectRefs: readonly ProjectRef[];
|
||||
agentsByWorkspace: ReadonlyMap<string, readonly AgentRef[]>;
|
||||
collapsed: boolean;
|
||||
onToggleCollapsed(hostId: string): void;
|
||||
theme: PluginTheme;
|
||||
compact: boolean;
|
||||
platform: "ios" | "android" | "web";
|
||||
showAgents: boolean;
|
||||
activeWorkspaceKey: string | null;
|
||||
activeAgentKey: string | null;
|
||||
activeMenuKey: string | null;
|
||||
hasActiveWorkspaceInHost: boolean;
|
||||
onToggleMenu(key: string): void;
|
||||
onCloseMenu(): void;
|
||||
onOpenContextMenu(request: ContextMenuRequest): void;
|
||||
onOpenWorkspace(ref: WorkspaceRef): void;
|
||||
onOpenAgent(ref: AgentRef): void;
|
||||
onOpenProject(ref: ProjectRef): void;
|
||||
}
|
||||
|
||||
export function HostGroup({
|
||||
hostId,
|
||||
hostLabel,
|
||||
hostStatus,
|
||||
workspaceRefs,
|
||||
projectRefs,
|
||||
agentsByWorkspace,
|
||||
collapsed,
|
||||
onToggleCollapsed,
|
||||
theme,
|
||||
compact,
|
||||
platform,
|
||||
showAgents,
|
||||
activeWorkspaceKey,
|
||||
activeAgentKey,
|
||||
activeMenuKey,
|
||||
hasActiveWorkspaceInHost,
|
||||
onToggleMenu,
|
||||
onCloseMenu,
|
||||
onOpenContextMenu,
|
||||
onOpenWorkspace,
|
||||
onOpenAgent,
|
||||
onOpenProject,
|
||||
}: HostGroupProps) {
|
||||
const [projectsOpen, setProjectsOpen] = useState(false);
|
||||
|
||||
const statusColor = getHostStatusColor(hostStatus, theme);
|
||||
const statusLabel = getHostStatusLabel(hostStatus);
|
||||
const hasProjects = projectRefs.length > 0;
|
||||
|
||||
return (
|
||||
<View
|
||||
style={{
|
||||
borderRadius: 10,
|
||||
borderWidth: 1,
|
||||
borderColor: hasActiveWorkspaceInHost
|
||||
? theme.colors.accent
|
||||
: theme.colors.border,
|
||||
backgroundColor: theme.colors.surface1,
|
||||
overflow: "hidden",
|
||||
}}
|
||||
>
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
paddingRight: 6,
|
||||
backgroundColor: theme.colors.surface1,
|
||||
}}
|
||||
>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={`${collapsed ? "Expand" : "Collapse"} host ${hostLabel}`}
|
||||
onPress={() => onToggleCollapsed(hostId)}
|
||||
style={({ pressed }) => ({
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: 8,
|
||||
paddingVertical: compact ? 9 : 7,
|
||||
paddingLeft: 10,
|
||||
paddingRight: 6,
|
||||
backgroundColor: pressed ? theme.colors.surface2 : "transparent",
|
||||
})}
|
||||
>
|
||||
<Icon
|
||||
name={collapsed ? "ChevronRight" : "ChevronDown"}
|
||||
size={14}
|
||||
color={theme.colors.foregroundMuted}
|
||||
/>
|
||||
<View
|
||||
style={{
|
||||
width: 8,
|
||||
height: 8,
|
||||
borderRadius: 4,
|
||||
flexShrink: 0,
|
||||
backgroundColor: statusColor,
|
||||
}}
|
||||
/>
|
||||
<Icon name="Server" size={13} color={theme.colors.foregroundMuted} />
|
||||
<Text
|
||||
style={{
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
fontSize: 13,
|
||||
fontWeight: "600",
|
||||
color: theme.colors.foreground,
|
||||
}}
|
||||
>
|
||||
{hostLabel}
|
||||
</Text>
|
||||
{statusLabel ? (
|
||||
<View
|
||||
style={{
|
||||
paddingHorizontal: 6,
|
||||
paddingVertical: 2,
|
||||
borderRadius: 999,
|
||||
backgroundColor: theme.colors.surface2,
|
||||
}}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 10,
|
||||
fontWeight: "600",
|
||||
color: statusColor,
|
||||
}}
|
||||
>
|
||||
{statusLabel}
|
||||
</Text>
|
||||
</View>
|
||||
) : null}
|
||||
<View
|
||||
style={{
|
||||
minWidth: 20,
|
||||
paddingHorizontal: 6,
|
||||
paddingVertical: 2,
|
||||
borderRadius: 999,
|
||||
alignItems: "center",
|
||||
backgroundColor: theme.colors.surface2,
|
||||
}}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 11,
|
||||
fontWeight: "600",
|
||||
color: theme.colors.foregroundMuted,
|
||||
}}
|
||||
>
|
||||
{workspaceRefs.length}
|
||||
</Text>
|
||||
</View>
|
||||
</Pressable>
|
||||
|
||||
{hasProjects ? (
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={`New workspace on ${hostLabel}`}
|
||||
onPress={() => {
|
||||
if (collapsed) {
|
||||
onToggleCollapsed(hostId);
|
||||
setProjectsOpen(true);
|
||||
} else {
|
||||
setProjectsOpen((prev) => !prev);
|
||||
}
|
||||
}}
|
||||
style={({ pressed }) => ({
|
||||
padding: 6,
|
||||
borderRadius: 6,
|
||||
backgroundColor:
|
||||
projectsOpen || pressed ? theme.colors.surface2 : "transparent",
|
||||
})}
|
||||
>
|
||||
<Icon
|
||||
name={projectsOpen ? "X" : "Plus"}
|
||||
size={14}
|
||||
color={
|
||||
projectsOpen
|
||||
? theme.colors.foreground
|
||||
: theme.colors.foregroundMuted
|
||||
}
|
||||
/>
|
||||
</Pressable>
|
||||
) : null}
|
||||
</View>
|
||||
|
||||
{!collapsed ? (
|
||||
<View
|
||||
style={{
|
||||
paddingHorizontal: 6,
|
||||
paddingBottom: 6,
|
||||
paddingTop: 2,
|
||||
gap: 4,
|
||||
borderTopWidth: 1,
|
||||
borderTopColor: theme.colors.border,
|
||||
backgroundColor: theme.colors.surface0,
|
||||
}}
|
||||
>
|
||||
{projectsOpen && hasProjects ? (
|
||||
<View
|
||||
style={{
|
||||
padding: 6,
|
||||
marginTop: 4,
|
||||
borderRadius: 8,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.border,
|
||||
backgroundColor: theme.colors.surface1,
|
||||
gap: 2,
|
||||
}}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 10,
|
||||
fontWeight: "600",
|
||||
textTransform: "uppercase",
|
||||
color: theme.colors.foregroundMuted,
|
||||
paddingHorizontal: 8,
|
||||
paddingBottom: 2,
|
||||
}}
|
||||
>
|
||||
New workspace from project
|
||||
</Text>
|
||||
{projectRefs.map((projectRef) => (
|
||||
<ProjectItem
|
||||
key={projectRef.key}
|
||||
projectRef={projectRef}
|
||||
theme={theme}
|
||||
onOpenProject={(ref) => {
|
||||
setProjectsOpen(false);
|
||||
onOpenProject(ref);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{workspaceRefs.length > 0 ? (
|
||||
<View style={{ gap: 2, paddingTop: 2 }}>
|
||||
{workspaceRefs.map((workspaceRef) => (
|
||||
<WorkspaceRow
|
||||
key={workspaceRef.key}
|
||||
workspaceRef={workspaceRef}
|
||||
agentRefs={agentsByWorkspace.get(workspaceRef.key) ?? []}
|
||||
theme={theme}
|
||||
compact={compact}
|
||||
platform={platform}
|
||||
showAgents={showAgents}
|
||||
activeWorkspaceKey={activeWorkspaceKey}
|
||||
activeAgentKey={activeAgentKey}
|
||||
activeMenuKey={activeMenuKey}
|
||||
onToggleMenu={onToggleMenu}
|
||||
onCloseMenu={onCloseMenu}
|
||||
onOpenContextMenu={onOpenContextMenu}
|
||||
onOpenWorkspace={onOpenWorkspace}
|
||||
onOpenAgent={onOpenAgent}
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
) : (
|
||||
<Text
|
||||
style={{
|
||||
paddingVertical: 10,
|
||||
paddingHorizontal: 10,
|
||||
fontSize: 12,
|
||||
color: theme.colors.foregroundMuted,
|
||||
}}
|
||||
>
|
||||
{hostStatus === "offline" || hostStatus === "error"
|
||||
? "Host unavailable."
|
||||
: "No workspaces on this host."}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user