Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CE-1044-Add-Method-complaint-was-received-as-a-filter-option-for-CEEB #678

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 @@ -10,4 +10,5 @@ export interface ComplaintFilterParameters {
incidentReportedEnd?: Date;
status?: string;
girTypeCode?: string;
complaintMethod?: string;
}
2 changes: 2 additions & 0 deletions backend/src/v1/complaint/complaint.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export class ComplaintController {
@Query() model: ComplaintSearchParameters,
@Request() req,
) {

const hasCEEBRole = hasRole(req, Role.CEEB);

return this.service.mapSearch(complaintType, model, hasCEEBRole);
}

Expand Down
9 changes: 9 additions & 0 deletions backend/src/v1/complaint/complaint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export class ComplaintService {
speciesCode,
violationCode,
girTypeCode,
complaintMethod,
}: ComplaintFilterParameters,
complaintType: COMPLAINT_TYPE,
): SelectQueryBuilder<complaintAlias> {
Expand Down Expand Up @@ -311,6 +312,11 @@ export class ComplaintService {
ViolationCode: violationCode,
});
}
if (complaintMethod) {
builder.andWhere("method_xref.complaint_method_received_code = :ComplaintMethod", {
ComplaintMethod: complaintMethod,
});
}
break;
}
case "GIR": {
Expand Down Expand Up @@ -971,6 +977,7 @@ export class ComplaintService {
});
}

//-- added this for consistency with search method
//-- return Waste and Pestivide complaints for CEEB users
if (hasCEEBRole && complaintType === "ERS") {
complaintBuilder.andWhere("violation_code.agency_code = :agency", { agency: "EPO" });
Expand Down Expand Up @@ -1003,6 +1010,8 @@ export class ComplaintService {
});
}


