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

[MDS-5792] status codes and banners #2984

Merged
merged 13 commits into from
Mar 6, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
INSERT INTO
mine_report_submission_status_code (
mine_report_submission_status_code,
description,
display_order,
active_ind,
create_user,
create_timestamp,
update_user,
update_timestamp
)
VALUES
(
'WTD',
'Withdrawn',
'50',
True,
'system-mds',
current_timestamp,
'system-mds',
current_timestamp
);
1 change: 1 addition & 0 deletions services/common/src/constants/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export enum MINE_REPORT_SUBMISSION_CODES {
ACC = "ACC",
INI = "INI",
NON = "NON",
WTD = "WTD",
}

export enum REPORT_TYPE_CODES {
Expand Down
1 change: 1 addition & 0 deletions services/common/src/constants/strings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,5 @@ export const MINE_REPORT_STATUS_HASH = {
[MINE_REPORT_SUBMISSION_CODES.ACC]: "Accepted",
[MINE_REPORT_SUBMISSION_CODES.INI]: "Received",
[MINE_REPORT_SUBMISSION_CODES.NON]: "Report Requested",
[MINE_REPORT_SUBMISSION_CODES.WTD]: "Withdrawn",
};
25 changes: 24 additions & 1 deletion services/common/src/redux/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { createNumberMask } from "redux-form-input-masks";
import moment from "moment-timezone";
import { reset } from "redux-form";
import { ItemMap } from "@mds/common";
import { IMineReportDefinition } from "@mds/common/interfaces";
import { IMineReportDefinition, IMineReportSubmission } from "@mds/common/interfaces";
import { MINE_REPORT_SUBMISSION_CODES } from "../..";

/**
* Helper function to clear redux form after submission
Expand Down Expand Up @@ -616,3 +617,25 @@ export const getHighestConsequence = (tsf) => {
? CONSEQUENCE_CLASSIFICATION_CODE_HASH[highestRankedDam.consequence_classification]
: CONSEQUENCE_CLASSIFICATION_CODE_HASH[tsf.consequence_classification_status_code];
};

export const getMineReportStatusDescription = (
statusCode: MINE_REPORT_SUBMISSION_CODES,
latestSubmission: IMineReportSubmission
) => {
const currentDate = moment().format("YYYY-MM-DD");
const MINE_REPORT_STATUS_DESCRIPTION_HASH = {
[MINE_REPORT_SUBMISSION_CODES.ACC]:
"The Ministry has reviewed the report, no more revision is required",
[MINE_REPORT_SUBMISSION_CODES.REC]:
"Ministry has received changes after requesting for more information. The revised information has not been reviewed.",
[MINE_REPORT_SUBMISSION_CODES.REQ]: `Requesting more information from the proponent through MineSpace. Requested by ${
latestSubmission?.update_user
} on ${formatDate(currentDate)}`,
[MINE_REPORT_SUBMISSION_CODES.INI]: "The report has been submitted successfully",
[MINE_REPORT_SUBMISSION_CODES.WTD]: `The report has been withdrawn. Withdrew by ${
latestSubmission?.update_user
} on ${formatDate(currentDate)}`,
[MINE_REPORT_SUBMISSION_CODES.NRQ]: "This report is not requested",
};
return MINE_REPORT_STATUS_DESCRIPTION_HASH[statusCode] || "";
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

from tests.factories import MineFactory, MineDocumentFactory, MineReportFactory


# GET
def test_get_all_mine_report_submissions_for_report(test_client, db_session, auth_headers):
mine_report = MineReportFactory()

params = f'?mine_report_guid={mine_report.mine_report_guid}'
get_resp = test_client.get(
f'mines/reports/submissions{params}', headers=auth_headers['full_auth_header'])
Expand All @@ -21,6 +22,7 @@ def test_get_all_mine_report_submissions_for_report(test_client, db_session, aut
assert str(mine_report.mine_report_guid) == get_data[0]['mine_report_guid']
assert get_resp.status_code == 200


def test_get_mine_report_with_no_submissions(test_client, db_session, auth_headers):
mine_report = MineReportFactory(mine_report_submissions=0)

Expand All @@ -32,12 +34,13 @@ def test_get_mine_report_with_no_submissions(test_client, db_session, auth_heade
assert get_resp.status_code == 200
assert get_data['mine_report_guid'] == str(mine_report.mine_report_guid)
assert get_data['mine_report_submission_status_code'] == "NON"
assert get_data['mine_report_submission_guid'] == None
assert get_data['documents'] == None
assert get_data['mine_report_submission_guid'] == None
assert get_data['documents'] == None


def test_get_latest_mine_report_submission_for_report(test_client, db_session, auth_headers):
mine_report = MineReportFactory()

params = f'?latest_submission=true&mine_report_guid={mine_report.mine_report_guid}'
get_resp = test_client.get(
f'mines/reports/submissions{params}', headers=auth_headers['full_auth_header'])
Expand All @@ -48,14 +51,15 @@ def test_get_latest_mine_report_submission_for_report(test_client, db_session, a


def test_get_latest_report_submission_without_mine_report_guid(test_client, db_session, auth_headers):
# TODO: in the end this is not desired behaviour,
# this is just a reminder to write a real test when implementing
# TODO: in the end this is not desired behaviour,
# this is just a reminder to write a real test when implementing
params = '?latest_submission=true'
get_resp = test_client.get(
f'mines/reports/submissions{params}', headers=auth_headers['full_auth_header'])

assert get_resp.status_code == 400


# # POST
def test_post_initial_crr_mine_report_submission(test_client, db_session, auth_headers):
mine = MineFactory(minimal=True)
Expand All @@ -76,7 +80,7 @@ def test_post_initial_crr_mine_report_submission(test_client, db_session, auth_h
'received_date': "2024-02-09",
'submission_year': "2024",
'submitter_email': "[email protected]",
'submitter_name': "Submitter Name",
'submitter_name': "Submitter Name",
}

# post from Minespace
Expand All @@ -92,6 +96,7 @@ def test_post_initial_crr_mine_report_submission(test_client, db_session, auth_h
assert num_submissions == 1
assert latest_submission['mine_report_submission_status_code'] == "INI"


def test_post_requested_report(test_client, db_session, auth_headers):
mine_report = MineReportFactory(mine_report_submissions=0)

Expand All @@ -111,7 +116,7 @@ def test_post_requested_report(test_client, db_session, auth_headers):
'received_date': "2024-02-09",
'submission_year': "2024",
'submitter_email': "[email protected]",
'submitter_name': "Submitter Name",
'submitter_name': "Submitter Name",
}

# post from Minespace
Expand All @@ -124,6 +129,7 @@ def test_post_requested_report(test_client, db_session, auth_headers):
assert post_data['mine_report_submission_guid'] is not None
assert post_data['mine_report_definition_guid'] == str(mine_report_definition.mine_report_definition_guid)


def test_post_additional_mine_report_submission(test_client, db_session, auth_headers):
mine_report = MineReportFactory(mine_report_submissions=1)
first_submission = mine_report.mine_report_submissions[0]
Expand Down Expand Up @@ -159,7 +165,7 @@ def test_post_additional_mine_report_submission(test_client, db_session, auth_he
if x.mine_report_submission_status_code != first_submission.mine_report_submission_status_code
][0]
submission_data['mine_report_submission_status_code'] = new_status_code.mine_report_submission_status_code

submission_data['description_comment'] = "New description comment"

post_resp = test_client.post(
Expand All @@ -177,10 +183,10 @@ def test_post_additional_mine_report_submission(test_client, db_session, auth_he
# fields that should be changed
assert previous_submission['update_timestamp'] != latest_submission['update_timestamp']
assert previous_submission['submission_date'] != latest_submission['submission_date']
assert previous_submission['mine_report_submission_status_code'] != latest_submission['mine_report_submission_status_code']
assert previous_submission['mine_report_submission_status_code'] != latest_submission[
'mine_report_submission_status_code']
assert previous_submission['description_comment'] != latest_submission['description_comment']

# fields that should not change
assert previous_submission['received_date'] == latest_submission['received_date']
assert previous_submission['received_date'] == latest_submission['received_date']
assert previous_submission['create_timestamp'] + '+00:00' == latest_submission['create_timestamp']

2 changes: 1 addition & 1 deletion services/core-web/runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
"express-static-gzip": "2.1.7",
"helmet": "7.1.0"
}
}
}
71 changes: 51 additions & 20 deletions services/core-web/src/components/mine/Reports/ReportPage.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { FC, useEffect, useState } from "react";
import { Link, useParams } from "react-router-dom";
import { useSelector, useDispatch } from "react-redux";
import { change, isDirty, reset } from "redux-form";
import { Alert, Button, Modal, Row, Select, Tag, Typography } from "antd";
import { isDirty, reset } from "redux-form";
import { Alert, Button, Modal, Row, Tag, Typography } from "antd";
import ArrowLeftOutlined from "@ant-design/icons/ArrowLeftOutlined";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faLocationDot } from "@fortawesome/pro-light-svg-icons";
Expand All @@ -13,7 +13,6 @@ import {
IMineReportSubmission,
MINE_REPORT_STATUS_HASH,
MINE_REPORT_SUBMISSION_CODES,
reportStatusSeverityForDisplay,
} from "@mds/common";
import { getMineById } from "@mds/common/redux/selectors/mineSelectors";
import { fetchMineRecordById } from "@mds/common/redux/actionCreators/mineActionCreator";
Expand All @@ -28,6 +27,10 @@ import ReportDetailsForm from "@mds/common/components/reports/ReportDetailsForm"
import Loading from "@/components/common/Loading";
import { ScrollSideMenuProps } from "@mds/common/components/common/ScrollSideMenu";
import ScrollSidePageWrapper from "@mds/common/components/common/ScrollSidePageWrapper";
import modalConfig from "@/components/modalContent/config";
import { closeModal, openModal } from "@mds/common/redux/actions/modalActions";

import { getMineReportStatusDescription } from "@mds/common/redux/utils/helpers";

const ReportPage: FC = () => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -83,6 +86,42 @@ const ReportPage: FC = () => {
setIsEditMode(false);
};

const handleCloseModal = () => {
dispatch(closeModal());
};

const handleUpdateMineSubmissionStatus = (values) => {
const payload = {
...latestSubmission,
mine_report_submission_status_code: values.mine_report_submission_status_code,
};
handleCloseModal();
dispatch(createReportSubmission(payload)).then((response) => {
if (response.payload) {
dispatch(fetchLatestReportSubmission({ mine_report_guid: reportGuid }));
dispatch(fetchMineRecordById(mineGuid));
}
});
};

const openUpdateMineReportStatusModal = (event) => {
event.preventDefault();
dispatch(
openModal({
props: {
title: "Update Report Status",
closeModal: handleCloseModal,
handleSubmit: handleUpdateMineSubmissionStatus,
currentStatus:
MINE_REPORT_STATUS_HASH[latestSubmission?.mine_report_submission_status_code],
mineReportStatusOptions: mineReportStatusOptions,
latestSubmission: latestSubmission,
},
content: modalConfig.UPDATE_MINE_REPORT_STATUS_MODAL,
})
);
};

const getFormButtons = () => {
return isEditMode ? (
<Row justify="space-between">
Expand Down Expand Up @@ -149,11 +188,6 @@ const ReportPage: FC = () => {
</div>
);

const handleUpdateStatus = (value: MINE_REPORT_SUBMISSION_CODES) => {
dispatch(change(FORM.VIEW_EDIT_REPORT, "mine_report_submission_status_code", value));
setSelectedStatus(value);
};

const handleSubmit = (values: IMineReportSubmission) => {
dispatch(createReportSubmission(values)).then((response) => {
if (response.payload) {
Expand All @@ -165,24 +199,21 @@ const ReportPage: FC = () => {
<>
<Alert
message={
<Row justify="space-between" align="middle">
<Row justify="space-between" align="middle" className="alert-container">
<span>
{MINE_REPORT_STATUS_HASH[latestSubmission?.mine_report_submission_status_code]}
</span>
<Select
disabled={!isEditMode}
virtual={false}
dropdownMatchSelectWidth
allowClear={false}
value={selectedStatus}
options={mineReportStatusOptions}
onChange={handleUpdateStatus}
style={{ minWidth: "210px" }}
/>
<Button className="full-mobile" onClick={openUpdateMineReportStatusModal}>
Update Status
</Button>
</Row>
}
type={reportStatusSeverityForDisplay(latestSubmission?.mine_report_submission_status_code)}
type={"warning"}
showIcon
description={getMineReportStatusDescription(
latestSubmission?.mine_report_submission_status_code,
latestSubmission
)}
/>
<ReportDetailsForm
mineGuid={mineGuid}
Expand Down
Loading
Loading