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

Delete Comments #2046

Merged
merged 82 commits into from
May 28, 2021
Merged

Delete Comments #2046

merged 82 commits into from
May 28, 2021

Conversation

sketchydroide
Copy link
Contributor

@sketchydroide sketchydroide commented Mar 24, 2021

<If necessary, assign reviewers that know the area or changes well. Feel free to tag any additional reviewers you see fit.>

Details

Fixed Issues

Fixes https://github.com/Expensify/Expensify/issues/147483
Fixes #2966

Tests / QA Steps (web/desktop)

  1. Hover over a message that you did not write, and verify that you do not see the Edit Comment or Delete Comment actions as options in the ReportActionContextMenu
  2. Right-click a message that you did not write, and verify that you do not see the Edit Comment or Delete Comment actions as options in the ReportActionContextMenu
  3. Hover over a message that you did write, and press Edit Comment
  4. Make a change to the message, and press Save Changes.
  5. Verify that the change takes effect.
  6. Wait for a few seconds, then refresh the page.
  7. Verify that the comment remains edited.
  8. Right-click a message that you did write, and press Edit Comment
  9. Make a change to the message, and press Save Changes.
  10. Verify that the change takes effect.
  11. Wait for a few seconds, then refresh the page.
  12. Verify that the comment remains edited.
  13. Hover over a message that you did write, and press Delete Comment
  14. A confirmation modal should appear. Press cancel.
  15. Verify that the message is not deleted.
  16. Wait for a few seconds, then refresh the page.
  17. Verify that the message is still not deleted.
  18. Hover over a message that you did write, and press Delete Comment
  19. A confirmation modal should appear. Press confirm.
  20. Verify that the message no longer appears.
  21. Wait for a few seconds, then refresh the page.
  22. Verify that the message remains deleted.
  23. Right-click a message that you did write, and press Delete Comment
  24. A confirmation modal should appear. Press confirm.
  25. Verify that the message no longer appears.
  26. Wait for a few seconds, then refresh the page.
  27. Verify that the message remains deleted.
  28. Hover over a message that you did write, and press Edit Comment
  29. Erase all the content of the message, then hit Save Changes.
  30. Verify that the message no longer appears.
  31. Wait for a few seconds, then refresh the page.
  32. Verify that the message remains deleted.

Tests / QA Steps (iOS/Android/mWeb)

  1. LongPress a message that you did not write, and verify that you do not see the Edit Comment or Delete Comment actions as options in the ReportActionContextMenu
  2. LongPress a message that you did write, and press Edit Comment.
  3. Make a change to the message and press Save Changes
  4. Verify that the change takes effect.
  5. (mWeb only) Wait for a few seconds, then refresh the page.
  6. (mWeb only) Verify that the comment remains edited.
  7. LongPress a message that you did write, and press Delete Comment
  8. A confirmation modal should appear. Press cancel.
  9. Verify that the message is not deleted.
  10. (mWeb only) Wait for a few seconds, then refresh the page.
  11. (mWeb only) Verify that the comment is still visible.
  12. LongPress a message that you did write, and press Delete Comment
  13. A confirmation modal should appear. Press confirm.
  14. Verify that the message no longer appears.
  15. (mWeb only) Wait for a few seconds, then refresh the page.
  16. (mWeb only) Verify that the comment remains deleted.
  17. LongPress a message that you did write, and press Edit Comment
  18. Erase all the content of the message, then hit Save Changes
  19. Verify that the message no longer appears.
  20. (mWeb only) Wait for a few seconds, then refresh the page.
  21. (mWeb only) Verify that the comment remains deleted.

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

@sketchydroide sketchydroide self-assigned this Mar 24, 2021
@sketchydroide sketchydroide requested a review from a team as a code owner March 24, 2021 18:40
@sketchydroide sketchydroide marked this pull request as draft March 24, 2021 18:40
@botify botify requested review from Jag96 and removed request for a team March 24, 2021 18:40
@github-actions
Copy link
Contributor

github-actions bot commented Mar 24, 2021

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@sketchydroide sketchydroide removed the request for review from Jag96 March 26, 2021 16:53
@sketchydroide
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

# Conflicts:
#	src/libs/API.js
#	src/pages/home/report/ReportActionContextMenu.js
#	src/pages/home/report/ReportActionContextMenuItem.js
#	src/pages/home/report/ReportActionsView.js
but I'm going to try use
``` javascript
import Onyx, {withOnyx} from 'react-native-onyx';
```
 instead
