Skip to content

Attachment - Edit comment option is shown for .doc file#76167

Closed
lorretheboy wants to merge 21 commits intoExpensify:mainfrom
lorretheboy:fix/74031
Closed

Attachment - Edit comment option is shown for .doc file#76167
lorretheboy wants to merge 21 commits intoExpensify:mainfrom
lorretheboy:fix/74031

Conversation

@lorretheboy
Copy link
Copy Markdown
Contributor

@lorretheboy lorretheboy commented Nov 26, 2025

Explanation of Change

Fixed Issues

$ #74031
PROPOSAL: #74031 (comment)

Tests

  1. Launch app
  2. Open a chat
  3. Tap plus icon.l - attachment
  4. Upload a .doc file
  5. Long press step 4 file and VERIFY that edit comment option is shown
  6. Go to LHN
  7. Reopen the same chat
  8. Long press step 4 file and VERIFY that edit comment option is shown
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

Same as Tests

  • 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 verified there are no new alerts related to the canBeMissing param for useOnyx
  • 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 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 used JaimeGPT to get English > Spanish translation. I then posted it 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.ts 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 new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • 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.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • 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
Screen.Recording.2025-11-27.at.02.24.51.mov
Android: mWeb Chrome
Screen.Recording.2025-11-27.at.02.25.42.mov
iOS: Native
Screen.Recording.2025-11-27.at.02.23.07.mov
iOS: mWeb Safari
Screen.Recording.2025-11-27.at.02.22.14.mov
MacOS: Chrome / Safari
Screen.Recording.2025-11-27.at.02.26.34.mov

@lorretheboy lorretheboy changed the title fix: edit comment option is show for doc file Attachment - Edit comment option is shown for .doc file Nov 26, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Nov 26, 2025

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/libs/ReportUtils.ts 79.29% <ø> (-0.02%) ⬇️
... and 11 files with indirect coverage changes

@lorretheboy lorretheboy marked this pull request as ready for review November 26, 2025 18:28
@lorretheboy lorretheboy requested review from a team as code owners November 26, 2025 18:28
@melvin-bot melvin-bot bot requested review from situchan and removed request for a team November 26, 2025 18:28
@melvin-bot
Copy link
Copy Markdown

melvin-bot bot commented Nov 26, 2025

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

@melvin-bot melvin-bot bot requested review from trjExpensify and removed request for a team November 26, 2025 18:28
Copy link
Copy Markdown
Contributor

@trjExpensify trjExpensify left a comment

Choose a reason for hiding this comment

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

Commented on the issue, not sure we want to solve it like this.

@situchan
Copy link
Copy Markdown
Contributor

@lorretheboy can you please rework on this to allow editing all attachment-only messages?

@lorretheboy
Copy link
Copy Markdown
Contributor Author

lorretheboy commented Feb 8, 2026

@situchan If we allow to edit attachment only message, it will look like this

Screen.Recording.2026-02-09.at.01.12.21.mov

However, after edit the attachment, it turns to normal message like this. It should be editable as welll right?

image

Also I think there is no way to upload an attachment with text if we don't use rich text [file-sample_100kB__2_.doc](https://staging.expensify.com/chat-attachments/6308555414411337765/w_9499088b8535828c311cedef780f30130f325407.doc) like this

@situchan
Copy link
Copy Markdown
Contributor

situchan commented Feb 11, 2026

However, after edit the attachment, it turns to normal message like this. It should be editable as well right?

yes, it's the production behavior. We can move forward as long as the fix doesn't cause regression which doesn't happen on production.

Screen.Recording.2026-02-12.at.2.54.47.AM.mov

@lorretheboy
Copy link
Copy Markdown
Contributor Author

@situchan I pushed the fix but it won't work if we reload the page, we need update BE to return correct values isAttachmentOnly and isAttachmentWithText. Currently, these 2 values only available in optimistic data

website.mov

Optimistic data:

{
    "reportActionID": "8020209584774169997",
    "reportID": "4958621070272591",
    "actionName": "ADDCOMMENT",
    "actorAccountID": 21324019,
    "person": [
        {
            "style": "strong",
            "text": "Lorre",
            "type": "TEXT"
        }
    ],
    "automatic": false,
    "avatar": "https://d2k5nsl2zxldvw.cloudfront.net/images/avatars/default-avatar_7.png",
    "created": "2026-02-16 08:49:45.304",
    "message": [
        {
            "html": "AAAAAAAAA<br /><br /><a href=\"https://www.expensify.com/chat-attachments/8020209584774169997/w_f57043752d7f79dd0deb22fb57a33640150deea9.doc\" data-expensify-source=\"https://www.expensify.com/chat-attachments/8020209584774169997/w_f57043752d7f79dd0deb22fb57a33640150deea9.doc\">file-sample_100kB.doc</a>",
            "text": "AAAAAAAAA\n\n[Attachment]",
            "type": "COMMENT",
            "whisperedTo": []
        }
    ],
    "originalMessage": {
        "html": "AAAAAAAAA<br /><br /><a href=\"https://www.expensify.com/chat-attachments/8020209584774169997/w_f57043752d7f79dd0deb22fb57a33640150deea9.doc\" data-expensify-source=\"https://www.expensify.com/chat-attachments/8020209584774169997/w_f57043752d7f79dd0deb22fb57a33640150deea9.doc\">file-sample_100kB.doc</a>",
        "whisperedTo": [],
        "idempotencyKey": "06792075-225c-ef69-0bc2-0caa9426280d",
        "isNewDot": true,
        "lastModified": "2026-02-16 08:49:45.304"
    },
    "isFirstItem": false,
    "isAttachmentOnly": false,
    "isAttachmentWithText": true,
    "shouldShow": true,
    "lastModified": "2026-02-16 08:49:45.304"
}

