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): keep the relation cache fresh and the cap honest

Juane274098e161d
diff --git a/apps/web/src/components/list-view/index.tsx b/apps/web/src/components/list-view/index.tsx
index 5ce952fcb..c249e494c 100644
--- a/apps/web/src/components/list-view/index.tsx
+++ b/apps/web/src/components/list-view/index.tsx
@@ -459,6 +459,7 @@ function ListView({ project, disableDragDrop = false }: ListViewProps) {
task={row.task}
projectSlug={project?.slug ?? ""}
reserveToggleSpace={groupHasSubtasks}
+ isTaskDragging={activeId === row.task.id}
depth={row.depth}
rowId={row.rowId}
childCount={row.childCount}
diff --git a/apps/web/src/components/list-view/task-row.tsx b/apps/web/src/components/list-view/task-row.tsx
index 65502776e..91f85397c 100644
--- a/apps/web/src/components/list-view/task-row.tsx
+++ b/apps/web/src/components/list-view/task-row.tsx
@@ -67,6 +67,12 @@ type TaskRowProps = {
* a group containing subtasks stay on one vertical line.
*/
reserveToggleSpace?: boolean;
+ /**
+ * True while this task is being dragged from another of its rows. A subtask
+ * is repeated under each parent, and only the top-level row is the drag
+ * source, so the repeats would otherwise sit at full opacity beside it.
+ */
+ isTaskDragging?: boolean;
};
function TaskRow({
@@ -78,6 +84,7 @@ function TaskRow({
isExpanded = false,
onToggleExpanded,
reserveToggleSpace = false,
+ isTaskDragging = false,
}: TaskRowProps) {
const showToggleColumn = depth > 0 || childCount > 0 || reserveToggleSpace;
const { t } = useTranslation();
@@ -212,7 +219,7 @@ function TaskRow({
// than inside it: dnd-kit gives its activator role="button", and a
// button nested in one is an ambiguous control for assistive tech.
"group flex items-stretch border-b border-border/50 transition-colors duration-150",
- isDragging && "opacity-50",
+ (isDragging || isTaskDragging) && "opacity-50",
isTaskSelected &&
"bg-accent/60 shadow-sm ring-1 ring-inset ring-ring/30",
isTaskFocused && "ring-2 ring-inset ring-ring/50",
diff --git a/apps/web/src/hooks/mutations/task/use-delete-task.ts b/apps/web/src/hooks/mutations/task/use-delete-task.ts
index 1900ca2d4..fcd6c2866 100644
--- a/apps/web/src/hooks/mutations/task/use-delete-task.ts
+++ b/apps/web/src/hooks/mutations/task/use-delete-task.ts
@@ -22,6 +22,12 @@ export function useDeleteTask() {
void queryClient.invalidateQueries({
queryKey: ["tasks", deletedTask.projectId],
});
+ // Relations cascade with the task, and the TASK_DELETED broadcast skips
+ // the window that issued the delete, so this is the only path that
+ // refreshes the list view's edge set for whoever performed it.
+ void queryClient.invalidateQueries({
+ queryKey: ["task-relations", "project", deletedTask.projectId],
+ });
const { project, setProject } = useProjectStore.getState();
if (project?.id === deletedTask.projectId) {
diff --git a/apps/web/src/hooks/queries/task-relation/use-get-project-task-relations.ts b/apps/web/src/hooks/queries/task-relation/use-get-project-task-relations.ts
index 035b85789..ff3064b21 100644
--- a/apps/web/src/hooks/queries/task-relation/use-get-project-task-relations.ts
+++ b/apps/web/src/hooks/queries/task-relation/use-get-project-task-relations.ts
@@ -6,6 +6,11 @@ function useGetProjectTaskRelations(projectId: string) {
queryKey: ["task-relations", "project", projectId],
queryFn: () => getProjectTaskRelations(projectId),
enabled: !!projectId,
+ // The app disables refetchOnMount globally. Relations change while this
+ // view is closed — a subtask added from a task detail panel, a cascade
+ // from a delete — and an invalidation only marks an inactive query stale,
+ // so without this the list would reopen on the edges it last saw.
+ refetchOnMount: true,
});
}
diff --git a/apps/web/src/lib/subtask-tree.test.ts b/apps/web/src/lib/subtask-tree.test.ts
index a2eccfa9b..f95179fff 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 no children once the budget is spent", () => {
+ const tasks = [task("a"), task("b")];
+ const rows = flattenSubtaskRows({
+ tasks,
+ children: buildSubtaskChildren([subtask("a", "b"), subtask("b", "c")]),
+ tasksById: new Map(
+ [...tasks, task("c")].map((entry) => [entry.id, entry]),
+ ),
+ isExpanded: () => true,
+ maxNestedRows: 1,
+ });
+
+ // The nested "a/b" is the row that spends the budget, so it must not
+ // advertise a chevron that can reveal nothing.
+ expect(rows.find((row) => row.rowId === "a/b")).toMatchObject({
+ childCount: 0,
+ });
+ expect(rows.map((row) => row.rowId)).not.toContain("a/b/c");
+ });
+
it("leaves every task a top-level row even when nesting is capped", () => {
const tasks = [task("a"), task("b"), task("c")];
const rows = flattenSubtaskRows({
diff --git a/apps/web/src/lib/subtask-tree.ts b/apps/web/src/lib/subtask-tree.ts
index ea68b911c..0cd2e95d0 100644
--- a/apps/web/src/lib/subtask-tree.ts
+++ b/apps/web/src/lib/subtask-tree.ts
@@ -104,11 +104,15 @@ export function flattenSubtaskRows<T extends { id: string }>({
}
}
- rows.push({ task, depth, rowId, childCount: childTasks.length });
-
if (depth > 0) nested += 1;
- if (childTasks.length === 0 || !isExpanded(rowId)) return;
- if (nested >= maxNestedRows) return;
+
+ // Past the budget the row reports no children, so it renders no chevron
+ // rather than an expanded one with nothing beneath it.
+ const childCount = nested >= maxNestedRows ? 0 : childTasks.length;
+
+ rows.push({ task, depth, rowId, childCount });
+
+ if (childCount === 0 || !isExpanded(rowId)) return;
const nextAncestors = new Set(ancestors);
nextAncestors.add(task.id);