Skip to content

[MDS-6255] view mine report definitions #3398

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

Merged
merged 25 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8016d87
make the tab, put it on the page, fix the HSRC title
taraepp Jan 24, 2025
643993b
add pagination to mine report definitions in BE, take out of static c…
taraepp Jan 24, 2025
270ddc4
missed adding the slice file
taraepp Jan 24, 2025
b03c71c
get the data in the table and pagination working properly with BE pag…
taraepp Jan 24, 2025
9bb1a23
remove mine report definition options from static content, get basics…
taraepp Jan 30, 2025
8956fad
upstream changes
taraepp Jan 30, 2025
d47e73d
tell sqlalchemy where a table is
taraepp Jan 30, 2025
70460a7
change loading logic
taraepp Jan 31, 2025
8247171
make fetch happen in other places that use report definitions
taraepp Jan 31, 2025
880fc4f
fix BE filters for boolean values
taraepp Jan 31, 2025
293a372
remove logs
taraepp Jan 31, 2025
a07ec85
use string because boolean doesn't work
taraepp Jan 31, 2025
83297df
fix some sorting on BE, fix page size on FE
taraepp Jan 31, 2025
34d0dcd
do FE part of section filter
taraepp Jan 31, 2025
6805875
BE compliance article # search, little bit of clean up on codes page
taraepp Jan 31, 2025
da94f62
add backend search, tweak ordering of section sort
taraepp Feb 4, 2025
5d9d845
add api param documentation, take out unecessary param
taraepp Feb 4, 2025
af4d599
fix bug with searching section first, put search params in url
taraepp Feb 4, 2025
d37567a
FE snapshot test, make params comparison better
taraepp Feb 4, 2025
f4517b9
make test fancier
taraepp Feb 4, 2025
d9264bc
don't disable buttons
taraepp Feb 4, 2025
abc151b
upstream changes - merge conflicts
taraepp Feb 5, 2025
f7333a5
fix diff
taraepp Feb 5, 2025
8e04279
upstream changes
taraepp Feb 6, 2025
84e5185
did merge conflict resolution wrong
taraepp Feb 7, 2025
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
@@ -1,10 +1,8 @@
import { formatComplianceCodeReportName } from "@mds/common/redux/utils/helpers";
import React, { useEffect, useState } from "react";
import { useSelector } from "react-redux";
import { Field } from "@mds/common/components/forms/form";

import { getMineReportDefinitionOptions } from "@mds/common/redux/selectors/staticContentSelectors";

import { useAppDispatch as useDispatch, useAppSelector as useSelector } from "@mds/common/redux/rootState";
import { Field } from "redux-form";
import { fetchComplianceReports, getMineReportDefinitionOptions, getReportDefinitionsLoaded, reportParamsGetAll } from "@mds/common/redux/slices/complianceReportsSlice";
import RenderSelect from "../forms/RenderSelect";
import { uniqBy } from "lodash";
import moment from "moment";
Expand All @@ -20,9 +18,10 @@ export interface ReportDefinitionFieldSelectProps {
}

export const ReportDefinitionFieldSelect = (props: ReportDefinitionFieldSelectProps) => {
const dispatch = useDispatch();
const mineReportDefinitionOptions = useSelector(getMineReportDefinitionOptions);

const [formattedMineReportDefinitionOptions, setFormatMineReportDefinitionOptions] = useState([]);
const [formattedMineReportDefinitionOptions, setFormattedMineReportDefinitionOptions] = useState([]);
const reportDefinitionsLoaded = useSelector(getReportDefinitionsLoaded(reportParamsGetAll));

useEffect(() => {
// Format the mine report definition options for the search bar
Expand All @@ -39,9 +38,15 @@ export const ReportDefinitionFieldSelect = (props: ReportDefinitionFieldSelectPr
};
})
.sort((a, b) => a.label.localeCompare(b.label));
setFormatMineReportDefinitionOptions(uniqBy(newFormattedMineReportDefinitionOptions, "value"));
setFormattedMineReportDefinitionOptions(uniqBy(newFormattedMineReportDefinitionOptions, "value"));
}, [mineReportDefinitionOptions]);

