Skip to content

Commit

Permalink
[MDS-6073] Fix bugs on spatial docs upload. (#3227)
Browse files Browse the repository at this point in the history
* fix bug on spatial docs upload.

* fix PR comment

* update test.
  • Loading branch information
henryoforeh-dev authored Aug 23, 2024
1 parent 262e79a commit be1d7c0
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1,496 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from sqlalchemy.schema import FetchedValue
from werkzeug.exceptions import BadRequest, NotFound

from app.api.mines.documents.models.mine_document_bundle import MineDocumentBundle
from app.extensions import db

from app.config import Config
Expand Down Expand Up @@ -114,21 +116,30 @@ def generate_list_element(element):
def create(cls,
project,
status_code,
documents=[],
documents=None,
add_to_session=True):
major_mine_application = cls(
project_guid=project.project_guid,
status_code=status_code)
documents = documents or []

if add_to_session:
major_mine_application.save(commit=False)

if documents:
spatial_docs = [doc for doc in documents if doc['major_mine_application_document_type_code'] == 'SPT']
updated_spatial_docs = MineDocumentBundle.update_spatial_mine_document_with_bundle_id(spatial_docs)

# update the original documents array with the updated spatial documents
documents = [doc for doc in documents if doc['major_mine_application_document_type_code'] != 'SPT']
documents.extend(updated_spatial_docs)

for doc in documents:
mine_doc = MineDocument(
mine_guid=project.mine_guid,
document_name=doc.get('document_name'),
document_manager_guid=doc.get('document_manager_guid'))
document_manager_guid=doc.get('document_manager_guid'),
mine_document_bundle_id=doc['mine_document_bundle_id'] if doc.get('mine_document_bundle_id') else None)
major_mine_application_doc = MajorMineApplicationDocumentXref(
mine_document_guid=mine_doc.mine_document_guid,
major_mine_application_id=major_mine_application.major_mine_application_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class MajorMineApplicationDocumentXref(Base):
create_user = association_proxy('mine_document', 'create_user')
versions = association_proxy('mine_document', 'versions')
update_timestamp = association_proxy('mine_document', 'update_timestamp')
mine_document_bundle_id = association_proxy('mine_document', 'mine_document_bundle_id')

def __repr__(self):
return f'{self.__class__.__name__} {self.major_mine_application_document_xref_guid}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const MajorMineApplicationForm: React.FC<MajorMineApplicationFormProps> = ({
...fileData,
major_mine_application_document_type_code:
MAJOR_MINES_APPLICATION_DOCUMENT_TYPE_CODE.SPATIAL,
mine_guid: project?.mine_guid,
}),
},
content: AddSpatialDocumentsModal,
Expand Down Expand Up @@ -245,8 +246,14 @@ const MajorMineApplicationForm: React.FC<MajorMineApplicationFormProps> = ({
<Typography.Paragraph>
Please upload spatial files to support your application. You must upload at least one KML,
KMZ, or Shapefile at a time. Visit{" "}
<Link to={{ pathname: SPATIAL_DATA_STANDARDS_URL }}>GIS Shapefile Standards</Link> to
learn more about shapefile requirements and standards.
<Link
to={{ pathname: SPATIAL_DATA_STANDARDS_URL }}
target="_blank"
rel="noopener noreferrer"
>
GIS Shapefile Standards
</Link>{" "}
to learn more about shapefile requirements and standards.
</Typography.Paragraph>
{isFeatureEnabled(Feature.SPATIAL_BUNDLE) ? (
<>
Expand All @@ -258,9 +265,9 @@ const MajorMineApplicationForm: React.FC<MajorMineApplicationFormProps> = ({
>
Upload Spatial Data
</Button>
{spatialDocument.length > 0 && (
{spatial_documents?.length > 0 && (
<SpatialDocumentTable
documents={spatialDocument}
documents={spatial_documents}
documentParent="Major Mine Application"
onArchivedDocuments={refreshData}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ jest.mock(
)
);

jest.mock("@mds/common/components/documents/DocumentTable", () => (props: any) => (
<div>
<button onClick={() => props.onArchivedDocuments()}>Archive Documents</button>
</div>
));

const initialState = {
form: {
ADD_MINE_MAJOR_APPLICATION: {
Expand Down Expand Up @@ -114,4 +120,11 @@ describe("MajorMineApplicationForm", () => {
fireEvent.click(fileInput);
expect(mockDispatch).toHaveBeenCalled();
});

it("should call refreshData when documents are archived", () => {
const { getAllByText } = render(<WrappedMajorMineApplicationForm />);
const archiveButtons = getAllByText("Archive Documents");
fireEvent.click(archiveButtons[0]);
expect(props.refreshData).toHaveBeenCalled();
});
});
Loading

0 comments on commit be1d7c0

Please sign in to comment.