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

[$250] Report fields -System message shows undefined when list value is changed back to initial value #47067

Open
6 tasks done
IuliiaHerets opened this issue Aug 8, 2024 · 117 comments
Labels
Bug Something is broken. Auto assigns a BugZero manager. Design External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2

Comments

@IuliiaHerets
Copy link

IuliiaHerets commented Aug 8, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: v9.0.18-1
Reproducible in staging?: Y
Reproducible in production?: Y
Email or phone of affected tester (no customers): [email protected]
Issue reported by: Applause Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Submit two expenses.
  4. Go to workspace settings > Report fields (enable in More features).
  5. Add a list type report field, with some list values and an initial value.
  6. Return to the workspace chat.
  7. Go to expense report.
  8. Click on the list report field.
  9. Select a different list value.
  10. Revisit the report.
  11. Click on the list report field.
  12. Click on the already selected value (so that it will change to the initial value).
  13. Revisit the report.

Expected Result:

The system message will not contain "undefined".

Actual Result:

The system message contains "undefined" when the list value is changed back to the initial value.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug6565437_1723109214472.20240808_172103.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~014a67065c97e4bdba
  • Upwork Job ID: 1822942704704377446
  • Last Price Increase: 2024-08-19
  • Automatic offers:
    • dukenv0307 | Reviewer | 103641179
    • nkdengineer | Contributor | 103641182
    • etCoderDysto | Contributor | 105612296
Issue OwnerCurrent Issue Owner: @grgia
@IuliiaHerets IuliiaHerets added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Aug 8, 2024
Copy link

melvin-bot bot commented Aug 8, 2024

Triggered auto assignment to @bfitzexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@IuliiaHerets
Copy link
Author

We think that this bug might be related to #wave-control

@IuliiaHerets
Copy link
Author

@bfitzexpensify FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

@etCoderDysto
Copy link
Contributor

etCoderDysto commented Aug 8, 2024

Edited by proposal-police: This proposal was edited at 2024-08-08 13:17:27 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue.

System message shows undefined when list value is changed back to initial value

What is the root cause of that problem?

When selecting the same value (fieldValue === option.text), we assign empty string to fieldKey and pass it to the submit function

onSelectRow={(option) => onSubmit({[fieldKey]: !option?.text || fieldValue === option.text ? '' : option.text})}

