Skip to content

fix: preserve popup blocker text across report regeneration#538

Open
kaungmyatshwe1397 wants to merge 1 commit intofossasia:mainfrom
kaungmyatshwe1397:fix/blocker-test-reset
Open

fix: preserve popup blocker text across report regeneration#538
kaungmyatshwe1397 wants to merge 1 commit intofossasia:mainfrom
kaungmyatshwe1397:fix/blocker-test-reset

Conversation

@kaungmyatshwe1397
Copy link
Copy Markdown
Contributor

@kaungmyatshwe1397 kaungmyatshwe1397 commented Apr 13, 2026

📌 Fixes

Fixes #537


📝 Summary of Changes

  • Preserved custom blocker message across repeated popup report generation
  • Saved blocker edits from the popup preview to local storage
  • Restored the latest saved blocker text when cached popup content is loaded
  • Cleared saved blocker state only when the user explicitly refreshes data ( as initial state )

📸 Screenshots / Demo (if UI-related)

_ Testing demo of editing and replacing user custom blocker message and reset to initial state by refresh Data

Screen.Recording.2026-04-13.192140.mp4

_


✅ Checklist

  • [ x ] I’ve tested my changes locally
  • [ x ] I’ve added tests (if applicable)
  • [ ] I’ve updated documentation (if applicable)
  • [ x ] My code follows the project’s code style guidelines

👀 Reviewer Notes

  • The blocker text is no longer reset on every Generate click
  • Edited blocker text is now persisted from the popup preview
  • Saved blocker text is restored when cached popup content is loaded
  • Refresh Data now resets the saved blocker state
  • also done lint and forma testing in local while following codebase design
  • add comment section for new extended functions at the popup.js and scrumhelper.js

Summary by Sourcery

Preserve and persist the custom blocker message across popup scrum report generations and cache refreshes.

Bug Fixes:

  • Retain the user’s blocker text when regenerating scrum reports or loading from cached popup content instead of resetting to the default message.
  • Ensure the stored blocker reason is reapplied to restored reports for both GitHub and GitLab platforms.
  • Avoid overwriting the blocker input when it is not present in the DOM to prevent errors.

Enhancements:

  • Normalize and centralize handling of the default blocker message when reading from or writing to the report.
  • Persist edits to the blocker section made directly in the popup preview using debounced storage updates.
  • Clear cached reports and saved blocker state only when the user explicitly refreshes data, aligning cache behavior across platforms.
  • Improve popup script formatting and minor condition handling without changing behavior.

Copilot AI review requested due to automatic review settings April 13, 2026 12:29
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 13, 2026

Reviewer's Guide

This PR changes how the scrum report popup stores and restores the "blocker" text so that user-edited blocker content persists across report generations and cached loads, and is only reset on explicit data refresh, while also adding some small refactors/formatting tweaks.

Sequence diagram for blocker text persistence on edit and regeneration

sequenceDiagram
  actor User
  participant Popup as PopupScript_popup_js
  participant DOM as PopupDOM
  participant Storage as BrowserStorage
  participant Helper as ScrumHelper_scrumHelper_js

  User->>DOM: Edit blocker text in scrumReport
  DOM-->>Popup: input / focusout event
  Popup->>DOM: extractBlockerReasonFromReport(scrumReport)
  Popup-->>Popup: normalizeBlockerReason(blockerReason)
  Popup->>Storage: storage.local.set(userReason)

  User->>Popup: Click Generate
  Popup->>Storage: storage.local.get(platform)
  Popup->>Helper: allIncluded(outputTarget)
  Helper->>Storage: storage.local.get([... userReason ...])
  Helper-->>Helper: userReason = storedUserReason || DEFAULT
  Helper-->>Popup: Generated report HTML including blocker heading
  Popup->>DOM: Render new scrumReport HTML
  Popup->>DOM: applyBlockerReasonToReport(scrumReport, storedUserReason)
  DOM-->>User: Updated report with preserved blocker text
Loading

Sequence diagram for restoring blocker text from cached scrum report

sequenceDiagram
  participant Popup as PopupScript_popup_js
  participant DOM as PopupDOM
  participant Storage as BrowserStorage

  Popup->>Storage: storage.local.get([... platformSpecificKeys ..., userReason])
  Storage-->>Popup: lastScrumReportHtml, cacheKey, username, userReason
  Popup-->>Popup: Compute expectedUsername and isUsernameMatch
  Popup-->>Popup: Check ttlMs and matches
  alt Cache_valid_and_matches_and_report_empty
    Popup->>DOM: scrumReport.innerHTML = lastScrumReportHtml
    Popup->>DOM: applyBlockerReasonToReport(scrumReport, userReason)
  else Cache_expired_but_matches_and_report_empty
    Popup->>DOM: scrumReport.innerHTML = lastScrumReportHtml
    Popup->>DOM: applyBlockerReasonToReport(scrumReport, userReason)
  end
  Popup-->>DOM: Enable generate button if present
Loading

File-Level Changes

Change Details Files
Persist blocker reason across generate clicks and cached report loads using DOM helpers and local storage.
  • Introduce DEFAULT_BLOCKER_REASON and normalizeBlockerReason to standardize empty/whitespace blocker text.
  • Add DOM utilities (getBlockerHeading, extractBlockerReasonFromReport, applyBlockerReasonToReport) to read/write the blocker section of the scrum report based on the last bold heading.
  • When rehydrating cached scrum report HTML on popup load, reapply the stored blocker reason from local storage via applyBlockerReasonToReport.
  • Attach debounced input/focusout listeners to the scrumReport element so edits in the popup are extracted and persisted to browser.storage.local.userReason.
src/scripts/popup.js
Ensure userReason is kept across Generate clicks and only reset on explicit refresh.
  • In allIncluded, derive userReason from stored local value if present; otherwise fall back to the default "No Blocker at the moment" instead of clearing it on each run.
  • Extend the refreshCache handler to clear userReason and all scrum report cache keys for both GitHub and GitLab when the user explicitly refreshes data.
src/scripts/scrumHelper.js
src/scripts/popup.js
Minor robustness and style cleanups related to popup behavior and repo status messaging.
  • Guard assignment to userReasonInput to avoid errors when the element is missing.
  • Slightly refactor some event listener registrations and long i18n fallback lines for readability and consistency.
  • Ensure scrumReport is retrieved earlier in DOMContentLoaded to support new listeners, and keep behavior when switching platforms that clears the report and reboots bootstrapScrumReportOnPopupLoad.
src/scripts/popup.js

Assessment against linked issues

Issue Objective Addressed Explanation
#537 Preserve the user-edited blocker text in the popup scrum report across repeated Generate actions (including org changes), only resetting when the user explicitly refreshes/clears cached data.
#537 Ensure cached or restored popup reports reuse the latest saved blocker text so the editable preview workflow is consistent with the README’s promise of editable scrum updates.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions bot added javascript Pull requests that update javascript code core labels Apr 13, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The new blocker parsing logic in popup.js assumes the last <b> in the report is the blocker heading and that everything after it belongs to the blocker; this seems brittle and could break if more headings or sections are added later—consider anchoring on something more specific (e.g., known heading text or a dedicated wrapper) or at least limiting the range you clear/update.
  • In applyBlockerReasonToReport, you remove all siblings after the heading and then append the new content at the end of reportEl, which can both change section ordering and drop other trailing content; it may be safer to only replace the existing blocker content and insert the new span immediately after the heading.
  • The default blocker message string ('No Blocker at the moment') is now hard-coded in both popup.js and scrumHelper.js; extracting this into a shared constant or configuration would avoid divergence if the text ever changes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new blocker parsing logic in `popup.js` assumes the last `<b>` in the report is the blocker heading and that everything after it belongs to the blocker; this seems brittle and could break if more headings or sections are added later—consider anchoring on something more specific (e.g., known heading text or a dedicated wrapper) or at least limiting the range you clear/update.
