429155b536
* Add collapsed-project status badge to the sidebar Collapsed project rows now surface the most urgent hidden workspace's status as a corner badge on the project icon, instead of giving no signal at all: a loader for running, an alert for needs_input, a dot for attention/failed, nothing for done. Priority order (needs_input > failed > running > attention > done) means a working project keeps its loader even if another workspace is also awaiting review. Every surfaced status shares one badge shell (size, ring, offset) so the loader, alert, and dot never draw a differently-sized circle - previously the loader/alert used a 12pt ring while the dot used a 7-9pt one with a different corner offset. The running loader is also nudged half a point left so its visual center lands on the circle's center rather than reading as shifted right. Adds an e2e capture spec (run on demand, not part of CI) that seeds every state and edge case through the mock provider and dumps DOM geometry, for re-verifying the badge shell stays uniform. * Add PR review gallery images for the status badge PR Temporary evidence assets for pull request review, embedded via blob URLs in the PR description. Safe to delete after merge. * Swap misleading before/after PR images for clean per-state stills This feature never shipped on main, so there is no real "before" to compare against for a reviewer — the earlier before/after images were an artifact of local dev iteration, not a regression fix. Replaced with one clean still per status. * Fatten needs-input alert and dot to fill the shared badge shell Lucide's circle-alert only paints ~83% of its nominal size, so the prior 10pt glyph read as smaller than the loader inside the same 14pt shell. Sized both up so all three glyphs draw the same visual footprint against the shared ring. * Address review: extract pure badge-content selection, drop JSDOM tests Greptile flagged getStatusDotColorStyle's needs_input/running cases as dead (unreachable — shouldRenderSyncedStatusLoader and an explicit check already intercept those buckets earlier). Extracting the selection logic into a plain-TS descriptor function (getProjectStatusBadgeContent) makes that structural: the "dot" variant is typed to failed|attention only, so there's no switch left with unreachable branches. That extraction also resolves the JSDOM component test Greptile flagged (project-leading-visual.test.tsx used vi.hoisted/vi.mock/ createRoot mounting, all banned by docs/testing.md's two test categories) — the pure selector is now tested directly with a plain vitest file, no mounting needed. Dropped that test file and use-sidebar-project-status-bucket.test.tsx (same banned pattern); the real coverage was already redundant with sidebar-workspaces-view-model .test.ts's existing priority-order assertions and the e2e capture spec's real-app gating checks. Also split a conditional branch in the e2e capture spec's assertion loop into two deterministic loops (badge-expected vs no-badge cases) per Greptile's third note. * Size status-badge glyphs even so they center in the shell The badge shell's interior is 12pt (14pt minus the 1pt ring on each side). A centered glyph of size N sits at a (12 - N) / 2 offset, which is fractional for odd N and gets snapped to a device-pixel boundary, rendering visibly off-center (~1.5 device px at 3x). Drop the dot to 8pt and the alert to 10pt so both divide the interior into whole pixels and land dead center; Lucide's circle-alert paints ~83% of nominal, so 10pt draws a ~8.3pt disc that matches the 8pt dot. Also extends the on-demand capture spec to cover the failed bucket, the priority aggregation cases, dark mode, hover, a compact viewport, and a recorded running-to-expand transition, dumping DOM geometry that proves every shell shares one size/offset and every even glyph centers at 0px. * Refresh status-badge PR assets for the even-glyph sizing Recaptures every state at the approved 8pt-dot / 10pt-alert sizing, adds the failed bucket to the per-status set, a crosshair sizing/ centering proof, dark-mode and compact-form-factor shots, and replaces the soft upscaled spinner GIF with a crisp one assembled from native 3x-scale frames. Drops the stale pre-sizing images. * Add capture spec proving workspace statuses roll up to the project badge Seeds three collapsed projects, each with several same-directory workspaces in different buckets, so each resolves to a different highest-priority winner (needs_input / failed / running). Films the collapse and expand so the aggregation is provable as motion, not a single frame. * Add propagation recording showing statuses resolving to the project badge * Add higher-quality mp4 of the status propagation recording * Refactor project status badge coverage --------- Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
200 lines
6.7 KiB
TypeScript
200 lines
6.7 KiB
TypeScript
import { useCallback, useEffect, useMemo } from "react";
|
|
import { useStoreWithEqualityFn } from "zustand/traditional";
|
|
import { useCreateFlowStore } from "@/stores/create-flow-store";
|
|
import { useSessionStore } from "@/stores/session-store";
|
|
import { useHydratedWorkspaceServerIds } from "@/stores/session-store-hooks";
|
|
import { workspaceEqualityFns } from "@/stores/session-store-hooks/selectors";
|
|
import { useHostProjects } from "@/projects/host-projects";
|
|
import { getHostRuntimeStore, useHostRegistryLoaded, useHosts } from "@/runtime/host-runtime";
|
|
import { useSidebarOrderStore } from "@/stores/sidebar-order-store";
|
|
import { useSidebarViewStore } from "@/stores/sidebar-view-store";
|
|
import {
|
|
buildSidebarWorkspacePlacementModel,
|
|
computeSidebarOrderUpdates,
|
|
createSidebarWorkspaceEntry,
|
|
deriveProjectStatusBucket,
|
|
deriveSidebarLoadingState,
|
|
type ProjectStatusSession,
|
|
type SidebarProjectEntry,
|
|
type SidebarWorkspaceEntry,
|
|
type SidebarWorkspacePlacement,
|
|
} from "./sidebar-workspaces-view-model";
|
|
import type { SidebarStateBucket } from "@/utils/sidebar-agent-state";
|
|
|
|
export {
|
|
appendMissingOrderKeys,
|
|
applyStoredOrdering,
|
|
buildSidebarProjectsFromHostProjects,
|
|
buildSidebarProjectsFromStructure,
|
|
createSidebarWorkspaceEntry,
|
|
buildSidebarWorkspacePlacementModel,
|
|
computeSidebarOrderUpdates,
|
|
deriveProjectStatusBucket,
|
|
deriveSidebarLoadingState,
|
|
shouldShowSidebarHostLabels,
|
|
type SidebarLoadingState,
|
|
type SidebarOrderUpdates,
|
|
type SidebarStatusWorkspacePlacement,
|
|
type SidebarWorkspacePlacement,
|
|
type SidebarWorkspacePlacementModel,
|
|
type SidebarProjectEntry,
|
|
type SidebarStateBucket,
|
|
type SidebarWorkspaceEntry,
|
|
} from "./sidebar-workspaces-view-model";
|
|
|
|
/**
|
|
* Aggregate status for a project's workspaces, for the collapsed project row.
|
|
*
|
|
* `SidebarProjectEntry` is structural — it carries workspace identity but no status — and
|
|
* `ProjectBlock` is memoized on that stable reference, so the row can't learn about a
|
|
* child's status without its own subscription. Returns a primitive, so status churn in a
|
|
* project only re-renders the row when the aggregate actually moves.
|
|
*
|
|
* Pass `enabled: false` while the project is expanded: the child rows show their own dots
|
|
* and the selector is pure cost.
|
|
*/
|
|
export function useSidebarProjectStatusBucket(input: {
|
|
workspaces: readonly SidebarWorkspacePlacement[];
|
|
enabled: boolean;
|
|
}): SidebarStateBucket | null {
|
|
const { workspaces, enabled } = input;
|
|
const pendingCreateAttempts = useStoreWithEqualityFn(
|
|
useCreateFlowStore,
|
|
(state) => state.pendingByDraftId,
|
|
workspaceEqualityFns.deep,
|
|
);
|
|
|
|
const selector = useCallback(
|
|
(state: { sessions: Record<string, ProjectStatusSession | undefined> }) => {
|
|
if (!enabled) return null;
|
|
return deriveProjectStatusBucket({
|
|
workspaces,
|
|
sessions: state.sessions,
|
|
pendingCreateAttempts,
|
|
});
|
|
},
|
|
[enabled, pendingCreateAttempts, workspaces],
|
|
);
|
|
|
|
return useStoreWithEqualityFn(useSessionStore, selector, Object.is);
|
|
}
|
|
|
|
const EMPTY_ORDER: string[] = [];
|
|
const EMPTY_PROJECTS: SidebarProjectEntry[] = [];
|
|
const EMPTY_WORKSPACES: SidebarWorkspacePlacement[] = [];
|
|
const EMPTY_PROJECT_NAMES = new Map<string, string>();
|
|
|
|
export interface SidebarWorkspacesListResult {
|
|
workspacePlacements: SidebarWorkspacePlacement[];
|
|
projects: SidebarProjectEntry[];
|
|
projectNamesByViewKey: Map<string, string>;
|
|
isLoading: boolean;
|
|
isInitialLoad: boolean;
|
|
isRevalidating: boolean;
|
|
refreshAll: () => void;
|
|
}
|
|
|
|
export function useSidebarWorkspacesList(options?: {
|
|
hostFilters?: readonly string[];
|
|
enabled?: boolean;
|
|
}): SidebarWorkspacesListResult {
|
|
const runtime = getHostRuntimeStore();
|
|
const allHosts = useHosts();
|
|
const hostRegistryLoaded = useHostRegistryLoaded();
|
|
const allServerIds = useMemo(() => allHosts.map((h) => h.serverId), [allHosts]);
|
|
|
|
const storeHostFilters = useSidebarViewStore((state) => state.hostFilters);
|
|
const hostFilters = options?.hostFilters ?? storeHostFilters;
|
|
const reconcileHostFilters = useSidebarViewStore((state) => state.reconcileHostFilters);
|
|
const isActive = options?.enabled !== false;
|
|
|
|
const serverIds = useMemo(() => {
|
|
if (hostFilters.length === 0) {
|
|
return allServerIds;
|
|
}
|
|
const selected = new Set(hostFilters);
|
|
const matched = allServerIds.filter((id) => selected.has(id));
|
|
// Registry has settled but none of the pinned hosts still exist — fall back to every
|
|
// host rather than leaving the sidebar empty.
|
|
if (hostRegistryLoaded && matched.length === 0) {
|
|
return allServerIds;
|
|
}
|
|
return matched;
|
|
}, [allServerIds, hostFilters, hostRegistryLoaded]);
|
|
|
|
useEffect(() => {
|
|
if (!hostRegistryLoaded) {
|
|
return;
|
|
}
|
|
reconcileHostFilters(allServerIds);
|
|
}, [allServerIds, hostRegistryLoaded, reconcileHostFilters]);
|
|
|
|
const persistedProjectOrder = useSidebarOrderStore((state) => state.projectOrder ?? EMPTY_ORDER);
|
|
|
|
const hydratedServerIds = useHydratedWorkspaceServerIds(serverIds);
|
|
|
|
const hostProjects = useHostProjects(hydratedServerIds);
|
|
|
|
const sidebarModel = useMemo(
|
|
() =>
|
|
buildSidebarWorkspacePlacementModel({
|
|
projects: hostProjects,
|
|
}),
|
|
[hostProjects],
|
|
);
|
|
|
|
const projects = sidebarModel.projects.length > 0 ? sidebarModel.projects : EMPTY_PROJECTS;
|
|
const workspacePlacements =
|
|
sidebarModel.workspaces.length > 0 ? sidebarModel.workspaces : EMPTY_WORKSPACES;
|
|
const projectNamesByViewKey =
|
|
sidebarModel.projectNamesByViewKey.size > 0
|
|
? sidebarModel.projectNamesByViewKey
|
|
: EMPTY_PROJECT_NAMES;
|
|
|
|
useEffect(() => {
|
|
const orderStore = useSidebarOrderStore.getState();
|
|
const updates = computeSidebarOrderUpdates({
|
|
projects,
|
|
persistedProjectOrder,
|
|
getWorkspaceOrder: (projectViewKey) =>
|
|
orderStore.workspaceOrderByProject[projectViewKey] ?? EMPTY_ORDER,
|
|
});
|
|
|
|
if (updates.projectOrder) {
|
|
orderStore.setProjectOrder(updates.projectOrder);
|
|
}
|
|
for (const { projectViewKey, order } of updates.workspaceOrders) {
|
|
orderStore.setWorkspaceOrder(projectViewKey, order);
|
|
}
|
|
}, [persistedProjectOrder, projects]);
|
|
|
|
const refreshAll = useCallback(() => {
|
|
if (!isActive) return;
|
|
for (const serverId of serverIds) {
|
|
const snapshot = runtime.getSnapshot(serverId);
|
|
if (snapshot?.connectionStatus !== "online") continue;
|
|
void runtime.refreshDirectories(serverId).catch((error) => {
|
|
console.error("[WorkspaceFetch][sidebar-refresh] failed", {
|
|
serverId,
|
|
error,
|
|
});
|
|
});
|
|
}
|
|
}, [isActive, runtime, serverIds]);
|
|
|
|
const loadingState = deriveSidebarLoadingState({
|
|
isActive,
|
|
serverIds,
|
|
hydratedServerIds,
|
|
hasProjects: projects.length > 0,
|
|
});
|
|
|
|
return {
|
|
workspacePlacements,
|
|
projects,
|
|
projectNamesByViewKey,
|
|
...loadingState,
|
|
refreshAll,
|
|
};
|
|
}
|