Skip to content

[MDS-6911] improve speed when reviewing extracted permit conditions#3929

Open
asinn134 wants to merge 5 commits into
developfrom
mds-6911-improve-speed-when-reviewing-extracted-permit-conditions
Open

[MDS-6911] improve speed when reviewing extracted permit conditions#3929
asinn134 wants to merge 5 commits into
developfrom
mds-6911-improve-speed-when-reviewing-extracted-permit-conditions

Conversation

@asinn134

@asinn134 asinn134 commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Objective

MDS-6911

  • Change to use new GET request endpoint in refreshData function in the permit condition page to retrieve the necessary data only and not the whole permit

  • Adjusted 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

Copilot AI review requested due to automatic review settings June 5, 2026 00:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread services/common/src/components/permits/PermitConditions.tsx Outdated
Comment thread services/common/src/components/permits/PermitConditions.tsx Outdated
Comment thread services/common/src/components/permits/PermitConditionViewEdit.tsx Outdated
Comment thread services/common/src/components/permits/PermitConditionForm.tsx Outdated
Comment thread services/common/src/components/permits/PermitConditionForm.tsx
Comment thread services/common/src/components/permits/PermitConditionLayer.tsx
@sonarqubecloud

sonarqubecloud Bot commented Jun 6, 2026

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed for 'bcgov-sonarcloud_mds_minespace-web'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@sonarqubecloud

sonarqubecloud Bot commented Jun 6, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed for 'bcgov-sonarcloud_mds_common'

Failed conditions
41.8% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@sonarqubecloud

sonarqubecloud Bot commented Jun 6, 2026

Copy link
Copy Markdown

@sonarqubecloud

sonarqubecloud Bot commented Jun 6, 2026

Copy link
Copy Markdown

@alazar-aot alazar-aot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks great overall, just a few things that caught my eye

} else {
handleEdit();
if (editingFormName) {
dispatch(reset(editingFormName));

@alazar-aot alazar-aot Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Comment on lines +149 to +151
const setLoading = (value: boolean) => {
setLoadingCount(prev => value ? prev + 1 : Math.max(0, prev - 1));
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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) => {

@alazar-aot alazar-aot Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 = {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants