feat(daemon): collapse workspace noise into a "show hidden" section
Discovery returns every pi session directory ever seen, so the console opened on 47 rows on this machine: 20 ghosts (cwd deleted) and 21 scratch dirs under /tmp next to the real projects. Every row now carries a derived, non-persisted `visibility`/`visibilityReason`; nothing is filtered server-side, so `/workspace/<id>` deep links and the chat page's id lookup still resolve. Precedence: explicit `hidden` wins; a live instance, `pinned` or `trusted` rescues a row; then temp paths (`PI2_WORKSPACE_HIDE_TEMP`, on), ghosts (`PI2_WORKSPACE_HIDE_GHOSTS`, on), outside roots (`PI2_WORKSPACE_HIDE_OUTSIDE_ROOTS`, off) and staleness (`PI2_WORKSPACE_STALE_DAYS`, off). Measured on real data: 47 → 26 default rows, 0 openable rows lost. The browser collapses the secondary rows behind a persisted toggle and dims them with a reason badge; `workspace.add` now clears `hidden`.
This commit is contained in:
1 parent
58e247644d
commit
64a1a98c1f
12 files changed
+888
-38
No files matched your search
@@ -13,6 +13,12 @@ import { deriveServerIdentity, type InfoExtras } from "@/features/status/server"
|
||||
import { useInfoQuery, useWorkspacesQuery } from "@/features/status/queries";
|
||||
import { openWorkspace } from "@/features/workspaces/commands";
|
||||
import { NewWorkspaceDialog, type NewWorkspaceInput } from "@/features/workspaces/new-workspace-dialog";
|
||||
import {
|
||||
countSecondary,
|
||||
partitionWorkspaces,
|
||||
readShowAll,
|
||||
writeShowAll,
|
||||
} from "@/features/workspaces/visibility";
|
||||
import {
|
||||
ServerContextBar,
|
||||
WorkspaceRow,
|
||||
@@ -48,13 +54,25 @@ export function WorkspacesPage() {
|
||||
const workspaces = useWorkspacesQuery();
|
||||
const info = useInfoQuery();
|
||||
|
||||
const items = useMemo(
|
||||
() => (workspaces.data ?? []).filter((workspace) => !workspace.hidden).slice().sort(compareWorkspaces),
|
||||
[workspaces.data],
|
||||
);
|
||||
// Persisted "show N hidden" toggle (localStorage, default off): secondary
|
||||
// rows (hidden/ghost/temp/…) stay out of the list until asked for.
|
||||
const [showAll, setShowAll] = useState<boolean>(() => readShowAll());
|
||||
|
||||
function toggleShowAll() {
|
||||
setShowAll((previous) => {
|
||||
const next = !previous;
|
||||
writeShowAll(next);
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
const all = useMemo(() => (workspaces.data ?? []).slice().sort(compareWorkspaces), [workspaces.data]);
|
||||
const secondaryCount = useMemo(() => countSecondary(all), [all]);
|
||||
const { primary, secondary } = useMemo(() => partitionWorkspaces(all, showAll), [all, showAll]);
|
||||
const items = showAll ? [...primary, ...secondary].sort(compareWorkspaces) : primary;
|
||||
const sessionCount = useMemo(
|
||||
() => items.reduce((total, workspace) => total + Math.max(workspace.liveCount || 0, workspace.sessionCount || 0), 0),
|
||||
[items],
|
||||
() => primary.reduce((total, workspace) => total + Math.max(workspace.liveCount || 0, workspace.sessionCount || 0), 0),
|
||||
[primary],
|
||||
);
|
||||
|
||||
const server = deriveServerIdentity({
|
||||
@@ -85,10 +103,24 @@ export function WorkspacesPage() {
|
||||
subtitle={t("workspaces.subtitle")}
|
||||
docTitle={t("nav.workspaces")}
|
||||
actions={
|
||||
<Button variant="primary" onClick={() => setDialogOpen(true)}>
|
||||
<Icon name="plus" />
|
||||
{t("workspaces.new")}
|
||||
</Button>
|
||||
<>
|
||||
{secondaryCount > 0 ? (
|
||||
<Button
|
||||
variant={showAll ? "default" : "ghost"}
|
||||
aria-pressed={showAll}
|
||||
aria-label={t("workspaces.showHiddenAria")}
|
||||
data-testid="workspaces-show-all"
|
||||
onClick={toggleShowAll}
|
||||
>
|
||||
<Icon name="eye" />
|
||||
{t(showAll ? "workspaces.hideHidden" : "workspaces.showHidden", { n: secondaryCount })}
|
||||
</Button>
|
||||
) : null}
|
||||
<Button variant="primary" onClick={() => setDialogOpen(true)}>
|
||||
<Icon name="plus" />
|
||||
{t("workspaces.new")}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -116,17 +148,24 @@ export function WorkspacesPage() {
|
||||
}
|
||||
/>
|
||||
</Panel>
|
||||
) : items.length === 0 ? (
|
||||
) : all.length === 0 || (primary.length === 0 && !showAll) ? (
|
||||
<Panel>
|
||||
<Empty
|
||||
icon={<Icon name="folder" size={28} />}
|
||||
title={t("workspaces.emptyTitle")}
|
||||
description={t("workspaces.emptyText")}
|
||||
title={all.length === 0 ? t("workspaces.emptyTitle") : t("workspaces.allHidden")}
|
||||
description={all.length === 0 ? t("workspaces.emptyText") : t("workspaces.allHiddenText", { n: secondaryCount })}
|
||||
action={
|
||||
<Button variant="primary" onClick={() => setDialogOpen(true)}>
|
||||
<Icon name="plus" />
|
||||
{t("workspaces.new")}
|
||||
</Button>
|
||||
all.length === 0 ? (
|
||||
<Button variant="primary" onClick={() => setDialogOpen(true)}>
|
||||
<Icon name="plus" />
|
||||
{t("workspaces.new")}
|
||||
</Button>
|
||||
) : (
|
||||
<Button variant="ghost" onClick={toggleShowAll}>
|
||||
<Icon name="eye" />
|
||||
{t("workspaces.showHidden", { n: secondaryCount })}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
/>
|
||||
</Panel>
|
||||
|
||||
Reference in new issue
Block a user