Skip to content
Merged
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 @@ -12,6 +12,15 @@ function getNextTabOrder(items: Array<{ tabOrder: number }>): number {
return maxTabOrder + 1;
}

function getPrependTabOrder(items: Array<{ tabOrder: number }>): number {
if (items.length === 0) return 1;
const minTabOrder = items.reduce(
(minValue, item) => Math.min(minValue, item.tabOrder),
Number.POSITIVE_INFINITY,
);
return minTabOrder - 1;
}
Comment on lines +15 to +22
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Empty-project seed value is 0 while the rest of the codebase uses 1-based ordering

When items is empty (first workspace in a brand-new project) getPrependTabOrder returns 0, whereas every other insertion helper (getNextTabOrder, reorderProjectChildren, reorderWorkspaces, moveWorkspaceToSectionAtIndex) normalises to 1-based tabOrders on the next drag. This is functionally harmless — 0 < 1 so the workspace still sorts first — but it is a mild inconsistency worth documenting or aligning with 1.

If you want to keep the 1-based convention you could return 1 instead:

Suggested change
function getPrependTabOrder(items: Array<{ tabOrder: number }>): number {
if (items.length === 0) return 0;
const minTabOrder = items.reduce(
(minValue, item) => Math.min(minValue, item.tabOrder),
Number.POSITIVE_INFINITY,
);
return minTabOrder - 1;
}
function getPrependTabOrder(items: Array<{ tabOrder: number }>): number {
if (items.length === 0) return 1;
const minTabOrder = items.reduce(
(minValue, item) => Math.min(minValue, item.tabOrder),
Number.POSITIVE_INFINITY,
);
return minTabOrder - 1;
}

This way the first workspace starts at 1, the second at 0, the third at -1, etc. — all still sorts correctly and matches the "index + 1" convention used by the reorder helpers.

Not blocking; leaving as a suggestion.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/renderer/routes/_authenticated/hooks/useDashboardSidebarState/useDashboardSidebarState.ts
Line: 15-22

Comment:
**Empty-project seed value is `0` while the rest of the codebase uses `1`-based ordering**

When `items` is empty (first workspace in a brand-new project) `getPrependTabOrder` returns `0`, whereas every other insertion helper (`getNextTabOrder`, `reorderProjectChildren`, `reorderWorkspaces`, `moveWorkspaceToSectionAtIndex`) normalises to `1`-based tabOrders on the next drag. This is functionally harmless — `0 < 1` so the workspace still sorts first — but it is a mild inconsistency worth documenting or aligning with `1`.

If you want to keep the `1`-based convention you could return `1` instead:
```suggestion
function getPrependTabOrder(items: Array<{ tabOrder: number }>): number {
	if (items.length === 0) return 1;
	const minTabOrder = items.reduce(
		(minValue, item) => Math.min(minValue, item.tabOrder),
		Number.POSITIVE_INFINITY,
	);
	return minTabOrder - 1;
}
```
This way the first workspace starts at `1`, the second at `0`, the third at `-1`, etc. — all still sorts correctly and matches the "index + 1" convention used by the reorder helpers.

Not blocking; leaving as a suggestion.

How can I resolve this? If you propose a fix, please make it concise.


function ensureSidebarProjectRecord(
collections: Pick<AppCollections, "v2SidebarProjects">,
projectId: string,
Expand Down Expand Up @@ -60,7 +69,7 @@ function ensureSidebarWorkspaceRecord(
createdAt: new Date(),
sidebarState: {
projectId,
tabOrder: getNextTabOrder(topLevelOrders),
tabOrder: getPrependTabOrder(topLevelOrders),
sectionId: null,
},
paneLayout: {
Expand Down
Loading