Skip to content

[Bugfix:Forum] Sync forum toggle text#12568

Merged
bmcutler merged 6 commits into
Submitty:mainfrom
Ash092016:bugfix/forum-attachment-toggle-sync
Mar 22, 2026
Merged

[Bugfix:Forum] Sync forum toggle text#12568
bmcutler merged 6 commits into
Submitty:mainfrom
Ash092016:bugfix/forum-attachment-toggle-sync

Conversation

@Ash092016

Copy link
Copy Markdown
Contributor

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_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.

@github-project-automation github-project-automation Bot moved this to Seeking Reviewer in Submitty Development Mar 11, 2026
@roye2
roye2 self-requested a review March 13, 2026 02:23
@roye2 roye2 self-assigned this Mar 13, 2026
@automateprojectmangement automateprojectmangement Bot moved this from Seeking Reviewer to In Review in Submitty Development Mar 13, 2026

@roye2 roye2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I did a code & functionality review:

  1. The changes to the code look good and I agree with the method of the implementation (syncing the button with the image loading).
  2. 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.

Image Image

@codecov

codecov Bot commented Mar 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 21.66%. Comparing base (9cb25d6) to head (3e5e05e).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            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           
Flag Coverage Δ
autograder 21.32% <ø> (ø)
js 2.04% <ø> (ø)
migrator 100.00% <ø> (ø)
php 20.68% <ø> (ø)
python_submitty_utils 80.08% <ø> (ø)
submitty_daemon_jobs 91.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Ash092016

Copy link
Copy Markdown
Contributor Author

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.

@Ash092016

Copy link
Copy Markdown
Contributor Author

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:
$('#toggle-attachments-button').find('.attachment-badge').text($('.attachment-btn').length);

Should I go ahead and include that fix in this PR, or would you prefer it in a separate one?

@Ash092016
Ash092016 requested a review from roye2 March 13, 2026 04:45
@roye2

roye2 commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

@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 :)

@Ash092016

Copy link
Copy Markdown
Contributor Author

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 roye2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@Ash092016

Copy link
Copy Markdown
Contributor Author

Hi @roye2, thank you for the detailed feedback!
You're absolutely right—the current count is tied to the backend rendering process, which makes it "context-sensitive" (only counting what's on the page) rather than truly global. I agree that making this count globally accurate while respecting all permission checks is a more complex task than originally anticipated.
I'll look into addressing the global attachment count in a separate, dedicated PR so we can handle the database logic properly there. Looking forward to your approval on this one!

@Ash092016
Ash092016 requested a review from roye2 March 17, 2026 15:41

@roye2 roye2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Aside from reverting the previous change, I approve of the changes made in this PR.

Comment thread site/public/js/forum.js
@github-project-automation github-project-automation Bot moved this from In Review to Work in Progress in Submitty Development Mar 17, 2026
@Ash092016

Copy link
Copy Markdown
Contributor Author

Hi @roye2 , I have revert the changes and have added the same!

@Ash092016
Ash092016 requested a review from roye2 March 19, 2026 17:24
@automateprojectmangement automateprojectmangement Bot moved this from Work in Progress to In Review in Submitty Development Mar 19, 2026
@github-project-automation github-project-automation Bot moved this from In Review to Awaiting Maintainer Review in Submitty Development Mar 20, 2026
@bmcutler
bmcutler merged commit a853d1b into Submitty:main Mar 22, 2026
26 checks passed
@github-project-automation github-project-automation Bot moved this from Awaiting Maintainer Review to Done in Submitty Development Mar 22, 2026
IDzyre pushed a commit to IDzyre/Submitty that referenced this pull request Mar 22, 2026
### 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.
GarvitKhandelwal31 pushed a commit to GarvitKhandelwal31/Submitty that referenced this pull request Mar 25, 2026
### 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.
GarvitKhandelwal31 pushed a commit to GarvitKhandelwal31/Submitty that referenced this pull request Mar 29, 2026
### 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.
GarvitKhandelwal31 pushed a commit to GarvitKhandelwal31/Submitty that referenced this pull request Apr 14, 2026
### 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Fix Discussion Forum show/hide thread attachments toggle text

3 participants