useEffect(() => {
if (!reportDefinitionsLoaded) {
dispatch(fetchComplianceReports(reportParamsGetAll));
}
}, []);

return (
<Field
component={RenderSelect}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as MOCK from "@mds/common/tests/mocks/dataMocks";
import { SystemFlagEnum } from "@mds/common/constants/enums";
import { USER_ROLES } from "@mds/common/constants/environment";
import { IMineReportSubmission } from "@mds/common/interfaces/reports/mineReportSubmission.interface";
import { complianceReportReducerType, reportParamsGetAll } from "@mds/common/redux/slices/complianceReportsSlice";

const mineReportSubmission = MOCK.MINE_REPORT_SUBMISSIONS[0];
const initialState = {
Expand All @@ -16,10 +17,19 @@ const initialState = {
mineReportGuid: mineReportSubmission.mine_report_guid,
},
[STATIC_CONTENT]: {
mineReportDefinitionOptions: MOCK.BULK_STATIC_CONTENT_RESPONSE.mineReportDefinitionOptions,
permitConditionCategoryOptions:
MOCK.BULK_STATIC_CONTENT_RESPONSE.permitConditionCategoryOptions,
},
[complianceReportReducerType]: {
reportPageData: {
records: MOCK.MINE_REPORT_DEFINITION_OPTIONS,
current_page: 1,
items_per_page: MOCK.MINE_REPORT_DEFINITION_OPTIONS.length,
total: MOCK.MINE_REPORT_DEFINITION_OPTIONS.length,
total_pages: 1
},
params: reportParamsGetAll,
},
[AUTHENTICATION]: {
systemFlag: SystemFlagEnum.core,
userAccessData: [USER_ROLES.role_edit_reports],
Expand Down
18 changes: 12 additions & 6 deletions services/common/src/components/reports/ReportDetailsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { Alert, Button, Col, Row, Typography } from "antd";
import React, { FC, ReactNode, useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { useAppDispatch as useDispatch, useAppSelector as useSelector } from "@mds/common/redux/rootState";
import { arrayPush, change, Field, FieldArray, getFormValues } from "@mds/common/components/forms/form";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faTrashAlt } from "@fortawesome/pro-light-svg-icons";

import {
getDropdownPermitConditionCategoryOptions,
getMineReportDefinitionOptions,
} from "@mds/common/redux/selectors/staticContentSelectors";
import { fetchComplianceReports, getMineReportDefinitionOptions, getReportDefinitionsLoaded, reportParamsGetAll } from "@mds/common/redux/slices/complianceReportsSlice";
import ReportFileUpload from "@mds/common/components/reports/ReportFileUpload";

import { FORM } from "@mds/common/constants/forms";
import {
email,
Expand Down Expand Up @@ -152,7 +150,7 @@ const ReportDetailsForm: FC<ReportDetailsFormProps> = ({
} = formValues;

const [selectedReportCode, setSelectedReportCode] = useState("");
const [formattedMineReportDefinitionOptions, setFormatMineReportDefinitionOptions] = useState([]);
const [formattedMineReportDefinitionOptions, setFormattedMineReportDefinitionOptions] = useState([]);
const [isLoading, setIsLoading] = useState(false);

const partyRelationships: IPartyAppt[] = useSelector((state) => getPartyRelationships(state));
Expand All @@ -165,6 +163,8 @@ const ReportDetailsForm: FC<ReportDetailsFormProps> = ({
const MinistryContactsByRegion: IMinistryContact[] = useSelector(getMinistryContactsByRegion);
const [contactEmail, setContactEmail] = useState<string>();

const reportDefinitionsLoaded = useSelector(getReportDefinitionsLoaded(reportParamsGetAll));

// PRR
const permit = useSelector(getPermitByGuid(permit_guid));
const dropdownPermitConditionCategoryOptions = useSelector(
Expand Down Expand Up @@ -245,7 +245,7 @@ const ReportDetailsForm: FC<ReportDetailsFormProps> = ({
};
})
.sort((a, b) => a.label.localeCompare(b.label));
setFormatMineReportDefinitionOptions(uniqBy(newFormattedMineReportDefinitionOptions, "value"));
setFormattedMineReportDefinitionOptions(uniqBy(newFormattedMineReportDefinitionOptions, "value"));
}, [mineReportDefinitionOptions]);

useEffect(() => {
Expand Down Expand Up @@ -287,6 +287,12 @@ const ReportDetailsForm: FC<ReportDetailsFormProps> = ({
}
}, [formValues.mine_report_guid, formValues.mine_report_submission_guid]);

useEffect(() => {
if (!reportDefinitionsLoaded) {
dispatch(fetchComplianceReports(reportParamsGetAll));
}
}, []);

const handleAddComment = async (values) => {
const formVals = {
report_comment: values.comment,
Expand Down
14 changes: 10 additions & 4 deletions services/common/src/components/reports/ReportGetStarted.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Alert, Button, Col, Row, Typography } from "antd";
import React, { FC, ReactNode, useEffect, useState } from "react";
import { Field, getFormValues, change } from "@mds/common/components/forms/form";
import ArrowRightOutlined from "@ant-design/icons/ArrowRightOutlined";
import { useSelector, useDispatch } from "react-redux";
import { useAppDispatch as useDispatch, useAppSelector as useSelector } from "@mds/common/redux/rootState";
import { IMine, IMineReportDefinition, IMineReportSubmission } from "@mds/common/interfaces";
import {
createDropDownList,
Expand All @@ -15,9 +15,8 @@ import { required, requiredRadioButton } from "@mds/common/redux/utils/Validate"
import RenderSelect from "../forms/RenderSelect";
import {
getDropdownPermitConditionCategoryOptions,
getFormattedMineReportDefinitionOptions,
getMineReportDefinitionByGuid,
} from "@mds/common/redux/selectors/staticContentSelectors";
import { fetchComplianceReports, getFormattedMineReportDefinitionOptions, getMineReportDefinitionByGuid, getReportDefinitionsLoaded, reportParamsGetAll } from "@mds/common/redux/slices/complianceReportsSlice";
import { getPermits } from "@mds/common/redux/selectors/permitSelectors";
import { fetchPermits } from "@mds/common/redux/actionCreators/permitActionCreator";
import { getSystemFlag } from "@mds/common/redux/selectors/authenticationSelectors";
Expand Down Expand Up @@ -171,9 +170,16 @@ const ReportGetStarted: FC<ReportGetStartedProps> = ({
const selectedReportDefinition: IMineReportDefinition = useSelector(
getMineReportDefinitionByGuid(formValues?.mine_report_definition_guid)
);
const reportDefinitionsLoaded = useSelector(getReportDefinitionsLoaded(reportParamsGetAll));

useEffect(() => {
if (selectedReportDefinition && selectedReportDefinition.is_prr_only) {
if (!reportDefinitionsLoaded) {
dispatch(fetchComplianceReports(reportParamsGetAll));
}
}, []);

useEffect(() => {
if (selectedReportDefinition?.is_prr_only) {
setDisableNextButton(true);
} else {
setDisableNextButton(false);
Expand Down
2 changes: 1 addition & 1 deletion services/common/src/constants/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export const MINE_WORK_INFORMATION = (mineGuid, mineWorkInformationGuid) =>
export const REPORTS = (params = {}) => `/mines/reports?${queryString.stringify(params)}`;
export const REPORT_SUBMISSIONS = (params?) =>
`/mines/reports/submissions?${queryString.stringify(params)}`;
export const MINE_REPORT_DEFINITIONS = () => `/mines/reports/definitions`;
export const MINE_REPORT_DEFINITIONS = (params = {}) => `/mines/reports/definitions?${queryString.stringify(params)}`;
export const MINE_REPORTS = (mineGuid, params?) =>
`/mines/${mineGuid}/reports?${queryString.stringify(params)}`;
export const MINE_REPORT = (mineGuid, mineReportGuid) =>
Expand Down
1 change: 0 additions & 1 deletion services/common/src/constants/actionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const STORE_MINE_DOCUMENTS = "STORE_MINE_DOCUMENTS";
export const STORE_MINE_TSF_REQUIRED_DOCUMENTS = "STORE_MINE_TSF_REQUIRED_DOCUMENTS";
export const STORE_MINE_COMPLIANCE_INFO = "STORE_MINE_COMPLIANCE_INFO";
export const STORE_PROVINCE_OPTIONS = "STORE_PROVINCE_OPTIONS";
export const STORE_MINE_REPORT_DEFINITION_OPTIONS = "STORE_MINE_REPORT_DEFINITION_OPTIONS";

export const STORE_PARTY = "STORE_PARTY";
export const STORE_PARTIES = "STORE_PARTIES";
Expand Down
2 changes: 2 additions & 0 deletions services/common/src/constants/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ export enum REPORT_REGULATORY_AUTHORITY_CODES {
export enum REPORT_REGULATORY_AUTHORITY_ENUM {
CPO = "Chief Permitting Officer",
CIM = "Chief Inspector of Mines",
Both = "Both",

}

export enum MineReportType {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface ISearchParams {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels strange that we don't already have this. Nice!

page?: number;
per_page?: number;
sort_field?: string;
sort_dir?: string;
};
4 changes: 2 additions & 2 deletions services/common/src/interfaces/complianceArticle.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export interface IComplianceArticle {
sub_paragraph: string;
description: string;
long_description: string;
effective_date: Date;
expiry_date: Date;
effective_date: string;
expiry_date: string;
help_reference_link: string;
cim_or_cpo: string;
reports: IMineReportDefinition[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface IMineReportDefinition {
active_ind: boolean;
categories: IMineReportDefinitionCategory[];
compliance_articles: IComplianceArticle[];
default_due_date?: number;
default_due_date?: string;
description: string;
due_date_period_months?: number;
is_common: boolean;
Expand Down
8 changes: 5 additions & 3 deletions services/common/src/redux/reducers/rootReducerShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,22 @@ import verifiableCredentialsReducer from "@mds/common/redux/slices/verifiableCre

import regionsReducer from "@mds/common/redux/slices/regionsSlice";
import complianceCodeReducer, { complianceCodeReducerType } from "../slices/complianceCodesSlice";
import complianceReportReducer, { complianceReportReducerType } from "../slices/complianceReportsSlice";
import spatialDataReducer, { spatialDataReducerType } from "../slices/spatialDataSlice";
import permitServiceReducer, { permitServiceReducerType } from "../slices/permitServiceSlice";
import searchConditionCategoriesReducer, {
searchConditionCategoriesType,
} from "../slices/permitConditionCategorySlice";
import helpReducer, { helpReducerType } from "../slices/helpSlice";
import userReducer, { userReducerType } from "@mds/common/redux/slices/userSlice";
import mineReportPermitRequirementReducer, { mineReportPermitRequirementReducerType } from "../slices/mineReportPermitRequirementSlice";
import permitConditionDiffReducer, { permitConditionDiffReducerType } from "../slices/permitConditionDiffSlice";


const networkReducers = Object.fromEntries(Object.entries(NetworkReducerTypes).map(([key, value]) =>
[NetworkReducerTypes[key], createReducer(networkReducer, value)]
));

import userReducer, { userReducerType } from "@mds/common/redux/slices/userSlice";
import permitConditionDiffReducer, { permitConditionDiffReducerType } from "../slices/permitConditionDiffSlice";

export const sharedReducer = {
...activityReducer,
...authenticationReducer,
Expand Down Expand Up @@ -83,6 +84,7 @@ export const sharedReducer = {
regions: regionsReducer,
[spatialDataReducerType]: spatialDataReducer,
[complianceCodeReducerType]: complianceCodeReducer,
[complianceReportReducerType]: complianceReportReducer,
[permitServiceReducerType]: permitServiceReducer,
[helpReducerType]: helpReducer,
[searchConditionCategoriesType]: searchConditionCategoriesReducer,
Expand Down
3 changes: 0 additions & 3 deletions services/common/src/redux/reducers/staticContentReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const initialState = {
informationRequirementsTableDocumentTypes: [],
majorMineApplicationStatusCodes: [],
majorMineApplicationDocumentTypes: [],
mineReportDefinitionOptions: [],
mineReportStatusOptions: [],
mineReportCategoryOptions: [],
partyRelationshipTypes: [],
Expand Down Expand Up @@ -113,8 +112,6 @@ export const getMajorMinesApplicationStatusCodes = (state) =>
state[STATIC_CONTENT].majorMineApplicationStatusCodes;
export const getMajorMinesApplicationDocumentTypes = (state) =>
state[STATIC_CONTENT].majorMineApplicationDocumentTypes;
export const getMineReportDefinitionOptions = (state) =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah!

state[STATIC_CONTENT].mineReportDefinitionOptions;
export const getMineReportStatusOptions = (state) => state[STATIC_CONTENT].mineReportStatusOptions;
export const getMineReportCategoryOptions = (state) =>
state[STATIC_CONTENT].mineReportCategoryOptions;
Expand Down
45 changes: 1 addition & 44 deletions services/common/src/redux/selectors/staticContentSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import {
createLabelHash,
createDropDownList,
compareCodes,
formatComplianceCodeReportName,
} from "../utils/helpers";
import { RootState } from "@mds/common/redux/rootState";
import { getMunicipalityOptions } from "../reducers/staticContentReducer";
import { IMineReportDefinition } from "@mds/common/interfaces/reports/mineReportDefinition.interface";

export const {
getStaticContentLoadingIsComplete,
Expand All @@ -18,7 +16,6 @@ export const {
getMineTenureTypeOptions,
getMineCommodityOptions,
getMineDisturbanceOptions,
getMineReportDefinitionOptions,
getMineReportStatusOptions,
getMineReportCategoryOptions,
getProvinceOptions,
Expand Down Expand Up @@ -80,7 +77,7 @@ const getOptions = (transformOptionsFunc, showActiveOnly) => {
: options;
};

const createSelectorWrapper = (
export const createSelectorWrapper = (
getOptionsMethod,
transformOptionsMethod,
transformOptionsFuncArgs = []
Expand Down Expand Up @@ -460,46 +457,6 @@ export const getVarianceDocumentCategoryOptionsHash = createSelector(
createLabelHash
);

export const getDropdownMineReportDefinitionOptions = createSelectorWrapper(
getMineReportDefinitionOptions,
createDropDownList,
["report_name", "mine_report_definition_guid", "active_ind"]
);

export const getFormattedMineReportDefinitionOptions = createSelectorWrapper(
getMineReportDefinitionOptions,
(options: IMineReportDefinition[]) => {
return options
.map((item) => {
return {
label: formatComplianceCodeReportName(item),
value: item.mine_report_definition_guid,
isActive: item.active_ind,
is_common: item.is_common,
report_name: item.report_name,
};
})
.sort((a, b) => a.label.localeCompare(b.label));
}
);

export const getMineReportDefinitionByGuid = (mineReportDefinitionGuid: string) =>
createSelector([getMineReportDefinitionOptions], (reportDefs) => {
return reportDefs.find((r) => r.mine_report_definition_guid === mineReportDefinitionGuid);
});

export const getMineReportDefinitionHash = createSelector(
getMineReportDefinitionOptions,
(options) =>
options.reduce(
(map, mine_report_definition) => ({
[mine_report_definition.mine_report_definition_guid]: mine_report_definition,
...map,
}),
{}
)
);

export const getDropdownMineReportCategoryOptions = createSelectorWrapper(
getMineReportCategoryOptions,
createDropDownList,
Expand Down
Loading
Loading