Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MDS-5809] - Fix loading bug on new IRT/Update IRT Import Form #3068

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { FC, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { change, Field, formValueSelector, InjectedFormProps, reduxForm } from "redux-form";
import { change, Field, formValueSelector } from "redux-form";
import { Alert, Col, Form, Row, Typography } from "antd";
import { remove } from "lodash";
import { ENVIRONMENT, IProject } from "@mds/common";
import { ENVIRONMENT, IFileInfo, IProject } from "@mds/common";
import * as API from "@mds/common/constants/API";
import {
createInformationRequirementsTable,
Expand All @@ -23,6 +23,7 @@ import {
import { formatDateTime } from "@common/utils/helpers";
import { documentNameColumn } from "@/components/common/DocumentColumns";
import { MineDocument } from "@mds/common/models/documents/document";
import FormWrapper from "@mds/common/components/forms/FormWrapper";

interface IRTFileImportProps {
projectGuid: string;
Expand All @@ -31,7 +32,7 @@ interface IRTFileImportProps {
downloadIRTTemplate: (url: string) => void;
}

export const IRTFileImport: FC<IRTFileImportProps & Partial<InjectedFormProps<any>>> = ({
export const IRTFileImport: FC<IRTFileImportProps> = ({
projectGuid,
importIsSuccessful,
downloadIRTTemplate,
Expand Down Expand Up @@ -76,8 +77,32 @@ export const IRTFileImport: FC<IRTFileImportProps & Partial<InjectedFormProps<an
renderTextColumn("create_user", "Imported By"),
];

const handleCreateInformationRequirementsTable = (
projectGuid: string,
file: IFileInfo,
documentGuid: string
) => {
dispatch(createInformationRequirementsTable(projectGuid, file, documentGuid));
};

const handleUpdateInformationRequirementsTableByFile = (
projectGuid: string,
informationRequirementsTableGuid: string,
file: IFileInfo,
documentGuid: string
) => {
dispatch(
updateInformationRequirementsTableByFile(
projectGuid,
informationRequirementsTableGuid,
file,
documentGuid
)
);
};

return (
<>
<FormWrapper name={FORM.INFORMATION_REQUIREMENTS_TABLE} onSubmit={() => {}}>
<Row>
<Col span={24}>
<Typography.Title level={4}>Import IRT file</Typography.Title>
Expand Down Expand Up @@ -125,10 +150,10 @@ export const IRTFileImport: FC<IRTFileImportProps & Partial<InjectedFormProps<an
name="final_irt"
onFileLoad={onFileLoad}
onRemoveFile={onRemoveFile}
createInformationRequirementsTable={dispatch(createInformationRequirementsTable)}
updateInformationRequirementsTableByFile={dispatch(
updateInformationRequirementsTableByFile
)}
createInformationRequirementsTable={handleCreateInformationRequirementsTable}
updateInformationRequirementsTableByFile={
handleUpdateInformationRequirementsTableByFile
}
irtGuid={project?.information_requirements_table?.irt_guid}
projectGuid={projectGuid}
acceptedFileTypesMap={acceptedFileTypesMap}
Expand All @@ -138,13 +163,8 @@ export const IRTFileImport: FC<IRTFileImportProps & Partial<InjectedFormProps<an
</Form.Item>
</Col>
</Row>
</>
</FormWrapper>
);
};

export default (reduxForm({
form: FORM.INFORMATION_REQUIREMENTS_TABLE,
destroyOnUnmount: false,
touchOnBlur: true,
forceUnregisterOnUnmount: true,
})(IRTFileImport as any) as unknown) as FC<IRTFileImportProps>;
export default IRTFileImport;
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,15 @@ export const InformationRequirementsTablePage = () => {
};

useEffect(() => {
if (!location.state?.current) {
history.replace(location.pathname, { current: 0 });
}
handleFetchData();
}, []);

useEffect(() => {
if (project) {
setCurrent(location.state.current);
setCurrent(location.state?.current ?? 0);
if (project?.information_requirements_table?.status_code !== "DFT") {
setEditMode(true);
}
Expand All @@ -139,10 +142,16 @@ export const InformationRequirementsTablePage = () => {
};
}, []);

const getRequirementsVersion = () => {
return (
project.information_requirements_table.requirements?.[0].version ??
requirements[requirements.length - 1].version
);
};

useEffect(() => {
if (requirements.length > 0 && project.information_requirements_table) {
const projectRequirementsVersion =
project.information_requirements_table.requirements[0].version;
const projectRequirementsVersion = getRequirementsVersion();

setProjectRequirementsVersion(projectRequirementsVersion);

Expand Down
Loading