Skip to content

Commit

Permalink
[MDS-5640] ESUP Modal Bugs (#2820)
Browse files Browse the repository at this point in the history
* make the actions a little closer to readable, pass a param to the esup form to hide the decision modal

* moved things around on the form to group like with like for better readability. Added an enum for how the form should be viewed and changed some state variables and useeffects to use that instead. Took out validateSelectOptions because infinite re-render. Added text for edit document mode. Hid back button when it should be hidden

* decision modal wasn't what I thought it was- rename enum value for better clarity. Put in feature flag to be very explicit about code thhat can be removed later. Saw some unused imports, deleted them

* remove Edit Documents from applications tab, and modify handlers to match desired flow more, bring up issuance modal so that Editing an application can lead to Issuing it and amendments will be issued

* simplify function call

* add logic in esup reducer to format with amendment data and fix document issue immediately. Change some logic in BE for when we close prior amendments. Ignore the amendment fields and guids in diff modal. Take out unused params from form and add popconfirm to the cancel button. Replace any logic in ExplosivesPermit to get amendment data with record values, tweak the initial values in some places so that we don't end up with is_closed = null, update orig system on amendments to Core, tell it when necessary that it's an amendment. Changed Edit action to Edit Draft to make it clear what they're doing, and fixed a minor gaffe from earlier where the view modal shows 'example' as the mines permit number

* give tests the data and props they need to pass. Fix a mis-named test suite.

* fix a can't get property of undefined error, a backwards ternary, and don't allow to delete any esups with amendments

* fix diff
  • Loading branch information
taraepp authored Nov 23, 2023
1 parent 79d0172 commit 721908a
Show file tree
Hide file tree
Showing 18 changed files with 623 additions and 506 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export interface IExplosivesPermit {
now_number: string;
closed_by: string;
explosives_permit_amendments: IExplosivesPermitAmendment[];
// does not include the initial record as amendment
amendment_count: number;
// starts at 0 for initial record
amendment_no: number;
isAmendment: boolean;
}

export interface IExplosivesPermitStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,17 @@ export const fetchExplosivesPermits = (
};

export const updateExplosivesPermit = (
mineGuid: string,
explosivesPermitGuid: string,
payload: Partial<IExplosivesPermit>,
generate_documents = false
): AppThunk<Promise<AxiosResponse<IExplosivesPermit>>> => (
dispatch
): Promise<AxiosResponse<IExplosivesPermit>> => {
const { mine_guid, explosives_permit_guid } = payload;
dispatch(request(reducerTypes.UPDATE_EXPLOSIVES_PERMIT));
dispatch(showLoading("modal"));
return CustomAxios()
.put(
ENVIRONMENT.apiUrl + API.EXPLOSIVES_PERMIT(mineGuid, explosivesPermitGuid),
ENVIRONMENT.apiUrl + API.EXPLOSIVES_PERMIT(mine_guid, explosives_permit_guid),
{ ...payload, generate_documents },
createRequestHeader()
)
Expand Down
20 changes: 19 additions & 1 deletion services/common/src/redux/reducers/explosivesPermitReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,27 @@ const initialState: IExplosivesPermitReducerState = {
export const explosivesPermitReducer = (state = initialState, action) => {
switch (action.type) {
case actionTypes.STORE_EXPLOSIVES_PERMITS:
const records = action.payload?.records ?? [];
const explosivesPermits = records.map((permit) => {
const amendment_count = permit.explosives_permit_amendments.length;
const amendments = permit.explosives_permit_amendments.map((a, index) => {
const documents = a.documents.map((d) => ({
...d,
explosives_permit_document_type_code: d.explosives_permit_amendment_document_type_code,
}));
return { ...a, documents, amendment_count, isAmendment: true, amendment_no: index + 1 };
});
return {
...permit,
explosives_permit_amendments: amendments ?? [],
amendment_count,
isAmendment: false,
amendment_no: 0,
};
});
return {
...state,
explosivesPermits: action.payload.records,
explosivesPermits,
};
default:
return state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@ def create_issued_permit():
return ExplosivesPermitAmendmentDocumentResource.generate_explosives_permit_document(
token, True, False, False)

permit_number = ExplosivesPermit.find_permit_number_by_explosives_permit_id(explosives_permit_id)
# Close any previously open permit versions & amendments
ExplosivesPermit.update_permit_status(self.explosives_permit_id, True)
ExplosivesPermitAmendment.update_amendment_status_by_explosives_permit_id(self.explosives_permit_id, True, self.explosives_permit_amendment_guid)
if generate_documents:
create_permit_enclosed_letter()
create_issued_permit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,16 @@ def post(self, mine_guid):
data.get('now_application_guid'))
explosives_permit_amendment.save()

# Updating the previous amendments' is_closed status to True.
updated_columns = ExplosivesPermitAmendment.update_amendment_status_by_explosives_permit_id(
data.get('explosives_permit_id'), True,
explosives_permit_amendment.explosives_permit_amendment_guid)
# only update previous status if new amendment is ready to issue
is_draft = explosives_permit_amendment.application_status != 'APP'

if updated_columns == 0: #Explosive Permit status need to be updated.
ExplosivesPermit.update_permit_status(explosives_permit_amendment.explosives_permit_id, True)
if not is_draft:
# Updating the previous amendments' is_closed status to True.
updated_columns = ExplosivesPermitAmendment.update_amendment_status_by_explosives_permit_id(
data.get('explosives_permit_id'), True,
explosives_permit_amendment.explosives_permit_amendment_guid)

if updated_columns == 0: #Explosive Permit status need to be updated.
ExplosivesPermit.update_permit_status(explosives_permit_amendment.explosives_permit_id, True)

return explosives_permit_amendment, 201
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ const ExplosivesPermitDiffModal: FC<ExplosivesPermitDiffModalProps> = ({
(a, b) => a.explosives_permit_amendment_id - b.explosives_permit_amendment_id
);

const ignoredFields = ["explosives_permit_amendment_id", "explosives_permit_amendment_guid"];
const ignoredFields = [
"explosives_permit_amendment_id",
"explosives_permit_amendment_guid",
"issuing_inspector_party_guid",
"isAmendment",
"amendment_no",
];

const differences: IPermitDifferencesByAmendment = permitVersions.reduce(
(acc, currAmendment, i) => {
Expand Down
Loading

0 comments on commit 721908a

Please sign in to comment.