perf(app): limit initial sidebar workspace rendering
Large project, status, and pinned groups now render 20 rows until expanded. Newly discovered workspaces are prepended without disturbing the saved order.
This commit is contained in:
@@ -471,7 +471,7 @@ describe("computeSidebarOrderUpdates", () => {
|
||||
expect(updates).toEqual({ projectOrder: null, workspaceOrders: [] });
|
||||
});
|
||||
|
||||
it("appends unseen projects and workspaces to the persisted orders", () => {
|
||||
it("appends unseen projects while putting unseen workspaces before the saved order", () => {
|
||||
const projects = [
|
||||
sidebarProject({ projectKey: "project-a", workspaceKeys: ["ws-1", "ws-2"] }),
|
||||
sidebarProject({ projectKey: "project-b", workspaceKeys: ["ws-3"] }),
|
||||
@@ -485,11 +485,33 @@ describe("computeSidebarOrderUpdates", () => {
|
||||
|
||||
expect(updates.projectOrder).toEqual(["project-a", "project-b"]);
|
||||
expect(updates.workspaceOrders).toEqual([
|
||||
{ projectKey: "project-a", order: ["srv:ws-1", "srv:ws-2"] },
|
||||
{ projectKey: "project-a", order: ["srv:ws-2", "srv:ws-1"] },
|
||||
{ projectKey: "project-b", order: ["srv:ws-3"] },
|
||||
]);
|
||||
});
|
||||
|
||||
it("preserves the saved workspace order behind multiple newly discovered workspaces", () => {
|
||||
const projects = [
|
||||
sidebarProject({
|
||||
projectKey: "project-a",
|
||||
workspaceKeys: ["newest", "newer", "old-a", "old-b"],
|
||||
}),
|
||||
];
|
||||
|
||||
const updates = computeSidebarOrderUpdates({
|
||||
projects,
|
||||
persistedProjectOrder: ["project-a"],
|
||||
getWorkspaceOrder: () => ["srv:old-b", "srv:old-a"],
|
||||
});
|
||||
|
||||
expect(updates.workspaceOrders).toEqual([
|
||||
{
|
||||
projectKey: "project-a",
|
||||
order: ["srv:newest", "srv:newer", "srv:old-b", "srv:old-a"],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("returns no project-order update when persisted order already covers visible keys", () => {
|
||||
const projects = [
|
||||
sidebarProject({ projectKey: "project-a", workspaceKeys: ["ws-1"] }),
|
||||
|
||||
@@ -477,6 +477,23 @@ export function appendMissingOrderKeys(input: {
|
||||
return [...input.currentOrder, ...missingKeys];
|
||||
}
|
||||
|
||||
export function prependMissingOrderKeys(input: {
|
||||
currentOrder: string[];
|
||||
visibleKeys: string[];
|
||||
}): string[] {
|
||||
if (input.visibleKeys.length === 0) {
|
||||
return input.currentOrder;
|
||||
}
|
||||
|
||||
const existingKeys = new Set(input.currentOrder);
|
||||
const missingKeys = input.visibleKeys.filter((key) => !existingKeys.has(key));
|
||||
if (missingKeys.length === 0) {
|
||||
return input.currentOrder;
|
||||
}
|
||||
|
||||
return [...missingKeys, ...input.currentOrder];
|
||||
}
|
||||
|
||||
export interface SidebarOrderUpdates {
|
||||
projectOrder: string[] | null;
|
||||
workspaceOrders: Array<{ projectKey: string; order: string[] }>;
|
||||
@@ -500,7 +517,7 @@ export function computeSidebarOrderUpdates(input: {
|
||||
const workspaceOrders: Array<{ projectKey: string; order: string[] }> = [];
|
||||
for (const project of input.projects) {
|
||||
const persistedWorkspaceOrder = input.getWorkspaceOrder(project.projectKey);
|
||||
const nextWorkspaceOrder = appendMissingOrderKeys({
|
||||
const nextWorkspaceOrder = prependMissingOrderKeys({
|
||||
currentOrder: persistedWorkspaceOrder,
|
||||
visibleKeys: project.workspaces.map((workspace) => workspace.workspaceKey),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user