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: load task statuses on direct page visits (#1403)

Tin Sever1ca05c4c7857
diff --git a/apps/web/src/components/task/task-status-popover.test.tsx b/apps/web/src/components/task/task-status-popover.test.tsx
new file mode 100644
index 000000000..758c48e63
--- /dev/null
+++ b/apps/web/src/components/task/task-status-popover.test.tsx
@@ -0,0 +1,116 @@
+import { cleanup, fireEvent, render, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { Button } from "@/components/ui/button";
+import type Task from "@/types/task";
+import TaskStatusPopover from "./task-status-popover";
+
+const useGetColumns = vi.fn();
+
+afterEach(() => {
+ cleanup();
+ document.body.innerHTML = "";
+});
+
+vi.mock("@/hooks/queries/column/use-get-columns", () => ({
+ useGetColumns: (projectId: string) => useGetColumns(projectId),
+}));
+
+vi.mock("@/hooks/mutations/task/use-update-task-status", () => ({
+ useUpdateTaskStatus: () => ({ mutateAsync: vi.fn() }),
+}));
+
+vi.mock("@/hooks/use-numbered-shortcuts", () => ({
+ useNumberedShortcuts: vi.fn(),
+}));
+
+vi.mock("@/hooks/use-workspace-permission", () => ({
+ useWorkspacePermission: () => ({ canManageTasks: () => true }),
+}));
+
+vi.mock("react-i18next", () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+}));
+
+const task: Task = {
+ id: "task-1",
+ title: "Directly loaded task",
+ number: 1,
+ description: null,
+ status: "to-do",
+ priority: null,
+ startDate: null,
+ dueDate: null,
+ position: 1,
+ createdAt: "2026-07-17T00:00:00.000Z",
+ userId: null,
+ assigneeId: null,
+ assigneeName: null,
+ projectId: "project-1",
+};
+
+describe("TaskStatusPopover", () => {
+ it("loads status options for the task project without relying on board state", async () => {
+ useGetColumns.mockReturnValue({
+ data: [
+ {
+ id: "column-1",
+ slug: "to-do",
+ name: "Ready",
+ icon: null,
+ isFinal: false,
+ },
+ ],
+ isLoading: false,
+ isError: false,
+ });
+
+ render(
+ <TaskStatusPopover task={task}>
+ <Button>Status</Button>
+ </TaskStatusPopover>,
+ );
+
+ expect(useGetColumns).toHaveBeenCalledWith("project-1");
+ expect(screen.queryByRole("button", { name: /Ready/ })).toBeNull();
+
+ fireEvent.click(screen.getByRole("button", { name: "Status" }));
+
+ expect(await screen.findByRole("button", { name: /Ready/ })).toBeVisible();
+ });
+
+ it("shows loading feedback while status options are loading", async () => {
+ useGetColumns.mockReturnValue({
+ data: undefined,
+ isLoading: true,
+ isError: false,
+ });
+
+ render(
+ <TaskStatusPopover task={task}>
+ <Button>Status</Button>
+ </TaskStatusPopover>,
+ );
+
+ fireEvent.click(screen.getByRole("button", { name: "Status" }));
+
+ expect(await screen.findByText("common:empty.loading")).toBeVisible();
+ });
+
+ it("shows error feedback when status options fail to load", async () => {
+ useGetColumns.mockReturnValue({
+ data: undefined,
+ isLoading: false,
+ isError: true,
+ });
+
+ render(
+ <TaskStatusPopover task={task}>
+ <Button>Status</Button>
+ </TaskStatusPopover>,
+ );
+
+ fireEvent.click(screen.getByRole("button", { name: "Status" }));
+
+ expect(await screen.findByText("common:error.title")).toBeVisible();
+ });
+});
diff --git a/apps/web/src/components/task/task-status-popover.tsx b/apps/web/src/components/task/task-status-popover.tsx
index 54d83be7a..fa5ff29a4 100644
--- a/apps/web/src/components/task/task-status-popover.tsx
+++ b/apps/web/src/components/task/task-status-popover.tsx
@@ -28,7 +28,7 @@ export default function TaskStatusPopover({
}: TaskStatusPopoverProps) {
const { t } = useTranslation();
const [open, setOpen] = useState(false);
- const { data: columns } = useGetColumns(task.projectId);
+ const { data: columns, isLoading, isError } = useGetColumns(task.projectId);
const statusOptions = useMemo(
() =>
(columns ?? []).map((col) => ({
@@ -79,25 +79,35 @@ export default function TaskStatusPopover({
<PopoverTrigger asChild>{children}</PopoverTrigger>
<PopoverContent className="w-48 p-0" align="start">
<div>
- {statusOptions.map((status, index) => (
- <Button
- key={status.value}
- variant="ghost"
- size="sm"
- className="w-full justify-start gap-2 h-8 px-2 rounded-none first:rounded-t-md last:rounded-b-md"
- onClick={() => handleStatusChange(status.value)}
- >
- {getColumnIcon(status.value, status.isFinal, status.icon)}
- <span className="text-sm">
- {getStatusDisplayLabel(status.value, status.label)}
- </span>
- {task.status === status.value ? (
- <Check className="ml-auto h-4 w-4" />
- ) : (
- <ShortcutNumber number={index + 1} />
- )}
- </Button>
- ))}
+ {isLoading ? (
+ <div className="p-3 text-center text-sm text-muted-foreground">
+ {t("common:empty.loading")}
+ </div>
+ ) : isError ? (
+ <div className="p-3 text-center text-sm text-destructive">
+ {t("common:error.title")}
+ </div>
+ ) : (
+ statusOptions.map((status, index) => (
+ <Button
+ key={status.value}
+ variant="ghost"
+ size="sm"
+ className="w-full justify-start gap-2 h-8 px-2 rounded-none first:rounded-t-md last:rounded-b-md"
+ onClick={() => handleStatusChange(status.value)}
+ >
+ {getColumnIcon(status.value, status.isFinal, status.icon)}
+ <span className="text-sm">
+ {getStatusDisplayLabel(status.value, status.label)}
+ </span>
+ {task.status === status.value ? (
+ <Check className="ml-auto h-4 w-4" />
+ ) : (
+ <ShortcutNumber number={index + 1} />
+ )}
+ </Button>
+ ))
+ )}
</div>
</PopoverContent>
</Popover>