Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(web): make the chevron follow the rendering, not the preference

Juane0041178c6cd
diff --git a/apps/web/src/components/list-view/index.tsx b/apps/web/src/components/list-view/index.tsx
index b2764d7b1..4e15deb67 100644
--- a/apps/web/src/components/list-view/index.tsx
+++ b/apps/web/src/components/list-view/index.tsx
@@ -462,7 +462,7 @@ function ListView({ project, disableDragDrop = false }: ListViewProps) {
depth={row.depth}
rowId={row.rowId}
childCount={row.childCount}
- isExpanded={Boolean(expandedTasks[row.rowId])}
+ isExpanded={row.isExpanded}
onToggleExpanded={() => toggleTaskExpanded(row.rowId)}
/>
</motion.div>
diff --git a/apps/web/src/lib/subtask-tree.test.ts b/apps/web/src/lib/subtask-tree.test.ts
index f95179fff..9ba98a11a 100644
--- a/apps/web/src/lib/subtask-tree.test.ts
+++ b/apps/web/src/lib/subtask-tree.test.ts
@@ -207,6 +207,26 @@ describe("flattenSubtaskRows", () => {
expect(rows.filter((row) => row.depth > 0)).toHaveLength(10);
});
+ it("reports the expansion that was actually rendered", () => {
+ const tasks = [task("parent"), task("child")];
+ const relations = [subtask("parent", "child")];
+
+ const open = flatten(tasks, relations);
+ expect(open.find((row) => row.rowId === "parent")?.isExpanded).toBe(true);
+
+ // The stored preference is irrelevant once the flattener declines to
+ // expand — during a drag, say — and the chevron follows this, not the map.
+ const shut = flatten(tasks, relations, { expanded: false });
+ expect(shut.find((row) => row.rowId === "parent")?.isExpanded).toBe(false);
+ expect(shut.find((row) => row.rowId === "parent")?.childCount).toBe(1);
+ });
+
+ it("never reports a childless row as expanded", () => {
+ const rows = flatten([task("a")], []);
+
+ expect(rows[0].isExpanded).toBe(false);
+ });
+
it("reports no children once the budget is spent", () => {
const tasks = [task("a"), task("b")];
const rows = flattenSubtaskRows({
diff --git a/apps/web/src/lib/subtask-tree.ts b/apps/web/src/lib/subtask-tree.ts
index 0cd2e95d0..0021d0110 100644
--- a/apps/web/src/lib/subtask-tree.ts
+++ b/apps/web/src/lib/subtask-tree.ts
@@ -15,6 +15,13 @@ export type SubtaskRow<T> = {
*/
rowId: string;
childCount: number;
+ /**
+ * Whether this row's children are actually rendered beneath it. Not the same
+ * as the stored preference: a drag collapses every row, and the budget stops
+ * deep ones expanding. The chevron and its aria-expanded must follow this,
+ * or the control describes a subtree that is not on screen.
+ */
+ isExpanded: boolean;
};
/**
@@ -110,9 +117,11 @@ export function flattenSubtaskRows<T extends { id: string }>({
// rather than an expanded one with nothing beneath it.
const childCount = nested >= maxNestedRows ? 0 : childTasks.length;
- rows.push({ task, depth, rowId, childCount });
+ const expanded = childCount > 0 && isExpanded(rowId);
+
+ rows.push({ task, depth, rowId, childCount, isExpanded: expanded });
- if (childCount === 0 || !isExpanded(rowId)) return;
+ if (!expanded) return;
const nextAncestors = new Set(ancestors);
nextAncestors.add(task.id);