Skip to content

fix: ux enhance for report insertion#460

Open
Mateeb-Haider wants to merge 2 commits intofossasia:mainfrom
Mateeb-Haider:fix/enhance-insert-in-to-mail-functionality
Open

fix: ux enhance for report insertion#460
Mateeb-Haider wants to merge 2 commits intofossasia:mainfrom
Mateeb-Haider:fix/enhance-insert-in-to-mail-functionality

Conversation

@Mateeb-Haider
Copy link
Contributor

@Mateeb-Haider Mateeb-Haider commented Mar 17, 2026

📌 Fixes

Fixes #459


📝 Summary of Changes

Error Handling: Added robust error detection for the "Insert to Email" feature. It now catches connection errors when a supported email tab (Gmail/Outlook/Yahoo) is not active.


📸 Screenshots / Demo (if UI-related)

image

✅ Checklist

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

👀 Reviewer Notes

The toast system is now completely self-contained with inline styles, ensuring it works reliably even if external CSS is missing. It prioritizes visibility with high z-index and optimized shadows for both themes.

Summary by Sourcery

Improve popup toast notifications and error messaging for email report insertion and org validation.

Bug Fixes:

  • Show a clear error toast when inserting a report into an email fails due to missing or unsupported email tabs.
  • Display localized error messages when GitHub org validation fails instead of silently logging issues.

Enhancements:

  • Replace legacy toasts with a unified, self-contained popup toast component that matches the report section styling, supports dark mode, and animates in/out.

Copilot AI review requested due to automatic review settings March 17, 2026 15:19
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 17, 2026

Reviewer's Guide

Refactors and unifies the popup toast/notification system with inline, theme-aware styling and adds explicit error handling and user feedback for the "Insert to Email" flow and org validation failures.

Sequence diagram for Insert to Email error handling and toast feedback

sequenceDiagram
    actor User
    participant PopupScript
    participant ChromeTabsAPI
    participant EmailTabContentScript

    User->>PopupScript: Click insertToEmail button
    PopupScript->>ChromeTabsAPI: sendMessage(action insertReportToEmail)
    ChromeTabsAPI-->>PopupScript: Callback with chrome.runtime.lastError set
    alt Runtime error (no supported email tab)
        PopupScript->>PopupScript: Build errorMsg from i18n insertInEmailFailed
        PopupScript->>PopupScript: showPopupMessage(errorMsg, error)
        PopupScript-->>User: Toast shown: open email tab (Gmail/Outlook/Yahoo)
    else No runtime error but response not success
        ChromeTabsAPI-->>PopupScript: response.success = false, response.error
        PopupScript->>PopupScript: errorMsg = response.error or i18n insertInEmailFailed
        PopupScript->>PopupScript: showPopupMessage(errorMsg, error)
        PopupScript-->>User: Toast shown: insert to email failed
    else Success
        ChromeTabsAPI-->>PopupScript: response.success = true
        PopupScript-->>User: Report inserted, no error toast
    end
Loading

Sequence diagram for unified org validation error toasts

sequenceDiagram
    actor User
    participant PopupScript
    participant GitHubAPI

    User->>PopupScript: Blur org input field
    PopupScript->>GitHubAPI: Fetch organisation details
    alt Organisation not found (404)
        GitHubAPI-->>PopupScript: Response status 404
        PopupScript->>PopupScript: message = i18n orgNotFoundMessage
        PopupScript->>PopupScript: showPopupMessage(message, error)
        PopupScript-->>User: Error toast: organisation not found
    else Network or other error
        GitHubAPI-->>PopupScript: Promise rejected
        PopupScript->>PopupScript: message = i18n orgValidationErrorMessage
        PopupScript->>PopupScript: showPopupMessage(message, error)
        PopupScript-->>User: Error toast: validation problem
    else Organisation exists
        GitHubAPI-->>PopupScript: Response status 200
        PopupScript->>PopupScript: Remove caches and trigger repo fetch
        PopupScript-->>User: No error toast
    end
Loading

Flow diagram for unified toast creation and display

flowchart TD
    A[showPopupMessage called
      with message and type] --> B{message present?}
    B -- No --> C[Return without action]
    B -- Yes --> D[Remove existing
      scrum-helper-toast element]
    D --> E[Create new div
      id scrum-helper-toast]
    E --> F[Check body has
      class dark-mode]
    F --> G[Apply base positioning,
      padding, radius, typography,
      transform, opacity 0]
    G --> H[Apply boxShadow
depending on theme]
    H --> I[Apply background,
      borderColor, text color
      for light or dark mode]
    I --> J[Set textContent
      to message]
    J --> K[Append toast to body]
    K --> L[requestAnimationFrame
      animate opacity to 1 and
      translateY to 0]
    L --> M[setTimeout 4000ms
      start hide animation]
    M --> N[Animate opacity to 0
      and translateY -20px]
    N --> O[After 300ms remove
      toast from DOM if present]
Loading

File-Level Changes

