Skip to content

Commit 872316f

Browse files
authored
[Comp-763] Fix complaints grid sort by project name (#666)
1 parent d1ada4b commit 872316f

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

compliance-api/src/compliance_api/services/complaint.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,13 @@ def _apply_complaints_sorting(query, args):
542542
sort_order = args.get("sort_order", "asc").lower()
543543

544544
# Handle project sorting with join to ProjectModel
545-
if sort_by == "project":
546-
# Join with ProjectModel to sort by project name
547-
query = query.outerjoin(
548-
ProjectModel, CaseFileModel.project_id == ProjectModel.id
549-
)
545+
if sort_by == "project_name":
546+
# Only join if ProjectModel isn't already joined
547+
if not any(isinstance(desc['entity'], type(ProjectModel))
548+
for desc in query.column_descriptions):
549+
query = query.outerjoin(
550+
ProjectModel, CaseFileModel.project_id == ProjectModel.id
551+
)
550552
sort_field = ProjectModel.name
551553
return query.order_by(
552554
sort_field.asc() if sort_order == "asc" else sort_field.desc()

compliance-web/src/components/App/Complaints/ComplaintsGrid/ComplaintsGridUtils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export const useComplaintsGridColumns = (
145145
},
146146
{
147147
accessorFn: (row) => row.case_file?.project?.name,
148-
id: "project",
148+
id: "project_name",
149149
header: "Project",
150150
filterVariant: "multi-select",
151151
filterSelectOptions:

0 commit comments

Comments
 (0)