Backend returns

{
    "person": [
        {
            "type": "TEXT",
            "style": "strong",
            "text": "Lorre"
        }
    ],
    "actorAccountID": 21324019,
    "message": [
        {
            "type": "COMMENT",
            "html": "AAAAAAAAA<br \/><br \/><a href=\"https:\/\/www.expensify.com\/chat-attachments\/8020209584774169997\/w_f57043752d7f79dd0deb22fb57a33640150deea9.doc\" data-expensify-source=\"https:\/\/www.expensify.com\/chat-attachments\/8020209584774169997\/w_f57043752d7f79dd0deb22fb57a33640150deea9.doc\">file-sample_100kB.doc<\/a>",
            "text": "AAAAAAAAA\n\nfile-sample_100kB.doc https:\/\/www.expensify.com\/chat-attachments\/8020209584774169997\/w_f57043752d7f79dd0deb22fb57a33640150deea9.doc",
            "isEdited": false,
            "whisperedTo": [],
            "isDeletedParentAction": false,
            "deleted": "",
            "reactions": []
        }
    ],
    "originalMessage": {
        "html": "AAAAAAAAA<br \/><br \/><a href=\"https:\/\/www.expensify.com\/chat-attachments\/8020209584774169997\/w_f57043752d7f79dd0deb22fb57a33640150deea9.doc\" data-expensify-source=\"https:\/\/www.expensify.com\/chat-attachments\/8020209584774169997\/w_f57043752d7f79dd0deb22fb57a33640150deea9.doc\">file-sample_100kB.doc<\/a>",
        "idempotencyKey": "06792075-225c-ef69-0bc2-0caa9426280d",
        "isNewDot": true,
        "lastModified": "2026-02-16 08:49:45.304"
    },
    "avatar": "https:\/\/d2k5nsl2zxldvw.cloudfront.net\/images\/avatars\/default-avatar_7.png",
    "created": "2026-02-16 08:49:45.304",
    "timestamp": 1771231785,
    "reportActionTimestamp": 1771231785304,
    "automatic": false,
    "actionName": "ADDCOMMENT",
    "shouldShow": true,
    "reportActionID": "8020209584774169997",
    "lastModified": "2026-02-16 08:49:45.304",
    "whisperedToAccountIDs": []
}

@situchan
Copy link
Copy Markdown
Contributor

I think those values are optimistic only. It's expected not coming from backend.

@lorretheboy
Copy link
Copy Markdown
Contributor Author

I will have another look today

@situchan
Copy link
Copy Markdown
Contributor

situchan commented Mar 8, 2026

@lorretheboy how's it going?

@lorretheboy
Copy link
Copy Markdown
Contributor Author

lorretheboy commented Mar 10, 2026

@situchan Sorry for the delay, I pushed the latest code. Is it matched your expectation? The logic here is that we only allow edit the msg for attachment only messages

Screen.Recording.2026-03-11.at.00.34.07.mov

@situchan
Copy link
Copy Markdown
Contributor

Please merge main

@situchan
Copy link
Copy Markdown
Contributor

The logic here is that we only allow edit the msg for attachment only messages

Why can't edit attachment+text messages?

@MelvinBot
Copy link
Copy Markdown
Contributor

🤖 PR Review

CI Failures

1. ESLint errors (PR-related, must fix):

In src/libs/isReportMessageAttachment.ts line 9, the attachmentElementRegex has unnecessary escape characters \/ inside a new RegExp() constructor string. Unlike regex literals (/.../), forward slashes don't need escaping in string-based regex:

 const attachmentElementRegex = new RegExp(
-    `<img[^>]* ${CONST.ATTACHMENT_SOURCE_ATTRIBUTE}="[^"]*"[^>]*\/?>|<(?:a|video)[^>]* ${CONST.ATTACHMENT_SOURCE_ATTRIBUTE}="[^"]*"[^>]*>[\\s\\S]*?<\/(?:a|video)>`,
+    `<img[^>]* ${CONST.ATTACHMENT_SOURCE_ATTRIBUTE}="[^"]*"[^>]*/?>|<(?:a|video)[^>]* ${CONST.ATTACHMENT_SOURCE_ATTRIBUTE}="[^"]*"[^>]*>[\\s\\S]*?</(?:a|video)>`,
     'gi',
 );

