Skip to content

Commit

Permalink
fix: Map Search Filters / Officers (#817)
Browse files Browse the repository at this point in the history
Co-authored-by: afwilcox <[email protected]>
  • Loading branch information
2 people authored and mikevespi committed Jan 2, 2025
1 parent def1ebc commit 394ddec
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
49 changes: 26 additions & 23 deletions backend/src/v1/complaint/complaint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,28 @@ export class ComplaintService {
query: string,
token: string,
): Promise<SelectQueryBuilder<complaintAlias>> {
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}%`,
});
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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 });
Expand Down
4 changes: 2 additions & 2 deletions backend/src/v1/officer/officer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const ComplaintFilter: FC<Props> = ({ type }) => {
const setFilter = useCallback(
(name: string, value?: Option | Date | null) => {
let payload: ComplaintFilterPayload = { filter: name, value };

dispatch(updateFilter(payload));
},
[dispatch],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,8 +17,11 @@ type Props = {
export const generateMapComplaintRequestPayload = (
complaintType: string,
filters: ComplaintFilters,
searchQuery: string,
): ComplaintRequestPayload => {
const {
sortColumn,
sortOrder,
region,
zone,
community,
Expand All @@ -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,
Expand All @@ -49,6 +52,7 @@ export const generateMapComplaintRequestPayload = (
actionTakenFilter: actionTaken,
outcomeAnimalStartDateFilter: outcomeAnimalStartDate,
outcomeAnimalEndDateFilter: outcomeAnimalEndDate,
query: searchQuery,
};

switch (complaintType) {
Expand Down Expand Up @@ -96,7 +100,9 @@ export const ComplaintMapWithServerSideClustering: FC<Props> = ({ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ 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;
complaintType: string;
}

export const ComplaintSummaryPopup: FC<Props> = ({ complaint_identifier, complaintType }) => {
const navigate = useNavigate();
const { officerAssigned, natureOfComplaint, species, violationType, loggedDate, status, girType } = useAppSelector(
selectComplaintHeader(complaintType),
);
Expand Down Expand Up @@ -77,7 +79,7 @@ export const ComplaintSummaryPopup: FC<Props> = ({ 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
</Button>
Expand Down

0 comments on commit 394ddec

Please sign in to comment.