Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions AUTHENTICATED_BUG_REPORT_FIX.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Fix Summary: Authenticated Bug Report UI

## Issue
Authenticated users clicking "Report an issue" were being redirected to GitHub instead of seeing the fancy bug report UI modal when clicking DAK issue buttons (like "Report content issue").

## Root Cause
The original fix only addressed the `openSgexIssue` function but missed the `openDakIssue` function. When users clicked DAK issue buttons without a repository selected (e.g., on the profile selection page), the code would fall back to opening GitHub directly, even for authenticated users.

The `openDakIssue` function had two code paths:
1. **With repository**: Opens issue for the specific DAK repository (redirects to that repo's GitHub)
2. **Without repository**: Falls back to SGEX repository (should show fancy UI for authenticated users)

Authentication was checked using the `isAuthenticated` property instead of the `isAuth()` method, and more critically, the check was missing entirely from the DAK issue flow.

### Why this matters:
- `isAuthenticated` is a **property** that can be directly set to `true` or `false`
- `isAuth()` is a **method** that checks both:
1. The `isAuthenticated` property is `true`, AND
2. The `octokit` instance exists and is not `null`

This dual check ensures that the authentication state is valid and the GitHub API client is properly initialized.

## Changes Made

### 1. HelpModal.js (Line 77) - SGEX Issues [Original Fix]
**Before:**
```javascript
const isAuthenticated = githubService.isAuthenticated;
```

**After:**
```javascript
const isAuthenticated = githubService.isAuth();
```

### 2. HelpModal.js (Lines 144-155) - DAK Issues [New Fix]
**Added authentication check for DAK issues without repository:**
```javascript
// Check if user is authenticated and should see the fancy bug report form
const isAuthenticated = githubService.isAuth();
console.log('[HelpModal] DAK issue clicked without repository. Authenticated:', isAuthenticated);

if (isAuthenticated) {
console.log('[HelpModal] Showing bug report form for DAK issue');
setShowBugReportForm(true);
return;
}

// If not authenticated, fall through to open GitHub issue page directly
console.log('[HelpModal] Not authenticated, opening GitHub issue page for DAK issue');
```

### 3. BugReportForm.js (5 instances) [Original Fix]

**Line 163 - API submission check:**
```javascript
// Before:
if (githubService.isAuthenticated) {

// After:
if (githubService.isAuth()) {
```

**Line 628 - Context display:**
```javascript
// Before:
<li><strong>Authentication:</strong> {githubService.isAuthenticated ? 'Authenticated' : 'Demo Mode'}</li>

// After:
<li><strong>Authentication:</strong> {githubService.isAuth() ? 'Authenticated' : 'Demo Mode'}</li>
```

**Line 684 - Button text:**
```javascript
// Before:
{submitting ? 'Opening...' :
githubService.isAuthenticated ? 'Submit Issue' : 'Open in GitHub'}

// After:
{submitting ? 'Opening...' :
githubService.isAuth() ? 'Submit Issue' : 'Open in GitHub'}
```

**Line 709 - Authentication status display:**
```javascript
// Before:
{githubService.isAuthenticated ? (

// After:
{githubService.isAuth() ? (
```

## Testing
A comprehensive test suite was added in `src/tests/AuthenticatedBugReportUI.test.js` that validates:
1. HelpModal shows bug report form when authenticated (SGEX issues)
2. HelpModal redirects to GitHub when not authenticated (SGEX issues)
3. **NEW**: HelpModal shows bug report form when authenticated (DAK issues without repo)
4. **NEW**: HelpModal redirects to GitHub when not authenticated (DAK issues without repo)
5. BugReportForm uses `isAuth()` for authentication checks
6. BugReportForm shows correct UI for authenticated users
7. BugReportForm shows correct UI for unauthenticated users
8. The `isAuth()` method is preferred over the `isAuthenticated` property

## Expected Behavior After Fix

### For Authenticated Users on Profile Selection Page:
**Scenario**: User clicks "Report content issue" button when no DAK repository is selected

**Before Fix:**
1. Click on DAK issue button (e.g., "Report content issue")
2. Browser opens GitHub.com in new tab
3. User fills form manually on GitHub

**After Fix:**
1. Click on DAK issue button (e.g., "Report content issue")
2. Fancy bug report form appears in a modal overlay
3. User can fill out the form with auto-captured context
4. Issue submitted directly via GitHub API to SGEX repository
5. Success message shows "Issue #123 has been created successfully!"

### For Authenticated Users with DAK Repository:
1. Click on DAK issue button
2. Issue is opened in the DAK repository's GitHub page (unchanged - expected behavior for DAK-specific issues)

### For Unauthenticated Users:
1. Click on any issue button
2. User is redirected to GitHub's issue creation page (unchanged - expected behavior)

## Impact
- **Minimal changes**: Only 19 lines of code added to fix the DAK issue flow
- **No breaking changes**: The fix maintains backward compatibility
- **Improved UX**: Authenticated users now get the intended fancy UI experience for both SGEX and DAK issues
- **Consistent pattern**: All authentication checks now use `isAuth()` method

## References
- Original Issue: [authenticated users fancy UI for issues/report is not working]
- Related code: `src/services/githubService.js` line 323-325 (isAuth() method definition)
- Similar correct usage: `src/components/BranchListing.js`, `src/components/framework/PageProvider.js`

## User Feedback
The fix was tested with the specific scenario reported:
- User on page: `https://litlfred.github.io/sgex/copilot-fix-fancy-ui-for-reports/select_profile`
- User clicks DAK issue button (content)
- Console shows: "No DAK repository specified, falling back to sgex repository"
- **Before**: Redirected to GitHub (incorrect)
- **After**: Fancy bug report form appears (correct)
120 changes: 120 additions & 0 deletions BUG_REPORT_FIX_FLOW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Bug Report UI Flow - Before and After Fix

## Before Fix (Broken)

```
User clicks "Report an issue"
HelpModal checks: githubService.isAuthenticated (property)
Property returns: TRUE (but octokit might be null!)
Code attempts to show fancy UI... but fails
Falls back to opening GitHub URL
User redirected to GitHub (unexpected behavior)
```

**Problem**: The `isAuthenticated` property can be `true` even when the `octokit` instance is `null`, leading to inconsistent state where the code thinks it's authenticated but can't actually make API calls.

## After Fix (Working)

```
User clicks "Report an issue"
HelpModal checks: githubService.isAuth() (method)
isAuth() returns: isAuthenticated && octokit !== null
Method returns: TRUE (both conditions met!)
Fancy bug report UI modal appears
User fills form and submits
Issue created via GitHub API
Success message: "Issue #123 created!"
```

**Solution**: The `isAuth()` method checks **both** the `isAuthenticated` flag AND the `octokit` instance, ensuring the authentication state is valid and the GitHub API client is ready.

## Visual Comparison

### For Authenticated Users:

**Before:**
```
┌─────────────────────────────┐
│ Help Menu │
│ [Report an issue] ← Click │
└─────────────────────────────┘
Opens GitHub webpage
(not what user expected!)
```

**After:**
```
┌─────────────────────────────┐
│ Help Menu │
│ [Report an issue] ← Click │
└─────────────────────────────┘
┌─────────────────────────────┐
│ 🐛 Bug Report Form │
│ ┌───────────────────────┐ │
│ │ Issue Type: Bug │ │
│ │ Title: [________] │ │
│ │ Description: │ │
│ │ [________________] │ │
│ │ [Submit Issue] │ │
│ └───────────────────────┘ │
└─────────────────────────────┘
Fancy UI modal appears!
```

## Code Changes Summary

### File: HelpModal.js
```diff
- const isAuthenticated = githubService.isAuthenticated;
+ const isAuthenticated = githubService.isAuth();
```

### File: BugReportForm.js
```diff
- if (githubService.isAuthenticated) {
+ if (githubService.isAuth()) {

- {githubService.isAuthenticated ? 'Authenticated' : 'Demo Mode'}
+ {githubService.isAuth() ? 'Authenticated' : 'Demo Mode'}

- githubService.isAuthenticated ? 'Submit Issue' : 'Open in GitHub'
+ githubService.isAuth() ? 'Submit Issue' : 'Open in GitHub'

- {githubService.isAuthenticated ? (
+ {githubService.isAuth() ? (
```

## Testing

Run the test suite:
```bash
npm test -- --testPathPattern=AuthenticatedBugReportUI --no-coverage --watchAll=false
```

Tests validate:
- ✅ Authenticated users see the fancy UI
- ✅ Unauthenticated users are redirected to GitHub
- ✅ `isAuth()` method is used, not the property
- ✅ Authentication status is displayed correctly
- ✅ Button text updates based on authentication state

## Impact

- **User Experience**: Authenticated users now get the intended rich form experience
- **Code Quality**: Follows the established pattern used in `BranchListing.js` and `PageProvider.js`
- **Reliability**: Prevents edge cases where `isAuthenticated=true` but `octokit=null`
- **Maintainability**: All authentication checks now use the same method
Loading