Skip to content

[Search] Add Export CSV and handle offline for all actions#45468

Merged
luacmartins merged 10 commits intoExpensify:mainfrom
software-mansion-labs:search/export-csv-items
Jul 17, 2024
Merged

[Search] Add Export CSV and handle offline for all actions#45468
luacmartins merged 10 commits intoExpensify:mainfrom
software-mansion-labs:search/export-csv-items

Conversation

@filip-solecki
Copy link
Contributor

@filip-solecki filip-solecki commented Jul 16, 2024

Details

Fixed Issues

$ #44576
PROPOSAL:

Tests

  1. Log in to the account with Search Data
  2. Select a few items
  3. Click on "X selected" button
  4. Click "Download"
  5. When offline you should see Modal with information otherwise the file will be downloaded
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop

@filip-solecki filip-solecki marked this pull request as ready for review July 16, 2024 13:11
@filip-solecki filip-solecki requested a review from a team as a code owner July 16, 2024 13:11
@melvin-bot melvin-bot bot requested review from ikevin127 and removed request for a team July 16, 2024 13:11
@melvin-bot
Copy link

melvin-bot bot commented Jul 16, 2024

@ikevin127 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

Copy link
Contributor

@Kicu Kicu left a comment

Choose a reason for hiding this comment

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

Looks moreless ok, left some comments

export {search, createTransactionThread, deleteMoneyRequestOnSearch, holdMoneyRequestOnSearch, unholdMoneyRequestOnSearch};
type Params = Record<string, string | string[]>;

function exportSearchItemsToCSV(query: string, reportIDList: string[] | undefined, transactionIDList: string[], policyIDs: string[]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we will very soon remove query, do you how this will work then? Could you please ping here whoever is responsible for backend for CSV?
in Search v2.1 we're moving to a parser and AST object for search

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc @rlinoz

Copy link
Contributor

Choose a reason for hiding this comment

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

This will need to keep parity with how search works, so we will need to update it to use the same AST object when it is available. I am not sure if this is part of Search v2.1 as well, but I think it should be since export is tied to search.

cc: @luacmartins @trjExpensify

Copy link
Contributor

@Kicu Kicu Jul 16, 2024

Choose a reason for hiding this comment

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

my understanding is that switching Search to use AST is within v2.1 and some of us in SWM are currently working on this "migration" already. This is one of the issues you can monitor: #45027

Will keep this in mind and communicate when we will be doing the switch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, sounds good. Glad it's on everyone's radar for when that is!

Copy link
Contributor

Choose a reason for hiding this comment

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

We're moving to the jsonQuery AST in Search v2.1 and have already implemented parts of the changes, currently working on the final switch to the new syntax, so we'll need to update this code to work with the syntax.

@trjExpensify trjExpensify requested review from rushatgabhane and removed request for ikevin127 July 16, 2024 14:07
@trjExpensify
Copy link
Contributor

@rushatgabhane has been C+'ing this project, so I'm switching him in for a review now as we're trying to get this deployed through to prod by the end of the week before the conference on Monday. 👍

@trjExpensify trjExpensify requested a review from rlinoz July 16, 2024 14:08
@trjExpensify
Copy link
Contributor

Adding you for a review as well, @rlinoz!

Comment on lines +102 to +104
const queryString = Object.entries(finalParameters)
.map(([key, value]) => `${key}=${Array.isArray(value) ? value.join(',') : String(value)}`)
.join('&');
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm couldn't this hit the url limit of 2048 chars? Each transactionID is ~19 chars long, so if the user selects ~100 transactions we'll hit that limit already, no?

Copy link
Contributor

Choose a reason for hiding this comment

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

That is a good point, @filip-solecki I think we will have to go back to the previous idea of finding a way to send a post in the native apps for downloads.

Copy link
Member

@rushatgabhane rushatgabhane Jul 16, 2024

Choose a reason for hiding this comment

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

I had this issue at prev full time work. I remember writing a hack to create an a tag, setting the post response as the target for the a tag and clicking it using javascript

const response = postRequest(url, contentType: 'text/csv', body);
const blob = await response.blob();

const a = document.createElement('a'); 
a.href = URL.createObjectURL(blob);
a.download = 'fileName.csv';

document.body.appendChild(a);
a.click(); 

For native we could do something similar

RNFetchBlob.config({}).postRequest(url, contentType: 'text/csv', body)

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure that the lib can't handle post requests? It seems to define other types and handle a body param in fetch

Copy link
Contributor

Choose a reason for hiding this comment

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

We are using the downloadManager which according to the docs doesn't support a POST.

I think we should try to download without the downloadManager set to true and check what happens, but let's do it in the other issue so we can get this done by EOW.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's worth a shot with useDownloadManager: false the downside is that it won't show progress, notifications, etc.

Is the issue only on android?

Copy link
Contributor

Choose a reason for hiding this comment

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

cc @Julesssss maybe you might have some insights on using android's Download Manager and passing params to the request (not in the URL)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

both Android and iOS. Desktop also needs refactor but it is more likely to fix it quickly there

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't recall any specifics regarding the download manager GET limitation. Is it essential we use the native download manager lib? it has nice functionality but perhaps we can use an alternative method to download the CSV file (I think that is what we are trying to do here?) then show our own custom notification

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly, this is what I am working on right now, downloading seems to be working on iOS right now

Copy link
Contributor

@rlinoz rlinoz left a comment

Choose a reason for hiding this comment

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

It is working well overall, lets just polish a few things

}

const itemsToDelete = Object.keys(selectedItems ?? {}).filter((id) => selectedItems[id].canDelete);
const options: Array<DropdownOption<SearchHeaderOptionValue>> = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are doing the native elsewhere, lets add the download option only if we are on web for now.

body: formData,
};

return fetch(url, fetchOptions)
Copy link
Contributor

Choose a reason for hiding this comment

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

Currently if some error occurs we are opening the the url in a new tab (line 59), lets show the generic error modal for the CSV download case

image

@github-actions
Copy link
Contributor

@luacmartins luacmartins merged commit c4dc4aa into Expensify:main Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants