Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import {
PANEL_MAX_HEIGHT_PX,
VIEW_ENTER_CLASSNAME,
} from "./constants";
import { useActivityPanelVisibility } from "./hooks/useActivityPanelVisibility";
import { useAgentWork } from "./hooks/useAgentWork";
import { useAgentWorkActions } from "./hooks/useAgentWorkActions";
import { useWorkspacePullRequests } from "./hooks/useWorkspacePullRequests";
Expand Down Expand Up @@ -172,10 +173,7 @@ export function WorkspaceActivityMenu({
const fits = useActivityPanelStore(
(state) => state.fits[workspaceId] === true,
);
const hidden = useActivityPanelStore(
(state) => state.hidden[workspaceId] === true,
);
const setHidden = useActivityPanelStore((state) => state.setHidden);
const { hidden, setHidden } = useActivityPanelVisibility(workspaceId);
const subagentsCollapsed = useActivityPanelStore(
(state) => state.subagentsCollapsed[workspaceId] === true,
);
Expand Down Expand Up @@ -566,7 +564,7 @@ export function WorkspaceActivityMenu({
: null;
const onTriggerClick = () => {
if (fits) {
setHidden(workspaceId, !hidden);
setHidden(!hidden);
return;
}
setFloating(!popoverOpen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
PANEL_TOP_GAP_PX,
PANEL_WIDTH_PX,
} from "../../constants";
import { useActivityPanelVisibility } from "../../hooks/useActivityPanelVisibility";
import { useActivityPanelStore } from "../../stores/activityPanelStore";

const INSET_PX = PANEL_WIDTH_PX + PANEL_EDGE_GAP_PX + PANEL_CONTENT_GAP_PX;
Expand All @@ -25,9 +26,7 @@ export function ActivityPanelAside({ workspaceId }: { workspaceId: string }) {
const clearAnchorNode = useActivityPanelStore(
(state) => state.clearAnchorNode,
);
const hidden = useActivityPanelStore(
(state) => state.hidden[workspaceId] === true,
);
const { hidden } = useActivityPanelVisibility(workspaceId);
const fits = hasRoom && isTabVisible;
const shown = fits && !hidden;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useActivityPanelVisibility } from "./useActivityPanelVisibility";
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { eq } from "@tanstack/db";
import { useLiveQuery } from "@tanstack/react-db";
import { useCallback } from "react";
import { useWorkspace } from "renderer/routes/_authenticated/_dashboard/workspace/providers/WorkspaceProvider";
import { useDashboardSidebarState } from "renderer/routes/_authenticated/hooks/useDashboardSidebarState";
import { useCollections } from "renderer/routes/_authenticated/providers/CollectionsProvider";

export function useActivityPanelVisibility(workspaceId: string) {
const collections = useCollections();
const { workspace } = useWorkspace();
const { ensureWorkspaceInSidebar } = useDashboardSidebarState();
const { data: rows = [] } = useLiveQuery(
(query) =>
query
.from({ localState: collections.workspaceLocalState })
.where(({ localState }) => eq(localState.workspaceId, workspaceId))
.select(({ localState }) => ({
workspaceId: localState.workspaceId,
hidden: localState.activityPanelHidden,
})),
[collections, workspaceId],
);
const hidden =
rows.find((row) => row.workspaceId === workspaceId)?.hidden ??
collections.workspaceLocalState.get(workspaceId)?.activityPanelHidden ??
false;
const setHidden = useCallback(
(next: boolean) => {
if (!collections.workspaceLocalState.has(workspaceId)) {
ensureWorkspaceInSidebar(workspaceId, workspace.projectId);
}
collections.workspaceLocalState.update(workspaceId, (draft) => {
draft.activityPanelHidden = next;
});
},
[collections, workspaceId, workspace.projectId, ensureWorkspaceInSidebar],
);
return { hidden, setHidden };
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ test("fits and stopped keys are tracked per call and cleared on demand", () => {
);
});

test("hiding the docked card is per workspace", () => {
const { setHidden } = useActivityPanelStore.getState();
setHidden("ws-a", true);
expect(useActivityPanelStore.getState().hidden["ws-a"]).toBe(true);
expect(useActivityPanelStore.getState().hidden["ws-b"]).toBeUndefined();
setHidden("ws-a", false);
expect("ws-a" in useActivityPanelStore.getState().hidden).toBe(false);
});

test("the floating popover stays open per workspace and closing removes the key", () => {
const { setFloatingOpen } = useActivityPanelStore.getState();
setFloatingOpen("ws-a", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ interface ActivityPanelStore {
asideNodes: Record<string, HTMLElement>;
fits: Record<string, true>;
setFits: (workspaceId: string, fits: boolean) => void;
hidden: Record<string, true>;
setHidden: (workspaceId: string, hidden: boolean) => void;
floatingOpen: Record<string, true>;
setFloatingOpen: (workspaceId: string, open: boolean) => void;
subagentsCollapsed: Record<string, true>;
Expand Down Expand Up @@ -48,13 +46,6 @@ export const useActivityPanelStore = create<ActivityPanelStore>()((set) => ({
const { [workspaceId]: _previous, ...rest } = state.fits;
return { fits: fits ? { ...rest, [workspaceId]: true } : rest };
}),
hidden: {},
setHidden: (workspaceId, hidden) =>
set((state) => {
if ((state.hidden[workspaceId] === true) === hidden) return state;
const { [workspaceId]: _previous, ...rest } = state.hidden;
return { hidden: hidden ? { ...rest, [workspaceId]: true } : rest };
}),
floatingOpen: {},
setFloatingOpen: (workspaceId, open) =>
set((state) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export const workspaceLocalStateSchema = z.object({
paneLayout: paneWorkspaceStateSchema,
rightPaneLayout: paneWorkspaceStateSchema.optional(),
rightSidebarOpen: z.boolean().optional(),
activityPanelHidden: z.boolean().optional(),
// TODO(2027-01-31): delete with useRestoreExpandedPaneArea / restoreExpandedPaneArea once builds that wrote it are gone.
rightPaneAreaExpansion: z
.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,58 @@ const noopEvents = {
removeEventListener: () => {},
};

it("workspace activity choices survive saving and reopening the workspace collection", async () => {
const { api: storage } = makeMapStorage();
const makeCollection = (id: string) =>
createCollection(
localStorageCollectionOptions(
withReadHeal(
{
id,
storageKey: "test-activity-visibility",
schema: workspaceLocalStateSchema,
getKey: (item: WorkspaceLocalStateRow) => item.workspaceId,
storage,
storageEventApi: noopEvents,
},
healWorkspaceLocalState,
),
),
);
const hiddenId = "11111111-1111-4111-8111-111111111111";
const shownId = "22222222-2222-4222-8222-222222222222";
const before = makeCollection("activity-before");
await before.preload();
for (const workspaceId of [hiddenId, shownId]) {
await before.insert({
workspaceId,
createdAt: new Date(),
sidebarState: { projectId: null },
paneLayout: { version: 1, tabs: [], activeTabId: null },
}).isPersisted.promise;
}
for (const [workspaceId, hidden] of [
[hiddenId, true],
[shownId, false],
] as const) {
await before.update(workspaceId, (draft) => {
draft.activityPanelHidden = hidden;
}).isPersisted.promise;
}
await before.cleanup();
const after = makeCollection("activity-after");
await after.preload();
expect(after.get(hiddenId)?.activityPanelHidden).toBe(true);
expect(after.get(shownId)?.activityPanelHidden).toBe(false);
await after.delete(hiddenId).isPersisted.promise;
await after.cleanup();
const reopened = makeCollection("activity-reopened");
await reopened.preload();
expect(reopened.has(hiddenId)).toBe(false);
expect(reopened.get(shownId)?.activityPanelHidden).toBe(false);
await reopened.cleanup();
});

describe("withReadHeal parser", () => {
it("heals each entry's data through the heal fn while preserving the envelope", () => {
const heal = (raw: unknown) => ({ ...(raw as object), healed: true });
Expand Down
Loading