//-- added this for consistency with search method
//-- return Waste and Pestivide complaints for CEEB users
if (hasCEEBRole && complaintType === "ERS") {
unMappedBuilder.andWhere("violation_code.agency_code = :agency", { agency: "EPO" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const ComplaintFilterBar: FC<Props> = ({
natureOfComplaint,
violationType,
girType,
complaintMethod,
} = state;

const dateRangeLabel = (): string | undefined => {
Expand Down Expand Up @@ -209,6 +210,15 @@ export const ComplaintFilterBar: FC<Props> = ({
clear={removeFilter}
/>
)}

{hasFilter("complaintMethod") && (
<FilterButton
id="comp-complaint-method-filter"
label={complaintMethod?.label}
name="complaintMethod"
clear={removeFilter}
/>
)}
</div>
</div>
);
Expand Down
167 changes: 100 additions & 67 deletions frontend/src/app/components/containers/complaints/complaint-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
selectCascadedCommunity,
selectComplaintStatusWithPendingCodeDropdown,
selectGirTypeCodeDropdown,
selectComplaintReceivedMethodDropdown,
} from "../../../store/reducers/code-table";
import { selectOfficersDropdown } from "../../../store/reducers/officer";
import COMPLAINT_TYPES from "../../../types/app/complaint-types";
Expand Down Expand Up @@ -40,6 +41,7 @@ export const ComplaintFilter: FC<Props> = ({ type }) => {
startDate,
endDate,
girType,
complaintMethod,
},
dispatch,
} = useContext(ComplaintFilterContext);
Expand All @@ -59,6 +61,8 @@ export const ComplaintFilter: FC<Props> = ({ type }) => {
const zones = useAppSelector(selectCascadedZone(region?.value, zone?.value, community?.value));
const communities = useAppSelector(selectCascadedCommunity(region?.value, zone?.value, community?.value));

const complaintMethods = useAppSelector(selectComplaintReceivedMethodDropdown);

const activeFilters = useAppSelector(listActiveFilters());

const setFilter = useCallback(
Expand Down Expand Up @@ -112,98 +116,102 @@ export const ComplaintFilter: FC<Props> = ({ type }) => {
const renderComplaintFilters = (): JSX.Element => {
return (
<div className="comp-filter-container">
{COMPLAINT_TYPES.HWCR === type && activeFilters.showNatureComplaintFilter && activeFilters.showSpeciesFilter && ( // wildlife only filter
<>
<div id="comp-filter-nature-of-complaint-id">
<label htmlFor="nature-of-complaint-select-id">Nature of Complaint</label>
{COMPLAINT_TYPES.HWCR === type &&
activeFilters.showNatureComplaintFilter &&
activeFilters.showSpeciesFilter && ( // wildlife only filter
<>
<div id="comp-filter-nature-of-complaint-id">
<label htmlFor="nature-of-complaint-select-id">Nature of Complaint</label>
<div className="filter-select-padding">
<CompSelect
id="nature-of-complaint-select-id"
classNamePrefix="comp-select"
onChange={(option) => {
setFilter("natureOfComplaint", option);
}}
classNames={{
menu: () => "top-layer-select",
}}
options={natureOfComplaintTypes}
placeholder="Select"
enableValidation={false}
value={natureOfComplaint}
isClearable={true}
/>
</div>
</div>

<div id="comp-species-filter-id">
<label htmlFor="species-select-id">Species</label>
<div className="filter-select-padding">
<CompSelect
id="species-select-id"
classNamePrefix="comp-select"
onChange={(option) => {
setFilter("species", option);
}}
classNames={{
menu: () => "top-layer-select",
}}
options={speciesTypes}
placeholder="Select"
enableValidation={false}
value={species}
isClearable={true}
/>
</div>
</div>
</>
)}

{COMPLAINT_TYPES.ERS === type &&
activeFilters.showViolationFilter && ( // wildlife only filter
<div id="comp-filter-violation-id">
{/* <!-- violation types --> */}
<label htmlFor="violation-type-select-id">Violation Type</label>
<div className="filter-select-padding">
<CompSelect
id="nature-of-complaint-select-id"
id="violation-type-select-id"
classNamePrefix="comp-select"
onChange={(option) => {
setFilter("natureOfComplaint", option);
setFilter("violationType", option);
}}
classNames={{
menu: () => "top-layer-select",
}}
options={natureOfComplaintTypes}
options={violationTypes}
placeholder="Select"
enableValidation={false}
value={natureOfComplaint}
value={violationType}
isClearable={true}
/>
</div>
</div>
)}

<div id="comp-species-filter-id">
<label htmlFor="species-select-id">Species</label>
{COMPLAINT_TYPES.GIR === type &&
activeFilters.showGirTypeFilter && ( // GIR only filter
<div id="comp-filter-gir-id">
<label htmlFor="gir-type-select-id">Gir Type</label>
<div className="filter-select-padding">
<CompSelect
id="species-select-id"
id="gir-type-select-id"
classNamePrefix="comp-select"
onChange={(option) => {
setFilter("species", option);
setFilter("girType", option);
}}
classNames={{
menu: () => "top-layer-select",
}}
options={speciesTypes}
options={girTypes}
placeholder="Select"
enableValidation={false}
value={species}
value={girType}
isClearable={true}
/>
</div>
</div>
</>
)}

{COMPLAINT_TYPES.ERS === type && activeFilters.showViolationFilter && ( // wildlife only filter
<div id="comp-filter-violation-id">
{/* <!-- violation types --> */}
<label htmlFor="violation-type-select-id">Violation Type</label>
<div className="filter-select-padding">
<CompSelect
id="violation-type-select-id"
classNamePrefix="comp-select"
onChange={(option) => {
setFilter("violationType", option);
}}
classNames={{
menu: () => "top-layer-select",
}}
options={violationTypes}
placeholder="Select"
enableValidation={false}
value={violationType}
isClearable={true}
/>
</div>
</div>
)}

{COMPLAINT_TYPES.GIR === type && activeFilters.showGirTypeFilter && ( // GIR only filter
<div id="comp-filter-gir-id">
<label htmlFor="gir-type-select-id">Gir Type</label>
<div className="filter-select-padding">
<CompSelect
id="gir-type-select-id"
classNamePrefix="comp-select"
onChange={(option) => {
setFilter("girType", option);
}}
classNames={{
menu: () => "top-layer-select",
}}
options={girTypes}
placeholder="Select"
enableValidation={false}
value={girType}
isClearable={true}
/>
</div>
</div>
)}
)}

{activeFilters.showDateFilter && (
<div id="comp-filter-date-id">
Expand All @@ -216,8 +224,9 @@ export const ComplaintFilter: FC<Props> = ({ type }) => {
<div>
<button
aria-label="Previous Month"
className={`react-datepicker__navigation react-datepicker__navigation--previous ${customHeaderCount === 1 ? "datepicker-nav-hidden" : "datepicker-nav-visible"
}`}
className={`react-datepicker__navigation react-datepicker__navigation--previous ${
customHeaderCount === 1 ? "datepicker-nav-hidden" : "datepicker-nav-visible"
}`}
onClick={decreaseMonth}
>
<span
Expand All @@ -236,8 +245,9 @@ export const ComplaintFilter: FC<Props> = ({ type }) => {
</span>
<button
aria-label="Next Month"
className={`react-datepicker__navigation react-datepicker__navigation--next ${customHeaderCount === 1 ? "datepicker-nav-hidden" : "datepicker-nav-visible"
}`}
className={`react-datepicker__navigation react-datepicker__navigation--next ${
customHeaderCount === 1 ? "datepicker-nav-hidden" : "datepicker-nav-visible"
}`}
onClick={increaseMonth}
>
<span
Expand Down Expand Up @@ -289,6 +299,29 @@ export const ComplaintFilter: FC<Props> = ({ type }) => {
</div>
</div>
)}

{COMPLAINT_TYPES.ERS === type && activeFilters.showMethodFilter && (
<div id="comp-filter-complaint-method-id">
<label htmlFor="complaint-method-select-id">Complaint Method</label>
<div className="filter-select-padding">
<CompSelect
id="complaint-method-select-id"
classNamePrefix="comp-select"
onChange={(option) => {
setFilter("complaintMethod", option);
}}
classNames={{
menu: () => "top-layer-select",
}}
options={complaintMethods}
placeholder="Select"
enableValidation={false}
value={complaintMethod}
isClearable={true}
/>
</div>
</div>
)}
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const generateComplaintRequestPayload = (
natureOfComplaint,
violationType,
girType,
complaintMethod,
} = filters;

const common = {
Expand Down Expand Up @@ -78,6 +79,7 @@ export const generateComplaintRequestPayload = (
return {
...common,
violationFilter: violationType,
complaintMethodFilter: complaintMethod,
} as ComplaintRequestPayload;
case COMPLAINT_TYPES.HWCR:
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,19 @@ export const generateMapComplaintRequestPayload = (
sortKey: string,
sortDirection: string,
): ComplaintRequestPayload => {
const { region, zone, community, officer, startDate, endDate, status, species, natureOfComplaint, violationType } =
filters;
const {
region,
zone,
community,
officer,
startDate,
endDate,
status,
species,
natureOfComplaint,
violationType,
complaintMethod,
} = filters;

const common = {
sortColumn: sortKey,
Expand All @@ -44,6 +55,7 @@ export const generateMapComplaintRequestPayload = (
return {
...common,
violationFilter: violationType,
complaintMethodFilter: complaintMethod,
} as ComplaintRequestPayload;
case COMPLAINT_TYPES.HWCR:
default:
Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/providers/complaint-filter-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let initialState: ComplaintFilters = {
natureOfComplaint: null,
violationType: null,
filters: [],
complaintMethod: null,
};

const ComplaintFilterContext = createContext<ComplaintFilterContextType>({
Expand Down
Loading
Loading