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

feat: Integrate report fields with backend #34483

Merged
merged 19 commits into from
Feb 1, 2024

Conversation

allroundexperts
Copy link
Contributor

@allroundexperts allroundexperts commented Jan 14, 2024

Details

This PR Integrates the policy report fields with the backend.

Fixed Issues

$ #34198
PROPOSAL: N/A

Tests

  1. Open any expense report.
  2. Execute the following in console, replacing the policyID with the policyID of the policy the opened report is attached to:
Onyx.set('policyReportFields_47FB5109E0654E15', {
    text_title: {
        "defaultValue": "{report:type} #{report:reportID}",
        "fieldID": "text_title",
        "name": "Title",
        "orderWeight": 0,
        "type": "formula",

    },
    field_id_TEST: {
        "defaultValue": null,
        "fieldID": "field_id_TEST",
        "name": "Tax Code",
        "orderWeight": 1,
        "type": "text",
    },
    field_id_ANOTHER_ONE: {

        "defaultValue": "option A",
        "fieldID": "field_id_ANOTHER_ONE",
        "name": "Project",
        "orderWeight": 2,
        "type": "dropdown",
     	"values": ["option1", "option2", "option3"]
    },
    field_id_DATE_FIELD: {
        "defaultValue": "2023-11-19",
        "fieldID": "field_id_DATE_FIELD",
        "name": "Effective Date",
        "orderWeight": 3,
        "type": "date",
    }
})
  1. Enable canUseReportFields beta in Permissions.ts file.
  2. Verify that the custom fields show up.
  3. Click on each of the field.
  4. Enter a value and save it.
  5. Make sure that the field gets saved successfully.
  • Verify that no errors appear in the JS console

Offline tests

Same as above

QA Steps

  1. In Old dot, create a new Collect / Control policy.
  2. Go to the settings of this workspace and execute the following in console:
p = Policy.getCurrent();
p.policy.isPolicyExpenseChatEnabled = "true";
p.save();
  1. Go to the reports section of the settings of the newly create workspace and add some report fields.
  2. Invite a user to be a member of this new workspace.
  3. In NewDot, login as the invited user. Make sure canUseReportFields beta is enabled for the user.
  4. Go to the workspace chat room and request some money.
  5. Open the created expense report.
  6. Verify that the custom fields show up.
  7. Click on each of the field.
  8. Enter a value and save it.
  9. Make sure that the field gets saved successfully.
  • 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 approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • 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 form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label 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
Screen.Recording.2024-01-14.at.11.24.36.PM.mov
iOS: Native
Screen.Recording.2024-01-14.at.11.23.15.PM.mov
iOS: mWeb Safari
Screen.Recording.2024-01-14.at.10.57.37.PM.mov
MacOS: Chrome / Safari
Screen.Recording.2024-01-14.at.10.51.35.PM.mov
MacOS: Desktop
Screen.Recording.2024-01-14.at.10.55.37.PM.mov

@allroundexperts allroundexperts requested a review from a team as a code owner January 14, 2024 18:55
@melvin-bot melvin-bot bot requested review from sobitneupane and removed request for a team January 14, 2024 18:55
Copy link

melvin-bot bot commented Jan 14, 2024

@sobitneupane 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]

@allroundexperts
Copy link
Contributor Author

Hi @sobitneupane!
Can you please prioritise this? This has been pending for some time now.

@sobitneupane
Copy link
Contributor

@allroundexperts I won't be able to review it soon. So, can we get someone else assigned?

@jjcoffee
Copy link
Contributor

jjcoffee commented Jan 22, 2024

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (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
    • 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 approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • 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
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • 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 form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
android-native-2024-01-22_16.53.24.mp4
Android: mWeb Chrome
android-chrome-2024-01-22_16.41.02.mp4
iOS: Native
ios-native-2024-01-22_17.01.51.mp4
iOS: mWeb Safari
ios-safari-2024-01-22_17.06.03.mp4
MacOS: Chrome / Safari
desktop-chrome-2024-01-22_17.08.48.mp4
MacOS: Desktop
desktop-app-2024-01-22_17.21.49.mp4

@jjcoffee
Copy link
Contributor

@allroundexperts Could you add an Android native screenshot?

@allroundexperts
Copy link
Contributor Author

@jjcoffee I am having issues with Android build. I think testing on web should be sufficient, no?

const reportFieldValue = report?.reportFields?.[policyReportField?.fieldID ?? ''];

// Decides whether to allow or disallow editing a money request
useEffect(() => {}, []);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe tidy this away for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't really matter. It would be filled in an upcoming PR anyways. I think this would be a reminder to not miss this case!

@jjcoffee
Copy link
Contributor

@allroundexperts Testing well! I guess the relevant changes for OpenReport aren't live yet as signing out and back in resets the changes?

@allroundexperts
Copy link
Contributor Author

@allroundexperts Testing well! I guess the relevant changes for OpenReport aren't live yet as signing out and back in resets the changes?

That's correct!

Copy link
Contributor

@thienlnam thienlnam left a comment

Choose a reason for hiding this comment

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

Looking good, just one small comment

};

if (policyReportField) {
if (policyReportField.type === 'text' || policyReportField.type === 'formula') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we create constants for these report field types?

@thienlnam
Copy link
Contributor

I will make an issue so that openReport returns the report fields - I thought it returned all report NVPS but let me double check

Comment on lines 1552 to 1554
reportID,
reportFields: JSON.stringify({[policyField.fieldID]: {fieldID: policyField.fieldID, value: fieldValue, type: policyField.type, name: policyField.name}}),
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we include all values from the policyField at this time? When OpenReport passes back the reports, it will have a reportField list that contains the reportFields at the time of creation.

So if the weights change later, this report should have the same report fields weights at the time of storage for historical context

@thienlnam
Copy link
Contributor

thienlnam commented Jan 23, 2024

Also while we're here, could we also update the Report.ts to include a new key called reportFields which is a json keyed by reportfieldIDs like below? I have a PR up that passes these down

image

@jjcoffee

This comment was marked as resolved.

@allroundexperts
Copy link
Contributor Author

Also while we're here, could we also update the Report.ts to include a new key called reportFields which is a json keyed by reportfieldIDs like below? I have a PR up that passes these down

image

@thienlnam That exists already. One thing to note is that for the reports, we don't really need the full reportField object. That object exists in the policy already so I don't see any point in duplicating that into reports everywhere. We should just store the value of the field in the report.

Screenshot 2024-01-23 at 11 55 10 PM

@allroundexperts
Copy link
Contributor Author

@allroundexperts There seems to be quite a delay for updating the field value on Android native only, compared with updating a request:

android-speed-2024-01-23_10.58.53.mp4
(It could be something to do with the size of the report)

This doesn't seem to have anything to do with the code of this PR. I think we can ignore this here.

@jjcoffee
Copy link
Contributor

This doesn't seem to have anything to do with the code of this PR. I think we can ignore this here.

Agreed, I guess it's an Onyx issue. I retested on a smaller report and it's much faster.

@thienlnam
Copy link
Contributor

thienlnam commented Jan 24, 2024

One thing to note is that for the reports, we don't really need the full reportField object. That object exists in the policy already so I don't see any point in duplicating that into reports everywhere. We should just store the value of the field in the report.

We do this because we store the report fields at the time the report was created. For example, if you had some report fields, all expense reports would use those fields.

If you decided to change all of your report fields, you don't actually want it to change on your previous submitted reports. Those will retain the report fields that were already set. If we only had the object in the policy, we wouldn't have a way to see the old set report fields on an older report

@allroundexperts
Copy link
Contributor Author

We do this because we store the report fields at the time the report was created. For example, if you had some report fields, all expense reports would use those fields.

If you decided to change all of your report fields, you don't actually want it to change on your previous submitted reports. Those will retain the report fields that were already set. If we only had the object in the policy, we wouldn't have a way to see the old set report fields on an older report

I thought we discussed this at some point and decided to use the fields stored in the policy as a single source of truth. However, if we need to change that, then the backend will need to ensure that for an open report (one that hasn't been settled), the fields attached to a report are in sync with the fields that are attached to the policy.

Given this, do you think I should do the changes in this PR or as a separate issue?

Copy link
Contributor

@thienlnam thienlnam left a comment

Choose a reason for hiding this comment

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

Nice - this looks solid! Thanks

@thienlnam
Copy link
Contributor

@jjcoffee There's been a lot that has changed in this PR since your original review, could you please do another review / quick round of testing just to make sure none of the changes add any blockers?

@thienlnam
Copy link
Contributor

Additionally, @allroundexperts could you please update the QA steps with the these instructions #34889 (comment) so that applause can test this when it goes to staging?

@allroundexperts
Copy link
Contributor Author

Additionally, @allroundexperts could you please update the QA steps with the these instructions #34889 (comment) so that applause can test this when it goes to staging?

Sure thing. I'm done with my day so will take care of it tomorrow!

@thienlnam thienlnam requested review from jjcoffee and removed request for sobitneupane January 31, 2024 01:19
@jjcoffee
Copy link
Contributor

@thienlnam Testing well so far! Just wondering if the OpenReport fix for setting the fields has hit production yet? None of the changes seem to persist, e.g. on navigating to another report or refreshing.

@jjcoffee
Copy link
Contributor

Not sure if this is within scope of this PR, but trying to save the text_title field results in a You can't rename the report of a free plan 666 error from the BE, which isn't displayed anywhere on the FE.

@jjcoffee
Copy link
Contributor

@allroundexperts Bug: Open any report (without doing any of the Onyx.set steps), enter some value for the VAT Number default field returned from BE. Note several console errors:

image

@jjcoffee
Copy link
Contributor

Bug: Go offline, update some field values and save, go back online. The field values disappear. (I assume this is related to the BE changes not being live).

desktop-chrome-offline-2024-01-31_12.11.42.mp4

@jjcoffee
Copy link
Contributor

Bug? Going in to edit the default title returned by the BE I'd expect this to be an editable formula.

image

@thienlnam
Copy link
Contributor

thienlnam commented Jan 31, 2024

@thienlnam Testing well so far! Just wondering if the OpenReport fix for setting the fields has hit production yet? None of the changes seem to persist, e.g. on navigating to another report or refreshing.

OpenReport should be returning the fields under report.reportFields, I'm not aware of anything being broken with it, but I also have some pusher updates changes for Report_SetFields

Not sure if this is within scope of this PR, but trying to save the text_title field results in a You can't rename the report of a free plan 666 error from the BE, which isn't displayed anywhere on the FE.

I think this because we're trying to add reportFields on a free plan for testing here - in theory, you won't be able to add these for free plans

Bug? Going in to edit the default title returned by the BE I'd expect this to be an editable formula.

You won't be able to change the formula, just the value so this works as expected

@allroundexperts
Copy link
Contributor Author

I agree with @thienlnam about all these bugs.

@allroundexperts
Copy link
Contributor Author

Added the correct QA steps @thienlnam. Please let me know if they look good enough.

@thienlnam
Copy link
Contributor

thienlnam commented Jan 31, 2024

Yup - the QA steps look solid

@allroundexperts Bug: Open any report (without doing any of the Onyx.set steps), enter some value for the VAT Number default field returned from BE. Note several console errors:

Have you been able to check this bug?

EDIT: Oh, I actually think this might be related to the free workspace thing. So going to merge without this since it doesn't appear to be a blocker

@thienlnam thienlnam merged commit c2083e3 into Expensify:main Feb 1, 2024
17 checks passed
@OSBotify
Copy link
Contributor

OSBotify commented Feb 1, 2024

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

OSBotify commented Feb 5, 2024

🚀 Deployed to production by https://github.com/marcaaron in version: 1.4.36-5 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

* Given a report field, check if the field is for the report title.
*/
function isReportFieldOfTypeTitle(reportField: OnyxEntry<PolicyReportField>): boolean {
return reportField?.type === 'formula' && reportField?.fieldID === CONST.REPORT_FIELD_TITLE_FIELD_ID;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should Custom report name field necessarily be a formula?

We have an issue here #49077. The bug here is if we set the custom report name as some text string instead of a formula, backend returns the type of the title field as text. Then this check fails and Title field shows up in the report though it should not show up here as per this code

if (ReportUtils.isReportFieldOfTypeTitle(reportField)) {
return null;

Can you please help here?

@thienlnam @allroundexperts @jjcoffee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants