Skip to content

Commit

Permalink
fixed min time, draft logic (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhavya-egov authored Jun 14, 2024
1 parent 4ac7d2a commit 8e1615b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const UploadData = ({ formData, onSelect, ...props }) => {
const { data: Schemas, isLoading: isThisLoading } = Digit.Hooks.useCustomMDMS(tenantId, "HCM-ADMIN-CONSOLE", [{ name: "adminSchema" }]);

const { data: readMe } = Digit.Hooks.useCustomMDMS(tenantId, "HCM-ADMIN-CONSOLE", [{ name: "ReadMeConfig" }]);
const { data: baseTimeOut } = Digit.Hooks.useCustomMDMS(tenantId, "HCM-ADMIN-CONSOLE", [{ name: "baseTimeOut" }]);
const { data: baseTimeOut } = Digit.Hooks.useCustomMDMS(tenantId, "HCM-ADMIN-CONSOLE", [{ name: "baseTimeout" }]);
const [sheetHeaders, setSheetHeaders] = useState({});
const [translatedSchema, setTranslatedSchema] = useState({});
const [readMeInfo, setReadMeInfo] = useState({});
Expand Down Expand Up @@ -306,16 +306,6 @@ const UploadData = ({ formData, onSelect, ...props }) => {
.map(({ index, errors }) => {
const formattedErrors = errors
.map((error) => {
// let formattedError = `${error.instancePath}: ${error.message}`;
// if (error.keyword === "enum" && error.params && error.params.allowedValues) {
// formattedError += `. Allowed values are: ${error.params.allowedValues.join("/ ")}`;
// }
// return formattedError;
// })
// .join(", ");
// return `Data at row ${index}: ${formattedErrors}`;
// })
// .join(" , ");
let instancePath = error.instancePath || ""; // Assign an empty string if dataPath is not available
if (instancePath.startsWith("/")) {
instancePath = instancePath.slice(1);
Expand Down Expand Up @@ -395,6 +385,7 @@ const UploadData = ({ formData, onSelect, ...props }) => {
let validate = ajv.compile(translatedSchema[type]);
const errors = []; // Array to hold validation errors


data.forEach((item, index) => {
if (!validate(item)) {
errors.push({ index: (item?.["!row#number!"] || item?.["__rowNum__"]) + 1, errors: validate.errors });
Expand Down Expand Up @@ -428,16 +419,6 @@ const UploadData = ({ formData, onSelect, ...props }) => {
.map(({ index, errors }) => {
const formattedErrors = errors
.map((error) => {
// let formattedError = `${error.instancePath}: ${error.message}`;
// if (error.keyword === "enum" && error.params && error.params.allowedValues) {
// formattedError += `. Allowed values are: ${error.params.allowedValues.join("/ ")}`;
// }
// return formattedError;
// })
// .join(", ");
// return `Data at row ${index}: ${formattedErrors}`;
// })
// .join(" , ");
let instancePath = error.instancePath || ""; // Assign an empty string if dataPath is not available
if (instancePath.startsWith("/")) {
instancePath = instancePath.slice(1);
Expand All @@ -460,6 +441,7 @@ const UploadData = ({ formData, onSelect, ...props }) => {
})
.join(", ");


setIsError(true);
targetError.push(errorMessage);
return false;
Expand Down Expand Up @@ -795,7 +777,7 @@ const UploadData = ({ formData, onSelect, ...props }) => {
type,
tenantId,
id,
baseTimeOut?.["HCM-ADMIN-CONSOLE"]?.baseTimeOut?.[0]?.baseTimeOut
baseTimeOut?.["HCM-ADMIN-CONSOLE"]
);
if (temp?.isError) {
setLoader(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const baseTimeOut =
{
baseTimeOut: 100
baseTimeOut: 100,
maxTime: 5000
};

Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ export const useResourceData = async (data, hierarchyType, type, tenantId, id ,

let searchResponse;
let status = "validation-started";
const baseDelay = baseTimeOut;
let retryInterval = baseDelay * jsonDataLength;
const baseDelay = baseTimeOut?.baseTimeout?.[0]?.baseTimeOut;
const maxTime = baseTimeOut?.baseTimeout?.[0]?.maxTime;
let retryInterval = Math.min(baseDelay * jsonDataLength , maxTime);

await new Promise((resolve) => setTimeout(resolve, retryInterval));

Expand All @@ -96,7 +97,6 @@ export const useResourceData = async (data, hierarchyType, type, tenantId, id ,
});
status = searchResponse?.ResourceDetails?.[0]?.status;
if (status !== "failed" && status !== "invalid" && status !== "completed") {
retryInterval *= 2;
await new Promise((resolve) => setTimeout(resolve, retryInterval));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,19 @@ const SetupCampaign = ({ hierarchyType }) => {
},
},
HCM_CAMPAIGN_UPLOAD_BOUNDARY_DATA: {
uploadBoundary: { uploadedFile: draftData?.resources?.filter((i) => i?.type === "boundaryWithTarget") },
uploadBoundary: { uploadedFile: draftData?.resources?.filter((i) => i?.type === "boundaryWithTarget"),
isSuccess : draftData?.resources?.filter((i) => i?.type === "boundaryWithTarget").length>0
},
},
HCM_CAMPAIGN_UPLOAD_FACILITY_DATA: {
uploadFacility: { uploadedFile: draftData?.resources?.filter((i) => i?.type === "facility") },
uploadFacility: { uploadedFile: draftData?.resources?.filter((i) => i?.type === "facility") ,
isSuccess : draftData?.resources?.filter((i) => i?.type === "facility").length>0
}
},
HCM_CAMPAIGN_UPLOAD_USER_DATA: {
uploadUser: { uploadedFile: draftData?.resources?.filter((i) => i?.type === "user") },
uploadUser: { uploadedFile: draftData?.resources?.filter((i) => i?.type === "user") ,
isSuccess : draftData?.resources?.filter((i) => i?.type === "user").length>0
},
},
};
setParams({ ...restructureFormData });
Expand Down

0 comments on commit 8e1615b

Please sign in to comment.