Change Details Files
Replace ad-hoc and Materialize-dependent toast logic with a unified, inline-styled toast helper that supports dark mode and animations.
  • Updated showPopupMessage to always render a custom toast element with inline styles instead of delegating to Materialize toasts
  • Introduced a single toast DOM id and removed any previous instance before rendering a new toast
  • Implemented theme-aware colors, elevated box-shadow, borders, and enter/exit animations for better visibility and UX
src/scripts/popup.js
Surface clear error toasts when "Insert to Email" cannot send to the current tab due to connection/runtime issues.
  • Extended the insertReportToEmail callback to check chrome.runtime.lastError and failed responses
  • Show a localized or fallback error message via showPopupMessage when the tab connection fails or the content script reports an error
src/scripts/popup.js
Reuse the shared toast helper for GitHub organization validation errors instead of custom inline elements.
  • Replaced bespoke invalid-org toast creation/removal logic with showPopupMessage for 404 and network error cases
  • Ensured org validation messages use localized strings and the unified toast styling
src/scripts/popup.js

Assessment against linked issues

Issue Objective Addressed Explanation
#459 Update popup.js so that the 'Insert to Email' action no longer fails silently on unsupported/non-email tabs, by catching chrome.runtime.lastError or missing responses and showing a concise, theme-aware toast message instead of only logging to the console.
#459 Add a new localized string insertInEmailFailed in messages.json with a short instruction (e.g., telling the user to open a Gmail/Outlook/Yahoo email tab) and use it for the error toast message.

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 the javascript Pull requests that update javascript code label Mar 17, 2026
Copy link
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 type parameter on showPopupMessage is never used to alter styling or behavior; either wire it up to differentiate error/info toasts or remove it to avoid confusion.
  • The new implementation completely drops the window.Materialize.toast fallback, which changes behavior in environments where Materialize is present; consider preserving the existing fallback and only using the custom toast when Materialize is unavailable.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `type` parameter on `showPopupMessage` is never used to alter styling or behavior; either wire it up to differentiate error/info toasts or remove it to avoid confusion.
- The new implementation completely drops the `window.Materialize.toast` fallback, which changes behavior in environments where Materialize is present; consider preserving the existing fallback and only using the custom toast when Materialize is unavailable.

## Individual Comments

### Comment 1
<location path="src/scripts/popup.js" line_range="285" />
<code_context>
 	}

-	function showPopupMessage(message) {
+	function showPopupMessage(message, type = 'info') {
 		if (!message) return;

</code_context>
<issue_to_address>
**suggestion:** The `type` parameter is currently unused and could either be removed or leveraged for variant-specific styling.

Since callers always pass `'error'` but the implementation ignores `type`, consider either using it to drive variant styling (e.g., warning/success/error colors and borders) or dropping it for now to keep the API clear and avoid misleading future callers.

```suggestion
	function showPopupMessage(message) {
```
</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.

}

function showPopupMessage(message) {
function showPopupMessage(message, type = 'info') {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: The type parameter is currently unused and could either be removed or leveraged for variant-specific styling.

Since callers always pass 'error' but the implementation ignores type, consider either using it to drive variant styling (e.g., warning/success/error colors and borders) or dropping it for now to keep the API clear and avoid misleading future callers.

Suggested change
function showPopupMessage(message, type = 'info') {
function showPopupMessage(message) {

Copy link
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 improves the UX of the “Insert to Email” flow in the extension popup by surfacing connection/unsupported-tab failures to the user via a self-contained toast message, and introduces a new localized string for that failure case.

Changes:

  • Replace the popup toast implementation with an inline-styled, theme-aware toast utility and reuse it for org validation errors.
  • Add user-visible error handling for “Insert to Email” when content scripts aren’t reachable or return a failure.
  • Add a new i18n message key (insertInEmailFailed) for the new error toast.

Reviewed changes

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

File Description
src/scripts/popup.js Adds toast UX + wiring to show user-friendly errors for “Insert to Email” failures and org validation failures.
src/_locales/en/messages.json Adds a new English i18n string used by the new error handling path.

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

Comment on lines +285 to 289
function showPopupMessage(message, type = 'info') {
if (!message) return;

// Materialize toast if available
if (window.Materialize && typeof window.Materialize.toast === 'function') {
window.Materialize.toast(message, 4000);
return;
}

const old = document.getElementById('scrum-cache-toast');
const old = document.getElementById('scrum-helper-toast');
if (old) old.remove();
toast.style.fontWeight = 'bold';
toast.style.padding = '12px 24px';
toast.style.borderRadius = '8px';
toast.id = 'scrum-helper-toast';
Comment on lines +307 to 310
"insertInEmailFailed": {
"message": "Open an email tab (Gmail/Outlook/Yahoo) to use this feature.",
"description": "Error message shown when the extension cannot connect to an email tab."
}
@Mateeb-Haider
Copy link
Contributor Author

@vedansh-5
Review when you have some time.
Thanku!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

javascript Pull requests that update javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement]: Improve UX for 'Insert to Email' failures

2 participants