2. Full ESLint check: Same 2 errors above — the other 327 warnings are pre-existing and unrelated to this PR.

3. test (job 6): Failure in tests/ui/NewChatPageTest.tsx:112 — completely unrelated to this PR's changes (flaky/pre-existing test).

Code Review

Approach: The refactor from flag-based detection (isAttachmentWithText, isAttachmentOnly, isOptimisticAction) to content-based detection (isReportMessageWithAttachment, isAttachmentOnlyMessage) is a good improvement. Those flags were only available in optimistic data and not returned by the backend, which was the root cause of the .doc edit option appearing after reload.

Logic in canEditReportAction:

(!isAttachmentMessage || isEditableAttachment)

This allows editing when the message either (a) has no attachment, or (b) is attachment-only (no authored text). This means:

  • ✅ Plain text messages → editable
  • ✅ Attachment-only messages (just a file) → editable
  • ❌ Attachment-with-text messages → not editable

Note: The old code allowed editing attachment-with-text messages when they were non-optimistic (i.e., after reload from server). The new code blocks editing for all attachment-with-text messages. Based on the PR conversation, this appears to be the accepted direction, but worth confirming this is intentional.

isAttachmentOnlyMessage implementation: The approach of stripping attachment HTML elements via regex and checking if any authored text remains (Parser.htmlToText + StringUtils.normalize) is solid and works for both images and non-image attachments like .doc files.

Tests: Good coverage of the key cases (translated attachment-only, file attachment-only, attachment-with-text, non-attachment). Consider adding a video attachment test case as well.

Action Items

  1. Fix the ESLint errors — remove \ before / in the regex string (2 occurrences on line 9)
  2. Merge main as requested by situchan

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to set up container
ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@lorretheboy
Copy link
Copy Markdown
Contributor Author

lorretheboy commented Mar 18, 2026

@lorretheboy can you please rework on this to allow editing all attachment-only messages?

Why can't edit attachment+text messages?

@situchan At the beginning, we agree that we should rework to allow editing all attachment-only messages?

Not allow:

image

Allow:

image image

@situchan
Copy link
Copy Markdown
Contributor

@lorretheboy can you please rework on this to allow editing all attachment-only messages?

Why can't edit attachment+text messages?

@situchan At the beginning, we agree that we should rework to allow editing all attachment-only messages?

yes because we already support editing attachment+text messages in production.
But it looks like this PR is regressing the behavior by disabling it.

@lorretheboy
Copy link
Copy Markdown
Contributor Author

Alright I just to confirm again the logic, we are now switch back to original approach right? We will allow to edit any msg that contains attachment, am I correct? @situchan

@situchan
Copy link
Copy Markdown
Contributor

Alright I just to confirm again the logic, we are now switch back to original approach right? We will allow to edit any msg that contains attachment, am I correct? @situchan

Correct

Expected Result: attachment-only ✅, attachment+text ✅
Actual Result: attachment-only ❌, attachment+text ✅

(✅: editable, ❌: not editable)

Let me know if anything is unclear.

@lorretheboy
Copy link
Copy Markdown
Contributor Author

attachment+text ✅

image

attachment-only ✅
Screenshot 2026-03-19 at 11 27 29

@lorretheboy
Copy link
Copy Markdown
Contributor Author

@situchan Kindly check this please. Thx

@situchan
Copy link
Copy Markdown
Contributor

situchan commented Mar 22, 2026

The solution is completely wrong. It causes various regressions.

  • offline attachment is editable
  • last message in LHN is missing text when last visible action is attachment+text

Please update code in high quality.

  • canEditReportAction should return false when reportAction is optimistic and has attachment
  • isReportMessageAttachment should return false when message is attachment+text (or if return true, fix all regressions caused by this change)

Test both and compare this branch vs main, find & fix all regressions in 8 (2x4) cases:

  • action type: attachment-only, attachment+text
  • attachment type: image, doc, pdf, video

Test scope: LHN last message, report action style, edit visibility, after edit

@lorretheboy
Copy link
Copy Markdown
Contributor Author

I couldn't come up with new solution (the original one is outdated already). Maybe can ask for re-assign...

@situchan
Copy link
Copy Markdown
Contributor

situchan commented Apr 5, 2026

@MelvinBot implement this in new PR

@MelvinBot
Copy link
Copy Markdown
Contributor

🤖 Cannot proceed: situchan does not have write access to the target repository (Expensify/App). MelvinBot will not create branches or PRs on repos that the requesting user cannot access themselves.

@lorretheboy lorretheboy closed this Apr 8, 2026
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.

4 participants