Skip to content

Commit

Permalink
Merge branch 'release/0.6.12' into CE-1336
Browse files Browse the repository at this point in the history
  • Loading branch information
nayr974 authored Jan 10, 2025
2 parents e57bba7 + 801ece5 commit 0f842f4
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 33 deletions.
2 changes: 2 additions & 0 deletions frontend/cypress/e2e/complaint-filters-ceeb.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ describe("Verify CEEB specific search filters work", () => {
cy.get("#comp-filter-btn").should("exist").click({ force: true });
cy.selectItemById("action-taken-select-id", actionTaken);
cy.waitForSpinner();
cy.clearFilterById("comp-officer-filter");
cy.waitForSpinner();
cy.get(`#${complaintWithActionTakenID}`).should("exist");
});
});
44 changes: 25 additions & 19 deletions frontend/src/app/components/containers/complaints/complaints.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
selectActiveTab,
selectActiveComplaintsViewType,
setActiveComplaintsViewType,
selectDefaultRegion,
} from "../../../store/reducers/app";

import { ComplaintMapWithServerSideClustering } from "./complaint-map-with-server-side-clustering";
Expand All @@ -28,6 +29,8 @@ import UserService from "@service/user-service";
import Roles from "@apptypes/app/roles";
import Option from "@apptypes/app/option";
import { resetComplaintSearchParameters, selectComplaintSearchParameters } from "@/app/store/reducers/complaints";
import { AgencyType } from "@/app/types/app/agency-types";
import { DropdownOption } from "@/app/types/app/drop-down-option";

type Props = {
defaultComplaintType: string;
Expand All @@ -45,7 +48,7 @@ export const Complaints: FC<Props> = ({ defaultComplaintType }) => {
if (!storedComplaintType) dispatch(setActiveTab(defaultComplaintType));
}, [storedComplaintType, dispatch, defaultComplaintType]);
const [complaintType, setComplaintType] = useState(
UserService.hasRole([Roles.CEEB]) ? CEEB_TYPES.ERS : (storedComplaintType ?? defaultComplaintType),
UserService.hasRole([Roles.CEEB]) ? CEEB_TYPES.ERS : storedComplaintType ?? defaultComplaintType,
);