- In `applyBlockerReasonToReport`, you remove all siblings after the heading and then append the new content at the end of `reportEl`, which can both change section ordering and drop other trailing content; it may be safer to only replace the existing blocker content and insert the new span immediately after the heading.
- The default blocker message string ('No Blocker at the moment') is now hard-coded in both `popup.js` and `scrumHelper.js`; extracting this into a shared constant or configuration would avoid divergence if the text ever changes.

## Individual Comments

### Comment 1
<location path="src/scripts/scrumHelper.js" line_range="159-161" />
<code_context>

-				userReason = 'No Blocker at the moment';
-				browser.storage.local.remove(['userReason']);
+				// Keep user's blocking reason across Generate btn clicks
+				const storedUserReason = typeof items.userReason === 'string' ? items.userReason.trim() : '';
+				userReason = storedUserReason || 'No Blocker at the moment';
 				githubToken = items.githubToken;
 				gitlabToken = items.gitlabToken || '';
</code_context>
<issue_to_address>
**suggestion:** The default blocker message string is duplicated and could drift from `DEFAULT_BLOCKER_REASON` in `popup.js`.

This string duplicates `DEFAULT_BLOCKER_REASON` in `popup.js`. To avoid these drifting apart (e.g., if the text changes or gets localized), please source the default from a single shared constant or otherwise centralize it so both the popup and generated report stay in sync.

Suggested implementation:

```javascript
				// Keep user's blocking reason across Generate btn clicks
				const storedUserReason = typeof items.userReason === 'string' ? items.userReason.trim() : '';
				const defaultBlockerReason = typeof window !== 'undefined' && typeof window.DEFAULT_BLOCKER_REASON === 'string'
					? window.DEFAULT_BLOCKER_REASON
					: 'No Blocker at the moment';
				userReason = storedUserReason || defaultBlockerReason;
				githubToken = items.githubToken;

```

If your build setup supports ES module imports between `popup.js` and `scrumHelper.js`, you may instead want to export `DEFAULT_BLOCKER_REASON` from `popup.js` and import it directly into `scrumHelper.js` to avoid relying on the global `window` object.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +159 to +161
// Keep user's blocking reason across Generate btn clicks
const storedUserReason = typeof items.userReason === 'string' ? items.userReason.trim() : '';
userReason = storedUserReason || 'No Blocker at the moment';
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.

suggestion: The default blocker message string is duplicated and could drift from DEFAULT_BLOCKER_REASON in popup.js.

This string duplicates DEFAULT_BLOCKER_REASON in popup.js. To avoid these drifting apart (e.g., if the text changes or gets localized), please source the default from a single shared constant or otherwise centralize it so both the popup and generated report stay in sync.

Suggested implementation:

				// Keep user's blocking reason across Generate btn clicks
				const storedUserReason = typeof items.userReason === 'string' ? items.userReason.trim() : '';
				const defaultBlockerReason = typeof window !== 'undefined' && typeof window.DEFAULT_BLOCKER_REASON === 'string'
					? window.DEFAULT_BLOCKER_REASON
					: 'No Blocker at the moment';
				userReason = storedUserReason || defaultBlockerReason;
				githubToken = items.githubToken;

If your build setup supports ES module imports between popup.js and scrumHelper.js, you may instead want to export DEFAULT_BLOCKER_REASON from popup.js and import it directly into scrumHelper.js to avoid relying on the global window object.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #537 by persisting the popup report’s “blocker” text (userReason) across repeated report generation and restoring it when cached report HTML is reloaded, only resetting it when the user explicitly refreshes data.

Changes:

  • Stop clearing userReason on each report generation; instead default to a stored value when available.
  • Persist blocker edits made directly in the contenteditable report preview to browser.storage.local.
  • When loading cached report HTML, re-apply the latest saved blocker text and clear it on “Refresh Data”.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/scripts/scrumHelper.js Uses stored userReason (trimmed) as the blocker text instead of resetting/removing it during generation.
