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: preserve global alerts and keep workspace views current

Tin61fdde3aefb7
diff --git a/apps/api/src/notification/schema.ts b/apps/api/src/notification/schema.ts
index 91b4c9cce..63c36c9d6 100644
--- a/apps/api/src/notification/schema.ts
+++ b/apps/api/src/notification/schema.ts
@@ -3,7 +3,7 @@ import { z } from "../openapi";
export const notificationWorkspaceQuery = z.object({
workspaceId: z.string().min(1).optional().openapi({
description:
- "Limit notifications to resources currently in this workspace. Omit to include all workspaces.",
+ "Limit notifications to resources currently in this workspace, plus user-wide notifications with no resource. Omit to include all workspaces.",
}),
});
diff --git a/apps/api/src/notification/workspace-filter.ts b/apps/api/src/notification/workspace-filter.ts
index 414efc355..d9631958b 100644
--- a/apps/api/src/notification/workspace-filter.ts
+++ b/apps/api/src/notification/workspace-filter.ts
@@ -6,6 +6,8 @@ import { notificationTable } from "../database/schema";
export function notificationWorkspaceFilter(workspaceId?: string) {
if (!workspaceId) return undefined;
return sql<boolean>`(
+ (${notificationTable.resourceId} IS NULL AND ${notificationTable.resourceType} IS NULL)
+ OR
(${notificationTable.resourceType} = 'workspace' AND ${notificationTable.resourceId} = ${workspaceId})
OR (${notificationTable.resourceType} = 'task' AND EXISTS (
SELECT 1 FROM task AS inbox_task
diff --git a/apps/docs/openapi.json b/apps/docs/openapi.json
index 926d30945..079ffe41d 100644
--- a/apps/docs/openapi.json
+++ b/apps/docs/openapi.json
@@ -12719,10 +12719,10 @@
"schema": {
"type": "string",
"minLength": 1,
- "description": "Limit notifications to resources currently in this workspace. Omit to include all workspaces."
+ "description": "Limit notifications to resources currently in this workspace, plus user-wide notifications with no resource. Omit to include all workspaces."
},
"required": false,
- "description": "Limit notifications to resources currently in this workspace. Omit to include all workspaces.",
+ "description": "Limit notifications to resources currently in this workspace, plus user-wide notifications with no resource. Omit to include all workspaces.",
"name": "workspaceId",
"in": "query"
}
@@ -12894,10 +12894,10 @@
"schema": {
"type": "string",
"minLength": 1,
- "description": "Limit notifications to resources currently in this workspace. Omit to include all workspaces."
+ "description": "Limit notifications to resources currently in this workspace, plus user-wide notifications with no resource. Omit to include all workspaces."
},
"required": false,
- "description": "Limit notifications to resources currently in this workspace. Omit to include all workspaces.",
+ "description": "Limit notifications to resources currently in this workspace, plus user-wide notifications with no resource. Omit to include all workspaces.",
"name": "workspaceId",
"in": "query"
}
@@ -12932,10 +12932,10 @@
"schema": {
"type": "string",
"minLength": 1,
- "description": "Limit notifications to resources currently in this workspace. Omit to include all workspaces."
+ "description": "Limit notifications to resources currently in this workspace, plus user-wide notifications with no resource. Omit to include all workspaces."
},
"required": false,
- "description": "Limit notifications to resources currently in this workspace. Omit to include all workspaces.",
+ "description": "Limit notifications to resources currently in this workspace, plus user-wide notifications with no resource. Omit to include all workspaces.",
"name": "workspaceId",
"in": "query"
}
diff --git a/apps/web/src/components/home/activity-feed-item.tsx b/apps/web/src/components/home/activity-feed-item.tsx
index ab7a120f8..0c77708eb 100644
--- a/apps/web/src/components/home/activity-feed-item.tsx
+++ b/apps/web/src/components/home/activity-feed-item.tsx
@@ -53,7 +53,9 @@ export function ActivityFeedItem({
className="min-w-0 truncate hover:text-foreground"
>
<span className="font-medium">
- {activity.projectSlug}-{activity.taskNumber}
+ {activity.taskNumber == null
+ ? activity.projectSlug
+ : `${activity.projectSlug}-${activity.taskNumber}`}
</span>{" "}
{activity.taskTitle}
</Link>
diff --git a/apps/web/src/components/home/week-strip.tsx b/apps/web/src/components/home/week-strip.tsx
index b0093e13e..29038b2cf 100644
--- a/apps/web/src/components/home/week-strip.tsx
+++ b/apps/web/src/components/home/week-strip.tsx
@@ -83,7 +83,9 @@ export function WeekStrip({ tasks, workspaceId }: WeekStripProps) {
>
{day.isPast
? t("workspace:myWork.due.overdue")
- : `${task.projectSlug}-${task.number}`}
+ : task.number == null
+ ? task.projectSlug
+ : `${task.projectSlug}-${task.number}`}
</span>
<span className="truncate text-foreground text-xs">
{task.title}
diff --git a/apps/web/src/components/inbox/inbox-task.tsx b/apps/web/src/components/inbox/inbox-task.tsx
index 4e3226738..a28b977b7 100644
--- a/apps/web/src/components/inbox/inbox-task.tsx
+++ b/apps/web/src/components/inbox/inbox-task.tsx
@@ -22,12 +22,12 @@ const VISIBLE_ACTIVITIES = 6;
// without leaving the inbox.
export function InboxTask({ taskId }: InboxTaskProps) {
const { t } = useTranslation();
- const { data: task, isLoading, isError } = useGetTask(taskId);
+ const { data: task, isLoading, isError } = useGetTask(taskId, true);
const {
data: activities = [],
isPending: activityPending,
isError: activityError,
- } = useGetActivitiesByTaskId(taskId);
+ } = useGetActivitiesByTaskId(taskId, true);
const { canUpdateTasks } = useWorkspacePermission();
if (isLoading) {
diff --git a/apps/web/src/components/my-work/assigned-task-row.tsx b/apps/web/src/components/my-work/assigned-task-row.tsx
index 755e0e127..0092b1727 100644
--- a/apps/web/src/components/my-work/assigned-task-row.tsx
+++ b/apps/web/src/components/my-work/assigned-task-row.tsx
@@ -33,7 +33,9 @@ export function AssignedTaskRow({
{getColumnIcon(task.status, false, task.statusIcon)}
</span>
<span className="w-16 shrink-0 truncate font-medium text-muted-foreground text-xs">
- {task.projectSlug}-{task.number}
+ {task.number == null
+ ? task.projectSlug
+ : `${task.projectSlug}-${task.number}`}
</span>
<span className="min-w-0 flex-1 truncate text-foreground text-sm">
{task.title}
diff --git a/apps/web/src/components/my-work/due-date-text.test.tsx b/apps/web/src/components/my-work/due-date-text.test.tsx
new file mode 100644
index 000000000..5b8826a18
--- /dev/null
+++ b/apps/web/src/components/my-work/due-date-text.test.tsx
@@ -0,0 +1,22 @@
+import { act, cleanup, render, screen } from "@testing-library/react";
+import { afterEach, expect, it, vi } from "vite-plus/test";
+import { DueDateText } from "./due-date-text";
+
+vi.mock("react-i18next", async (original) => ({
+ ...(await original<object>()),
+ useTranslation: () => ({ t: (key: string) => key }),
+}));
+
+afterEach(() => {
+ cleanup();
+ vi.useRealTimers();
+});
+
+it("updates relative due-date text at midnight with unchanged props", () => {
+ vi.useFakeTimers();
+ vi.setSystemTime(new Date(2030, 0, 1, 23, 59, 59));
+ render(<DueDateText dueDate={new Date(2030, 0, 2, 12).toISOString()} />);
+ expect(screen.getByText("workspace:myWork.due.tomorrow")).toBeVisible();
+ act(() => vi.advanceTimersByTime(1000));
+ expect(screen.getByText("workspace:myWork.due.today")).toBeVisible();
+});
diff --git a/apps/web/src/components/my-work/due-date-text.tsx b/apps/web/src/components/my-work/due-date-text.tsx
index 7deb9dc5c..3caffa2bd 100644
--- a/apps/web/src/components/my-work/due-date-text.tsx
+++ b/apps/web/src/components/my-work/due-date-text.tsx
@@ -1,5 +1,6 @@
import { differenceInCalendarDays } from "date-fns";
import { useTranslation } from "react-i18next";
+import { useLocalDay } from "@/hooks/use-local-day";
import { cn } from "@/lib/cn";
import { formatDate, formatDateShort } from "@/lib/format";
@@ -10,10 +11,11 @@ type DueDateTextProps = {
export function DueDateText({ dueDate, className }: DueDateTextProps) {
const { t } = useTranslation();
+ const day = useLocalDay();
if (!dueDate) return null;
- const days = differenceInCalendarDays(new Date(dueDate), new Date());
+ const days = differenceInCalendarDays(new Date(dueDate), new Date(day));
const text =
days === 0
? t("workspace:myWork.due.today")
diff --git a/apps/web/src/hooks/queries/activity/use-get-activities-by-task-id.ts b/apps/web/src/hooks/queries/activity/use-get-activities-by-task-id.ts
index 642b6c2e8..eeb80246e 100644
--- a/apps/web/src/hooks/queries/activity/use-get-activities-by-task-id.ts
+++ b/apps/web/src/hooks/queries/activity/use-get-activities-by-task-id.ts
@@ -1,7 +1,10 @@
import { useQuery } from "@tanstack/react-query";
import getActivitesByTaskId from "@/fetchers/activity/get-activites-by-task-id";
-function useGetActivitiesByTaskId(taskId: string | undefined) {
+function useGetActivitiesByTaskId(
+ taskId: string | undefined,
+ refreshWhileVisible = false,
+) {
return useQuery({
queryKey: ["activities", taskId],
queryFn: () => {
@@ -11,6 +14,9 @@ function useGetActivitiesByTaskId(taskId: string | undefined) {
return getActivitesByTaskId({ taskId });
},
enabled: !!taskId,
+ refetchOnMount: refreshWhileVisible ? "always" : false,
+ refetchInterval: refreshWhileVisible ? 30_000 : false,
+ refetchOnWindowFocus: refreshWhileVisible ? "always" : false,
});
}
diff --git a/apps/web/src/hooks/queries/personal-work-refresh.test.tsx b/apps/web/src/hooks/queries/personal-work-refresh.test.tsx
index 051ea25b0..44985055e 100644
--- a/apps/web/src/hooks/queries/personal-work-refresh.test.tsx
+++ b/apps/web/src/hooks/queries/personal-work-refresh.test.tsx
@@ -8,10 +8,16 @@ import type { PropsWithChildren } from "react";
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
import useGetWorkspaceActivities from "./activity/use-get-workspace-activities";
import useGetAssignedTasks from "./task/use-get-assigned-tasks";
+import useGetTask from "./task/use-get-task";
+import useGetActivitiesByTaskId from "./activity/use-get-activities-by-task-id";
+import useGetProjects from "./project/use-get-projects";
const mocks = vi.hoisted(() => ({
assigned: vi.fn(),
activities: vi.fn(),
+ task: vi.fn(),
+ comments: vi.fn(),
+ projects: vi.fn(),
}));
vi.mock("@/fetchers/task/get-assigned-tasks", () => ({
default: mocks.assigned,
@@ -20,6 +26,12 @@ vi.mock("@/fetchers/activity/get-workspace-activities", () => ({
default: mocks.activities,
}));
+vi.mock("@/fetchers/task/get-task", () => ({ default: mocks.task }));
+vi.mock("@/fetchers/activity/get-activites-by-task-id", () => ({
+ default: mocks.comments,
+}));
+vi.mock("@/fetchers/project/get-projects", () => ({ default: mocks.projects }));
+
afterEach(() => {
cleanup();
focusManager.setFocused(undefined);
@@ -42,11 +54,22 @@ describe("personal work refresh", () => {
total: 1,
});
mocks.activities.mockResolvedValue([]);
+ mocks.task.mockResolvedValue({ title: "Before" });
+ mocks.comments.mockResolvedValue([]);
+ mocks.projects.mockResolvedValue([
+ { statistics: { completionPercentage: 0 } },
+ ]);
const { result } = renderHook(
() => {
const tasks = useGetAssignedTasks("workspace");
const activity = useGetWorkspaceActivities("workspace");
+ const task = useGetTask("task", true);
+ const comments = useGetActivitiesByTaskId("task", true);
+ const projects = useGetProjects({ workspaceId: "workspace" });
return {
+ task: task.data,
+ comments: comments.data,
+ projects: projects.data,
tasks: tasks.data,
activity: activity.data,
ready: tasks.isSuccess && activity.isSuccess,
@@ -63,6 +86,11 @@ describe("personal work refresh", () => {
total: 1,
});
mocks.activities.mockResolvedValue([{ id: "comment" }]);
+ mocks.task.mockResolvedValue({ title: "After" });
+ mocks.comments.mockResolvedValue([{ id: "comment" }]);
+ mocks.projects.mockResolvedValue([
+ { statistics: { completionPercentage: 50 } },
+ ]);
await act(async () => {
await vi.advanceTimersByTimeAsync(30_010);
});
@@ -73,6 +101,12 @@ describe("personal work refresh", () => {
expect(result.current.tasks?.tasks[0].title).toBe("After");
expect(result.current.activity).toEqual([{ id: "comment" }]);
+ expect(result.current.task?.title).toBe("After");
+ expect(result.current.comments).toEqual([{ id: "comment" }]);
+ expect(result.current.projects?.[0].statistics.completionPercentage).toBe(
+ 50,
+ );
+
focusManager.setFocused(false);
const calls = mocks.assigned.mock.calls.length;
await act(async () => {
diff --git a/apps/web/src/hooks/queries/project/use-get-projects.ts b/apps/web/src/hooks/queries/project/use-get-projects.ts
index 486a3495e..1566b7327 100644
--- a/apps/web/src/hooks/queries/project/use-get-projects.ts
+++ b/apps/web/src/hooks/queries/project/use-get-projects.ts
@@ -6,6 +6,10 @@ function useGetProjects({ workspaceId }: { workspaceId: string }) {
queryFn: () => getProjects({ workspaceId }),
queryKey: ["projects", workspaceId],
enabled: !!workspaceId,
+ // Home and the sidebar show statistics without a project socket.
+ refetchInterval: 30_000,
+ refetchOnWindowFocus: "always",
+ refetchOnMount: "always",
});
}
diff --git a/apps/web/src/hooks/queries/task/use-get-task.ts b/apps/web/src/hooks/queries/task/use-get-task.ts
index 0dadc5ad0..4a305f6ca 100644
--- a/apps/web/src/hooks/queries/task/use-get-task.ts
+++ b/apps/web/src/hooks/queries/task/use-get-task.ts
@@ -1,13 +1,15 @@
import { useQuery } from "@tanstack/react-query";
import getTask from "@/fetchers/task/get-task";
-function useGetTask(taskId: string) {
+function useGetTask(taskId: string, refreshWhileVisible = false) {
return useQuery({
queryKey: ["task", taskId],
queryFn: () => getTask(taskId),
enabled: Boolean(taskId),
refetchOnMount: "always",
staleTime: 0,
+ refetchInterval: refreshWhileVisible ? 30_000 : false,
+ refetchOnWindowFocus: refreshWhileVisible ? "always" : false,
});
}
diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/index.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/index.tsx
index 3490de2a9..08698759c 100644
--- a/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/index.tsx
+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/index.tsx
@@ -13,6 +13,7 @@ import PageTitle from "@/components/page-title";
import CreateTaskModal from "@/components/shared/modals/create-task-modal";
import { Button } from "@/components/ui/button";
import useGetAssignedTasks from "@/hooks/queries/task/use-get-assigned-tasks";
+import { useLocalDay } from "@/hooks/use-local-day";
import { useWorkspacePermission } from "@/hooks/use-workspace-permission";
import { formatDate } from "@/lib/format";
@@ -24,6 +25,7 @@ export const Route = createFileRoute(
function RouteComponent() {
const { t } = useTranslation();
+ const day = useLocalDay();
const { workspaceId } = Route.useParams();
const {
data: assigned,
@@ -49,7 +51,7 @@ function RouteComponent() {
<header className="flex items-end justify-between gap-4">
<div className="flex flex-col gap-1.5">
<p className="font-medium text-[13px] text-muted-foreground">
- {formatDate(new Date(), {
+ {formatDate(new Date(day), {
weekday: "long",
month: "long",
day: "numeric",
diff --git a/tests/api-integration/notification-workspace.test.ts b/tests/api-integration/notification-workspace.test.ts
index 4f7a086a5..65d18f13a 100644
--- a/tests/api-integration/notification-workspace.test.ts
+++ b/tests/api-integration/notification-workspace.test.ts
@@ -114,6 +114,43 @@ describe("workspace inbox", () => {
).toEqual([foreign.id, anotherUser.id].sort());
});
+ it("keeps resource-less integration alerts accessible in workspace inboxes", async () => {
+ const { member, other, app } = await fixture();
+ const [global] = await db
+ .insert(schema.notificationTable)
+ .values({
+ userId: member.user.id,
+ title: "Integration alert",
+ })
+ .returning();
+ for (const workspaceId of [member.workspace.id, other.workspace.id]) {
+ const response = await app.request(
+ `/api/notification?workspaceId=${workspaceId}`,
+ );
+ expect(await response.json()).toEqual(
+ expect.arrayContaining([expect.objectContaining({ id: global.id })]),
+ );
+ }
+ await app.request(
+ `/api/notification/read-all?workspaceId=${member.workspace.id}`,
+ { method: "PATCH" },
+ );
+ expect(
+ (await db.select().from(schema.notificationTable)).find(
+ (n) => n.id === global.id,
+ )?.isRead,
+ ).toBe(true);
+ await app.request(
+ `/api/notification/clear-all?workspaceId=${other.workspace.id}`,
+ { method: "DELETE" },
+ );
+ expect(
+ (await db.select().from(schema.notificationTable)).some(
+ (n) => n.id === global.id,
+ ),
+ ).toBe(false);
+ });
+
it("keeps the unscoped API compatible and rejects empty workspace filters", async () => {
const { local, workspace, foreign, app } = await fixture();
const response = await app.request("/api/notification");