-
Notifications
You must be signed in to change notification settings - Fork 3
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
fix(RV-428): Fix change upload flow to reflect UI #494
Conversation
154a7d8
to
ab5c187
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG, just have a question regarding the error handling logic in case the file that is uploaded is not a pdf. Are we considering that?
if (files.length > 0) { | ||
setUploadedFile([]); | ||
clearFiles(); | ||
setHasError(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setHasError
is set to false
here. Is there a try/catch logic that will handle errors in case the file that is uploaded is not a pdf?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handled outside in the extractProcess page
try {
setIsLoading(true);
const newQueries = pdfs
.map((pdf) => {
return pdf.images.map((page, index) => {
const selectedTemplateName = selectedTemplates.find(
(temp) => temp.fileName === pdf.file,
)?.templateName;
return {
pdfName: pdf.file,
fieldNames: templates.find(
(template) => template.name === selectedTemplateName,
)?.pages[index].fieldNames as Field[],
sourceImage: page,
templateImage: templates.find(
(template) => template.name === selectedTemplateName,
)?.pages[index].templateImage as string,
};
});
})
.map((perBatch) =>
perBatch.map(async (args) => ({
name: args.pdfName,
resp: await ImageToText({
sourceImage: args.sourceImage,
templateImage: args.templateImage,
fieldNames: args.fieldNames,
}),
})),
)
.flat();
const new_responses = await Promise.all(
newQueries.map(async (query) => ({
name: (await query).name,
resp: (await query).resp,
})),
);
const arrResults: { [key: string]: IResults } = {};
new_responses.forEach((response) => {
if (response.name in arrResults) {
Object.keys(response.resp as ImageToTextResponse).forEach((key) => {
arrResults[response.name][key] = {
text: response.resp ? response.resp[key][0] : "",
confidence: response.resp ? response.resp[key][1] : 0,
};
});
} else {
arrResults[response.name] = {};
Object.keys(response.resp as ImageToTextResponse).forEach((key) => {
arrResults[response.name][key] = {
text: response.resp ? response.resp[key][0] : "",
confidence: response.resp ? response.resp[key][1] : 0,
};
});
}
});
const arrTransformedResponses: Submission[] = Object.keys(arrResults).map(
(key) => {
const transformedResponses: Submission = {
template_name: templates[0].name,
template_image: templates[0].pages[0].templateImage,
file_name: key,
file_image: pdfs.find((pdf) => pdf.file === key)
?.images[0] as string,
results: arrResults[key],
};
return transformedResponses;
},
);
localStorage.setItem(
"arr_submissions",
JSON.stringify(arrTransformedResponses),
);
// Update loading state and navigate
setIsLoading(false);
navigate("/extract/review");
} catch (error) {
console.error("Error processing templates:", error);
setIsLoading(false);
navigate("/extract/upload");
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [navigate]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we navigate back to the start of the flow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we def need to get design/product for the app when the user uploads not a pdf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now i just gated the input to only take in pdfs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
ab5c187
to
1258741
Compare
1258741
to
6972ebd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
if (files.length > 0) { | ||
setUploadedFile([]); | ||
clearFiles(); | ||
setHasError(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
Description
fix change upload button
Screenshots (if applicable)
Related Issues
[Link any related issues or tasks from your project management system.]
Checklist