[MDS-6911] improve speed when reviewing extracted permit conditions#3929
[MDS-6911] improve speed when reviewing extracted permit conditions#3929asinn134 wants to merge 5 commits into
Conversation
… endpoint call on the page
There was a problem hiding this comment.
Pull request overview
This PR introduces a slimmer backend endpoint and frontend state-management/UI changes to speed up the Permit Conditions review workflow and enable per-condition loading/disabled behavior instead of blocking the entire form.
Changes:
- Added a new Core API endpoint (
.../conditions-data) and response model to return only permit-amendment data needed by the Permit Conditions page. - Updated common-web permit conditions UI to track “active” and “submitting” condition families, showing per-condition loading spinners and allowing parallel edits across different conditions.
- Added Redux support (actions/reducer/tests) and a new thunk (
fetchPermitConditionsData) to refresh only conditions-related amendment fields.
Reviewed changes
Copilot reviewed 24 out of 25 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| services/core-web/src/styles/components/PermitConditions.scss | Adds per-condition loading spinner styling on .condition-layer--loading. |
| services/core-web/src/components/Forms/permits/conditions/snapshots/StandardPermitConditions.spec.tsx.snap | Updates snapshots for new editable class and edit labels/titles. |
| services/core-api/tests/mines/permit/resources/test_permit_conditions_data_resource.py | Adds tests for the new conditions-data endpoint (200/404/400). |
| services/core-api/app/api/mines/response_models.py | Adds PERMIT_CONDITIONS_DATA_MODEL for the slim response payload. |
| services/core-api/app/api/mines/permits/permit_amendment/resources/permit_conditions_data.py | Implements PermitConditionsDataResource GET endpoint. |
| services/core-api/app/api/mines/namespace.py | Registers the new conditions-data API route. |
| services/common/src/utils/helpers.ts | Adds containsConditionId helper for condition-tree membership checks. |
| services/common/src/redux/selectors/permitSelectors.spec.ts | Adds reducer tests for the new amendment-conditions patch action. |
| services/common/src/redux/reducers/permitReducer.ts | Adds STORE_PERMIT_AMENDMENT_CONDITIONS case to patch a permit amendment in-place. |
| services/common/src/redux/actions/permitActions.tsx | Adds storePermitAmendmentConditions action creator. |
| services/common/src/redux/actionCreators/permitActionCreator.ts | Adds fetchPermitConditionsData thunk and re-formats surrounding code. |
| services/common/src/redux/actionCreators/permitActionCreator.spec.js | Adds thunk tests for fetchPermitConditionsData. |
| services/common/src/constants/networkReducerTypes.ts | Adds GET_PERMIT_CONDITIONS_DATA. |
| services/common/src/constants/API.ts | Adds PERMIT_CONDITIONS_DATA endpoint constant. |
| services/common/src/constants/actionTypes.ts | Adds STORE_PERMIT_AMENDMENT_CONDITIONS. |
| services/common/src/components/permits/SubConditionForm.tsx | Tracks per-subcondition submit state and updates submitting-condition tracking. |
| services/common/src/components/permits/ReportPermitRequirementForm.tsx | Adds per-condition-family loading/active handling for report requirement edits/deletes. |
| services/common/src/components/permits/PermitConditionViewEdit.tsx | Adjusts edit-form closing behavior and passes sibling ids to layers. |
| services/common/src/components/permits/PermitConditionStatus.tsx | Disables/loads complete-review per condition family using new tracking. |
| services/common/src/components/permits/PermitConditionsContext.tsx | Extends context with active/submitting condition tracking APIs. |
| services/common/src/components/permits/PermitConditions.tsx | Switches refresh to fetchPermitConditionsData and adds local in-flight tracking. |
| services/common/src/components/permits/PermitConditionReportRequirements.tsx | Passes condition id/loading state to report-requirement forms. |
| services/common/src/components/permits/PermitConditionLayer.tsx | Applies per-condition loading class, move-up/down family disabling, and tracking propagation. |
| services/common/src/components/permits/PermitConditionForm.tsx | Implements per-condition submit state, active/submitting tracking, and new disabling rules. |
| services/common/src/components/permits/DeleteConditionModal.tsx | Adds explicit onCancel callback plumbing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
|
|
alazar-aot
left a comment
There was a problem hiding this comment.
Looks great overall, just a few things that caught my eye
| } else { | ||
| handleEdit(); | ||
| if (editingFormName) { | ||
| dispatch(reset(editingFormName)); |
There was a problem hiding this comment.
The removed code showed a Modal (Modal.confirm), but now it's calling the dispatch without any confirmation - is this intentional? Users can lose in-progress edits without any way to cancel
| const setLoading = (value: boolean) => { | ||
| setLoadingCount(prev => value ? prev + 1 : Math.max(0, prev - 1)); | ||
| }; |
There was a problem hiding this comment.
I think this should be wrapped in a useCallback, right now every component calling usePermitConditions() will re-render whenever PermitConditions re-renders.
Something like
const setLoading = useCallback((value: boolean) => {
setLoadingCount(prev => value ? prev + 1 : Math.max(0, prev - 1));
}, []);
|
|
||
| // This keeps track of condition ids that are currently being submitted. | ||
| const [submittingConditionIds, setSubmittingConditionIds] = useState<Record<number, number>>({}); | ||
| const addSubmittingCondition = (id: number) => { |
There was a problem hiding this comment.
Same with this (and all the others in this file)
| prev.conditionCount === next.conditionCount && | ||
| prev.canEditPermitConditions === next.canEditPermitConditions && | ||
| prev.isInsideSubmittingCondition === next.isInsideSubmittingCondition && | ||
| prev.isInsideActiveCondition === next.isInsideActiveCondition |
There was a problem hiding this comment.
The handleMove function defined above closes over siblingIds from the render closure, but this doesn't check siblingIds, so I think it can return true (skip re-render) even when siblingIds changes and should re-render.... meaning handleMove would end up with a stale copy of the sibling ID?
I think this should use a ref, like how we've done elsewhere in the code with activeConditionId.
| width: 2048, | ||
| content: (props) => { | ||
| const value = { mineGuid, permitGuid, latestAmendment, previousAmendment, currentAmendment, loading, setLoading, refreshData }; | ||
| const value = { |
There was a problem hiding this comment.
This is manually mirroring the PermitConditionsContextType interface, anytime we update the interface we'd need to remember to update here. Instead this should use a helper function or export/spread the data so it reflects the interface automatically





Objective
MDS-6911
Change to use new GET request endpoint in
refreshDatafunction in the permit condition page to retrieve the necessary data only and not the whole permitAdjusted permit condition form UI so when a user makes a change in the form (text edit, add new condition, delete condition, editing report requirement, complete review) it doesn't disable the whole form. Instead now when a condition has some change submitted for it, the condition and it's sub conditions are disabled with a load spinner indicating that part is loading. While that condition and it's sub conditions are disabled the user can potentially click on other conditions and start making edits on those.
I did not make much change around when a user creates a new report requirement or when they delete a report requirement because a modal is used for both of these processes and the modal does not go away until submission is done loading.
When it comes to moving a condition up or down the condition, it's sub conditions and it's sibling conditions within that specific condition group will be disabled