Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function useCommentTag(
apiPath: apiPathUser,
params: {
sortOrder: SortOrder.NewToOld,
filter: { role: UserRole.COORDINATOR },
role: UserRole.COORDINATOR,
},
staleTime: cacheTTL,
enabled: !!setNewCommentText,
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useGetQuery.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from "@tanstack/react-query";
import axios, { AxiosResponse } from "axios";
import { Lang, SortOrder } from "need4deed-sdk";
import { Lang, SortOrder, UserRole } from "need4deed-sdk";
import { useParams } from "next/navigation";
import { useEffect } from "react";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -44,6 +44,7 @@ interface Params {
limit?: number;
sortOrder?: SortOrder;
filter?: FilterParam;
role?: UserRole;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This bolts a one-off role?: UserRole field onto the shared, resource-agnostic Params interface used by ~30 useGetQuery call sites app-wide. The hook already has a generic mechanism for exactly this (filter?: FilterParam, a Record<string, unknown>), used elsewhere for arbitrary resource filters, e.g. filter: { status: OpportunityStatusType.NEW } in NewestVolunteers.tsx/NewestOpportunities.tsx/OpportunityListController.tsx/AgentListController.tsx.

role is only ever set here, at this one call site. Since be's userListQuerySchema has additionalProperties: false and expects role as a flat param rather than nested, could this instead flow through the generic filter path if getReducedFilter flattened it accordingly (e.g. treating filter entries as top-level query keys), rather than adding a domain-specific field to the shared interface? Otherwise this sets a precedent: the next resource that needs a one-off top-level param gets its own bespoke field added here too, and Params keeps growing with fields most callers never use.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

thanks @nadavosa for reviewing! Tbh I'm not sure if there's a clean solution to this cleanup problem you highlighted considering in the be it doesn't accept filter: {role } anymore.

The main blocker here is that if we try to handle this inside the hook by flattening the filter object, it actually breaks the other 30 call sites. For example, if a query passes { filter: { status: 'new', role: 'coordinator' } }, we would have to write complex logic inside the generic hook to pluck role out to the top level while leaving status nested inside the object so the be views don't break.

My reasoning for adding it to the shared interface was that UserRole is a core concept that we will probably need in the future. Plus, since it’s optional, it won't affect any existing callers if left undefined.

That said, if you have something in mind, I'd love to hear it

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

alternatively, the other solution would be to change it back to what it was in the be where role is nested within filter . Either way, the fe and be should be aligned

}
interface UseGetQuery {
apiPath: string;
Expand Down
Loading