# Conflicts:
#	src/pages/home/report/ReportActionContextMenu.js
#	src/pages/home/report/ReportActionItem.js
@sketchydroide sketchydroide changed the title [WIP] started work on this [WIP] Delete Comments Apr 9, 2021
@sketchydroide sketchydroide changed the title [WIP] Delete Comments Delete Comments Apr 12, 2021
@sketchydroide sketchydroide requested review from roryabraham and a team April 12, 2021 15:50
@@ -112,9 +120,10 @@ class ReportActionContextMenu extends React.Component {
{
text: this.props.translate('reportActionContextMenu.editComment'),
icon: Pencil,
shouldShow: this.props.reportAction.actorEmail === this.props.session.email
shouldShow: () => (
this.canEdit
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this.canEdit
this.canEdit()

# Conflicts:
#	src/languages/en.js
/**
* A list of all the context actions in this menu.
*/
this.contextActions = [
Copy link
Contributor

Choose a reason for hiding this comment

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

sooooo, heh, sorry to keep commenting here, but are these going to be moved outside the class?

}

/**
Confirms the deletion of the comment and hides the confirmation modal.
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need this method doc (or the one below) at all (like PHP, they are only needed if the method is non-obvious)

@@ -248,7 +248,13 @@ class ReportActionsView extends React.Component {
updateSortedReportActions(reportActions) {
this.sortedReportActions = _.chain(reportActions)
.sortBy('sequenceNumber')
.filter(action => action.actionName === 'ADDCOMMENT' || action.actionName === 'IOU')
.filter((action) => {
// Only show non-empty ADDCOMMENT actions or IOU actions
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment does a good job of explaining "what" the code is doing, but not "why" it's doing it. The comment could be improved to explain why it's not showing any other actions.

Copy link
Contributor

@tgolen tgolen left a comment

Choose a reason for hiding this comment

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

OK, thanks for moving that. After seeing it, I agree with you that it can be reverted. I didn't realize we would have to pass more than props and seeing all this stuff being passed around is worse than just keeping it in the constructor. There are probably some ways around all this, but let's just revert this last change and get this out.

@tgolen
Copy link
Contributor

tgolen commented May 25, 2021

I just tested this quickly and found an interesting bug.

  1. On Web (maybe desktop too) Click the delete icon in the hover-menu
  2. Verify the confirmation pops up
  3. Move your mouse outside of the window
  4. 💥 notice that the confirmation window disappears
  5. Move your mouse back inside the window
  6. Once you hover over the same comment you are trying to delete, the confirmation window appears again

* @return {Boolean}
*/
canEdit() {
return this.props.reportAction.actorEmail === this.props.session.email
Copy link
Contributor

Choose a reason for hiding this comment

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

@sketchydroide we also shouldn't be able to edit/delete IOU actions, or any other type of report action (not yet, anyways). So let's add a check for that here:

canEditReportAction() {
    return this.props.reportAction.actionName === 'ADDCOMMENT' // Bonus: make a constant for report action names
        && this.props.reportAction.actorEmail === this.props.session.email
        && this.props.reportAction.reportActionID;
}

@sketchydroide
Copy link
Contributor Author

I just tested this quickly and found an interesting bug.

  1. On Web (maybe desktop too) Click the delete icon in the hover-menu
  2. Verify the confirmation pops up
  3. Move your mouse outside of the window
  4. 💥 notice that the confirmation window disappears
  5. Move your mouse back inside the window
  6. Once you hover over the same comment you are trying to delete, the confirmation window appears again

While I completly agree this is a bug, I would suggest creating a GH for it, this PR is already a bit complex, and fixing that bug would add further complexity.
But I think the solution would involve changing Hoverable here and add a state variable that we would use on ReportActionItem here and that when we show the ConfirmModal this would let the hoverable know that it can't be dismissed until the ConfirmModal is resolved

Not sure if that makes sense.

@tgolen
Copy link
Contributor

tgolen commented May 27, 2021

OK, I'm fine with opening a separate GH to handle that.

@sketchydroide
Copy link
Contributor Author

...reportAction,
message: [
{
type: 'COMMENT',
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this should be moved to a constant to be consistent with the other actions having constants too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that is just the type of the message not the action, but I'm happy with adding those to constants as well

Copy link
Contributor

@roryabraham roryabraham left a comment

Choose a reason for hiding this comment

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

Okay, I think this is looking good 👍

@sketchydroide sketchydroide requested a review from tgolen May 28, 2021 16:29
Copy link
Contributor

@tgolen tgolen left a comment

Choose a reason for hiding this comment

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

Looks good! In some future improvement, we probably could allow editing the optimistic comment. In that case, it would just fire off a second edit comment request to the API and things would probably work fine.

@tgolen
Copy link
Contributor

tgolen commented May 28, 2021

and that would allow you to edit comments while offline, which would be kinda cool...

@tgolen tgolen merged commit e7ec636 into main May 28, 2021
@tgolen tgolen deleted the afonseca_delete_comments branch May 28, 2021 18:07
@OSBotify
Copy link
Contributor

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

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.

Edit button does not show up on Hover Menu for recently sent message
6 participants