Files
Robert Bond ffcccf8981 Merged PR 2240: refactor(newappeal): simplify nested prop boundaries (Slice 7)
refactor(newappeal): simplify nested prop boundaries (Slice 7)

Related work items: #22588
2026-04-13 12:25:45 +00:00

198 lines
7.9 KiB
JavaScript

import _ from "lodash";
import useTranslation from "next-translate/useTranslation";
import { useRouter } from "next/router";
import BuildField from "./buildfield";
import {
parseRowOuterHTML,
selectRowDataFieldContent,
selectRowDataFieldName,
selectRowDateEnd,
selectRowDateStart,
selectRowDocumentTypeCode,
selectRowFieldType,
selectRowHint,
selectRowLabelDescriptions,
selectRowMaxFieldLength,
selectRowMaxSubField,
selectRowParentField,
selectRowParentFieldShowOnValue,
selectRowRequiredDocumentLabel,
selectRowRequiredDocumentValue,
selectRowValidation
} from "../../lib/newappeal/formDerivation";
export default function BuildRow(props) {
let { t } = useTranslation();
const legacyProps = props.props;
const legacyPageProps = legacyProps.props;
const router = useRouter();
const { locale } = router;
const {
rowXML,
whichSection,
sectionCount,
onSubmit,
mandatoryFieldsData,
setUploadCount,
uploadCount,
setFileCount,
completedUploadFilesCount,
setCompletedUploadFilesCount
} = props;
return (
<div className="govuk-grid-column-full">
{Object.keys(rowXML).map((key, index) => {
var doc = parseRowOuterHTML(rowXML[key].outerHTML);
if (_.isEmpty(rowXML[key].innerHTML)) {
("");
} else {
var rows = selectRowLabelDescriptions(doc);
var fieldtype = selectRowFieldType(doc);
var validation = selectRowValidation(doc);
var maxFieldLength = selectRowMaxFieldLength(doc);
var maxSubField = selectRowMaxSubField(doc);
var datafieldname = selectRowDataFieldName(doc);
var datafieldcontent = selectRowDataFieldContent(doc);
var parentField = selectRowParentField(doc);
var parentFieldShowOnValue =
selectRowParentFieldShowOnValue(doc);
var requiredDocumentValue =
selectRowRequiredDocumentValue(doc);
var requiredDocumentLabel =
selectRowRequiredDocumentLabel(doc);
var documentTypeCode = selectRowDocumentTypeCode(doc);
var hint = selectRowHint(doc);
var dateStart = selectRowDateStart(doc);
var dateEnd = selectRowDateEnd(doc);
hint = !_.isEmpty(hint) && hint[0].value;
validation = !_.isEmpty(validation)
? validation[0].value
: [];
maxFieldLength =
!_.isEmpty(maxFieldLength) && maxFieldLength[0].value;
maxSubField =
!_.isEmpty(maxSubField) && maxSubField[0].value;
parentField =
!_.isEmpty(parentField) && parentField[0].value;
parentFieldShowOnValue =
!_.isEmpty(parentFieldShowOnValue) &&
parentFieldShowOnValue[0].value;
datafieldcontent =
!_.isEmpty(datafieldcontent) &&
datafieldcontent[0].value;
requiredDocumentValue =
!_.isEmpty(requiredDocumentValue) &&
requiredDocumentValue[0].value;
requiredDocumentLabel =
!_.isEmpty(requiredDocumentLabel) &&
requiredDocumentLabel[0].value;
documentTypeCode =
!_.isEmpty(documentTypeCode) &&
documentTypeCode[0].value;
dateStart = !_.isEmpty(dateStart) && dateStart[0].value;
dateEnd = !_.isEmpty(dateEnd) && dateEnd[0].value;
//const isRequiredField = jsonpath({path:
// "$..value[?(@ && @.LogicalName=='" +
// datafieldname[0].value +
// "')]",
// mandatoryFieldsData
// );
//console.log("build row datafieldname[0]", datafieldname[0]);
if (datafieldname[0].value == "pinswg_fileUpload") {
return (
<BuildField
fieldType={fieldtype[0].value}
label={rows[0].value}
datafieldname={datafieldname[0].value}
key={key}
props={props}
picklistData={
legacyPageProps.formData.pickListData
}
mandatoryFieldsData={mandatoryFieldsData}
documentTypeCode={documentTypeCode}
setFileCount={setFileCount}
setUploadCount={setUploadCount}
uploadCount={uploadCount}
/>
);
} else {
//console.log(
// datafieldname[0].value,
// isRequiredField[0].RequiredLevel.Value
// );
// if (typeof isRequiredField[0] != "undefined") {
// if (
// isRequiredField[0].RequiredLevel.Value != "None"
// ) {
//console.log(datafieldname[0].value, validation);
return (
<BuildField
fieldType={fieldtype[0].value}
label={rows[0].value}
datafieldname={datafieldname[0].value}
datafieldcontent={datafieldcontent}
parentField={parentField}
parentFieldShowOnValue={parentFieldShowOnValue}
key={key}
props={props}
picklistData={
legacyPageProps.formData.pickListData
}
mandatoryFieldsData={mandatoryFieldsData}
hint={hint}
requiredDocumentLabel={requiredDocumentLabel}
requiredDocumentValue={requiredDocumentValue}
validation={validation}
maxFieldLength={maxFieldLength}
dateStart={dateStart}
dateEnd={dateEnd}
setDocumentsList={legacyProps.setDocumentsList}
documentList={
legacyProps.appealType.documentList
}
documentTypeCode={documentTypeCode}
setFilesForAppeal={
legacyProps.setFilesForAppeal
}
maxSubField={maxSubField}
setFileCount={setFileCount}
setUploadCount={setUploadCount}
/>
);
// } else {
// return null;
// }
// } else {
// return null;
// }
}
}
})}
</div>
);
}