Skip to content

[MDS-7019] - Fix replace documents in Major Projects on Core - #3996

Merged
matbusby-fw merged 4 commits into
developfrom
mds-7019-major-project-document-mismatch
Sep 14, 2026
Merged

matbusby-fw merged 4 commits into
developfrom
mds-7019-major-project-document-mismatch

Conversation

@matbusby-fw

Copy link
Copy Markdown
Collaborator

Objective

MDS-7019

Fix document replacement display issues in Major Projects where replacing an existing document caused version ordering in the accordion to invert (newest at bottom, oldest at top) and left the table row displaying stale details. Also migrates DecisionPackageTab from JavaScript to TypeScript (.tsx).


Source of the Issue

  1. Version History Inversion in Constructor:

    • In ReplaceDocumentModal.tsx, the list of existing versions was reversed before creating the new version entries. However, the MineDocument model constructor also performs its own sort/reversal handling for version history. This resulted in a double reversal: the newest replaced version was pushed to the bottom of the accordion list instead of remaining at the top.
  2. Date Format Inconsistency:

    • The replacement timestamp was previously formatted without time precision (or in non-ISO format), causing date comparisons against ISO backend timestamps (YYYY-MM-DDTHH:mm:ssZ) in Ant Design table sorters to tie or sort inconsistently.
  3. Loss of Document Subclass / Metadata:

    • When preparing the replaced document, it was being re-instantiated strictly as a generic MineDocument, dropping subclass-specific attributes and prototype methods associated with MajorMineApplicationDocument (e.g., category codes, labels, and document subtypes).
  4. Missing Callback Propagation (onReplaceDocument):

    • DocumentTable opened the replacement modal and triggered the upload action, but did not accept or invoke an onReplaceDocument callback upon completion. Because the parent tabs (ProjectDocumentsTab, MajorMineApplicationTab, DecisionPackageTab) were not notified of the replacement, the parent container never re-fetched the updated project/document list from the backend, leaving the table display out of sync until a manual page reload.

Why This Fixes It

  1. Corrects Version Array Ordering & Subclass Preservation (ReplaceDocumentModal.tsx):

    • Retains the original document's constructor prototype (e.g., MajorMineApplicationDocument) so all custom getters and metadata remain intact.
    • Sets update_timestamp using new Date().toISOString() for exact chronological comparison against backend timestamps.
    • Ensures versions are chronologically ordered before passing to the document constructor, ensuring index 0 correctly represents the latest version at the top of the version accordion.
    • Awaits props.handleSubmit(newDocument) before closing the modal.
  2. Propagates Refresh Callbacks (DocumentTable.tsx, ProjectDocumentsTab.tsx, ProjectDocumentsTabSection.tsx):

    • Added onReplaceDocument?: (document: T) => void | Promise<void> prop to DocumentTableProps.
    • Wired onReplaceDocument in ProjectDocumentsTab to trigger refreshData / refreshAmsApps across all document sections (primary, appendix, supporting, ministry decision, authorization amendment, and AMS documents).
    • Wired onReplaceDocument={fetchData} in MajorMineApplicationTab.tsx and DecisionPackageTab.tsx.
  3. Migrated DecisionPackageTab to TypeScript (DecisionPackageTab.tsx):

    • Converted the legacy React class component to a TypeScript functional component (FC) using React hooks (useDispatch, useSelector, useParams, useFeatureFlag, useState, useEffect).
    • Defined DecisionPackageTabProps to remain backward-compatible with unit tests that pass props directly while cleanly falling back to Redux selectors and React Router hooks when mounted in Project.tsx.
    • Deleted the obsolete DecisionPackageTab.js.

Automated Tests & Verification

  • Common Unit Tests:
    • DocumentTable.spec.tsx: Added test verifying that onReplaceDocument is invoked with the updated document when a replacement is submitted.
    • ReplaceDocumentModal.spec.tsx: Added test verifying that document version history correctly sorts newest versions first.
    yarn workspace @mds/common run test DocumentTable.spec.tsx ReplaceDocumentModal.spec.tsx

Mat Busby added 2 commits September 11, 2026 15:25
…hooks; add document replacement support in `DocumentTable`.

Signed-off-by: Mat Busby <mat.busby@studio.ey.com>
…istency.

Signed-off-by: Mat Busby <mat.busby@studio.ey.com>
@matbusby-fw
matbusby-fw force-pushed the mds-7019-major-project-document-mismatch branch from d7d5e87 to 8eef7c1 Compare September 11, 2026 21:25
…geTab`.

Signed-off-by: Mat Busby <mat.busby@studio.ey.com>

@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.

Noticed 2 small things, but looks super solid overall! Should be easy fixes

Comment thread services/common/src/components/documents/ReplaceDocumentModal.tsx Outdated
… enhance `DecisionPackageTab` with initial mount check.

Signed-off-by: Mat Busby <mat.busby@studio.ey.com>
@sonarqubecloud

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

@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.

LGTM!

@sonarqubecloud

Copy link
Copy Markdown

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

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

See analysis details on SonarQube Cloud

@sonarqubecloud

Copy link
Copy Markdown

@matbusby-fw
matbusby-fw merged commit 0fb46ce into develop Sep 14, 2026
16 of 17 checks passed
@matbusby-fw
matbusby-fw deleted the mds-7019-major-project-document-mismatch branch September 14, 2026 19:42
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.

2 participants