const storedComplaintViewType = useAppSelector(selectActiveComplaintsViewType);
Expand All @@ -57,6 +60,7 @@ export const Complaints: FC<Props> = ({ defaultComplaintType }) => {
const currentOfficer = useAppSelector(selectCurrentOfficer(), shallowEqual);

const defaultZone = useAppSelector(selectDefaultZone);
const defaultRegion = useAppSelector(selectDefaultRegion);

//-- this is used to apply the search to the pager component
const storedSearchParams = useAppSelector(selectComplaintSearchParameters);
Expand All @@ -65,7 +69,7 @@ export const Complaints: FC<Props> = ({ defaultComplaintType }) => {
const handleComplaintTabChange = (complaintType: string) => {
setComplaintType(complaintType);
dispatch(resetComplaintSearchParameters());
let filters = getFilters(currentOfficer, defaultZone);
let filters = getFilters(currentOfficer, defaultZone, defaultRegion);

const payload: Array<ComplaintFilterPayload> = [
...Object.entries(filters).map(([filter, value]) => ({
Expand Down Expand Up @@ -180,14 +184,13 @@ export const Complaints: FC<Props> = ({ defaultComplaintType }) => {

export const ComplaintsWrapper: FC<Props> = ({ defaultComplaintType }) => {
const defaultZone = useAppSelector(selectDefaultZone, shallowEqual);
const defaultRegion = useAppSelector(selectDefaultRegion);
const currentOfficer = useAppSelector(selectCurrentOfficer(), shallowEqual);
const storedSearchParams = useAppSelector(selectComplaintSearchParameters);
// If the search is fresh, there are only 2 default parameters set. If more than 2 exist,
// this is not a fresh search as the search funtion itself sets more filters, even if blank.
const freshSearch = Object.keys(storedSearchParams).length === 2;
const defaultFilters = getFilters(currentOfficer, defaultZone);
const complaintFilters = freshSearch ? defaultFilters : storedSearchParams;

const complaintFilters = freshSearch ? getFilters(currentOfficer, defaultZone, defaultRegion) : storedSearchParams;
return (
<>
{currentOfficer && (
Expand All @@ -205,24 +208,27 @@ const getComplaintTypes = () => {
return UserService.hasRole(Roles.CEEB) ? CEEB_TYPES : COMPLAINT_TYPES;
};

const getFilters = (currentOfficer: any, defaultZone: any) => {
const getFilters = (currentOfficer: any, defaultZone: DropdownOption | null, defaultRegion: DropdownOption | null) => {
let filters: any = {};

if (UserService.hasRole([Roles.CEEB]) && !UserService.hasRole([Roles.CEEB_COMPLIANCE_COORDINATOR])) {
if (currentOfficer) {
let {
person: { firstName, lastName, id },
} = currentOfficer;
const officer = { label: `${lastName}, ${firstName}`, value: id };

filters = { ...filters, officer };
}
// Province-wide role defaults to only "Open" so skip the other checks
if (UserService.hasRole(Roles.PROVINCE_WIDE)) {
return filters;
}

if (UserService.hasRole([Roles.CEEB, Roles.CEEB_COMPLIANCE_COORDINATOR])) {
// No additional filters needed, default will apply
} else if (defaultZone) {
filters = { ...filters, zone: defaultZone };
const userAgency = UserService.getUserAgency();
if (userAgency === AgencyType.COS) {
if (UserService.hasRole(Roles.INSPECTOR)) {
filters = { ...filters, region: defaultRegion };
} else {
filters = { ...filters, zone: defaultZone };
}
} else if (currentOfficer && !UserService.hasRole(Roles.CEEB_COMPLIANCE_COORDINATOR)) {
const {
person: { firstName, lastName, id },
} = currentOfficer;
const officer = { label: `${lastName}, ${firstName}`, value: id };
filters = { ...filters, officer };
}

return filters;
Expand Down
22 changes: 14 additions & 8 deletions frontend/src/app/components/containers/layout/side-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,26 @@ export const SideBar: FC = () => {
name: "Complaints",
icon: "bi bi-file-earmark-medical",
route: "/complaints",
roles: [Roles.COS_OFFICER, Roles.CEEB],
},
{
id: "create-complaints-link",
name: "Create Complaint",
icon: "bi bi-plus-circle",
route: "complaint/createComplaint",
roles: [Roles.COS_OFFICER, Roles.CEEB],
},
{
id: "zone-at-a-glance-link",
name: "Zone at a Glance",
icon: "bi bi-buildings",
route: "/zone/at-a-glance",
roles: [Roles.COS_OFFICER],
excludedRoles: [Roles.CEEB, Roles.PROVINCE_WIDE],
},
{
id: "user-management",
name: "User Administration",
icon: "bi bi-people",
route: "/admin/user",
roles: [Roles.TEMPORARY_TEST_ADMIN],
requiredRoles: [Roles.TEMPORARY_TEST_ADMIN],
},
];

Expand Down Expand Up @@ -110,10 +108,18 @@ export const SideBar: FC = () => {
{/* <!-- menu items for the organization --> */}
<ul className="nav nav-pills flex-column mb-auto comp-sidenav-list">
{menueItems.map((item, idx) => {
const authorizeMenuView = item.roles.some((role) => UserService.hasRole(role));
if (authorizeMenuView) {
return renderSideBarMenuItem(idx, item);
} else return null;
// Check if the user has an excluded role (e.g. hide ZAG)
if (item.excludedRoles && UserService.hasRole(item.excludedRoles)) {
return null; // Exclude this item if the user has an excluded role
}

// Check if the item has required roles and if the user has the required role
if (item.requiredRoles && !UserService.hasRole(item.requiredRoles)) {
return null; // Exclude this item if the user does not have the required role
}

// If neither excludedRoles nor requiredRoles conditions apply, render the item
return renderSideBarMenuItem(idx, item);
})}
</ul>
<div
Expand Down
8 changes: 3 additions & 5 deletions frontend/src/app/providers/complaint-filter-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let initialState: ComplaintFilters = {
outcomeAnimalEndDate: undefined,
};

const mapFilters = (complaintFilters: Partial<ComplaintFilters>) => {
const convertFilterNames = (complaintFilters: Partial<ComplaintFilters>) => {
/**
* This funtion takes a partial set of filters in the shape of the ComplaintSearchParameters from
* the store, and maps them into the initial state for this provider. This enables the search page
Expand Down Expand Up @@ -119,11 +119,9 @@ const ComplaintFilterContext = createContext<ComplaintFilterContextType>({
const ComplaintFilterProvider: FC<ProviderProps> = ({ children, freshSearch, complaintFilters }) => {
let startingState = { ...initialState };
if (freshSearch) {
startingState = complaintFilters.zone
? { ...startingState, status: { value: "OPEN", label: "Open" }, zone: complaintFilters.zone }
: { ...startingState, status: { value: "OPEN", label: "Open" } };
startingState = { ...startingState, ...complaintFilters, status: { value: "OPEN", label: "Open" } };
} else {
const activeFilters = mapFilters(complaintFilters);
const activeFilters = convertFilterNames(complaintFilters);
startingState = { ...startingState, ...activeFilters };
}

Expand Down
13 changes: 13 additions & 0 deletions frontend/src/app/store/reducers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ export const selectDefaultZone = (state: RootState): DropdownOption | null => {
return value && label ? { value, label } : null;
};

export const selectDefaultRegion = (state: RootState): DropdownOption | null => {
const {
profile: { region: value, regionDescription: label },
} = state.app;

return value && label ? { value, label } : null;
};

export const selectModalOpenState = (state: RootState): boolean => {
const { app } = state;
return app.modalIsOpen;
Expand Down Expand Up @@ -366,6 +374,7 @@ export const getTokenProfile = (): AppThunk => async (dispatch) => {

let office = "";
let region = "";
let regionDescription = "";
let zone = "";
let zoneDescription = "";
let agency = "";
Expand All @@ -380,6 +389,7 @@ export const getTokenProfile = (): AppThunk => async (dispatch) => {

office = unit.office_location_code;
region = unit.region_code;
regionDescription = unit.region_name;
zone = unit.zone_code;
zoneDescription = unit.zone_name;
agency = agencyCode.agency_code;
Expand All @@ -402,6 +412,7 @@ export const getTokenProfile = (): AppThunk => async (dispatch) => {
idir_username: idir_username,
office: office,
region: region,
regionDescription: regionDescription,
zone: zone,
zoneDescription: zoneDescription,
agency,
Expand Down Expand Up @@ -537,6 +548,7 @@ const initialState: AppState = {
idir_username: "",
office: "",
region: "",
regionDescription: "",
zone: "",
zoneDescription: "",
agency: "",
Expand Down Expand Up @@ -592,6 +604,7 @@ const reducer = (state: AppState = initialState, action: any): AppState => {
idir_username: payload.idir_username,
office: payload.office,
region: payload.region,
regionDescription: payload.regionDescription,
zone: payload.zone,
zoneDescription: payload.zoneDescription,
agency: payload.agency,
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/app/types/app/menu-item.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Roles from "@/app/types/app/roles";

export default interface MenuItem {
id?: string;
name: string;
icon: string;
route?: string;
roles: Array<string>;
excludedRoles?: Array<Roles>;
requiredRoles?: Array<Roles>;
}
1 change: 1 addition & 0 deletions frontend/src/app/types/app/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default interface Profile {
idir_username: string;
office: string;
region: string;
regionDescription: string;
zone: string;
zoneDescription: string;
agency: string;
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app/types/app/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ enum Roles {
COS_OFFICER = "COS Officer",
TEMPORARY_TEST_ADMIN = "TEMPORARY_TEST_ADMIN",
READ_ONLY = "READ ONLY",
INSPECTOR = "Inspector",
PROVINCE_WIDE = "Province-wide",
}

export default Roles;

0 comments on commit 0f842f4

Please sign in to comment.