-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[$250] [Support CSV] Categories - File contains errors when downloading CSV with no category #49022
Comments
Triggered auto assignment to @Christinadobrzyn ( |
Triggered auto assignment to @blimpich ( |
👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:
|
Looking into this. |
Talked about it in Slack, decided its not a deploy blocker. Doesn't prevent them from using the app and is also pretty edge case. |
Job added to Upwork: https://www.upwork.com/jobs/~021833956684433969336 |
Triggered auto assignment to Contributor-plus team member for initial proposal review - @brunovjk ( |
Discussed expected behavior in this #expensify-open-source thread. Probably should just not be showing the "download csv" button if there are no categories. @rlinoz can you confirm that? |
Yeah, I think we can go with that. Another thing that we should do is make sure that if a download CSV request throws an error we don't write it in the CSV and instead show a modal. |
Edited by proposal-police: This proposal was edited at 2024-09-11 20:22:19 UTC. ProposalPlease re-state the problem that we are trying to solve in this issue.
What is the root cause of that problem?
What changes do you think we should make in order to solve the problem?
const menuItems = [
{
icon: Expensicons.Table,
text: translate('spreadsheet.importSpreadsheet'),
onSelected: () => {
if (isOffline) {
Modal.close(() => setIsOfflineModalVisible(true));
return;
}
Navigation.navigate(ROUTES.WORKSPACE_CATEGORIES_IMPORT.getRoute(policyId));
},
},
];
if (hasVisibleCategory) {
menuItems.push({
icon: Expensicons.Download,
text: translate('spreadsheet.downloadCSV'),
onSelected: () => {
if (isOffline) {
Modal.close(() => setIsOfflineModalVisible(true));
return;
}
Category.downloadCategoriesCSV(policyId);
},
});
} What alternative solutions did you explore? (Optional)Or any similar method to hide the option could be used. Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job. |
ProposalPlease re-state the problem that we are trying to solve in this issue.File contains errors when downloading CSV with no category What is the root cause of that problem?We show the download csv option here even when there are no categories. What changes do you think we should make in order to solve the problem?We will remove the option to download CSV here if the user has no visible categories, i.e, App/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx Lines 313 to 323 in 2add16c
|
Proposalupdated added code. |
/issues/49022#issuecomment-2344598138) added code.) |
ProposalPlease re-state the problem that we are trying to solve in this issue.Categories - File contains errors when downloading CSV with no category What is root cause of that problem?We show the download option despite the fact that we have no categories. In addition to this we don’t have a modal that will be shown when a csv download request throws an error. What Changes do you think we should make in order to solve the problem?For the first issue, we can simply push the App/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx Lines 313 to 315 in 5327409
For the second issue mentioned here,
We can achieve it by following a similar approach we used while downloading csv’s in search page. App/src/components/Search/index.tsx Lines 426 to 434 in 5327409
Next, set the modal to true here by updating it to the following.
- function downloadCategoriesCSV(policyID: string) {
+ function downloadCategoriesCSV(policyID: string, onDownloadFailed: () => void) {
.
.
.
- fileDownload(ApiUtils.getCommandURL({command: WRITE_COMMANDS.EXPORT_CATEGORIES_CSV}), 'Categories.csv', '', false, formData, CONST.NETWORK.METHOD.POST);
+ fileDownload(ApiUtils.getCommandURL({command: WRITE_COMMANDS.EXPORT_CATEGORIES_CSV}), 'Categories.csv', '', false, formData, CONST.NETWORK.METHOD.POST, onDownloadFailed);
The same way we do for What alternative solutions did you explore? (Optional)None |
@HezekielT Your proposal will be dismissed because you did not follow the proposal template. |
I have followed the proposal template! Proposal Updated.
|
Edited by proposal-police: This proposal was edited at 2024-09-12 04:42:44 UTC. ProposalPlease re-state the problem that we are trying to solve in this issue.Issue 1: The download button appears even when no categories are visible. Issue 2: There is no mechanism to prevent users from downloading files that contain errors. What is the root cause of that problem?Issue 1: The Download button is always visible in the three-dot menu. There is no condition in place to control its visibility App/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx Lines 313 to 320 in 336e478
Issue 2: We do not check the content from the API before initiating the download App/src/libs/fileDownload/DownloadUtils.ts Lines 56 to 63 in 336e478
In this scenario, the backend returns And this JSON response will be downloaded to the user's device. What changes do you think we should make in order to solve the problem?Issue 1: The Download button should only be added to the three-dot menu when hasVisibleCategories is true. Issue 2: We need to read and verify the content of the blob before proceeding with the download. We have two options to implement this Solution 1:PART 1: Handle exception (@rlinoz Suggestion: #49022 (comment))For downloading .csv file, we should check the response headers to determine the content type; if it’s is application/json, we can throw an error to trigger the catch block App/src/libs/fileDownload/DownloadUtils.ts Lines 56 to 63 in 336e478
PART 2: Show a modal to inform the user of an error (Similar to solution 1)Next, we need to pass onDownloadFailed function to downloadCategoriesCSV and fileDownload functions. (this function will show a new warning modal when the catch block is triggered) App/src/libs/actions/Policy/Category.ts Line 1014 in 336e478
onDownloadFailed will open new modal to announce that the download fail because some reason. We can utilize Solution 2 (my original proposal):PART 1: Handle exceptionThis is a preliminary outline of my proposal. App/src/libs/fileDownload/DownloadUtils.ts Lines 56 to 63 in 336e478
New function to validate and parse JSON
PART 2: Show a modal to inform the user of an error.Similar to Solution 1 What alternative solutions did you explore? (Optional) |
reviewing proposals |
keldansig Your proposal will be dismissed because you did not follow the proposal template. |
@blazejkustra Absolutely. However, as per @rlinoz's suggestion, we still need to implement a mechanism to handle errors that might occur during file downloads. |
@rlinoz Currently BE doesn't throw an error, instead the response is 200 with this payload:
With the current logic, the above json is copied as plain text to the file because processHTTPRequest logic that validates Wouldn't it make more sense to throw a real error from backend so the catch block in return fetch(url, fetchOptions)
.then((blob) => {
...
})
.catch(() => {
if (onDownloadFailed) {
onDownloadFailed();
} else {
// file could not be downloaded, open sourceURL in new tab
Link.openExternalLink(url);
}
}); Another approach would be to extract the logic from |
With this method, we might still need to make updates on the backend side. Here's the current response: In case, we decide to give an update in BE. We still need to adjust some things on the FE. I already updated proposal #49022 (comment) |
I would love that, but I think for historical reasons we send the error in the I think we already validate the @cretadn22 I think we can verify the headers of the response to check the content type and if it is different than |
@rlinoz the headers object is empty in this case
In this case, to get jsonCode we need to read reponse.blob() first |
@cretadn22 It's not true, you can read the headers, just not directly: const contentType = response.headers.get('content-type');
if (contentType === 'application/json') {
const json = response.json() as Promise<Response>;
} |
@blazejkustra Perfect. It works for me.
@rlinoz @brunovjk I think we can use the above suggestion to verify all .csv files or introduce new param to decide if we should verify the header. Wdyt? Note:
|
@brunovjk I updated my proposal: #49022 (comment) |
Nice, I will review it today |
Yeah, I think that should work. If we go with that let's just make sure that we can also download a csv attachment, although I see no reason why that would fail. |
@rlinoz Sure. I tested it thoroughly, and it worked well. |
If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!
Version Number: 9.0.32-3
Reproducible in staging?: Y
Reproducible in production?: N/A - new feature, doesn't exist in prod
Email or phone of affected tester (no customers): applausetester+kh010901@applause.expensifail.com
Issue reported by: Applause Internal Team
Action Performed:
Expected Result:
The file should not contain error when downloading CSV with no categories.
Actual Result:
The file contains errors when downloading CSV with no category.
Workaround:
Unknown
Platforms:
Screenshots/Videos
Bug6600256_1726080845912.Screen_Recording_20240912_024951_Sheets.mp4
View all open jobs on GitHub
Upwork Automation - Do Not Edit
Issue Owner
Current Issue Owner: @brunovjkThe text was updated successfully, but these errors were encountered: