Skip to content
Open
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
@@ -1,10 +1,12 @@
import { useCallback } from "react";
import { DashboardSidebarDeleteDialog } from "renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarDeleteDialog";
import { useDashboardSidebarState } from "renderer/routes/_authenticated/hooks/useDashboardSidebarState";
import { useDeleteWorkspaceIntent } from "renderer/stores/delete-workspace-intent";

export function DeleteWorkspaceMount() {
const target = useDeleteWorkspaceIntent((s) => s.target);
const close = useDeleteWorkspaceIntent((s) => s.close);
const { hideWorkspaceInSidebar } = useDashboardSidebarState();

const handleOpenChange = useCallback(
(open: boolean) => {
Expand All @@ -20,6 +22,10 @@ export function DeleteWorkspaceMount() {
workspaceName={target.workspaceName}
open
onOpenChange={handleOpenChange}
onDeleted={() => {
hideWorkspaceInSidebar(target.workspaceId);
close();
}}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import { useRemoveFromSidebarIntent } from "renderer/stores/remove-workspace-fro
export function RemoveFromSidebarMount() {
const target = useRemoveFromSidebarIntent((s) => s.target);
const clear = useRemoveFromSidebarIntent((s) => s.clear);
const { hideWorkspaceInSidebar, removeWorkspaceFromSidebar } =
useDashboardSidebarState();
const { hideWorkspaceInSidebar } = useDashboardSidebarState();
const { navigateAwayFromWorkspace } = useNavigateAwayFromWorkspace();

const handleOpenChange = useCallback(
Expand All @@ -29,19 +28,9 @@ export function RemoveFromSidebarMount() {
const handleConfirm = useCallback(() => {
if (!target) return;
navigateAwayFromWorkspace(target.workspaceId);
if (target.isMain) {
hideWorkspaceInSidebar(target.workspaceId, target.projectId);
} else {
removeWorkspaceFromSidebar(target.workspaceId);
}
hideWorkspaceInSidebar(target.workspaceId);
clear();
}, [
target,
navigateAwayFromWorkspace,
hideWorkspaceInSidebar,
removeWorkspaceFromSidebar,
clear,
]);
}, [target, navigateAwayFromWorkspace, hideWorkspaceInSidebar, clear]);

return (
<AlertDialog open={!!target} onOpenChange={handleOpenChange}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function useDashboardSidebarWorkspaceItemActions({
);
const setManualUnread = useV2NotificationStore((s) => s.setManualUnread);
const isUnread = useV2WorkspaceIsUnread(workspaceId);
const { createSection, moveWorkspaceToSection, removeWorkspaceFromSidebar } =
const { createSection, hideWorkspaceInSidebar, moveWorkspaceToSection } =
useDashboardSidebarState();

const [isRenaming, setIsRenaming] = useState(false);
Expand Down Expand Up @@ -82,7 +82,7 @@ export function useDashboardSidebarWorkspaceItemActions({
};

const handleDeleted = () => {
removeWorkspaceFromSidebar(workspaceId);
hideWorkspaceInSidebar(workspaceId);
};

const handleRemoveFromSidebar = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import { describe, expect, it } from "bun:test";
import {
buildSidebarProjects,
type SidebarProjectRow,
shouldIncludeSidebarWorkspace,
} from "./sidebarDefaultVisibility";

const userId = "user-1";

describe("shouldIncludeSidebarWorkspace", () => {
it("includes workspaces with explicit local sidebar state", () => {
expect(
shouldIncludeSidebarWorkspace(
{
type: "main",
createdByUserId: null,
hasUserHostAccess: false,
hasLocalSidebarState: true,
},
userId,
),
).toBe(true);
});

it("defaults current-user worktree workspaces visible when host is accessible", () => {
expect(
shouldIncludeSidebarWorkspace(
{
type: "worktree",
createdByUserId: userId,
hasUserHostAccess: true,
hasLocalSidebarState: false,
},
userId,
),
).toBe(true);
});

it("does not default main, inaccessible, or other-user workspaces visible", () => {
expect(
shouldIncludeSidebarWorkspace(
{
type: "main",
createdByUserId: userId,
hasUserHostAccess: true,
hasLocalSidebarState: false,
},
userId,
),
).toBe(false);
expect(
shouldIncludeSidebarWorkspace(
{
type: "worktree",
createdByUserId: userId,
hasUserHostAccess: false,
hasLocalSidebarState: false,
},
userId,
),
).toBe(false);
expect(
shouldIncludeSidebarWorkspace(
{
type: "worktree",
createdByUserId: "user-2",
hasUserHostAccess: true,
hasLocalSidebarState: false,
},
userId,
),
).toBe(false);
expect(
shouldIncludeSidebarWorkspace(
{
type: "worktree",
createdByUserId: null,
hasUserHostAccess: true,
hasLocalSidebarState: false,
},
null,
),
).toBe(false);
});
});

describe("buildSidebarProjects", () => {
const date = new Date("2026-01-01T00:00:00.000Z");
const explicitProject: SidebarProjectRow = {
id: "project-explicit",
name: "Explicit",
slug: "explicit",
githubRepositoryId: null,
githubOwner: null,
githubRepoName: null,
iconUrl: null,
createdAt: date,
updatedAt: date,
isCollapsed: true,
tabOrder: 1,
};
const { tabOrder: _explicitTabOrder, ...expectedExplicitProject } =
explicitProject;

it("adds default project rows without replacing explicit projects", () => {
expect(
buildSidebarProjects(
[explicitProject],
[
{
projectId: "project-explicit",
projectName: "Ignored",
projectSlug: "ignored",
projectGithubRepositoryId: "ignored-repo",
projectGithubOwner: "ignored-owner",
projectGithubRepoName: "ignored-name",
projectIconUrl: null,
projectCreatedAt: date,
projectUpdatedAt: date,
},
{
projectId: "project-default",
projectName: "Default",
projectSlug: "default",
projectGithubRepositoryId: "repo-1",
projectGithubOwner: "owner",
projectGithubRepoName: "repo",
projectIconUrl: "https://example.com/icon.png",
projectCreatedAt: date,
projectUpdatedAt: date,
},
],
),
).toEqual([
expectedExplicitProject,
{
id: "project-default",
name: "Default",
slug: "default",
githubRepositoryId: "repo-1",
githubOwner: "owner",
githubRepoName: "repo",
iconUrl: "https://example.com/icon.png",
createdAt: date,
updatedAt: date,
isCollapsed: false,
},
]);
});

it("sorts explicit projects by tab order and default projects by name after them", () => {
const laterProject: SidebarProjectRow = {
...explicitProject,
id: "project-later",
name: "Later",
slug: "later",
tabOrder: 2,
};

expect(
buildSidebarProjects(
[laterProject, explicitProject],
[
{
projectId: "project-z",
projectName: "Zulu",
projectSlug: "zulu",
projectGithubRepositoryId: null,
projectGithubOwner: null,
projectGithubRepoName: null,
projectIconUrl: null,
projectCreatedAt: date,
projectUpdatedAt: date,
},
{
projectId: "project-a",
projectName: "Alpha",
projectSlug: "alpha",
projectGithubRepositoryId: null,
projectGithubOwner: null,
projectGithubRepoName: null,
projectIconUrl: null,
projectCreatedAt: date,
projectUpdatedAt: date,
},
],
).map((project) => project.id),
).toEqual(["project-explicit", "project-later", "project-a", "project-z"]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import type {
DashboardSidebarProject,
DashboardSidebarWorkspaceType,
} from "../../types";

export type SidebarProjectRow = Omit<DashboardSidebarProject, "children"> & {
tabOrder: number;
};

export interface SidebarWorkspaceVisibilitySource {
type: DashboardSidebarWorkspaceType;
createdByUserId: string | null;
hasUserHostAccess: boolean;
hasLocalSidebarState: boolean;
}

export interface SidebarProjectWorkspaceSource {
projectId: string;
projectName: string;
projectSlug: string;
projectGithubRepositoryId: string | null;
projectGithubOwner: string | null | undefined;
projectGithubRepoName: string | null | undefined;
projectIconUrl: string | null;
projectCreatedAt: Date;
projectUpdatedAt: Date;
}

export function shouldIncludeSidebarWorkspace(
workspace: SidebarWorkspaceVisibilitySource,
currentUserId: string | null,
): boolean {
if (workspace.hasLocalSidebarState) return true;
if (currentUserId === null) return false;
return (
workspace.type === "worktree" &&
workspace.createdByUserId === currentUserId &&
workspace.hasUserHostAccess
);
}

export function buildSidebarProjects(
explicitProjects: readonly SidebarProjectRow[],
workspaces: readonly SidebarProjectWorkspaceSource[],
): Array<Omit<DashboardSidebarProject, "children">> {
const explicitProjectIds = new Set(
explicitProjects.map((project) => project.id),
);
const defaultProjects = new Map<string, SidebarProjectRow>();

for (const workspace of workspaces) {
if (explicitProjectIds.has(workspace.projectId)) continue;
if (defaultProjects.has(workspace.projectId)) continue;

defaultProjects.set(workspace.projectId, {
id: workspace.projectId,
name: workspace.projectName,
slug: workspace.projectSlug,
githubRepositoryId: workspace.projectGithubRepositoryId,
githubOwner: workspace.projectGithubOwner ?? null,
githubRepoName: workspace.projectGithubRepoName ?? null,
iconUrl: workspace.projectIconUrl,
createdAt: workspace.projectCreatedAt,
updatedAt: workspace.projectUpdatedAt,
isCollapsed: false,
tabOrder: Number.MAX_SAFE_INTEGER,
});
}

return [...explicitProjects, ...defaultProjects.values()]
.sort((left, right) => {
const orderDelta = left.tabOrder - right.tabOrder;
if (orderDelta !== 0) return orderDelta;
return left.name.localeCompare(right.name);
})
.map(({ tabOrder: _tabOrder, ...project }) => project);
}
Loading
Loading