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

added active inactive validation #820

Merged
merged 1 commit into from
Jun 10, 2024
Merged
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
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;
}
});
Comment on lines +471 to +480
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declare variables at the root of the enclosing function to avoid confusion.

Move the declaration of jsonData to the top of the function to improve readability and maintainability:

+ var jsonData;
  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;
    }
  });
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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;
}
});
var jsonData;
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;
}
});
Tools
Biome

[error] 471-480: This var should be declared at the root of the enclosing function. (lint/correctness/noInnerDeclarations)

The var is accessible in the whole body of the enclosing function.
To avoid confusion, it should be declared at the root of the enclosing function.


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
Loading