Skip to content

filter archived tasks by user uuid#3070

Open
salihudickson wants to merge 3 commits into
PostHog:mainfrom
salihudickson:fix/filter-archives
Open

filter archived tasks by user uuid#3070
salihudickson wants to merge 3 commits into
PostHog:mainfrom
salihudickson:fix/filter-archives

Conversation

@salihudickson

Copy link
Copy Markdown
Contributor

Problem

#2745

Changes

  • Added filtering for archived tasks based on user uuid

How did you test this?

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

@salihudickson salihudickson force-pushed the fix/filter-archives branch from 8e3c8a9 to ae2ee34 Compare July 1, 2026 22:21
@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "add tests" | Re-trigger Greptile

Comment on lines +35 to +41
return archivedTasks.reduce<ArchivedTaskWithDetails[]>((acc, archived) => {
const task = taskMap.get(archived.taskId) ?? null;
if (task?.created_by?.uuid === userId) {
acc.push({ archived, task });
}
return acc;
}, []);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 When userId is undefined (the optional parameter is omitted, or the user query hasn't resolved yet), the condition task?.created_by?.uuid === userId evaluates as task?.created_by?.uuid === undefined, which is true for any archived task whose corresponding task is missing from the map (null?.created_by?.uuid is undefined) or has no created_by — returning a wrong, non-empty subset instead of either all items or an empty list. This breaks the pre-existing "no filter" contract for callers that don't pass a userId, and causes the UI to briefly flash incorrect results while the user query is still loading.

Suggested change
return archivedTasks.reduce<ArchivedTaskWithDetails[]>((acc, archived) => {
const task = taskMap.get(archived.taskId) ?? null;
if (task?.created_by?.uuid === userId) {
acc.push({ archived, task });
}
return acc;
}, []);
return archivedTasks.reduce<ArchivedTaskWithDetails[]>((acc, archived) => {
const task = taskMap.get(archived.taskId) ?? null;
if (userId === undefined || task?.created_by?.uuid === userId) {
acc.push({ archived, task });
}
return acc;
}, []);

Comment on lines +62 to +79
describe("mergeArchivedWithTasks", () => {
it("returns only archived tasks owned by the requested user id", () => {
const archived = [
makeArchived("a", "2024-01-02T00:00:00.000Z"),
makeArchived("b", "2024-01-03T00:00:00.000Z"),
makeArchived("c", "2024-01-04T00:00:00.000Z"),
];

const tasks = [
makeTask("a", { created_by: { uuid: "user-1" } as Task["created_by"] }),
makeTask("b", { created_by: { uuid: "user-2" } as Task["created_by"] }),
makeTask("c", { created_by: { uuid: "user-1" } as Task["created_by"] }),
];

const result = mergeArchivedWithTasks(archived, tasks, "user-1");
expect(result.map((item) => item.archived.taskId)).toEqual(["a", "c"]);
});
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Missing parameterised coverage for userId = undefined

The team rule prefers parameterised tests. The existing single case tests the happy path, but the userId = undefined scenario (user query still loading, or userId omitted by a non-UI caller) is entirely untested. Adding cases for: undefined userId returning all items, a userId with zero matches, and an archived task whose id is absent from the task map would both document the intended contract and catch the present regression.

Context Used: Do not attempt to comment on incorrect alphabetica... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant