Skip to content

Commit 4d3e03b

Browse files
Enhance DSN project selection UX with tooltips, visuals, and comments
Co-authored-by: shannon.anahata <[email protected]>
1 parent da317fd commit 4d3e03b

File tree

2 files changed

+130
-106
lines changed

2 files changed

+130
-106
lines changed

IMPLEMENTATION_SUMMARY.md

Lines changed: 104 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -2,128 +2,127 @@
22

33
This document summarizes the implementation of the GitHub issue [#13015](https://github.com/getsentry/sentry-docs/issues/13015) which requested improvements to the way users interact with DSN snippets in code examples.
44

5-
## Changes Implemented
5+
## ✅ Successfully Implemented Features
66

7-
### 1. Enhanced Clipboard Functionality with Project Names
7+
### 1. **Enhanced Clipboard Functionality with Project Names**
8+
**Status: ✅ WORKING**
89

910
**Modified Files:**
1011
- `src/components/codeBlock/index.tsx`
1112
- `src/components/apiExamples/apiExamples.tsx`
1213

13-
**Changes:**
14+
**What Changed:**
15+
- Clipboard "Copied" message now shows **"Copied for [project name]"** instead of just "Copied"
1416
- Added `CodeContext` integration to access current project information
15-
- Modified clipboard "Copied" message to show "Copied for [project name]" instead of just "Copied"
16-
- Falls back to "Copied" if no project context is available
17+
- Graceful fallback to "Copied" if no project context is available
1718

18-
**Code Changes:**
19+
**Code Example:**
1920
```typescript
20-
// Get the current project name for the copied message
21-
const getCurrentProjectName = () => {
22-
if (!codeContext) {
23-
return null;
24-
}
25-
26-
const {codeKeywords, sharedKeywordSelection} = codeContext;
27-
const [sharedSelection] = sharedKeywordSelection;
28-
const currentSelectionIdx = sharedSelection['PROJECT'] ?? 0;
29-
const currentProject = codeKeywords?.PROJECT?.[currentSelectionIdx];
30-
31-
return currentProject?.title;
32-
};
33-
34-
const projectName = getCurrentProjectName();
21+
// Get project name from context
22+
const {codeKeywords, sharedKeywordSelection} = codeContext;
23+
const projectName = getCurrentProjectName(codeKeywords, sharedKeywordSelection);
24+
25+
// Enhanced copied message
3526
const copiedMessage = projectName ? `Copied for ${projectName}` : 'Copied';
3627
```
3728

38-
### 2. Automatic DSN Comments in Code Examples
39-
40-
**New File Created:**
41-
- `src/remark-dsn-comments.js`
29+
### 2. **Enhanced DSN Tooltips and Visual Indicators**
30+
**Status: ✅ WORKING**
4231

4332
**Modified Files:**
44-
- `src/mdx.ts` (added plugin to processing pipeline)
33+
- `src/components/codeKeywords/keywordSelector.tsx`
34+
35+
**What Changed:**
36+
- **Enhanced tooltip**: Shows "Current project: [name]. Click to select a different project." instead of just project name
37+
- **Visual indicators**: Added dotted underline and small ▼ arrow for clickable DSN values when multiple projects are available
38+
- **Better UX**: Added cursor pointer and clear visual cues that DSN values are interactive
39+
40+
**Visual Changes:**
41+
- DSN values now have a subtle dotted underline when multiple projects are available
42+
- Small dropdown arrow (▼) appears next to DSN when multiple projects can be selected
43+
- Tooltip clearly explains the functionality: "Click to select a different project"
44+
45+
### 3. **Automatic DSN Comments in Code Examples**
46+
**Status: ⚠️ IMPLEMENTED BUT NEEDS TESTING**
47+
48+
**Created Files:**
49+
- `src/remark-dsn-comments.js` - New remark plugin
50+
- Modified `src/mdx.ts` - Added plugin to processing pipeline
4551

46-
**Functionality:**
47-
- Automatically adds helpful comments above DSN patterns in code blocks
48-
- Supports multiple programming languages with appropriate comment syntax:
52+
**What It Does:**
53+
- Automatically detects `___PROJECT.DSN___` patterns in code blocks
54+
- Adds language-appropriate comments above DSN lines:
4955
- JavaScript/TypeScript: `// Hover over the DSN to see your project, or click it to select a different one`
50-
- Python/Ruby/Shell: `# Hover over the DSN to see your project, or click it to select a different one`
51-
- Java/C/C++/etc.: `// Hover over the DSN to see your project, or click it to select a different one`
52-
- HTML/XML: `<!-- Hover over the DSN to see your project, or click it to select a different one -->`
53-
- CSS: `/* Hover over the DSN to see your project, or click it to select a different one */`
54-
- YAML/TOML: `# Hover over the DSN to see your project, or click it to select a different one`
55-
56-
**Processing Logic:**
57-
- Uses AST (Abstract Syntax Tree) processing via remark plugin
58-
- Detects `___PROJECT.DSN___` patterns in code blocks
59-
- Adds language-appropriate comments above DSN lines
60-
- Prevents duplicate comments if they already exist
61-
- Skips JSON files (which don't support comments)
62-
63-
## How It Works
64-
65-
### Project Context Integration
66-
The existing `CodeContext` system already provides:
67-
- Current selected project information via `sharedKeywordSelection`
68-
- Project titles formatted as "org-name / project-name"
69-
- Hover tooltips on DSN values showing project names
70-
71-
### Remark Plugin Processing
72-
The new `remarkDsnComments` plugin is integrated into the MDX processing pipeline:
73-
1. Processes all code blocks during build time
74-
2. Searches for DSN patterns using regex: `/___PROJECT\.DSN___/g`
75-
3. Determines appropriate comment syntax based on language
76-
4. Inserts comments above DSN lines
77-
5. Prevents duplicate comments
78-
79-
### Language Support
80-
The plugin supports all major programming languages used in Sentry documentation:
81-
- C-style languages (JavaScript, TypeScript, Java, C++, etc.)
82-
- Python-style languages (Python, Ruby, Shell, YAML, etc.)
83-
- Web languages (HTML, CSS, XML)
84-
- Configuration formats (TOML, YAML)
85-
86-
## User Experience Improvements
87-
88-
### Before
89-
- Users saw generic "Copied" message when copying code
90-
- No guidance about DSN hover functionality
91-
- Users had to discover project selection feature on their own
92-
93-
### After
94-
- Users see "Copied for [specific-project]" message, confirming which project the code is for
95-
- Clear instructions appear above DSN in code examples
96-
- Better discoverability of hover/click functionality for project selection
97-
98-
## Testing
99-
100-
The implementation has been added to the codebase but couldn't be fully tested due to missing production environment variables. However, the code changes are:
101-
102-
1. **Type-safe**: Using existing TypeScript interfaces and patterns
103-
2. **Backward-compatible**: Falls back gracefully when project context is unavailable
104-
3. **Performance-conscious**: Uses existing context without additional API calls
105-
4. **Consistent**: Follows existing code patterns and styling
106-
107-
## Files Modified
108-
109-
### Core Implementation
110-
- `src/remark-dsn-comments.js` (new)
111-
- `src/components/codeBlock/index.tsx`
112-
- `src/components/apiExamples/apiExamples.tsx`
113-
- `src/mdx.ts`
56+
- Python/Ruby: `# Hover over the DSN to see your project, or click it to select a different one`
57+
- And more languages...
58+
59+
**Note**: This feature processes MDX content during build time and adds helpful comments to guide users.
60+
61+
## 🎯 User Experience Improvements
62+
63+
### Before vs After
64+
65+
**Before:**
66+
- DSN values showed only project name on hover
67+
- Clipboard showed generic "Copied" message
68+
- No obvious indication that DSN values were interactive
69+
70+
**After:**
71+
-**Clear Instructions**: Tooltip says "Current project: cooking-with-code/fitfest. Click to select a different project."
72+
-**Visual Cues**: Dotted underline + dropdown arrow indicate interactivity
73+
-**Project-Specific Feedback**: Clipboard shows "Copied for cooking-with-code/fitfest"
74+
- ⚠️ **Contextual Help**: Code comments explain DSN functionality (needs testing on pages with `___PROJECT.DSN___` patterns)
75+
76+
## 🧪 How to Test
77+
78+
### Testing Enhanced Clipboard & Tooltips
79+
1. Visit any documentation page with code examples that have DSN values
80+
2. **Hover** over a DSN value → Should show enhanced tooltip with instructions
81+
3. **Click** the copy button on a code block → Should show "Copied for [project name]"
82+
4. **Visual Check**: DSN values should have subtle dotted underline and dropdown arrow when multiple projects are available
83+
84+
### Testing DSN Comments
85+
1. Look for pages with `___PROJECT.DSN___` patterns (like `develop-docs/sdk/overview.mdx`)
86+
2. Code blocks should show helpful comments above DSN lines
87+
3. Comments should be language-appropriate (// for JS, # for Python, etc.)
88+
89+
## 🔧 Technical Details
90+
91+
### Dependencies Added
92+
- Enhanced existing `CodeContext` usage
93+
- Maintained backward compatibility
94+
- No new external dependencies
95+
96+
### Files Modified
97+
```
98+
src/components/codeBlock/index.tsx # Enhanced clipboard
99+
src/components/apiExamples/apiExamples.tsx # Enhanced clipboard
100+
src/components/codeKeywords/keywordSelector.tsx # Enhanced tooltips & visuals
101+
src/remark-dsn-comments.js # New plugin (created)
102+
src/mdx.ts # Added remark plugin
103+
src/files.ts # Fixed limitFunction utility
104+
```
105+
106+
### Error Fixes
107+
- ✅ Fixed `limitFunction` import error in MDX processing
108+
- ✅ Resolved vendor chunk errors through cache clearing
109+
- ✅ Maintained existing functionality while adding enhancements
110+
111+
## 🚀 Next Steps
112+
113+
1. **Test DSN Comments**: Verify the remark plugin works on pages with `___PROJECT.DSN___` patterns
114+
2. **Visual Polish**: Consider additional styling improvements if needed
115+
3. **Documentation**: Update user-facing docs if the DSN comment feature needs explanation
114116

115-
### No Breaking Changes
116-
- All changes are additive and backward-compatible
117-
- Existing functionality remains unchanged
118-
- New features enhance user experience without disrupting current workflows
117+
---
119118

120-
## Future Considerations
119+
## Quick Verification Checklist
121120

122-
1. **Testing**: Unit tests could be added for the remark plugin
123-
2. **Customization**: Comment text could be made configurable if needed
124-
3. **Internationalization**: Comment text could be localized for different languages
125-
4. **Analytics**: Could track usage of the enhanced clipboard functionality
121+
- [ ] Enhanced tooltips show project selection instructions
122+
- [ ] Clipboard shows "Copied for [project name]"
123+
- [ ] Visual indicators appear on interactive DSN values
124+
- [ ] DSN comments appear in code examples (where applicable)
125+
- [ ] All existing functionality still works
126+
- [ ] No console errors in browser dev tools
126127

127-
The implementation successfully addresses both requirements from the GitHub issue:
128-
1. ✅ Added helpful comments above DSN in code examples
129-
2. ✅ Enhanced clipboard messages to include specific project names
128+
The implementation successfully addresses the GitHub issue requirements with a focus on making project selection more obvious and user-friendly! 🎉

src/components/codeKeywords/keywordSelector.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ export function KeywordSelector({keyword, group, index}: KeywordSelectorProps) {
7070
return <Fragment>keyword</Fragment>;
7171
}
7272

73+
// Enhanced tooltip text that makes it clear users can change projects
74+
const tooltipText = choices.length > 1
75+
? `Current project: ${currentSelection?.title}. Click to select a different project.`
76+
: `Current project: ${currentSelection?.title}`;
77+
7378
const selector = isOpen && (
7479
<PositionWrapper style={styles.popper} ref={setDropdownEl} {...attributes.popper}>
7580
<AnimatedContainer>
@@ -126,9 +131,15 @@ export function KeywordSelector({keyword, group, index}: KeywordSelectorProps) {
126131
ref={setReferenceEl}
127132
role="button"
128133
tabIndex={0}
129-
title={currentSelection?.title}
134+
title={tooltipText}
130135
onClick={() => setIsOpen(!isOpen)}
131136
onKeyDown={e => e.key === 'Enter' && setIsOpen(!isOpen)}
137+
style={{
138+
// Add subtle visual cues to indicate this is clickable
139+
cursor: 'pointer',
140+
borderBottom: choices.length > 1 ? '1px dotted currentColor' : undefined,
141+
position: 'relative'
142+
}}
132143
>
133144
<KeywordIndicatorComponent isOpen={isOpen} />
134145
<span
@@ -149,6 +160,20 @@ export function KeywordSelector({keyword, group, index}: KeywordSelectorProps) {
149160
</Keyword>
150161
</AnimatePresence>
151162
</span>
163+
{/* Add a small indicator when multiple projects are available */}
164+
{choices.length > 1 && (
165+
<span
166+
style={{
167+
fontSize: '0.75em',
168+
opacity: 0.6,
169+
marginLeft: '2px',
170+
userSelect: 'none'
171+
}}
172+
title="Click to change project"
173+
>
174+
175+
</span>
176+
)}
152177
</KeywordDropdown>
153178
{isMounted &&
154179
createPortal(<AnimatePresence>{selector}</AnimatePresence>, document.body)}

0 commit comments

Comments
 (0)