refactor(ui): build internal user options without a mutable seen set

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
shivam 2026-08-08 20:55:24 +00:00
parent 1eee8ce382
commit 4cc5cfc7c2
2 changed files with 26 additions and 9 deletions

View file

@ -215,6 +215,26 @@ describe("RequestLogsFilters", () => {
expect(set).toHaveBeenCalledWith(LOG_FILTER_IDS.USER_ID, "u-1");
});
it("offers a user repeated across page boundaries only once", async () => {
const bob = { user_id: "u-1", user_email: "bob@acme.com", user_alias: null };
vi.mocked(useInfiniteUsers).mockReturnValue({
...emptyInfiniteQuery,
data: {
pages: [
{ users: [bob], page: 1, page_size: 1, total: 2, total_pages: 2 },
{ users: [bob], page: 2, page_size: 1, total: 2, total_pages: 2 },
],
pageParams: [1, 2],
},
} as unknown as ReturnType<typeof useInfiniteUsers>);
const user = userEvent.setup();
renderFilters();
await user.click(await screen.findByPlaceholderText("Search a user by email"));
expect(await screen.findAllByText("bob@acme.com")).toHaveLength(1);
});
it("pushes the Internal User query to the server rather than filtering a preloaded list", async () => {
const user = userEvent.setup();
renderFilters();

View file

@ -204,15 +204,12 @@ function InternalUserFilterField({
);
const options = useMemo<SearchSelectOption[]>(() => {
const seen = new Set<string>();
return (data?.pages ?? []).flatMap((page) =>
page.users.flatMap((user) => {
if (!user.user_id || seen.has(user.user_id)) return [];
seen.add(user.user_id);
const name = user.user_email || user.user_alias || "";
return [{ label: name || user.user_id, value: user.user_id, sublabel: name === "" ? undefined : user.user_id }];
}),
);
const users = (data?.pages ?? []).flatMap((page) => page.users.filter((user) => user.user_id !== ""));
const byId = new Map(users.map((user) => [user.user_id, user] as const));
return [...byId.values()].map((user) => {
const name = user.user_email || user.user_alias || "";
return { label: name || user.user_id, value: user.user_id, sublabel: name === "" ? undefined : user.user_id };
});
}, [data]);
return (