Skip to content

Commit

Permalink
[MDS-5466]archive docs appearing randomly (#2651)
Browse files Browse the repository at this point in the history
fix for all archived documents from all projects in a mine showing up
  • Loading branch information
asinn134 authored Sep 8, 2023
1 parent 7e029c2 commit d4e9653
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,23 @@ def filter_by(cls, mine_guid, project_guid=None, major_mine_application_guid=Non
# - Project Summary
# - Project Decision Package
# - Information Requirements Table
qy.join(MajorMineApplicationDocumentXref)\
application_docs = qy.join(MajorMineApplicationDocumentXref)\
.join(MajorMineApplication)\
.join(ProjectSummaryDocumentXref)\
.filter(MajorMineApplication.project_guid == project_guid)

summary_docs = qy.join(ProjectSummaryDocumentXref)\
.join(ProjectSummary)\
.join(ProjectDecisionPackageDocumentXref)\
.filter(ProjectSummary.project_guid == project_guid)

decision_docs = qy.join(ProjectDecisionPackageDocumentXref)\
.join(ProjectDecisionPackage)\
.join(InformationRequirementsTableDocumentXref)\
.filter(ProjectDecisionPackage.project_guid == project_guid)

irt_docs = qy.join(InformationRequirementsTableDocumentXref)\
.join(InformationRequirementsTable)\
.filter(or_(
MajorMineApplication.project_guid == project_guid,
ProjectSummary.project_guid == project_guid,
ProjectDecisionPackage.project_guid == project_guid,
InformationRequirementsTable.project_guid == project_guid,
))
.filter(InformationRequirementsTable.project_guid == project_guid)

qy = application_docs.union(summary_docs, decision_docs, irt_docs)

if major_mine_application_guid is not None:
qy = qy.join(MajorMineApplicationDocumentXref)\
Expand All @@ -64,7 +67,7 @@ def filter_by(cls, mine_guid, project_guid=None, major_mine_application_guid=Non
qy = qy.join(ProjectDecisionPackageDocumentXref)\
.join(ProjectDecisionPackage)\
.filter(ProjectDecisionPackage.project_decision_package_guid == project_decision_package_guid)

return qy.all()

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,24 @@ export class DecisionPackageTab extends Component {
handleFetchData = async () => {
const { projectGuid } = this.props.match?.params;
const project = await this.props.fetchProjectById(projectGuid);
await this.props.fetchMineDocuments(project.mine_guid, {
is_archived: true,
...(project?.project_decision_package?.project_decision_package_guid && {
project_decision_package_guid:
project?.project_decision_package?.project_decision_package_guid,
}),
});
const decisionPackageGuid = project?.project_decision_package?.project_decision_package_guid;
if (decisionPackageGuid) {
await this.props.fetchMineDocuments(project.mine_guid, {
is_archived: true,
project_decision_package_guid: decisionPackageGuid,
});
}
};

componentDidUpdate(nextProps) {
if (
nextProps.match.params.tab !== this.props.match.params.tab &&
this.props.match.params.tab === "project-decision-package"
) {
this.handleFetchData();
}
}

handleUpdateProjectDecisionPackage = (event, values) => {
event.preventDefault();
const { projectGuid } = this.props.match?.params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,23 @@ export class MajorMineApplicationTab extends Component {
async fetchData() {
const { projectGuid } = this.props.match.params;
const project = await this.props.fetchProjectById(projectGuid);
this.props.fetchMineDocuments(project.mine_guid, {
is_archived: true,
project_guid: projectGuid,
});

const majorMineApplicationGuid = project?.major_mine_application?.major_mine_application_guid;
if (majorMineApplicationGuid) {
this.props.fetchMineDocuments(project.mine_guid, {
is_archived: true,
major_mine_application_guid: majorMineApplicationGuid,
});
}
}

componentDidUpdate(nextProps) {
if (
nextProps.match.params.tab !== this.props.match.params.tab &&
this.props.match.params.tab === "final-app"
) {
this.fetchData();
}
}

componentWillUnmount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ export class ProjectDocumentsTab extends Component {
});
};

componentDidUpdate(nextProps) {
if (
nextProps.match.params.tab !== this.props.match.params.tab &&
this.props.match.params.tab === "documents"
) {
this.handleFetchData();
}
}

handleDeleteDocument = (event, key, documentParent) => {
event.preventDefault();
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,13 @@ export class MajorMineApplicationPage extends Component {
handleFetchData = async () => {
const { projectGuid } = this.props.match?.params;
const project = await this.props.fetchProjectById(projectGuid);

this.props.fetchMineDocuments(project.mine_guid, {
is_archived: true,
...(project.major_mine_application?.major_mine_application_guid && {
major_mine_application_guid: project.major_mine_application?.major_mine_application_guid,
}),
});
const majorMineApplicationGuid = project?.major_mine_application?.major_mine_application_guid;
if (majorMineApplicationGuid) {
this.props.fetchMineDocuments(project.mine_guid, {
is_archived: true,
major_mine_application_guid: majorMineApplicationGuid,
});
}
};

handleCreateMajorMineApplication = (values, isDraft) => {
Expand Down
21 changes: 12 additions & 9 deletions services/minespace-web/src/components/pages/Project/ProjectPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,19 @@ export class ProjectPage extends Component {
fetchArchivedDocuments(activeTab = this.state.activeTab) {
let filters = { project_guid: this.props?.project?.project_guid, is_archived: true };
if (activeTab === "major-mine-application") {
filters = {
...(this.props?.project?.major_mine_application?.major_mine_application_guid && {
major_mine_application_guid: this.props?.project?.major_mine_application
?.major_mine_application_guid,
}),
is_archived: true,
};
}
const majorMineApplicationGuid = this.props?.project?.major_mine_application
?.major_mine_application_guid;
if (majorMineApplicationGuid) {
filters = {
major_mine_application_guid: majorMineApplicationGuid,
is_archived: true,
};

this.props.fetchMineDocuments(this.props?.project?.mine_guid, filters);
this.props.fetchMineDocuments(this.props?.project?.mine_guid, filters);
}
} else {
this.props.fetchMineDocuments(this.props?.project?.mine_guid, filters);
}
}

componentWillReceiveProps(nextProps) {
Expand Down

0 comments on commit d4e9653

Please sign in to comment.