Then when value is an empty string we assign null to value prop, update the BE with with a new reportField that has null as a value
const handleReportFieldChange = (form: FormOnyxValues<typeof ONYXKEYS.FORMS.REPORT_FIELDS_EDIT_FORM>) => {
const value = form[fieldKey];
if (isReportFieldTitle) {
ReportActions.updateReportName(report.reportID, value, report.reportName ?? '');
Navigation.goBack();
} else {
ReportActions.updateReportField(report.reportID, {...reportField, value: value === '' ? null : value}, reportField);

Then BE returns a report action object that have null on originalMessage.newValue prop

What changes do you think we should make in order to solve the problem?

We should remove

|| fieldValue === option.text

from

onSelectRow={(option) => onSubmit({[fieldKey]: !option?.text || fieldValue === option.text ? '' : option.text})}

Or we should change it to

 onSelectRow={(option) => onSubmit({[fieldKey]: option?.text  ??  '' })}

What alternative solutions did you explore? (Optional)

We can dismiss the modal when value is an empty string

if (value) {
ReportActions.updateReportField(report.reportID, {...reportField, value}, reportField);
            }
Navigation.dismissModal(report?.reportID);

@nkdengineer
Copy link
Contributor

nkdengineer commented Aug 8, 2024

Edited by proposal-police: This proposal was edited at 2024-08-08 13:11:00 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue.

The system message contains "undefined" when the list value is changed back to the initial value.

What is the root cause of that problem?

If the selected value is the current value of the report field, we pass it as empty string here

onSelectRow={(option) => onSubmit({[fieldKey]: !option?.text || fieldValue === option.text ? '' : option.text})}

Then here we pass the new value of the report field as null

ReportActions.updateReportField(report.reportID, {...reportField, value: value === '' ? null : value}, reportField);

So BE returns the new value in report action as null. Then when merging data to Onyx, the newValue field is deleted since it has null value.

Screenshot 2024-08-08 at 20 02 25

It leads newValue being undefined when we get the message here

return Localize.translateLocal('report.actions.type.changeField', {oldValue, newValue, fieldName});

What changes do you think we should make in order to solve the problem?

We should add another case when the new value doesn't exist to display a message like remove the ${fieldName} (previously "${oldValue}"). We also need to create a new translation key for this message

if (!newValue) {
    return // translated message;
}

if (!oldValue) {

What alternative solutions did you explore? (Optional)

We can do nothing if the user select the selected value

onSelectRow={(option) => {
    if (fieldValue === option.text || !option?.text) {
        return;
    }
    onSubmit({[fieldKey]: option.text})
}} 

onSelectRow={(option) => onSubmit({[fieldKey]: !option?.text || fieldValue === option.text ? '' : option.text})}
initiallyFocusedOptionKey={selectedOptionKey ?? undefined}

@nkdengineer
Copy link
Contributor

Updated proposal

  • Detail the RCA

@etCoderDysto
Copy link
Contributor

etCoderDysto commented Aug 8, 2024

Updated proposal

  • Added an alternative solution

@melvin-bot melvin-bot bot added the Overdue label Aug 12, 2024
@bfitzexpensify bfitzexpensify added the External Added to denote the issue can be worked on by a contributor label Aug 12, 2024
@melvin-bot melvin-bot bot changed the title Report fields -System message shows undefined when list value is changed back to initial value [$250] Report fields -System message shows undefined when list value is changed back to initial value Aug 12, 2024
Copy link

melvin-bot bot commented Aug 12, 2024

Job added to Upwork: https://www.upwork.com/jobs/~014a67065c97e4bdba

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 12, 2024
Copy link

melvin-bot bot commented Aug 12, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @dukenv0307 (External)

@melvin-bot melvin-bot bot removed the Overdue label Aug 12, 2024
@dukenv0307

This comment was marked as outdated.

Copy link

melvin-bot bot commented Aug 12, 2024

Triggered auto assignment to @grgia, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@etCoderDysto
Copy link
Contributor

etCoderDysto commented Aug 12, 2024

@dukenv0307 Can we please ask someone from internal to confirm the expected behaviour? From UX perspective, It doesn't make sense to select the default value when the user is selecting another report field twice. Especially when the user can select the default value if they want.

Report field values are 1, 2, 3. And the default value is 1 in the video. When selecting '2' twice, the value reverts to '1' which is the default value. If the user want to change the value to '1', they can select it form the list.

Screen.Recording.2024-08-12.at.2.12.40.in.the.afternoon.mp4

cc: @grgia @mountiny

@mountiny
Copy link
Contributor

@etCoderDysto can you please write this bug in numbered steps? That will be easier to understand

@etCoderDysto
Copy link
Contributor

@mountiny If we implement The selected solution, the result will be following

Steps

  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Submit two expenses.
  4. Go to workspace settings > Report fields (enable in More features).
  5. Add a list type report field, with some list values and an initial value. (in my video the initial value is '1')
  6. Return to the workspace chat.
  7. Go to expense report.
  8. Click on the list report field.
  9. Select a different list value. (in my video the value is 2)
  10. Click on the list report field.
  11. Click on the already selected value (in my video the value is 2)

Expected Result: The selected report field shouldn't fallback to default report field, and it should be the selected one which is ('2')
Actual result: The selected report field falls back to the initial report field('1') when user selects a report field that is already selected

Attachment:

Screen.Recording.2024-08-12.at.2.12.40.in.the.afternoon.mp4

@mountiny
Copy link
Contributor

@etCoderDysto got it, I agree with that, we should not change to the default.

Can we just close the panel and do nothing when user clicks on the already selected report field?

@nkdengineer
Copy link
Contributor

@mountiny

If we want to do nothing, I believe the proposal from @etCoderDysto doesn't get this expected behavior. This proposal makes the API called then a report action is created with the message displayed like change report field from value1 to value1

I updated my proposal with alternative solution to do that

@etCoderDysto
Copy link
Contributor

etCoderDysto commented Aug 12, 2024

Can we just close the panel and do nothing when user clicks on the already selected report field?

@mountiny When the user selects existing report field, handleReportFieldChange is called with value prop assigned to an empty string. We can check if 'value' is empty string and dismiss the modal when it is. But I have to check if this change won't introduce a regression since handleReportFieldChange is called when editing Date and Text report fields

if (value) {
  ReportActions.updateReportField(report.reportID, {...reportField, value}, reportField);reportField);
            }
Navigation.dismissModal(report?.reportID);

const handleReportFieldChange = (form: FormOnyxValues<typeof ONYXKEYS.FORMS.REPORT_FIELDS_EDIT_FORM>) => {
const value = form[fieldKey];
if (isReportFieldTitle) {
ReportActions.updateReportName(report.reportID, value, report.reportName ?? '');
Navigation.goBack();
} else {
ReportActions.updateReportField(report.reportID, {...reportField, value: value === '' ? null : value}, reportField);

Alternatively, my proposal states that we should call updateReportField, with the existing report field value when user selects existing report field.

@nkdengineer
Copy link
Contributor

@mountiny Additional I think we can do this because for tag or category, we can de-select the select tag/category when we click on the selected option. So I think can do the same for report field.

@etCoderDysto
Copy link
Contributor

etCoderDysto commented Aug 12, 2024

@mountiny

If we want to do nothing, I believe the proposal from @etCoderDysto doesn't get this expected behavior. This proposal makes the API called then a report action is created with the message displayed like change report field from value1 to value1

I updated my proposal with alternative solution to do that

It will make the API call, but there will be no action messages. The action message is only rendered when there is a change in value. And the alternative solution you just proposed won't close the modal, since dismmisModal is called only in handleReportFieldChange

@grgia
Copy link
Contributor

grgia commented Dec 4, 2024

@dukenv0307

Could you take a look at Role on a member in a workspace as a reference for behavior.

We'd like to mimic the behavior there where clicking the currently selected value just does nothing and navigates back. Basically like “reselecting” it.

@cead22 cead22 self-assigned this Dec 4, 2024
@nkdengineer
Copy link
Contributor

@grgia Based on the discussion above here. We want to use deselecting behavior like we do for category/tag and will display a violation after deselecting the selected report field list value.

So we need to make some changes:

  1. We will not display the default value as a fallback here

const fieldValue = reportField.value ?? reportField.defaultValue;

  1. When we create a new expense report, the value in reportField of the expense report should be the defaultValue of the policy reportField if it exists. With this when we create a new expense report, the default value can still display as reportField.value not reportField.defaultValue

  2. When we edit the report field, If we select the selected report field, we will send the value as null to the backend. In this case, the backend doesn't return a report violation now and we need to return a report violation in the case value is changed to null because we will not display reportField.defaultValue anymore.

@trjExpensify
Copy link
Contributor

Hm, but given that there always has to be a value for the report field (consistent with OldDot behaviour and what the backend expects) why don't we treat it like the Role select list where selecting the value already selected, doesn't deselect. That would avoid all of the downstream complications with "undefined", silently still setting the default value, or weird system messages that look broken.

2024-12-05_22-34-46.mp4

@grgia
Copy link
Contributor

grgia commented Dec 9, 2024

@nkdengineer any thoughts on the above?

@etCoderDysto
Copy link
Contributor

etCoderDysto commented Dec 9, 2024

@grgia When we select an already selected report field, we can avoid making an API request, and the already selected report field will remain selected. If we do that, we don't have to make BE changes to return a violation since we will not be submitting a report field with a null value. @dukenv0307 Can you please take a look at my proposal? In alternative solution, It suggests that we should close the modal without making an API request when the user selects an already selected report field. You can take a look at the result of my proposal in this video

Thanks!

@grgia
Copy link
Contributor

grgia commented Dec 9, 2024

Bump @dukenv0307

@nkdengineer
Copy link
Contributor

@nkdengineer any thoughts on the above?

Since BE allows changing the value of the list report field to empty, I think we should keep this behavior as we do for tag/category (For tag/category if we setting required, we can still change this to empty and display a violation about the requirement) and just need to fix the system message for more useful.

@grgia I suggest this behavior here because the backend still accepts changing the dropdown report field to empty. The context is here: #47067 (comment)

@dukenv0307
Copy link
Contributor

dukenv0307 commented Dec 10, 2024

@grgia @etCoderDysto I think we already discussed this issue before here then decided to go with @nkdengineer's idea

@dukenv0307
Copy link
Contributor

I think we should ask design team for the final decision

@shawnborton
Copy link
Contributor

I like @trjExpensify 's suggestion above.

@dannymcclain
Copy link
Contributor

I also like @trjExpensify's suggestion.

@grgia
Copy link
Contributor

grgia commented Dec 11, 2024

Yep let's stick with that behavior @dukenv0307

@dukenv0307
Copy link
Contributor

Seem like we want to change the expectation based on this comment. So @etCoderDysto's proposal is valid now. But should we re-assign to @etCoderDysto or assign both of them since @nkdengineer's proposal was selected before and he spent time on it? cc @grgia

@melvin-bot melvin-bot bot added the Overdue label Dec 20, 2024
@grgia
Copy link
Contributor

grgia commented Dec 20, 2024

@dukenv0307 given the scope changes, we should look at the proposals again holistically. Given the convo and participation, what would you suggest?

@melvin-bot melvin-bot bot removed the Overdue label Dec 20, 2024
@dukenv0307
Copy link
Contributor

@grgia We should go with @etCoderDysto's alternative solution

@melvin-bot melvin-bot bot added the Overdue label Dec 30, 2024
@etCoderDysto
Copy link
Contributor

@grgia A kind reminder to take a loo at this comment ↑

@dukenv0307
Copy link
Contributor

@grgia friendly bump

@grgia
Copy link
Contributor

grgia commented Jan 8, 2025

Great, thank you!

Copy link

melvin-bot bot commented Jan 8, 2025

📣 @etCoderDysto 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@etCoderDysto
Copy link
Contributor

@dukenv0307 PR is ready for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Design External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2
Projects
Status: Bugs and Follow Up Issues
Development

No branches or pull requests