diff --git a/backend/src/v1/complaint/complaint.service.ts b/backend/src/v1/complaint/complaint.service.ts index d3e36eef1..7216db94d 100644 --- a/backend/src/v1/complaint/complaint.service.ts +++ b/backend/src/v1/complaint/complaint.service.ts @@ -434,8 +434,28 @@ export class ComplaintService { query: string, token: string, ): Promise> { + let caseSearchData = []; + if (complaintType === "ERS") { + // Search CM for any case files that may match based on authorization id + const { data, errors } = await get(token, { + query: `{getCasesFilesBySearchString (searchString: "${query}") + { + leadIdentifier, + caseIdentifier + } + }`, + }); + + if (errors) { + this.logger.error("GraphQL errors:", errors); + throw new Error("GraphQL errors occurred"); + } + + caseSearchData = data.getCasesFilesBySearchString; + } + builder.andWhere( - new Brackets(async (qb) => { + new Brackets((qb) => { qb.orWhere("complaint.complaint_identifier ILIKE :query", { query: `%${query}%`, }); @@ -502,23 +522,6 @@ export class ComplaintService { switch (complaintType) { case "ERS": { - // Search CM for any case files that may match based on authorization id - const { data, errors } = await get(token, { - query: `{getCasesFilesBySearchString (searchString: "${query}") - { - leadIdentifier, - caseIdentifier - } - }`, - }); - - if (errors) { - this.logger.error("GraphQL errors:", errors); - throw new Error("GraphQL errors occurred"); - } - - const caseSearchData = data.getCasesFilesBySearchString; - if (caseSearchData.length > 0) { qb.orWhere("complaint.complaint_identifier IN(:...complaint_identifiers)", { complaint_identifiers: caseSearchData.map((caseData) => caseData.leadIdentifier), @@ -1133,16 +1136,16 @@ export class ComplaintService { const includeCosOrganization: boolean = Boolean(query || filters.community || filters.zone || filters.region); let builder = this._generateMapQueryBuilder(complaintType, includeCosOrganization); - //-- apply search - if (query) { - builder = await this._applySearch(builder, complaintType, query, token); - } - //-- apply filters if used if (Object.keys(filters).length !== 0) { builder = this._applyFilters(builder, filters as ComplaintFilterParameters, complaintType); } + //-- apply search + if (query) { + builder = await this._applySearch(builder, complaintType, query, token); + } + //-- only return complaints for the agency the user is associated with const agency = hasCEEBRole ? "EPO" : (await this._getAgencyByUser()).agency_code; agency && builder.andWhere("complaint.owned_by_agency_code.agency_code = :agency", { agency }); diff --git a/backend/src/v1/officer/officer.service.ts b/backend/src/v1/officer/officer.service.ts index df0180621..b9ad26c4b 100644 --- a/backend/src/v1/officer/officer.service.ts +++ b/backend/src/v1/officer/officer.service.ts @@ -34,8 +34,8 @@ export class OfficerService { .leftJoinAndSelect("officer.office_guid", "office") .leftJoinAndSelect("officer.person_guid", "person") .leftJoinAndSelect("office.agency_code", "agency") - // This view is slow, no need to join and select for the properties that are mapped in this call - //.leftJoinAndSelect("office.cos_geo_org_unit", "cos_geo_org_unit") + // This view is slow :( + .leftJoinAndSelect("office.cos_geo_org_unit", "cos_geo_org_unit") .leftJoinAndSelect("office.agency_code", "agency_code") .orderBy("person.last_name", "ASC") .getMany(); diff --git a/frontend/src/app/components/containers/complaints/complaint-filter.tsx b/frontend/src/app/components/containers/complaints/complaint-filter.tsx index 722fe4f15..82de291e2 100644 --- a/frontend/src/app/components/containers/complaints/complaint-filter.tsx +++ b/frontend/src/app/components/containers/complaints/complaint-filter.tsx @@ -77,6 +77,7 @@ export const ComplaintFilter: FC = ({ type }) => { const setFilter = useCallback( (name: string, value?: Option | Date | null) => { let payload: ComplaintFilterPayload = { filter: name, value }; + dispatch(updateFilter(payload)); }, [dispatch], diff --git a/frontend/src/app/components/containers/complaints/complaint-map-with-server-side-clustering.tsx b/frontend/src/app/components/containers/complaints/complaint-map-with-server-side-clustering.tsx index 4e4a65de4..aa43457d6 100644 --- a/frontend/src/app/components/containers/complaints/complaint-map-with-server-side-clustering.tsx +++ b/frontend/src/app/components/containers/complaints/complaint-map-with-server-side-clustering.tsx @@ -7,7 +7,7 @@ import { ComplaintRequestPayload } from "@/app/types/complaints/complaint-filter import LeafletMapWithServerSideClustering from "@components/mapping/leaflet-map-with-server-side-clustering"; import { generateApiParameters, get } from "@common/api"; import config from "@/config"; -import { setMappedComplaintsCount } from "@/app/store/reducers/complaints"; +import { setComplaint, setComplaintSearchParameters, setMappedComplaintsCount } from "@/app/store/reducers/complaints"; type Props = { type: string; @@ -17,8 +17,11 @@ type Props = { export const generateMapComplaintRequestPayload = ( complaintType: string, filters: ComplaintFilters, + searchQuery: string, ): ComplaintRequestPayload => { const { + sortColumn, + sortOrder, region, zone, community, @@ -37,8 +40,8 @@ export const generateMapComplaintRequestPayload = ( } = filters; let common = { - sortColumn: "", // sort or order has no bearing on map data - sortOrder: "", // sort or order has no bearing on map data + sortColumn: sortColumn, + sortOrder: sortOrder, regionCodeFilter: region, zoneCodeFilter: zone, areaCodeFilter: community, @@ -49,6 +52,7 @@ export const generateMapComplaintRequestPayload = ( actionTakenFilter: actionTaken, outcomeAnimalStartDateFilter: outcomeAnimalStartDate, outcomeAnimalEndDateFilter: outcomeAnimalEndDate, + query: searchQuery, }; switch (complaintType) { @@ -96,7 +100,9 @@ export const ComplaintMapWithServerSideClustering: FC = ({ type, searchQu }, ) => { setLoadingMapData(true); - let payload = generateMapComplaintRequestPayload(type, filters); + let payload = generateMapComplaintRequestPayload(type, filters, searchQuery); + dispatch(setComplaint(null)); + dispatch(setComplaintSearchParameters(payload)); let parms: any = { bbox: bbox ? `${bbox.west},${bbox.south},${bbox.east},${bbox.north}` : undefined, // If the bbox is not provided, return all complaint clusters diff --git a/frontend/src/app/components/mapping/complaint-summary-popup.tsx b/frontend/src/app/components/mapping/complaint-summary-popup.tsx index a36212939..db68f9558 100644 --- a/frontend/src/app/components/mapping/complaint-summary-popup.tsx +++ b/frontend/src/app/components/mapping/complaint-summary-popup.tsx @@ -5,6 +5,7 @@ import { ComplaintDetails } from "@apptypes/complaints/details/complaint-details import { applyStatusClass, formatDate } from "@common/methods"; import { Badge, Button } from "react-bootstrap"; import { Popup } from "react-leaflet"; +import { useNavigate } from "react-router-dom"; interface Props { complaint_identifier: string; @@ -12,6 +13,7 @@ interface Props { } export const ComplaintSummaryPopup: FC = ({ complaint_identifier, complaintType }) => { + const navigate = useNavigate(); const { officerAssigned, natureOfComplaint, species, violationType, loggedDate, status, girType } = useAppSelector( selectComplaintHeader(complaintType), ); @@ -77,7 +79,7 @@ export const ComplaintSummaryPopup: FC = ({ complaint_identifier, complai size="sm" className="comp-map-popup-details-btn" id="view-complaint-details-button-id" - href={`/complaint/${complaintType}/${complaint_identifier}`} + onClick={() => navigate(`/complaint/${complaintType}/${complaint_identifier}`)} > View Details