[Bugfix:Forum] Sync forum toggle text#12568
Conversation
…al post toggles
roye2
left a comment
There was a problem hiding this comment.
I did a code & functionality review:
- The changes to the code look good and I agree with the method of the implementation (syncing the button with the image loading).
- The functionality appears to work in that the button correctly hides and displays all attachments in the forum.
I did however notice that there is a number included on the button, that seems to display whether there are attachments present on the specific forum post you are viewing. I observed that the button will say 0 if there are no images or 1 if there is at least one image.
This may be outside the scope of this pr, but I wonder if it would be possible to update the number associated with the button s.t. it correctly displays the number of attachments in the forum as a whole (since the button is show/hide all for all posts.)
Screenshots attached depict the issue.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #12568 +/- ##
=========================================
Coverage 21.66% 21.66%
Complexity 9637 9637
=========================================
Files 268 268
Lines 36222 36222
Branches 487 487
=========================================
Hits 7847 7847
Misses 27892 27892
Partials 483 483
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
Hi @roye2, I have updated the branch with the requested changes. A new review is required to verify the fixes and to check if the previous CI failures persist. Regarding the failure in late_submission_warning_messages.spec.js (Cypress Gradeable tests), it appears to be unrelated to my forum changes, as it specifically involves late day calculations. Once the review is complete, we can confirm if this was an intermittent failure or a separate issue. |
|
Hi @roye2 , I checked the logic and it looks like the backend is already sending the correct total through {{total_attachments }} in ForumBar.twig. The issue is actually in forum.js. Inside showAttachmentsOnload(), there's a line that manually overwrites the badge text with $('.attachment-btn').length. Since that only counts what’s currently rendered, it messes up the global total. If I just pull out this line, it should stay synced with the backend value: Should I go ahead and include that fix in this PR, or would you prefer it in a separate one? |
|
@Ash092016 It is fine with me if you add that change to this PR as well, it seems like it is still sort of in the scope of the main issue. I will run the tests once you've done that. The cypress Gradeable test is flaky, there is a PR about a fix currently as far as I am aware :) |
|
Hi @roye2 , I've just pushed the fix for the attachment badge count. It now relies on the backend value from the template and won't be overwritten by the JS count anymore. |
roye2
left a comment
There was a problem hiding this comment.
I see that you have added the changes to the button, but upon testing I found that the count listed on the button still only references the page / post currently rendered, and not the whole forum. For example, when I am on a post with no attachments, the button says 0. Or, when I am on a post with multiple attachments, the button says 1. (In my test, I have multiple posts with multiple attachments.)
It seems like it may not be a simple fix to actually make the count display properly, so if you determine that the change is too complicated, we can move it to it's own PR and I will approve this one.
|
Hi @roye2, thank you for the detailed feedback! |
roye2
left a comment
There was a problem hiding this comment.
Aside from reverting the previous change, I approve of the changes made in this PR.
|
Hi @roye2 , I have revert the changes and have added the same! |
### Why is this Change Important & Necessary? Fixes Submitty#12477. Currently, the global "Show/Hide Attachments" toggle in the discussion forum functions independently of the individual post "Attachments" buttons. If a user manually opens or closes attachments on a per-post basis, the global menu text and browser cookie become inaccurate (e.g., the menu might show "Show Attachments" even if the user has already manually opened all of them). This PR ensures the UI remains consistent by synchronizing the global state with individual actions. ### What is the New Behavior? Every time an individual post's attachment is toggled, the page is scanned to check if any attachments are currently visible. The global "More" -> "Show/Hide Attachments" button text and the `show_forum_attachments` cookie are then updated to reflect the actual state of the page. - If at least one attachment is visible, the global button will say **"Hide attachments"**. - If all attachments are closed, the global button will say **"Show attachments"**. ### What steps should a reviewer take to reproduce or test the bug or new feature? 1. Open a forum thread that has multiple posts with attachments. 2. Click the **"More"** button and observe the state (default is usually "Show attachments"). 3. Manually click the **"Attachments"** button on an individual post to show its images. 4. Open the **"More"** dropdown again; it should now automatically say **"Hide attachments"**. 5. Manually hide that post's attachments. The **"More"** dropdown should now revert to saying **"Show attachments"**. ### Automated Testing & Documentation This is a client-side UI synchronization fix. It has been manually verified to ensure correctly functioning toggles and accurate cookie state updates. No changes to documentation or new automated tests were required for this specific UI patch. ### Other information - **Breaking Change-** No. - **Migrations-** No. - **Security Concerns-** None.
### Why is this Change Important & Necessary? Fixes Submitty#12477. Currently, the global "Show/Hide Attachments" toggle in the discussion forum functions independently of the individual post "Attachments" buttons. If a user manually opens or closes attachments on a per-post basis, the global menu text and browser cookie become inaccurate (e.g., the menu might show "Show Attachments" even if the user has already manually opened all of them). This PR ensures the UI remains consistent by synchronizing the global state with individual actions. ### What is the New Behavior? Every time an individual post's attachment is toggled, the page is scanned to check if any attachments are currently visible. The global "More" -> "Show/Hide Attachments" button text and the `show_forum_attachments` cookie are then updated to reflect the actual state of the page. - If at least one attachment is visible, the global button will say **"Hide attachments"**. - If all attachments are closed, the global button will say **"Show attachments"**. ### What steps should a reviewer take to reproduce or test the bug or new feature? 1. Open a forum thread that has multiple posts with attachments. 2. Click the **"More"** button and observe the state (default is usually "Show attachments"). 3. Manually click the **"Attachments"** button on an individual post to show its images. 4. Open the **"More"** dropdown again; it should now automatically say **"Hide attachments"**. 5. Manually hide that post's attachments. The **"More"** dropdown should now revert to saying **"Show attachments"**. ### Automated Testing & Documentation This is a client-side UI synchronization fix. It has been manually verified to ensure correctly functioning toggles and accurate cookie state updates. No changes to documentation or new automated tests were required for this specific UI patch. ### Other information - **Breaking Change-** No. - **Migrations-** No. - **Security Concerns-** None.
### Why is this Change Important & Necessary? Fixes Submitty#12477. Currently, the global "Show/Hide Attachments" toggle in the discussion forum functions independently of the individual post "Attachments" buttons. If a user manually opens or closes attachments on a per-post basis, the global menu text and browser cookie become inaccurate (e.g., the menu might show "Show Attachments" even if the user has already manually opened all of them). This PR ensures the UI remains consistent by synchronizing the global state with individual actions. ### What is the New Behavior? Every time an individual post's attachment is toggled, the page is scanned to check if any attachments are currently visible. The global "More" -> "Show/Hide Attachments" button text and the `show_forum_attachments` cookie are then updated to reflect the actual state of the page. - If at least one attachment is visible, the global button will say **"Hide attachments"**. - If all attachments are closed, the global button will say **"Show attachments"**. ### What steps should a reviewer take to reproduce or test the bug or new feature? 1. Open a forum thread that has multiple posts with attachments. 2. Click the **"More"** button and observe the state (default is usually "Show attachments"). 3. Manually click the **"Attachments"** button on an individual post to show its images. 4. Open the **"More"** dropdown again; it should now automatically say **"Hide attachments"**. 5. Manually hide that post's attachments. The **"More"** dropdown should now revert to saying **"Show attachments"**. ### Automated Testing & Documentation This is a client-side UI synchronization fix. It has been manually verified to ensure correctly functioning toggles and accurate cookie state updates. No changes to documentation or new automated tests were required for this specific UI patch. ### Other information - **Breaking Change-** No. - **Migrations-** No. - **Security Concerns-** None.
### Why is this Change Important & Necessary? Fixes Submitty#12477. Currently, the global "Show/Hide Attachments" toggle in the discussion forum functions independently of the individual post "Attachments" buttons. If a user manually opens or closes attachments on a per-post basis, the global menu text and browser cookie become inaccurate (e.g., the menu might show "Show Attachments" even if the user has already manually opened all of them). This PR ensures the UI remains consistent by synchronizing the global state with individual actions. ### What is the New Behavior? Every time an individual post's attachment is toggled, the page is scanned to check if any attachments are currently visible. The global "More" -> "Show/Hide Attachments" button text and the `show_forum_attachments` cookie are then updated to reflect the actual state of the page. - If at least one attachment is visible, the global button will say **"Hide attachments"**. - If all attachments are closed, the global button will say **"Show attachments"**. ### What steps should a reviewer take to reproduce or test the bug or new feature? 1. Open a forum thread that has multiple posts with attachments. 2. Click the **"More"** button and observe the state (default is usually "Show attachments"). 3. Manually click the **"Attachments"** button on an individual post to show its images. 4. Open the **"More"** dropdown again; it should now automatically say **"Hide attachments"**. 5. Manually hide that post's attachments. The **"More"** dropdown should now revert to saying **"Show attachments"**. ### Automated Testing & Documentation This is a client-side UI synchronization fix. It has been manually verified to ensure correctly functioning toggles and accurate cookie state updates. No changes to documentation or new automated tests were required for this specific UI patch. ### Other information - **Breaking Change-** No. - **Migrations-** No. - **Security Concerns-** None.
Why is this Change Important & Necessary?
Fixes #12477.
Currently, the global "Show/Hide Attachments" toggle in the discussion forum functions independently of the individual post "Attachments" buttons. If a user manually opens or closes attachments on a per-post basis, the global menu text and browser cookie become inaccurate (e.g., the menu might show "Show Attachments" even if the user has already manually opened all of them). This PR ensures the UI remains consistent by synchronizing the global state with individual actions.
What is the New Behavior?
Every time an individual post's attachment is toggled, the page is scanned to check if any attachments are currently visible. The global "More" -> "Show/Hide Attachments" button text and the
show_forum_attachmentscookie are then updated to reflect the actual state of the page.What steps should a reviewer take to reproduce or test the bug or new feature?
Automated Testing & Documentation
This is a client-side UI synchronization fix. It has been manually verified to ensure correctly functioning toggles and accurate cookie state updates. No changes to documentation or new automated tests were required for this specific UI patch.
Other information