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

fix: Recreated CE-1054 directly on the Orca release avoiding the rebase. #667

Merged
merged 9 commits into from
Sep 27, 2024
1 change: 1 addition & 0 deletions backend/src/types/models/code-tables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const AvailableCodeTables = [
"non-compliance",
"sector",
"schedule",
"schedule-sector-type",
"decision-type",
"team",
"complaint-method-received-codes",
Expand Down
6 changes: 6 additions & 0 deletions backend/src/types/models/code-tables/schedule-sector-xref.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BaseCodeTable } from "./code-table";

export interface ScheduleSectorXref extends BaseCodeTable {
schedule: string;
sector: string;
}
20 changes: 20 additions & 0 deletions backend/src/v1/code-table/code-table.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { TeamCode } from "../team_code/entities/team_code.entity";
import { TeamType } from "src/types/models/code-tables/team-type";
import { CompMthdRecvCdAgcyCdXref } from "../comp_mthd_recv_cd_agcy_cd_xref/entities/comp_mthd_recv_cd_agcy_cd_xref";
import { ComplaintMethodReceivedType } from "src/types/models/code-tables/complaint-method-received-type";
import { ScheduleSectorXref } from "src/types/models/code-tables/schedule-sector-xref";

@Injectable()
export class CodeTableService {
Expand Down Expand Up @@ -589,6 +590,25 @@ export class CodeTableService {
);
return results;
}
case "schedule-sector-type": {
const { data } = await get(token, {
query: "{scheduleSectorXrefs{scheduleCode sectorCode shortDescription longDescription activeIndicator}}",
});
const results = data.scheduleSectorXrefs.map(
({ sectorCode, scheduleCode, shortDescription, longDescription, activeIndicator: isActive }) => {
const table: ScheduleSectorXref = {
schedule: scheduleCode,
sector: sectorCode,
shortDescription,
longDescription,
displayOrder: 1,
isActive,
};
return table;
},
);
return results;
}
case "discharge": {
const { data } = await get(token, {
query: "{ dischargeCodes { dischargeCode shortDescription longDescription displayOrder activeIndicator} }",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
selectSectorDropdown,
selectScheduleDropdown,
selectDecisionTypeDropdown,
selectScheduleSectorXref,
} from "../../../../../../store/reducers/code-table-selectors";
import { selectLeadAgencyDropdown } from "../../../../../../store/reducers/code-table";
import { Decision } from "../../../../../../types/app/case-files/ceeb/decision/decision";
Expand Down Expand Up @@ -76,6 +77,7 @@ export const DecisionForm: FC<props> = ({
const leadAgencyOptions = useAppSelector(selectLeadAgencyDropdown);
const { ownedByAgencyCode } = useAppSelector(selectComplaintCallerInformation);
const officerOptions = useAppSelector(selectOfficersByAgencyDropdown(ownedByAgencyCode?.agency));
const scheduleSectorType = useAppSelector(selectScheduleSectorXref);

//-- error messgaes
const [scheduleErrorMessage, setScheduleErrorMessage] = useState("");
Expand All @@ -90,7 +92,7 @@ export const DecisionForm: FC<props> = ({

//-- component data
// eslint-disable-line no-console, max-len
const [data, applyData] = useState<Decision>({
const [data, setData] = useState<Decision>({
schedule,
sector,
discharge,
Expand All @@ -103,17 +105,29 @@ export const DecisionForm: FC<props> = ({
actionTakenDate,
});

const [sectorList, setSectorList] = useState<Array<Option>>();

useEffect(() => {
if (officerAssigned) {
applyData({ ...data, assignedTo: officerAssigned });
setData({ ...data, assignedTo: officerAssigned });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [officerAssigned]);

useEffect(() => {
if (sector && schedule) {
let options = scheduleSectorType.filter((item) => item.schedule === schedule).map(item => {
const record: Option = { label: item.longDescription, value: item.sector };
return record
});
setSectorList(options);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [officerAssigned]);
//-- update the decision state by property
const updateModel = (property: string, value: string | Date | undefined) => {
const model = { ...data, [property]: value };
applyData(model);
setData(model);
};

const getValue = (property: string): Option | undefined | null => {
Expand Down Expand Up @@ -181,11 +195,21 @@ export const DecisionForm: FC<props> = ({
updateModel("actionTakenDate", date);
};

const handleScheduleChange = (schedule: string) => {
let options = scheduleSectorType.filter((item) => item.schedule === schedule).map(item => {
const record: Option = { label: item.longDescription, value: item.sector };
return record
});
const model = { ...data, sector: "", schedule: schedule };
setData(model);
setSectorList(options);
};

const handleActionTakenChange = (value: string) => {
//-- if the action taken changes make sure to clear the
//-- lead agency and inspection number
const update = { ...data, actionTaken: value, leadAgency: undefined, inspectionNumber: undefined };
applyData(update);
setData(update);
};

const handleCancelButtonClick = () => {
Expand All @@ -198,7 +222,7 @@ export const DecisionForm: FC<props> = ({
description: "Your changes will be lost.",
cancelConfirmed: () => {
//-- reset the form to its original state
applyData({
setData({
schedule,
sector,
discharge,
Expand Down Expand Up @@ -357,7 +381,9 @@ export const DecisionForm: FC<props> = ({
errorMessage={scheduleErrorMessage}
placeholder="Select "
onChange={(evt) => {
updateModel("schedule", evt?.value);
if (evt?.value) {
handleScheduleChange(evt.value);
}
}}
value={getValue("schedule")}
/>
Expand All @@ -373,7 +399,7 @@ export const DecisionForm: FC<props> = ({
id="outcome-decision-sector-category"
className="comp-details-input"
classNamePrefix="comp-select"
options={sectorsOptions}
options={sectorList}
enableValidation={true}
errorMessage={sectorErrorMessage}
placeholder="Select "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const DecisionItem: FC<props> = ({
const nonComplianceOptions = useAppSelector(selectNonComplianceDropdown);
const sectorsOptions = useAppSelector(selectSectorDropdown);
const schedulesOptions = useAppSelector(selectScheduleDropdown);
const scheduleSectorsOptions = useAppSelector(selectSectorDropdown);
const decisionTypeOptions = useAppSelector(selectDecisionTypeDropdown);
const agencyOptions = useAppSelector(selectLeadAgencyDropdown);
const officerOptions = useAppSelector(selectOfficersDropdown(true));
Expand All @@ -62,7 +63,14 @@ export const DecisionItem: FC<props> = ({
result = sectorsOptions.find((item) => item.value === sector);
break;
}

case "schedule-sector": {
result = scheduleSectorsOptions.find((item) => item.value === sector);
break;
}
case "schedule-sector-type": {
result = scheduleSectorsOptions.find((item) => item.value === sector);
break;
}
case "discharge": {
result = dischargesOptions.find((item) => item.value === discharge);
break;
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app/constants/code-table-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const CODE_TABLE_TYPES = {
TEAM: "team",
COMPLAINT_METHOD_RECEIVED: "complaint-method-received-codes",
LEAD_AGENCY: "lead-agency",
SCHEDULE_SECTOR: "schedule-sector",
SCHEDULE_SECTOR_TYPE: "schedule-sector-type",

// ORGANIZATION_UNIT_TYPE: "organization-unit-type",
// ORGANIZATION_UNIT: "organization-unit",
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app/store/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { AddTeamCode } from "./migrations/migration-14";
import { Decision } from "./migrations/migration-15";
import { AddComplaintMethodReceivedCodes } from "./migrations/migration-16";
import { AddLeadAgencyCode } from "./migrations/migration-17";
import { AddScheduleSectorTypes } from "./migrations/migration-18";

const BaseMigration = {
0: (state: any) => {
Expand Down Expand Up @@ -42,6 +43,7 @@ migration = {
...Decision,
...AddComplaintMethodReceivedCodes,
...AddLeadAgencyCode,
...AddScheduleSectorTypes,
};

export default migration;
12 changes: 12 additions & 0 deletions frontend/src/app/store/migrations/migration-18.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//Add Schedule Sector Type Codes in code table
export const AddScheduleSectorTypes = {
18: (state: any) => {
return {
...state,
codeTables: {
...state.codeTables,
"schedule-sector-type": [],
},
};
},
};
7 changes: 7 additions & 0 deletions frontend/src/app/store/reducers/code-table-selectors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RootState } from "../store";
import Option from "../../types/app/option";
import { ScheduleSectorXref } from "../../types/app/code-tables/schedule-sector-xref";

export const selectDischargeDropdown = (state: RootState): Array<Option> => {
const {
Expand Down Expand Up @@ -37,6 +38,12 @@ export const selectSectorDropdown = (state: RootState): Array<Option> => {
return data;
};

export const selectScheduleSectorXref = (state: RootState): Array<ScheduleSectorXref> => {
const {
codeTables: { "schedule-sector-type": scheduleSectorType },
} = state;
return scheduleSectorType;
};
export const selectScheduleDropdown = (state: RootState): Array<Option> => {
const {
codeTables: { schedule: items },
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/app/store/reducers/code-table-thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Sector } from "../../types/app/code-tables/sector";
import { AppThunk } from "../store";
import { setCodeTable } from "./code-table";
import { DecisionType } from "../../types/app/code-tables/decision-type";
import { ScheduleSectorXref } from "../../types/app/code-tables/schedule-sector-xref";

export const fetchDischargeTypes = (): AppThunk => async (dispatch) => {
const parameters = generateApiParameters(`${config.API_BASE_URL}/v1/code-table/${CODE_TABLE_TYPES.DISCHARGE}`);
Expand Down Expand Up @@ -39,7 +40,17 @@ export const fetchSectorTypes = (): AppThunk => async (dispatch) => {
dispatch(setCodeTable(payload));
}
};
export const fetchScheduleSectorTypes = (): AppThunk => async (dispatch) => {
const parameters = generateApiParameters(
`${config.API_BASE_URL}/v1/code-table/${CODE_TABLE_TYPES.SCHEDULE_SECTOR_TYPE}`,
);

const response = await get<Array<ScheduleSectorXref>>(dispatch, parameters);
if (response && from(response).any()) {
const payload = { key: CODE_TABLE_TYPES.SCHEDULE_SECTOR_TYPE, data: response };
dispatch(setCodeTable(payload));
}
};
export const fetchScheduleTypes = (): AppThunk => async (dispatch) => {
const parameters = generateApiParameters(`${config.API_BASE_URL}/v1/code-table/${CODE_TABLE_TYPES.SCHEDULE}`);

Expand Down
8 changes: 8 additions & 0 deletions frontend/src/app/store/reducers/code-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
fetchSectorTypes,
fetchScheduleTypes,
fetchCEEBDecisionTypes,
fetchScheduleSectorTypes,
} from "./code-table-thunks";
import { TeamType } from "../../types/app/code-tables/team";

Expand Down Expand Up @@ -75,6 +76,8 @@ const initialState: CodeTableState = {
sector: [],
schedule: [],
"decision-type": [],
scheduleSector: [],
"schedule-sector-type": [],
team: [],
"complaint-method-received-codes": [],
"lead-agency": [],
Expand Down Expand Up @@ -135,6 +138,7 @@ export const fetchAllCodeTables = (): AppThunk => async (dispatch) => {
sector,
schedule,
"decision-type": decisionType,
"schedule-sector-type": scheduleSectorType,
team,
"complaint-method-received-codes": complaintMethodReceived,
"lead-agency": leadAgency,
Expand Down Expand Up @@ -243,6 +247,9 @@ export const fetchAllCodeTables = (): AppThunk => async (dispatch) => {
if (!from(schedule).any()) {
dispatch(fetchScheduleTypes());
}
if (!from(scheduleSectorType).any()) {
dispatch(fetchScheduleSectorTypes());
}
if (!from(decisionType).any()) {
dispatch(fetchCEEBDecisionTypes());
}
Expand Down Expand Up @@ -298,6 +305,7 @@ export const fetchCaseCodeTables = (): AppThunk => async (dispatch) => {
dispatch(fetchSectorTypes());
dispatch(fetchScheduleTypes());
dispatch(fetchCEEBDecisionTypes());
dispatch(fetchScheduleSectorTypes());
dispatch(fetchLeadAgencies());
} catch (error) {
console.error(error);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BaseCodeTable } from "./base-code-table";

export interface ScheduleSectorXref extends BaseCodeTable {
schedule: string;
sector: string;
}
4 changes: 4 additions & 0 deletions frontend/src/app/types/code-tables/schedule-sector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface ScheduleSector {
schedule: string;
sector: string;
}
3 changes: 3 additions & 0 deletions frontend/src/app/types/state/code-table-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { Schedule } from "../app/code-tables/schedule";
import { DecisionType } from "../app/code-tables/decision-type";
import { TeamType } from "../app/code-tables/team";
import { ComplaintMethodReceivedType } from "../app/code-tables/complaint-method-received-type";
import { ScheduleSectorXref } from "../app/code-tables/schedule-sector-xref";

export interface CodeTableState {
[key: string]:
Expand Down Expand Up @@ -70,6 +71,7 @@ export interface CodeTableState {
| Array<Sector>
| Array<Schedule>
| Array<GirType>
| Array<ScheduleSectorXref>
| Array<ComplaintMethodReceivedType>
| Array<DecisionType>
| Array<TeamType>;
Expand Down Expand Up @@ -104,6 +106,7 @@ export interface CodeTableState {
"non-compliance": Array<NonCompliance>;
sector: Array<Sector>;
schedule: Array<Schedule>;
"schedule-sector-type": Array<ScheduleSectorXref>;
"decision-type": Array<DecisionType>;
team: Array<TeamType>;
"complaint-method-received-codes": Array<ComplaintMethodReceivedType>;
Expand Down
Loading