src/scripts/popup.js Adds blocker extraction/apply helpers, persists edits from the contenteditable report, restores blocker text on cached HTML load, and clears userReason on refresh.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/scripts/popup.js
Comment on lines +101 to +108
// Use last bold heading as the anchor to read or write only that part
function getBlockerHeading(reportEl) {
if (!reportEl) {
return null;
}

const headings = reportEl.querySelectorAll('b');
return headings.length > 0 ? headings[headings.length - 1] : null;
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

getBlockerHeading() assumes the blocker section is always the last <b> in #scrumReport. Since #scrumReport is contenteditable, users can easily create additional <b> tags (e.g., by bolding any text), which will cause blocker extraction/apply to target the wrong anchor and can overwrite/delete unrelated report content. Consider anchoring the blocker section via a dedicated marker element/attribute generated by scrumHelper.js (e.g., a data-section="blocker" wrapper) or by matching the specific blocker heading text rather than relying on the last <b>.

Suggested change
// Use last bold heading as the anchor to read or write only that part
function getBlockerHeading(reportEl) {
if (!reportEl) {
return null;
}
const headings = reportEl.querySelectorAll('b');
return headings.length > 0 ? headings[headings.length - 1] : null;
function isBlockerHeadingText(text) {
return /^blockers?\b/i.test(typeof text === 'string' ? text.trim() : '');
}
// Find the blocker heading by a stable marker first, then by heading text.
function getBlockerHeading(reportEl) {
if (!reportEl) {
return null;
}
const blockerMarker = reportEl.querySelector('[data-section="blocker"]');
if (blockerMarker) {
if (blockerMarker.matches('b')) {
return blockerMarker;
}
const nestedHeading = blockerMarker.querySelector('b');
if (nestedHeading) {
return nestedHeading;
}
}
const headings = reportEl.querySelectorAll('b');
for (const heading of headings) {
if (isBlockerHeadingText(heading.textContent)) {
return heading;
}
}
return null;

Copilot uses AI. Check for mistakes.
Comment thread src/scripts/popup.js
Comment on lines +111 to +155
function extractBlockerReasonFromReport(reportEl) {
const blockerHeading = getBlockerHeading(reportEl);
if (!blockerHeading) {
return null;
}

const parts = [];
let currentNode = blockerHeading.nextSibling;

while (currentNode) {
if (currentNode.nodeType === Node.TEXT_NODE) {
const text = currentNode.textContent.trim();
if (text) {
parts.push(text);
}
} else if (currentNode.nodeName !== 'BR') {
const text = currentNode.textContent.trim();
if (text) {
parts.push(text);
}
}

currentNode = currentNode.nextSibling;
}

return parts.join('\n').trim();
}

function applyBlockerReasonToReport(reportEl, blockerReason) {
const blockerHeading = getBlockerHeading(reportEl);
if (!blockerHeading) {
return false;
}

let currentNode = blockerHeading.nextSibling;
while (currentNode) {
const nextNode = currentNode.nextSibling;
currentNode.remove();
currentNode = nextNode;
}

reportEl.appendChild(document.createElement('br'));
const blockerSpan = document.createElement('span');
blockerSpan.textContent = normalizeBlockerReason(blockerReason);
reportEl.appendChild(blockerSpan);
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

applyBlockerReasonToReport() removes all sibling nodes after the selected heading. Because the report is editable, users can add extra notes/content after the blocker section; this implementation will delete that content when cached HTML is loaded (and will also delete more than intended if the anchor heading is misidentified). Consider limiting the mutation to a specific blocker content container/span instead of removing everything after the heading.

Suggested change
function extractBlockerReasonFromReport(reportEl) {
const blockerHeading = getBlockerHeading(reportEl);
if (!blockerHeading) {
return null;
}
const parts = [];
let currentNode = blockerHeading.nextSibling;
while (currentNode) {
if (currentNode.nodeType === Node.TEXT_NODE) {
const text = currentNode.textContent.trim();
if (text) {
parts.push(text);
}
} else if (currentNode.nodeName !== 'BR') {
const text = currentNode.textContent.trim();
if (text) {
parts.push(text);
}
}
currentNode = currentNode.nextSibling;
}
return parts.join('\n').trim();
}
function applyBlockerReasonToReport(reportEl, blockerReason) {
const blockerHeading = getBlockerHeading(reportEl);
if (!blockerHeading) {
return false;
}
let currentNode = blockerHeading.nextSibling;
while (currentNode) {
const nextNode = currentNode.nextSibling;
currentNode.remove();
currentNode = nextNode;
}
reportEl.appendChild(document.createElement('br'));
const blockerSpan = document.createElement('span');
blockerSpan.textContent = normalizeBlockerReason(blockerReason);
reportEl.appendChild(blockerSpan);
function getBlockerReasonSpan(blockerHeading) {
let currentNode = blockerHeading ? blockerHeading.nextSibling : null;
let sawLineBreak = false;
while (currentNode) {
if (currentNode.nodeType === Node.TEXT_NODE) {
if (currentNode.textContent.trim() === '') {
currentNode = currentNode.nextSibling;
continue;
}
return null;
}
if (currentNode.nodeName === 'BR') {
sawLineBreak = true;
currentNode = currentNode.nextSibling;
continue;
}
if (
currentNode.nodeName === 'SPAN' &&
(currentNode.getAttribute('data-blocker-reason') === 'true' || sawLineBreak)
) {
return currentNode;
}
return null;
}
return null;
}
function ensureBlockerReasonSpan(reportEl, blockerHeading) {
let blockerSpan = getBlockerReasonSpan(blockerHeading);
if (blockerSpan) {
blockerSpan.setAttribute('data-blocker-reason', 'true');
return blockerSpan;
}
const br = document.createElement('br');
blockerSpan = document.createElement('span');
blockerSpan.setAttribute('data-blocker-reason', 'true');
if (blockerHeading.nextSibling) {
reportEl.insertBefore(br, blockerHeading.nextSibling);
} else {
reportEl.appendChild(br);
}
if (br.nextSibling) {
reportEl.insertBefore(blockerSpan, br.nextSibling);
} else {
reportEl.appendChild(blockerSpan);
}
return blockerSpan;
}
function extractBlockerReasonFromReport(reportEl) {
const blockerHeading = getBlockerHeading(reportEl);
if (!blockerHeading) {
return null;
}
const blockerSpan = getBlockerReasonSpan(blockerHeading);
if (!blockerSpan) {
return null;
}
return blockerSpan.textContent.trim();
}
function applyBlockerReasonToReport(reportEl, blockerReason) {
const blockerHeading = getBlockerHeading(reportEl);
if (!blockerHeading) {
return false;
}
const blockerSpan = ensureBlockerReasonSpan(reportEl, blockerHeading);
blockerSpan.textContent = normalizeBlockerReason(blockerReason);

Copilot uses AI. Check for mistakes.
Comment thread src/scripts/popup.js
Comment on lines +145 to +153
let currentNode = blockerHeading.nextSibling;
while (currentNode) {
const nextNode = currentNode.nextSibling;
currentNode.remove();
currentNode = nextNode;
}

reportEl.appendChild(document.createElement('br'));
const blockerSpan = document.createElement('span');
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

When restoring cached HTML, applyBlockerReasonToReport() replaces the original blocker markup (which scrumHelper.js renders via wrapCompactText() with an inline style) with a plain <span> that has no styling. This is a visible formatting regression for the blocker section. Consider reusing the existing blocker <span> (updating only its text) or applying the same inline style used in the generated report.

Suggested change
let currentNode = blockerHeading.nextSibling;
while (currentNode) {
const nextNode = currentNode.nextSibling;
currentNode.remove();
currentNode = nextNode;
}
reportEl.appendChild(document.createElement('br'));
const blockerSpan = document.createElement('span');
let blockerSpan = null;
let currentNode = blockerHeading.nextSibling;
while (currentNode) {
const nextNode = currentNode.nextSibling;
if (!blockerSpan && currentNode.nodeType === Node.ELEMENT_NODE && currentNode.nodeName === 'SPAN') {
blockerSpan = currentNode;
} else {
currentNode.remove();
}
currentNode = nextNode;
}
reportEl.appendChild(document.createElement('br'));
if (!blockerSpan) {
blockerSpan = document.createElement('span');
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core javascript Pull requests that update javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] : Popup Blocker message reset to default when regenerate

2 participants