Skip to content

Commit

Permalink
added active inactive validation (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhavya-egov authored Jun 10, 2024
1 parent 5974eb3 commit 1ba2098
Showing 1 changed file with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const UploadData = ({ formData, onSelect, ...props }) => {
// data.columns = sortedPropertyNames;
}


function convertIntoSchema(data) {
const properties = {};
const required = [];
Expand Down Expand Up @@ -159,7 +160,9 @@ const UploadData = ({ formData, onSelect, ...props }) => {
useEffect(async () => {
if (Schemas?.["HCM-ADMIN-CONSOLE"]?.adminSchema) {
const facility = await convertIntoSchema(Schemas?.["HCM-ADMIN-CONSOLE"]?.adminSchema?.filter((item) => item.title === "facility")?.[0]);
const boundary = await convertIntoSchema(Schemas?.["HCM-ADMIN-CONSOLE"]?.adminSchema?.filter((item) => item.title === "boundaryWithTarget")?.[0]);
const boundary = await convertIntoSchema(
Schemas?.["HCM-ADMIN-CONSOLE"]?.adminSchema?.filter((item) => item.title === "boundaryWithTarget")?.[0]
);
const user = await convertIntoSchema(Schemas?.["HCM-ADMIN-CONSOLE"]?.adminSchema?.filter((item) => item.title === "user")?.[0]);
const newFacilitySchema = await translateSchema(facility);
const newBoundarySchema = await translateSchema(boundary);
Expand All @@ -181,7 +184,6 @@ const UploadData = ({ formData, onSelect, ...props }) => {
}
}, [Schemas?.["HCM-ADMIN-CONSOLE"]?.adminSchema, type]);


useEffect(async () => {
if (readMe?.["HCM-ADMIN-CONSOLE"]) {
const newReadMeFacility = await translateReadMeInfo(
Expand Down Expand Up @@ -464,6 +466,20 @@ const UploadData = ({ formData, onSelect, ...props }) => {

const SheetNames = workbook.SheetNames[1];
const expectedHeaders = sheetHeaders[type];

const sheetData = XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[1]], { blankrows: true });
var jsonData = sheetData.map((row, index) => {
const rowData = {};
if (Object.keys(row).length > 0) {
Object.keys(row).forEach((key) => {
rowData[key] = row[key] === undefined || row[key] === "" ? "" : row[key];
});
rowData["!row#number!"] = index + 1; // Adding row number
return rowData;
}
});

jsonData = jsonData.filter((element) => element !== undefined);
if (type === "boundary") {
if (SheetNames !== t("HCM_ADMIN_CONSOLE_BOUNDARY_DATA")) {
const errorMessage = t("HCM_INVALID_BOUNDARY_SHEET");
Expand All @@ -475,6 +491,13 @@ const UploadData = ({ formData, onSelect, ...props }) => {
return;
}
} else if (type === "facilityWithBoundary") {
if (type === "facilityWithBoundary") {
const activeColumnName = t("HCM_ADMIN_CONSOLE_FACILITY_USAGE");
const uniqueIdentifierColumnName = t("HCM_ADMIN_CONSOLE_FACILITY_CODE");
if (activeColumnName && uniqueIdentifierColumnName) {
jsonData = jsonData.filter((item) => item[activeColumnName] === "Active" || !item[uniqueIdentifierColumnName]);
}
}
if (SheetNames !== t("HCM_ADMIN_CONSOLE_AVAILABLE_FACILITIES")) {
const errorMessage = t("HCM_INVALID_FACILITY_SHEET");
setErrorsType((prevErrors) => ({
Expand Down Expand Up @@ -513,19 +536,6 @@ const UploadData = ({ formData, onSelect, ...props }) => {
}
}

const sheetData = XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[1]], { blankrows: true });
var jsonData = sheetData.map((row, index) => {
const rowData = {};
if (Object.keys(row).length > 0) {
Object.keys(row).forEach((key) => {
rowData[key] = row[key] === undefined || row[key] === "" ? "" : row[key];
});
rowData["!row#number!"] = index + 1; // Adding row number
return rowData;
}
});

jsonData = jsonData.filter((element) => element !== undefined);

if (type === "boundary" && workbook?.SheetNames.length == 1) {
if (!validateTarget(jsonData, headersToValidate)) {
Expand Down

0 comments on commit 1ba2098

Please sign in to comment.